4 function hive.construct(pos)
5 local meta = minetest.get_meta(pos)
6 local inv = meta:get_inventory()
8 local formspec = [[ size[8,5;]
9 label[0.5,0;Bees are busy making honey...]
10 image[6,0;1,1;hive_bee.png]
11 image[5,0;1,1;hive_layout.png]
12 list[context;honey;5,0;1,1;]
13 list[current_player;main;0,1.35;8,4;] ]]
14 ..xbg..default.get_hotbar_bg(0,1.35)
16 meta:set_string("formspec", formspec)
17 meta:set_string("infotext", "Artificial Hive")
18 inv:set_size("honey", 1)
20 local timer = minetest.get_node_timer(pos)
21 timer:start(math.random(64, 128))
24 function hive.timer(pos)
25 local time = (minetest.get_timeofday() or 0) * 24000
26 if time < 5500 or time > 18500 then return true end
28 local inv = minetest.get_meta(pos):get_inventory()
29 local honeystack = inv:get_stack("honey", 1)
30 local honey = honeystack:get_count()
33 local minp = vector.add(pos, -radius)
34 local maxp = vector.add(pos, radius)
35 local flowers = minetest.find_nodes_in_area_under_air(minp, maxp, "group:flower")
37 if #flowers > 2 and honey < honey_max then
38 inv:add_item("honey", "xdecor:honey")
39 elseif honey == honey_max then
40 local timer = minetest.get_node_timer(pos)
41 timer:stop() return true
46 xdecor.register("hive", {
47 description = "Artificial Hive",
48 tiles = {"xdecor_hive_top.png", "xdecor_hive_top.png",
49 "xdecor_hive_side.png", "xdecor_hive_side.png",
50 "xdecor_hive_side.png", "xdecor_hive_front.png"},
51 groups = {choppy=3, oddly_breakable_by_hand=2, flammable=1},
52 on_construct = hive.construct,
53 on_timer = hive.timer,
54 can_dig = function(pos)
55 local inv = minetest.get_meta(pos):get_inventory()
56 return inv:is_empty("honey")
58 on_punch = function(_, _, puncher)
59 puncher:set_hp(puncher:get_hp() - 2)
61 allow_metadata_inventory_put = function() return 0 end,
62 on_metadata_inventory_take = function(pos, _, _, stack)
63 if stack:get_count() == honey_max then
64 local timer = minetest.get_node_timer(pos)
65 timer:start(math.random(64, 128))
72 minetest.register_craftitem("xdecor:honey", {
73 description = "Honey",
74 inventory_image = "xdecor_honey.png",
75 wield_image = "xdecor_honey.png",
76 groups = {food_honey = 1, food_sugar = 1, flammable = 2, not_in_creative_inventory=1},
77 on_use = minetest.item_eat(2)
82 minetest.register_craft({
83 output = "xdecor:hive",
85 {"group:stick", "group:stick", "group:stick"},
86 {"default:paper", "default:paper", "default:paper"},
87 {"group:stick", "group:stick", "group:stick"}