]> git.lizzy.rs Git - xdecor.git/blob - hive.lua
562d96210c677ad8b152f92d471c2b69a5c7c6ed
[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.35,0;Bees are making honey\nwith pollen around...]"..
5                 "image[-0.1,-0.2;1,1;flowers_tulip.png]"..
6                 "image[0.5,0.2;1,1;flowers_dandelion_yellow.png]"..
7                 "image[6.6,0.1;1,1;flowers_geranium.png]"..
8                 "image[7.2,-0.1;1,1;flowers_rose.png]"..
9                 "image[6,0;0.9,0.9;xdecor_bee.png]".. -- Bee texture by Charles Sanchez and Mark Weyer.
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 local function hive_dig(pos, player)
18         local meta = minetest.get_meta(pos)
19         local inv = meta:get_inventory()
20
21         if not inv:is_empty("honey") then
22                 return false
23         end
24         return true
25 end
26
27 xdecor.register("hive", {
28         description = "Artificial Hive",
29         tiles = {
30                 "xdecor_hive_top.png",
31                 "xdecor_hive_top.png",
32                 "xdecor_hive_side.png",
33                 "xdecor_hive_side.png",
34                 "xdecor_hive_side.png",
35                 "xdecor_hive_front.png",
36         },
37         groups = {snappy=3, flammable=1},
38         on_construct = hive_construct,
39         can_dig = hive_dig,
40         on_punch = function(pos, node, puncher, pointed_thing)
41                 local health = puncher:get_hp()
42                 puncher:set_hp(health-4)
43         end,
44         allow_metadata_inventory_put = function(pos, listname, index, stack, player)
45                 local meta = minetest.get_meta(pos)
46                 local inv = meta:get_inventory()
47
48                 if listname == "honey" then return 0 end
49                 return stack:get_count()
50         end,
51 })
52
53 minetest.register_abm({
54         nodenames = {"xdecor:hive"},
55         interval = 4, chance = 4,
56         action = function(pos, node, active_object_count, active_object_count_wider)
57                 local meta = minetest.get_meta(pos)
58                 local inv = meta:get_inventory()
59
60                 local radius = 16
61                 local minp = {x=pos.x-radius, y=pos.y-radius, z=pos.z-radius}
62                 local maxp = {x=pos.x+radius, y=pos.y+radius, z=pos.z+radius}
63                 local flowers = minetest.find_nodes_in_area(minp, maxp, "group:flower")
64
65                 if #flowers >= 4 then
66                         inv:add_item("honey", "xdecor:honey")
67                 end
68         end
69 })