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