summaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
authorLNJ <git@lnj.li>2017-03-26 20:53:04 +0200
committerLNJ <git@lnj.li>2017-03-26 20:53:04 +0200
commitfe0daf9bdce717db3a807b3e88d4f3b5c6913dcf (patch)
treea012b68d6b3840dec3305868d1e6b847bbeea46f /init.lua
parent4c3dd28fcd8c9cf89b8d58df53766c4d5a10cea9 (diff)
Drop all items on dug
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua20
1 files changed, 19 insertions, 1 deletions
diff --git a/init.lua b/init.lua
index 5ae8718..4ddf992 100644
--- a/init.lua
+++ b/init.lua
@@ -304,8 +304,26 @@ end
-- drop all items
local function drawer_on_dig(pos, node, player)
+ local meta = core.get_meta(pos)
+ local count = meta:get_int("count")
+ local name = meta:get_string("name")
+
+ -- remove node
core.node_dig(pos, node, player)
- return
+
+ -- drop the items
+ local stack_max = ItemStack(name):get_stack_max()
+
+ local j = math.floor(count / stack_max) + 1
+ local i = 1
+ while i <= j do
+ if not (i == j) then
+ core.add_item(pos, name .. " " .. stack_max)
+ else
+ core.add_item(pos, name .. " " .. count % stack_max)
+ end
+ i = i + 1
+ end
end
function drawers.register_drawer(name, def)