Save staticdata in throwables

This commit is contained in:
Wuzzy 2017-01-26 18:59:57 +01:00
parent a7ed0520b5
commit 460f7a1962
1 changed files with 32 additions and 3 deletions

View File

@ -24,28 +24,57 @@ local throw_function = function (entity_name, velocity)
return func return func
end end
-- Staticdata handling because objects may want to be reloaded
local get_staticdata = function(self)
local data = {
_lastpos = self._lastpos,
_thrower = self._thrower,
}
return minetest.serialize(data)
end
local on_activate = function(self, staticdata, dtime_s)
local data = minetest.deserialize(staticdata)
if data then
self._lastpos = data._lastpos
self._thrower = data._thrower
end
end
-- The snowball entity -- The snowball entity
local snowball_ENTITY={ local snowball_ENTITY={
physical = false, physical = false,
timer=0, timer=0,
textures = {"mcl_throwing_snowball.png"}, textures = {"mcl_throwing_snowball.png"},
_lastpos={},
collisionbox = {0,0,0,0,0,0}, collisionbox = {0,0,0,0,0,0},
get_staticdata = get_staticdata,
on_activate = on_activate,
_lastpos={},
} }
local egg_ENTITY={ local egg_ENTITY={
physical = false, physical = false,
timer=0, timer=0,
textures = {"mcl_throwing_egg.png"}, textures = {"mcl_throwing_egg.png"},
_lastpos={},
collisionbox = {0,0,0,0,0,0}, collisionbox = {0,0,0,0,0,0},
get_staticdata = get_staticdata,
on_activate = on_activate,
_lastpos={},
} }
-- Ender pearl entity -- Ender pearl entity
local pearl_ENTITY={ local pearl_ENTITY={
physical = false, physical = false,
timer=0, timer=0,
textures = {"mcl_throwing_ender_pearl.png"}, textures = {"mcl_throwing_ender_pearl.png"},
_lastpos={},
collisionbox = {0,0,0,0,0,0}, collisionbox = {0,0,0,0,0,0},
get_staticdata = get_staticdata,
on_activate = on_activate,
_lastpos={},
_thrower = nil, -- Player ObjectRef of the player who threw the ender pearl _thrower = nil, -- Player ObjectRef of the player who threw the ender pearl
} }