]> git.lizzy.rs Git - xdecor.git/blob - hive.lua
3e69acef86ba737fe4fb23131d86d19ba002d560
[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;]"..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[current_name;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         if not inv:is_empty("honey") then return false end
19         return true
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 = hive.dig,
32         on_punch = function(_, _, puncher, _)
33                 local health = puncher:get_hp()
34                 puncher:set_hp(health - 4)
35         end,
36         on_rightclick = function(_, _, clicker)
37                 local health = clicker:get_hp()
38                 clicker:set_hp(health - 1)
39         end,
40         allow_metadata_inventory_put = function(_, listname, _, stack, _)
41                 if listname == "honey" then return 0 end
42                 return stack:get_count()
43         end
44 })
45
46 minetest.register_abm({
47         nodenames = {"xdecor:hive"},
48         interval = 10, chance = 5,
49         action = function(pos, _, _, _)
50                 local inv = minetest.get_meta(pos):get_inventory()
51                 local honeystack = inv:get_stack("honey", 1)
52                 local honey = honeystack:get_count()
53
54                 local radius = 4
55                 local minp = vector.add(pos, -radius)
56                 local maxp = vector.add(pos, radius)
57                 local flowers = minetest.find_nodes_in_area(minp, maxp, "group:flower")
58
59                 if #flowers >= 2 and honey < 10 then
60                         inv:add_item("honey", "xdecor:honey") end
61         end
62 })