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