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
8 local formspec = "size[8,5;]"..xbg..
9 "label[1.35,0;Bees are making honey\nwith pollen around...]"..
10 "image[0.2,-0.1;1,1;flowers_dandelion_white.png]"..
11 "image[7,0.1;1,1;flowers_viola.png]"..
12 "image[6,0;1,1;xdecor_bee.png]"..
13 "list[current_name;honey;5,0;1,1;]"..
14 "list[current_player;main;0,1.35;8,4;]"
16 meta:set_string("formspec", formspec)
17 meta:set_string("infotext", "Artificial Hive")
18 inv:set_size("honey", 1)
21 function hive.dig(pos, _)
22 local inv = minetest.get_meta(pos):get_inventory()
23 if not inv:is_empty("honey") then return false end
27 xdecor.register("hive", {
28 description = "Artificial Hive",
30 "xdecor_hive_top.png", "xdecor_hive_top.png",
31 "xdecor_hive_side.png", "xdecor_hive_side.png",
32 "xdecor_hive_side.png", "xdecor_hive_front.png"
34 groups = {snappy=3, flammable=1},
35 on_construct = hive.construct,
37 on_punch = function(_, _, puncher, _)
38 local health = puncher:get_hp()
39 puncher:set_hp(health - 4)
41 allow_metadata_inventory_put = function(_, listname, _, stack, _)
42 if listname == "honey" then return 0 end
43 return stack:get_count()
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()
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")
60 if #flowers >= 4 and honey < 16 then
61 inv:add_item("honey", "xdecor:honey") end