diff --git a/handlers/registration.lua b/handlers/registration.lua index 218a9ee..544f974 100644 --- a/handlers/registration.lua +++ b/handlers/registration.lua @@ -44,6 +44,26 @@ local function get_formspec_by_size(size) return formspec or default_inventory_formspecs 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) def.drawtype = def.drawtype or (def.node_box and "nodebox") def.paramtype = def.paramtype or "light" @@ -75,8 +95,8 @@ function xdecor.register(name, def) inv:set_size("main", size) meta:set_string("formspec", inventory.formspec or get_formspec_by_size(size)) end - - def.can_dig = def.can_dig or default_can_dig + def.after_dig_node = def.after_dig_node or drop_chest_stuff() + --def.can_dig = def.can_dig or default_can_dig elseif infotext and not def.on_construct then def.on_construct = function(pos) local meta = minetest.get_meta(pos)