]> git.lizzy.rs Git - xdecor.git/blob - hive.lua
Avoid some formspec concatenations
[xdecor.git] / hive.lua
1 local hive = {}
2
3 function hive.construct(pos)
4         local meta = minetest.get_meta(pos)
5         local inv = meta:get_inventory()
6         local xbg = default.gui_bg..default.gui_bg_img..default.gui_slots..default.get_hotbar_bg(0,1.35)
7
8         local formspec = [[ size[8,5;]
9                         label[1.35,0;Bees are making honey]
10                         label[1.35,0.5;with pollen around...]
11                         image[6,0;1,1;hive_bee.png]
12                         image[5,0;1,1;hive_layout.png]
13                         list[context;honey;5,0;1,1;]
14                         list[current_player;main;0,1.35;8,4;] ]]
15
16         meta:set_string("formspec", formspec..xbg)
17         meta:set_string("infotext", "Artificial Hive")
18         inv:set_size("honey", 1)
19 end
20
21 function hive.dig(pos, _)
22         local inv = minetest.get_meta(pos):get_inventory()
23         return inv:is_empty("honey")
24 end
25
26 xdecor.register("hive", {
27         description = "Artificial Hive",
28         tiles = {
29                 "xdecor_hive_top.png", "xdecor_hive_top.png",
30                 "xdecor_hive_side.png", "xdecor_hive_side.png",
31                 "xdecor_hive_side.png", "xdecor_hive_front.png"
32         },
33         groups = {choppy=3, oddly_breakable_by_hand=2, flammable=1},
34         on_construct = hive.construct,
35         can_dig = hive.dig,
36         on_punch = function(_, _, puncher, _)
37                 local health = puncher:get_hp()
38                 puncher:set_hp(health - 4)
39         end,
40         on_rightclick = function(_, _, clicker)
41                 local health = clicker:get_hp()
42                 clicker:set_hp(health - 1)
43         end,
44         allow_metadata_inventory_put = function() return 0 end
45 })
46
47 minetest.register_abm({
48         nodenames = {"xdecor:hive"},
49         interval = 10, chance = 5,
50         action = function(pos, _, _, _)
51                 local inv = minetest.get_meta(pos):get_inventory()
52                 local honeystack = inv:get_stack("honey", 1)
53                 local honey = honeystack:get_count()
54
55                 local radius = 4
56                 local minp = vector.add(pos, -radius)
57                 local maxp = vector.add(pos, radius)
58                 local flowers = minetest.find_nodes_in_area(minp, maxp, "group:flower")
59
60                 if #flowers >= 2 and honey < 12 then
61                         inv:add_item("honey", "xdecor:honey")
62                 end
63         end
64 })