diff options
author | SmallJoker <SmallJoker@users.noreply.github.com> | 2018-07-09 23:33:21 +0200 |
---|---|---|
committer | Loïc Blot <nerzhul@users.noreply.github.com> | 2018-07-09 23:33:21 +0200 |
commit | 0cf36454d6403982ccc35a92f81c693c97b67cb9 (patch) | |
tree | a415aa1681b82a3db262bfee12171015ab472c7d /builtin/game | |
parent | 498078bfa09c19d42390161bc1b8b8c03b7b2956 (diff) | |
download | minetest-0cf36454d6403982ccc35a92f81c693c97b67cb9.tar.gz minetest-0cf36454d6403982ccc35a92f81c693c97b67cb9.tar.bz2 minetest-0cf36454d6403982ccc35a92f81c693c97b67cb9.zip |
core.spawn_falling_node: Keep metadata (#7476)
Diffstat (limited to 'builtin/game')
-rw-r--r-- | builtin/game/falling.lua | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/builtin/game/falling.lua b/builtin/game/falling.lua index 4ebe39f5f..4806a7427 100644 --- a/builtin/game/falling.lua +++ b/builtin/game/falling.lua @@ -132,11 +132,18 @@ core.register_entity(":__builtin:falling_node", { end }) -local function spawn_falling_node(p, node, meta) - local obj = core.add_entity(p, "__builtin:falling_node") - if obj then - obj:get_luaentity():set_node(node, meta) +local function convert_to_falling_node(pos, node) + local obj = core.add_entity(pos, "__builtin:falling_node") + if not obj then + return false end + node.level = core.get_node_level(pos) + local meta = core.get_meta(pos) + local metatable = meta and meta:to_table() or {} + + obj:get_luaentity():set_node(node, metatable) + core.remove_node(pos) + return true end function core.spawn_falling_node(pos) @@ -144,13 +151,7 @@ function core.spawn_falling_node(pos) if node.name == "air" or node.name == "ignore" then return false end - local obj = core.add_entity(pos, "__builtin:falling_node") - if obj then - obj:get_luaentity():set_node(node) - core.remove_node(pos) - return true - end - return false + return convert_to_falling_node(pos, node) end local function drop_attached_node(p) @@ -223,14 +224,7 @@ function core.check_single_for_falling(p) core.get_node_max_level(p_bottom))) and (not d_bottom.walkable or d_bottom.buildable_to) then - n.level = core.get_node_level(p) - local meta = core.get_meta(p) - local metatable = {} - if meta ~= nil then - metatable = meta:to_table() - end - core.remove_node(p) - spawn_falling_node(p, n, metatable) + convert_to_falling_node(p, n) return true end end |