1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-23 12:45:43 +02:00

Add callback to preserve node metadata as item metadata

This commit is contained in:
ashtrayoz
2017-11-09 23:29:04 +11:00
committed by paramat
parent 6e5109fd46
commit abd8a30c05
3 changed files with 36 additions and 1 deletions

View File

@@ -579,6 +579,20 @@ function core.node_dig(pos, node, digger)
digger:set_wielded_item(wielded)
end
-- Check to see if metadata should be preserved.
if def and def.preserve_metadata then
local oldmeta = core.get_meta(pos):to_table().fields
-- Copy pos and node because the callback can modify them.
local pos_copy = {x=pos.x, y=pos.y, z=pos.z}
local node_copy = {name=node.name, param1=node.param1, param2=node.param2}
local drop_stacks = {}
for k, v in pairs(drops) do
drop_stacks[k] = ItemStack(v)
end
drops = drop_stacks
def.preserve_metadata(pos_copy, node_copy, oldmeta, drops)
end
-- Handle drops
core.handle_node_drops(pos, drops, digger)