Crash fixes, multimesh support

This commit is contained in:
ElCeejo 2022-12-11 17:21:49 -08:00
parent 2b48caa781
commit 1b9382bee3
6 changed files with 49 additions and 102 deletions

View file

@ -222,6 +222,7 @@ end
------------------------ ------------------------
-- Environment Access -- -- Environment Access --
------------------------ ------------------------
function animalia.get_nearby_mate(self) function animalia.get_nearby_mate(self)
local pos = self.object:get_pos() local pos = self.object:get_pos()
if not pos then return end if not pos then return end

View file

@ -38,7 +38,7 @@ local generate_mobs = {
["animalia:chicken"] = "Chicken", ["animalia:chicken"] = "Chicken",
["animalia:cow"] = "Cow", ["animalia:cow"] = "Cow",
["animalia:owl"] = "Owl", ["animalia:owl"] = "Owl",
--["animalia:tropical_fish"] = "Tropical Fish", ["animalia:tropical_fish"] = "Tropical Fish",
["animalia:fox"] = "Fox", ["animalia:fox"] = "Fox",
["animalia:frog"] = "Frog", ["animalia:frog"] = "Frog",
["animalia:horse"] = "Horse", ["animalia:horse"] = "Horse",
@ -93,15 +93,24 @@ local function max_health(name)
return minetest.registered_entities[name].max_health or 20 return minetest.registered_entities[name].max_health or 20
end end
local function mob_textures(name) local function mob_textures(name, mesh_no)
local def = minetest.registered_entities[name] local def = minetest.registered_entities[name]
return def.textures or {unpack(def.male_textures), unpack(def.female_textures)} local textures = def.textures
if def.male_textures
or def.female_textures then
textures = {unpack(def.male_textures), unpack(def.female_textures)}
end
if def.mesh_textures then
textures = def.mesh_textures[mesh_no or 1]
end
return textures
end end
local biome_cubes = {} local biome_cubes = {}
local function generate_page(mob) local function generate_page(mob)
local name = mob:split(":")[2] local name = mob:split(":")[2]
local def = minetest.registered_entities[mob]
local page = { local page = {
{ -- Info { -- Info
element_type = "label", element_type = "label",
@ -114,8 +123,9 @@ local function generate_page(mob)
element_type = "model", element_type = "model",
offset = {x = 1.5, y = 1.5}, offset = {x = 1.5, y = 1.5},
size = {x = 5, y = 5}, size = {x = 5, y = 5},
mesh_iter = def.meshes and 1,
texture_iter = 1, texture_iter = 1,
text = "mesh;animalia_bat.b3d;" .. mob_textures(mob)[1] .. ";-30,225;false;false;0,0;0" text = "mesh;" .. def.mesh .. ";" .. mob_textures(mob)[1] .. ";-30,225;false;false;0,0;0"
}, },
{ -- Spawn Biome { -- Spawn Biome
element_type = "image", element_type = "image",
@ -228,82 +238,6 @@ minetest.register_on_mods_loaded(function()
start_iter = 12, start_iter = 12,
offset = {x = 1.75, y = 1.5} offset = {x = 1.75, y = 1.5}
} }
},
["animalia:tropical_fish"] = {
{ -- Info
element_type = "label",
center_text = true,
font_size = 20,
offset = {x = 8, y = 1.5},
file = "animalia_libri_tropical_fish.txt"
},
{ -- Image
element_type = "model",
offset = {x = 1.5, y = 1.5},
size = {x = 5, y = 5},
texture_iter = 1,
models = {
"animalia_clownfish.b3d",
"animalia_clownfish.b3d",
"animalia_angelfish.b3d"
},
text = "mesh;animalia_clownfish.b3d;" .. mob_textures("animalia:tropical_fish")[1] .. ";-30,225;false;false;0,0;0"
},
{ -- Spawn Biome
element_type = "image",
offset = {x = 0.825, y = 8.15},
size = {x = 1, y = 1},
biome_iter = 1,
text = biome_cubes[get_spawn_biomes("animalia:tropical_fish")[1]]
},
{ -- Biome Label
element_type = "tooltip",
offset = {x = 0.825, y = 8.15},
size = {x = 1, y = 1},
biome_iter = 1,
text = correct_string(get_spawn_biomes("animalia:tropical_fish")[1])
},
libri.render_element({ -- Health Icon
element_type = "image",
offset = {x = 2.535, y = 8.15},
size = {x = 1, y = 1},
text = "animalia_libri_health_fg.png"
}),
libri.render_element({ -- Health Amount
element_type = "label",
offset = {x = 3.25, y = 9},
text = "x" .. max_health("animalia:tropical_fish") / 2
}),
libri.render_element({ -- Lasso Icon
element_type = "item_image",
offset = {x = 4.25, y = 8.15},
size = {x = 1, y = 1},
text = "animalia:lasso"
}),
libri.render_element({ -- Lasso Indication Icon
element_type = "image",
offset = {x = 4.75, y = 8.75},
size = {x = 0.5, y = 0.5},
text = "animalia_libri_" .. can_lasso("animalia:tropical_fish") .. "_icon.png"
}),
libri.render_element({ -- Net Icon
element_type = "item_image",
offset = {x = 6, y = 8.15},
size = {x = 1, y = 1},
text = "animalia:net"
}),
libri.render_element({ -- Net Indication Icon
element_type = "image",
offset = {x = 6.5, y = 8.75},
size = {x = 0.5, y = 0.5},
text = "animalia_libri_" .. can_net("animalia:tropical_fish") .. "_icon.png"
}),
libri.render_element({ -- Styling
element_type = "image",
offset = {x = -0.7, y = -0.5},
size = {x = 17.5, y = 11.5},
text = "animalia_libri_info_fg.png"
})
} }
} }
for mob in pairs(generate_mobs) do for mob in pairs(generate_mobs) do
@ -462,13 +396,19 @@ local function iterate_libri_images()
if page ~= "home" then if page ~= "home" then
for _, info in ipairs(elements) do for _, info in ipairs(elements) do
if info.texture_iter then if info.texture_iter then
local textures = mob_textures(page) local def = minetest.registered_entities[page]
if textures[info.texture_iter + 1] then local textures = mob_textures(page, info.mesh_iter)
info.texture_iter = info.texture_iter + 1
else local tex_i = info.texture_iter
info.texture_iter = 1 info.texture_iter = (textures[tex_i + 1] and tex_i + 1) or 1
local mesh_i = info.mesh_iter
if info.texture_iter < 2 then -- Only iterate mesh if all textures have been shown
info.mesh_iter = def.meshes and ((def.meshes[mesh_i + 1] and mesh_i + 1) or 1)
textures = mob_textures(page, info.mesh_iter)
end end
local mesh = (info.models and info.models[info.texture_iter]) or minetest.registered_entities[page].mesh
local mesh = (info.mesh_iter and def.meshes[info.mesh_iter]) or def.mesh
info.text = "mesh;" .. mesh .. ";" .. textures[info.texture_iter] .. ";-30,225;false;false;0,0;0]" info.text = "mesh;" .. mesh .. ";" .. textures[info.texture_iter] .. ";-30,225;false;false;0,0;0]"
end end
if info.biome_iter then if info.biome_iter then

View file

@ -84,7 +84,8 @@ minetest.register_on_mods_loaded(function()
local pets = (name and animalia.pets[name]) or {} local pets = (name and animalia.pets[name]) or {}
for _, obj in ipairs(pets) do for _, obj in ipairs(pets) do
local ent = obj and obj:get_luaentity() local ent = obj and obj:get_luaentity()
if ent.assist_owner then if ent
and ent.assist_owner then
ent.owner_target = self ent.owner_target = self
end end
end end

View file

@ -204,4 +204,4 @@ creatura.register_mob("animalia:bat", {
creatura.register_spawn_item("animalia:bat", { creatura.register_spawn_item("animalia:bat", {
col1 = "392517", col1 = "392517",
col2 = "321b0b" col2 = "321b0b"
}) })

View file

@ -323,9 +323,12 @@ creatura.register_mob("animalia:cat", {
self:memorize("trust", self.trust) self:memorize("trust", self.trust)
end, end,
deactivate_func = function(self) deactivate_func = function(self)
if self.owner if self.owner then
and animalia.pets[self.owner][self.object] then for i, object in ipairs(animalia.pets[self.owner] or {}) do
animalia.pets[self.owner][self.object] = nil if object == self.object then
animalia.pets[self.owner][i] = nil
end
end
end end
end end
}) })

View file

@ -18,16 +18,23 @@ creatura.register_mob("animalia:tropical_fish", {
boid_seperation = 0.3, boid_seperation = 0.3,
bouyancy_multiplier = 0, bouyancy_multiplier = 0,
-- Visuals -- Visuals
mesh = "animalia_clownfish.b3d", meshes = {
"animalia_clownfish.b3d",
"animalia_angelfish.b3d"
},
hitbox = { hitbox = {
width = 0.15, width = 0.15,
height = 0.3 height = 0.3
}, },
visual_size = {x = 7, y = 7}, visual_size = {x = 10, y = 10},
textures = { mesh_textures = {
"animalia_clownfish.png", {
"animalia_blue_tang.png", "animalia_clownfish.png",
"animalia_angelfish.png" "animalia_blue_tang.png"
},
{
"animalia_angelfish.png"
}
}, },
animations = { animations = {
swim = {range = {x = 1, y = 20}, speed = 20, frame_blend = 0.3, loop = true}, swim = {range = {x = 1, y = 20}, speed = 20, frame_blend = 0.3, loop = true},
@ -61,11 +68,6 @@ creatura.register_mob("animalia:tropical_fish", {
activate_func = function(self) activate_func = function(self)
animalia.initialize_api(self) animalia.initialize_api(self)
animalia.initialize_lasso(self) animalia.initialize_lasso(self)
if self.texture_no == 3 then
self.object:set_properties({
mesh = "animalia_angelfish.b3d",
})
end
end, end,
step_func = function(self) step_func = function(self)
animalia.step_timers(self) animalia.step_timers(self)