1 --[[ local default_can_dig = function(pos, _)
2 local meta = minetest.get_meta(pos)
3 local inv = meta:get_inventory()
5 return inv:is_empty("main")
8 xbg = default.gui_bg..default.gui_bg_img..default.gui_slots
9 local default_inventory_size = 32
11 local default_inventory_formspecs = {
13 list[context;main;0,0;8,1;]
14 list[current_player;main;0,2;8,4;]
15 listring[current_player;main]
16 listring[context;main] ]]
17 ..default.get_hotbar_bg(0,2),
20 list[context;main;0,0;8,2;]
21 list[current_player;main;0,3;8,4;]
22 listring[current_player;main]
23 listring[context;main] ]]
24 ..default.get_hotbar_bg(0,3),
27 list[context;main;0,0;8,3;]
28 list[current_player;main;0,4;8,4;]
29 listring[current_player;main]
30 listring[context;main]" ]]
31 ..default.get_hotbar_bg(0,4),
34 list[context;main;0,0.3;8,4;]
35 list[current_player;main;0,4.85;8,1;]
36 list[current_player;main;0,6.08;8,3;8]
37 listring[current_player;main]
38 listring[context;main] ]]
39 ..default.get_hotbar_bg(0,4.85)
42 local function get_formspec_by_size(size)
43 local formspec = default_inventory_formspecs[tostring(size)]
44 return formspec or default_inventory_formspecs
47 local function drop_stuff()
48 return function(pos, oldnode, oldmetadata, digger)
49 local meta = minetest.get_meta(pos)
50 meta:from_table(oldmetadata)
51 local inv = meta:get_inventory()
53 for i=1, inv:get_size("main") do
54 local stack = inv:get_stack("main", i)
55 if not stack:is_empty() then
57 x = pos.x + math.random(0,5) / 5 - 0.5,
59 z = pos.z + math.random(0,5) / 5 - 0.5
61 minetest.add_item(p, stack)
67 function xdecor.register(name, def)
68 def.drawtype = def.drawtype or (def.node_box and "nodebox")
69 def.paramtype = def.paramtype or "light"
70 def.sounds = def.sounds or default.node_sound_defaults()
72 if not (def.drawtype == "normal" or def.drawtype == "signlike" or
73 def.drawtype == "plantlike" or def.drawtype == "glasslike_framed" or
74 def.drawtype == "glasslike_framed_optional") then
75 def.paramtype2 = def.paramtype2 or "facedir"
78 if def.drawtype == "plantlike" or def.drawtype == "torchlike" or
79 def.drawtype == "signlike" or def.drawtype == "fencelike" then
80 def.sunlight_propagates = true
83 local infotext = def.infotext
84 local inventory = def.inventory
88 def.on_construct = def.on_construct or function(pos)
89 local meta = minetest.get_meta(pos)
91 meta:set_string("infotext", infotext)
94 local size = inventory.size or default_inventory_size
95 local inv = meta:get_inventory()
96 inv:set_size("main", size)
97 meta:set_string("formspec", (inventory.formspec or get_formspec_by_size(size))..xbg)
99 def.after_dig_node = def.after_dig_node or drop_stuff()
100 --def.can_dig = def.can_dig or default_can_dig
101 elseif infotext and not def.on_construct then
102 def.on_construct = function(pos)
103 local meta = minetest.get_meta(pos)
104 meta:set_string("infotext", infotext)
108 minetest.register_node("xdecor:"..name, def)