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