Effects persist on loads for mobs too
parent
a808d648c1
commit
6655722f0b
|
@ -96,18 +96,20 @@ function mob_class:get_staticdata()
|
||||||
|
|
||||||
local tmp = {}
|
local tmp = {}
|
||||||
|
|
||||||
for _,stat in pairs(self) do
|
for tag, stat in pairs(self) do
|
||||||
|
|
||||||
local t = type(stat)
|
local t = type(stat)
|
||||||
|
|
||||||
if t ~= "function"
|
if t ~= "function"
|
||||||
and t ~= "nil"
|
and t ~= "nil"
|
||||||
and t ~= "userdata"
|
and t ~= "userdata"
|
||||||
and _ ~= "_cmi_components" then
|
and tag ~= "_cmi_components" then
|
||||||
tmp[_] = self[_]
|
tmp[tag] = self[tag]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
tmp._mcl_potions = self._mcl_potions
|
||||||
|
|
||||||
return minetest.serialize(tmp)
|
return minetest.serialize(tmp)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -306,7 +308,10 @@ function mob_class:mob_activate(staticdata, def, dtime)
|
||||||
self._run_armor_init = true
|
self._run_armor_init = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not self._mcl_potions then
|
||||||
|
self._mcl_potions = {}
|
||||||
|
end
|
||||||
|
mcl_potions._load_entity_effects(self)
|
||||||
|
|
||||||
|
|
||||||
if def.after_activate then
|
if def.after_activate then
|
||||||
|
|
|
@ -324,6 +324,7 @@ function mcl_mobs.register_mob(name, def)
|
||||||
attack_exception = def.attack_exception or function(p) return false end,
|
attack_exception = def.attack_exception or function(p) return false end,
|
||||||
|
|
||||||
_spawner = def._spawner,
|
_spawner = def._spawner,
|
||||||
|
_mcl_potions = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
if minetest.get_modpath("doc_identifier") ~= nil then
|
if minetest.get_modpath("doc_identifier") ~= nil then
|
||||||
|
|
|
@ -1339,8 +1339,13 @@ minetest.register_globalstep(function(dtime)
|
||||||
if effect.after_end then effect.after_end(object) end
|
if effect.after_end then effect.after_end(object) end
|
||||||
if object:is_player() then
|
if object:is_player() then
|
||||||
meta = object:get_meta()
|
meta = object:get_meta()
|
||||||
meta:set_string("mcl_potions:"..name, minetest.serialize(EF[name][object]))
|
meta:set_string("mcl_potions:_EF_"..name, "")
|
||||||
potions_set_hud(object)
|
potions_set_hud(object)
|
||||||
|
else
|
||||||
|
local ent = object:get_luaentity()
|
||||||
|
if ent then
|
||||||
|
ent._mcl_potions["_EF_"..name] = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
elseif object:is_player() then
|
elseif object:is_player() then
|
||||||
if vals.dur == math.huge then
|
if vals.dur == math.huge then
|
||||||
|
@ -1351,6 +1356,11 @@ minetest.register_globalstep(function(dtime)
|
||||||
object:hud_change(icon_ids[object:get_player_name()][vals.hud_index].timestamp,
|
object:hud_change(icon_ids[object:get_player_name()][vals.hud_index].timestamp,
|
||||||
"text", math.floor(dur/60)..string.format(":%02d",math.floor(dur % 60)))
|
"text", math.floor(dur/60)..string.format(":%02d",math.floor(dur % 60)))
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
local ent = object:get_luaentity()
|
||||||
|
if ent then
|
||||||
|
ent._mcl_potions["_EF_"..name] = EF[name][object]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1503,12 +1513,31 @@ function mcl_potions._load_player_effects(player)
|
||||||
-- new API effects + on_load for loaded legacy effects
|
-- new API effects + on_load for loaded legacy effects
|
||||||
for name, effect in pairs(registered_effects) do
|
for name, effect in pairs(registered_effects) do
|
||||||
local loaded = minetest.deserialize(meta:get_string("mcl_potions:_EF_"..name))
|
local loaded = minetest.deserialize(meta:get_string("mcl_potions:_EF_"..name))
|
||||||
if loaded then EF[name][player] = loaded end
|
if loaded then
|
||||||
if EF[name][player] and effect.on_load then
|
EF[name][player] = loaded
|
||||||
|
if effect.on_load then
|
||||||
effect.on_load(player, EF[name][player].factor)
|
effect.on_load(player, EF[name][player].factor)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function mcl_potions._load_entity_effects(entity)
|
||||||
|
if not entity or not entity._mcl_potions or entity._mcl_potions == {} then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local object = entity.object
|
||||||
|
if not object or not object:get_pos() then return end
|
||||||
|
for name, effect in pairs(registered_effects) do
|
||||||
|
local loaded = entity._mcl_potions["_EF_"..name]
|
||||||
|
if loaded then
|
||||||
|
EF[name][object] = loaded
|
||||||
|
if effect.on_load then
|
||||||
|
effect.on_load(object, EF[name][object].factor)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Returns true if object has given effect
|
-- Returns true if object has given effect
|
||||||
function mcl_potions.has_effect(object, effect_name)
|
function mcl_potions.has_effect(object, effect_name)
|
||||||
|
|
Loading…
Reference in New Issue