aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorashtrayoz <33517241+ashtrayoz@users.noreply.github.com>2017-11-09 23:29:04 +1100
committerparamat <mat.gregory@virginmedia.com>2017-12-14 20:54:04 +0000
commitabd8a30c0542c75622d8e2b46e3529c9e798d227 (patch)
tree0ced90b52d2ad08cfef8935ecf0d73192483134a /builtin
parent6e5109fd46fa93335aa8bc7d5e3edb738980241f (diff)
downloadminetest-abd8a30c0542c75622d8e2b46e3529c9e798d227.tar.gz
minetest-abd8a30c0542c75622d8e2b46e3529c9e798d227.tar.bz2
minetest-abd8a30c0542c75622d8e2b46e3529c9e798d227.zip
Add callback to preserve node metadata as item metadata
Diffstat (limited to 'builtin')
-rw-r--r--builtin/game/falling.lua16
-rw-r--r--builtin/game/item.lua14
2 files changed, 29 insertions, 1 deletions
diff --git a/builtin/game/falling.lua b/builtin/game/falling.lua
index 1876cf2a8..436350fa1 100644
--- a/builtin/game/falling.lua
+++ b/builtin/game/falling.lua
@@ -150,8 +150,22 @@ end
local function drop_attached_node(p)
local n = core.get_node(p)
+ local drops = core.get_node_drops(n, "")
+ local def = core.registered_items[n.name]
+ if def and def.preserve_metadata then
+ local oldmeta = core.get_meta(p):to_table().fields
+ -- Copy pos and node because the callback can modify them.
+ local pos_copy = {x=p.x, y=p.y, z=p.z}
+ local node_copy = {name=n.name, param1=n.param1, param2=n.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
core.remove_node(p)
- for _, item in pairs(core.get_node_drops(n, "")) do
+ for _, item in pairs(drops) do
local pos = {
x = p.x + math.random()/2 - 0.25,
y = p.y + math.random()/2 - 0.25,
diff --git a/builtin/game/item.lua b/builtin/game/item.lua
index 5e5696ff5..a7176711f 100644
--- a/builtin/game/item.lua
+++ b/builtin/game/item.lua
@@ -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)