Save metainfo for falling nodes

master
Vladislav Tsendrovskii 2017-02-17 04:48:48 +03:00 committed by Auke Kok
parent ff80696947
commit 7a4878cd0b
1 changed files with 25 additions and 8 deletions

View File

@ -18,9 +18,11 @@ core.register_entity(":__builtin:falling_node", {
}, },
node = {}, node = {},
meta = {},
set_node = function(self, node) set_node = function(self, node, meta)
self.node = node self.node = node
self.meta = meta or {}
self.object:set_properties({ self.object:set_properties({
is_visible = true, is_visible = true,
textures = {node.name}, textures = {node.name},
@ -28,15 +30,21 @@ core.register_entity(":__builtin:falling_node", {
end, end,
get_staticdata = function(self) get_staticdata = function(self)
return core.serialize(self.node) local ds = {
node = self.node,
meta = self.meta,
}
return core.serialize(ds)
end, end,
on_activate = function(self, staticdata) on_activate = function(self, staticdata)
self.object:set_armor_groups({immortal = 1}) self.object:set_armor_groups({immortal = 1})
local node = core.deserialize(staticdata) local ds = core.deserialize(staticdata)
if node then if ds and ds.node then
self:set_node(node) self:set_node(ds.node, ds.meta)
elseif ds then
self:set_node(ds)
elseif staticdata ~= "" then elseif staticdata ~= "" then
self:set_node({name = staticdata}) self:set_node({name = staticdata})
end end
@ -98,6 +106,10 @@ core.register_entity(":__builtin:falling_node", {
-- Create node and remove entity -- Create node and remove entity
if core.registered_nodes[self.node.name] then if core.registered_nodes[self.node.name] then
core.add_node(np, self.node) core.add_node(np, self.node)
if self.meta then
local meta = core.get_meta(np)
meta:from_table(self.meta)
end
end end
self.object:remove() self.object:remove()
core.check_for_falling(np) core.check_for_falling(np)
@ -111,10 +123,10 @@ core.register_entity(":__builtin:falling_node", {
end end
}) })
local function spawn_falling_node(p, node) local function spawn_falling_node(p, node, meta)
local obj = core.add_entity(p, "__builtin:falling_node") local obj = core.add_entity(p, "__builtin:falling_node")
if obj then if obj then
obj:get_luaentity():set_node(node) obj:get_luaentity():set_node(node, meta)
end end
end end
@ -189,8 +201,13 @@ function core.check_single_for_falling(p)
(not d_bottom.walkable or d_bottom.buildable_to) then (not d_bottom.walkable or d_bottom.buildable_to) then
n.level = core.get_node_level(p) 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) core.remove_node(p)
spawn_falling_node(p, n) spawn_falling_node(p, n, metatable)
return true return true
end end
end end