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