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