add staticdata clean function, update api.txt
This commit is contained in:
parent
407b2e7b56
commit
6b9331064c
95
api.lua
95
api.lua
@ -25,7 +25,7 @@ local use_cmi = minetest.global_exists("cmi")
|
|||||||
|
|
||||||
mobs = {
|
mobs = {
|
||||||
mod = "redo",
|
mod = "redo",
|
||||||
version = "20230331",
|
version = "20230403",
|
||||||
intllib = S,
|
intllib = S,
|
||||||
invis = minetest.global_exists("invisibility") and invisibility or {}
|
invis = minetest.global_exists("invisibility") and invisibility or {}
|
||||||
}
|
}
|
||||||
@ -3072,6 +3072,28 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- helper function to clean mob staticdata
|
||||||
|
local function clean_staticdata(self)
|
||||||
|
|
||||||
|
local tmp, t = {}
|
||||||
|
|
||||||
|
for _,stat in pairs(self) do
|
||||||
|
|
||||||
|
t = type(stat)
|
||||||
|
|
||||||
|
if t ~= "function"
|
||||||
|
and t ~= "nil"
|
||||||
|
and t ~= "userdata"
|
||||||
|
and _ ~= "object"
|
||||||
|
and _ ~= "_cmi_components" then
|
||||||
|
tmp[_] = self[_]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return tmp
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- get entity staticdata
|
-- get entity staticdata
|
||||||
function mob_class:mob_staticdata()
|
function mob_class:mob_staticdata()
|
||||||
|
|
||||||
@ -3111,22 +3133,7 @@ function mob_class:mob_staticdata()
|
|||||||
self.serialized_cmi_components = cmi.serialize_components(self._cmi_components)
|
self.serialized_cmi_components = cmi.serialize_components(self._cmi_components)
|
||||||
end
|
end
|
||||||
|
|
||||||
local tmp, t = {}
|
return minetest.serialize(clean_staticdata(self))
|
||||||
|
|
||||||
for _,stat in pairs(self) do
|
|
||||||
|
|
||||||
t = type(stat)
|
|
||||||
|
|
||||||
if t ~= "function"
|
|
||||||
and t ~= "nil"
|
|
||||||
and t ~= "userdata"
|
|
||||||
and _ ~= "object"
|
|
||||||
and _ ~= "_cmi_components" then
|
|
||||||
tmp[_] = self[_]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return minetest.serialize(tmp)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -3155,7 +3162,7 @@ function mob_class:mob_activate(staticdata, def, dtime)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- load entity variables
|
-- load entity variables from staticdata into self.
|
||||||
local tmp = minetest.deserialize(staticdata)
|
local tmp = minetest.deserialize(staticdata)
|
||||||
|
|
||||||
if tmp then
|
if tmp then
|
||||||
@ -4404,22 +4411,7 @@ function mobs:force_capture(self, clicker)
|
|||||||
-- add special mob egg with all mob information
|
-- add special mob egg with all mob information
|
||||||
local new_stack = ItemStack(self.name .. "_set")
|
local new_stack = ItemStack(self.name .. "_set")
|
||||||
|
|
||||||
local tmp, t = {}
|
local data_str = minetest.serialize(clean_staticdata(self))
|
||||||
|
|
||||||
for _,stat in pairs(self) do
|
|
||||||
|
|
||||||
t = type(stat)
|
|
||||||
|
|
||||||
if t ~= "function"
|
|
||||||
and t ~= "nil"
|
|
||||||
and t ~= "userdata"
|
|
||||||
and _ ~= "object"
|
|
||||||
and _ ~= "_cmi_components" then
|
|
||||||
tmp[_] = self[_]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local data_str = minetest.serialize(tmp)
|
|
||||||
|
|
||||||
new_stack:set_metadata(data_str)
|
new_stack:set_metadata(data_str)
|
||||||
|
|
||||||
@ -4518,22 +4510,7 @@ function mobs:capture_mob(
|
|||||||
|
|
||||||
new_stack = ItemStack(mobname .. "_set")
|
new_stack = ItemStack(mobname .. "_set")
|
||||||
|
|
||||||
local tmp, t = {}
|
local data_str = minetest.serialize(clean_staticdata(self))
|
||||||
|
|
||||||
for _,stat in pairs(self) do
|
|
||||||
|
|
||||||
t = type(stat)
|
|
||||||
|
|
||||||
if t ~= "function"
|
|
||||||
and t ~= "nil"
|
|
||||||
and t ~= "userdata"
|
|
||||||
and _ ~= "object"
|
|
||||||
and _ ~= "_cmi_components" then
|
|
||||||
tmp[_] = self[_]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local data_str = minetest.serialize(tmp)
|
|
||||||
|
|
||||||
new_stack:set_metadata(data_str)
|
new_stack:set_metadata(data_str)
|
||||||
end
|
end
|
||||||
@ -4811,23 +4788,7 @@ function mobs:alias_mob(old_name, new_name)
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
get_staticdata = function(self)
|
get_staticdata = function(self)
|
||||||
|
return minetest.serialize(clean_staticdata(self))
|
||||||
local tmp, t = {}
|
|
||||||
|
|
||||||
for _,stat in pairs(self) do
|
|
||||||
|
|
||||||
t = type(stat)
|
|
||||||
|
|
||||||
if t ~= "function"
|
|
||||||
and t ~= "nil"
|
|
||||||
and t ~= "userdata"
|
|
||||||
and _ ~= "object"
|
|
||||||
and _ ~= "_cmi_components" then
|
|
||||||
tmp[_] = self[_]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return minetest.serialize(tmp)
|
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
6
api.txt
6
api.txt
@ -351,6 +351,8 @@ for each mob.
|
|||||||
'self.child_texture' contains mob child texture when growing up
|
'self.child_texture' contains mob child texture when growing up
|
||||||
'self.base_texture' contains current skin texture which was randomly
|
'self.base_texture' contains current skin texture which was randomly
|
||||||
selected from textures list
|
selected from textures list
|
||||||
|
'self.texture_mods' contains a list of textures to overlay above the mobs
|
||||||
|
base texture (used for horse saddle)
|
||||||
'self.gotten' this is used for obtaining milk from cow and wool from
|
'self.gotten' this is used for obtaining milk from cow and wool from
|
||||||
sheep
|
sheep
|
||||||
'self.horny' when animal fed enough it is set to true and animal can
|
'self.horny' when animal fed enough it is set to true and animal can
|
||||||
@ -364,6 +366,10 @@ for each mob.
|
|||||||
'self.order' set to "follow" or "stand" so that npc will follow owner
|
'self.order' set to "follow" or "stand" so that npc will follow owner
|
||||||
or stand it's ground
|
or stand it's ground
|
||||||
'self.nametag' contains the name of the mob which it can show above
|
'self.nametag' contains the name of the mob which it can show above
|
||||||
|
'self.pause_timer' used to stop mob thinking when punched so that knockback
|
||||||
|
can take effect.
|
||||||
|
'self.disable_falling' currently used on spider mob when climbing walls, stops
|
||||||
|
the mob from experiencing gravity when true.
|
||||||
'self.state' Current mob state.
|
'self.state' Current mob state.
|
||||||
"stand": no movement (except turning around)
|
"stand": no movement (except turning around)
|
||||||
"walk": walk or move around aimlessly
|
"walk": walk or move around aimlessly
|
||||||
|
Loading…
x
Reference in New Issue
Block a user