Make safer get_staticdata

This commit is contained in:
kay27 2022-03-14 06:05:17 +04:00
parent a392d59cab
commit 7ca28d8a27
17 changed files with 23 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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,

View File

@ -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 = {}

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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,

View File

@ -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,

View File

@ -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