Drop items of digged storage nodes
This commit is contained in:
parent
1ea9ed745e
commit
51922dfe74
@ -44,6 +44,26 @@ local function get_formspec_by_size(size)
|
|||||||
return formspec or default_inventory_formspecs
|
return formspec or default_inventory_formspecs
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function drop_chest_stuff() -- thanks to LNJplus for this function
|
||||||
|
local random = math.random
|
||||||
|
return function(pos, oldnode, oldmetadata, digger)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:from_table(oldmetadata)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
|
||||||
|
for i=1, inv:get_size("main") do
|
||||||
|
local stack = inv:get_stack("main", i)
|
||||||
|
if not stack:is_empty() then
|
||||||
|
local p = {
|
||||||
|
x = pos.x + random(0,5) / 5 - 0.5,
|
||||||
|
y = pos.y,
|
||||||
|
z = pos.z + random(0,5) / 5 - 0.5}
|
||||||
|
minetest.add_item(p, stack)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function xdecor.register(name, def)
|
function xdecor.register(name, def)
|
||||||
def.drawtype = def.drawtype or (def.node_box and "nodebox")
|
def.drawtype = def.drawtype or (def.node_box and "nodebox")
|
||||||
def.paramtype = def.paramtype or "light"
|
def.paramtype = def.paramtype or "light"
|
||||||
@ -75,8 +95,8 @@ function xdecor.register(name, def)
|
|||||||
inv:set_size("main", size)
|
inv:set_size("main", size)
|
||||||
meta:set_string("formspec", inventory.formspec or get_formspec_by_size(size))
|
meta:set_string("formspec", inventory.formspec or get_formspec_by_size(size))
|
||||||
end
|
end
|
||||||
|
def.after_dig_node = def.after_dig_node or drop_chest_stuff()
|
||||||
def.can_dig = def.can_dig or default_can_dig
|
--def.can_dig = def.can_dig or default_can_dig
|
||||||
elseif infotext and not def.on_construct then
|
elseif infotext and not def.on_construct then
|
||||||
def.on_construct = function(pos)
|
def.on_construct = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
Loading…
Reference in New Issue
Block a user