forked from MineClone5/MineClone5
Make safer get_staticdata
This commit is contained in:
parent
a392d59cab
commit
7ca28d8a27
|
@ -54,10 +54,11 @@ minetest.register_entity("extra_mobs:glow_item_frame_item",{
|
|||
end
|
||||
end,
|
||||
get_staticdata = function(self)
|
||||
if not self then return end
|
||||
if self._nodename ~= nil and self._texture ~= nil then
|
||||
local ret = self._nodename .. ';' .. self._texture
|
||||
if self._scale ~= nil then
|
||||
ret = ret .. ';' .. self._scale
|
||||
ret = ret .. ';' .. tostring(self._scale)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
|
|
@ -175,10 +175,13 @@ function boat.on_activate(self, staticdata, dtime_s)
|
|||
end
|
||||
|
||||
function boat.get_staticdata(self)
|
||||
if not self then return end
|
||||
local object = self.object
|
||||
local object_properties = object and object.get_properties and object:get_properties()
|
||||
return minetest.serialize({
|
||||
v = self._v,
|
||||
itemstring = self._itemstring,
|
||||
textures = self.object:get_properties().textures
|
||||
textures = object_properties and object_properties.textures
|
||||
})
|
||||
end
|
||||
|
||||
|
|
|
@ -89,6 +89,7 @@ minetest.register_entity(":__builtin:falling_node", {
|
|||
})
|
||||
end,
|
||||
get_staticdata = function(self)
|
||||
if not self then return end
|
||||
local meta = self.meta
|
||||
-- Workaround: Save inventory seperately from metadata.
|
||||
-- Because Minetest crashes when a node with inventory gets deactivated
|
||||
|
|
|
@ -486,6 +486,7 @@ minetest.register_entity(":__builtin:item", {
|
|||
end,
|
||||
|
||||
get_staticdata = function(self)
|
||||
if not self then return end
|
||||
local data = minetest.serialize({
|
||||
itemstring = self.itemstring,
|
||||
always_collect = self.always_collect,
|
||||
|
|
|
@ -503,6 +503,7 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o
|
|||
end
|
||||
|
||||
function cart:get_staticdata()
|
||||
if not self then return end
|
||||
return minetest.serialize({_railtype = self._railtype})
|
||||
end
|
||||
|
||||
|
|
|
@ -425,7 +425,9 @@ function mobs:register_mob(name, def)
|
|||
end,
|
||||
|
||||
get_staticdata = function(self)
|
||||
if self and mobs then
|
||||
return mobs.mob_staticdata(self)
|
||||
end
|
||||
end,
|
||||
|
||||
--harmed_by_heal = def.harmed_by_heal,
|
||||
|
|
|
@ -42,7 +42,7 @@ mobs.mob_staticdata = function(self)
|
|||
self.following = nil
|
||||
|
||||
if use_cmi then
|
||||
self.serialized_cmi_components = cmi.serialize_components(self._cmi_components)
|
||||
self.serialized_cmi_components = cmi and cmi.serialize_components(self._cmi_components)
|
||||
end
|
||||
|
||||
local tmp = {}
|
||||
|
|
|
@ -160,6 +160,7 @@ minetest.register_entity("mcl_paintings:painting", {
|
|||
set_entity(self.object)
|
||||
end,
|
||||
get_staticdata = function(self)
|
||||
if not self then return end
|
||||
local data = {
|
||||
_facing = self._facing,
|
||||
_pos = self._pos,
|
||||
|
|
|
@ -618,6 +618,7 @@ local entity_standing = {
|
|||
-- pattern: name of pattern (see list above)
|
||||
|
||||
get_staticdata = function(self)
|
||||
if not self then return end
|
||||
local out = { _base_color = self._base_color, _layers = self._layers, _name = self._name }
|
||||
return minetest.serialize(out)
|
||||
end,
|
||||
|
|
|
@ -441,6 +441,7 @@ function ARROW_ENTITY.on_punch(self)
|
|||
end
|
||||
|
||||
function ARROW_ENTITY.get_staticdata(self)
|
||||
if not self then return end
|
||||
local out = {
|
||||
lastpos = self._lastpos,
|
||||
startpos = self._startpos,
|
||||
|
|
|
@ -630,6 +630,7 @@ function ARROW_ENTITY.on_punch(self)
|
|||
end
|
||||
|
||||
function ARROW_ENTITY.get_staticdata(self)
|
||||
if not self then return end
|
||||
local out = {
|
||||
lastpos = self._lastpos,
|
||||
startpos = self._startpos,
|
||||
|
|
|
@ -10,7 +10,7 @@ minetest.register_entity("mcl_end:ender_eye", {
|
|||
|
||||
-- Save and restore age
|
||||
get_staticdata = function(self)
|
||||
return tostring(self._age) or "0"
|
||||
return tostring(self and self._age) or "0"
|
||||
end,
|
||||
on_activate = function(self, staticdata, dtime_s)
|
||||
local age = tonumber(staticdata)
|
||||
|
|
|
@ -33,6 +33,7 @@ minetest.register_entity("mcl_itemframes:item",{
|
|||
end
|
||||
end,
|
||||
get_staticdata = function(self)
|
||||
if not self then return end
|
||||
if self._nodename and self._texture then
|
||||
local ret = self._nodename .. ";" .. self._texture
|
||||
if self._scale then
|
||||
|
|
|
@ -352,7 +352,7 @@ local doll_def = {
|
|||
}
|
||||
|
||||
doll_def.get_staticdata = function(self)
|
||||
return self._mob
|
||||
return self and self._mob
|
||||
end
|
||||
|
||||
doll_def.on_activate = function(self, staticdata, dtime_s)
|
||||
|
|
|
@ -391,6 +391,7 @@ function mcl_potions.register_arrow(name, desc, color, def)
|
|||
end
|
||||
|
||||
function ARROW_ENTITY.get_staticdata(self)
|
||||
if not self then return end
|
||||
local out = {
|
||||
lastpos = self._lastpos,
|
||||
startpos = self._startpos,
|
||||
|
|
|
@ -537,6 +537,7 @@ minetest.register_entity("mcl_signs:text", {
|
|||
self.object:set_armor_groups({ immortal = 1 })
|
||||
end,
|
||||
get_staticdata = function(self)
|
||||
if not self then return end
|
||||
local out = { _signnodename = self._signnodename }
|
||||
return minetest.serialize(out)
|
||||
end,
|
||||
|
|
|
@ -57,6 +57,7 @@ end
|
|||
|
||||
-- Staticdata handling because objects may want to be reloaded
|
||||
function mcl_throwing.get_staticdata(self)
|
||||
if not self then return end
|
||||
local thrower
|
||||
-- Only save thrower if it's a player name
|
||||
if type(self._thrower) == "string" then
|
||||
|
|
Loading…
Reference in New Issue