From ce47b81da56bba7618f1ab62ede0daaca1b88ced Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Sun, 15 Oct 2023 11:25:20 +0100 Subject: [PATCH] mobs:add_mob() can now set mob texture --- api.lua | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/api.lua b/api.lua index a0c04c0..7fd90e3 100644 --- a/api.lua +++ b/api.lua @@ -11,7 +11,7 @@ local use_mc2 = minetest.get_modpath("mcl_core") -- Global mobs = { mod = "redo", - version = "20231012", + version = "20231015", translate = S, invis = minetest.global_exists("invisibility") and invisibility or {}, node_snow = minetest.registered_aliases["mapgen_snow"] @@ -3851,18 +3851,22 @@ function mobs:add_mob(pos, def) effect(pos, 15, "tnt_smoke.png", 1, 2, 2, 15, 5) end + -- use new texture if found + local new_texture = def.texture or ent.base_texture + if def.child then - local textures = ent.base_texture + ent.mommy_tex = new_texture -- how baby looks when grown + ent.base_texture = new_texture -- using specific child texture (if found) if ent.child_texture then - textures = ent.child_texture[1] + new_texture = ent.child_texture[1] end -- and resize to half height (multiplication is faster than division) mob:set_properties({ - textures = textures, + textures = new_texture, visual_size = { x = ent.base_size.x * .5, y = ent.base_size.y * .5 @@ -3886,6 +3890,13 @@ function mobs:add_mob(pos, def) }) ent.child = true + + -- if not child set new texture + elseif def.texture then + + ent.base_texture = new_texture + + mob:set_properties({textures = new_texture}) end if def.owner then