1
0
Fork 0

Fix mob textures getting reset on shutdown/startup

This commit is contained in:
ancientmarinerdev 2023-05-12 14:27:02 +01:00
parent b3a6970370
commit 818052dc6c
1 changed files with 23 additions and 4 deletions

View File

@ -111,6 +111,21 @@ function mob_class:get_staticdata()
return minetest.serialize(tmp) return minetest.serialize(tmp)
end end
local function valid_texture(self, def_textures)
if not self.base_texture then
return false
end
if self.texture_selected then
if #def_textures < self.texture_selected then
self.texture_selected = nil
else
return true
end
end
return false
end
function mob_class:mob_activate(staticdata, def, dtime) function mob_class:mob_activate(staticdata, def, dtime)
if not self.object:get_pos() or staticdata == "remove" then if not self.object:get_pos() or staticdata == "remove" then
mcl_burning.extinguish(self.object) mcl_burning.extinguish(self.object)
@ -133,16 +148,20 @@ function mob_class:mob_activate(staticdata, def, dtime)
end end
--If textures in definition change, reload textures --If textures in definition change, reload textures
if not self.base_texture or (def.textures and table.indexof(def.textures, self.base_texture) == -1) then if not valid_texture(self, def.textures) then
-- compatiblity with old simple mobs textures -- compatiblity with old simple mobs textures
if type(def.textures[1]) == "string" then if type(def.textures[1]) == "string" then
def.textures = {def.textures} def.textures = {def.textures}
end end
local c = 1 if not self.texture_selected then
if #def.textures > c then c = #def.textures end local c = 1
if #def.textures > c then c = #def.textures end
self.texture_selected = math.random(c)
end
self.base_texture = def.textures[math.random(c)] self.base_texture = def.textures[self.texture_selected]
self.base_mesh = def.mesh self.base_mesh = def.mesh
self.base_size = self.visual_size self.base_size = self.visual_size
self.base_colbox = self.collisionbox self.base_colbox = self.collisionbox