]> git.lizzy.rs Git - xdecor.git/blob - hive.lua
5ff11398e019a488b10259bf7729b8a0ce8b8b3a
[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
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                         ..xbg..default.get_hotbar_bg(0,1.35)
16
17         meta:set_string("formspec", formspec)
18         meta:set_string("infotext", "Artificial Hive")
19         inv:set_size("honey", 1)
20 end
21
22 xdecor.register("hive", {
23         description = "Artificial Hive",
24         tiles = {
25                 "xdecor_hive_top.png", "xdecor_hive_top.png",
26                 "xdecor_hive_side.png", "xdecor_hive_side.png",
27                 "xdecor_hive_side.png", "xdecor_hive_front.png"
28         },
29         groups = {choppy=3, oddly_breakable_by_hand=2, flammable=1},
30         on_construct = hive.construct,
31         can_dig = function(pos, _)
32                 return minetest.get_meta(pos):get_inventory():is_empty("honey")
33         end,
34         on_punch = function(_, _, puncher)
35                 puncher:set_hp(puncher:get_hp()-4)
36         end,
37         allow_metadata_inventory_put = function() return 0 end
38 })
39
40 minetest.register_abm({
41         nodenames = {"xdecor:hive"},
42         interval = 20, chance = 10,
43         action = function(pos, _, _, _)
44                 local inv = minetest.get_meta(pos):get_inventory()
45                 local honeystack = inv:get_stack("honey", 1)
46                 local honey = honeystack:get_count()
47
48                 local radius = 4
49                 local minp = vector.add(pos, -radius)
50                 local maxp = vector.add(pos, radius)
51                 local flowers = minetest.find_nodes_in_area(minp, maxp, "group:flower")
52
53                 if #flowers >= 2 and honey < 16 then
54                         inv:add_item("honey", "xdecor:honey")
55                 end
56         end
57 })