@@ -49,19 +49,25 @@ npc.log_level = {
4949 DEBUG = false
5050}
5151
52+ npc .texture_check = {
53+ timer = 0 ,
54+ interval = 0
55+ }
56+
5257---- -----------------------------------------------------------------------------------
5358-- General functions
5459---- -----------------------------------------------------------------------------------
5560-- Logging
5661function npc .log (level , message )
5762 if npc .log_level [level ] then
58- minetest .log (" [advanced_npc] " .. type .. " : " .. message )
63+ minetest .log (" [advanced_npc] " .. level .. " : " .. message )
5964 end
6065end
6166
6267-- NPC chat
6368function npc .chat (npc_name , player_name , message )
6469 minetest .chat_send_player (player_name , npc_name .. " : " .. message )
70+ end
6571
6672-- Gets name of player or NPC
6773function npc .get_entity_name (entity )
@@ -123,10 +129,6 @@ local function get_random_texture(sex, age)
123129 textures = minetest .registered_entities [" advanced_npc:npc" ].child_texture
124130 end
125131
126- minetest .log (" Textures: " .. dump (textures ))
127- minetest .log (" Sex: " .. sex )
128- minetest .log (" Age: " .. age )
129-
130132 for i = 1 , # textures do
131133 local current_texture = textures [i ][1 ]
132134 if (sex == npc .MALE
@@ -236,8 +238,8 @@ function npc.initialize(entity, pos, is_lua_entity, npc_stats)
236238 if npc_stats [" adult_total" ] >= 2 then
237239 if npc_stats [" adult_total" ] % 2 == 0
238240 and (npc_stats [" adult_total" ] / 2 > npc_stats [" child_total" ]) then
239- child_s ,child_e = 51 , 100
240- adult_e = 50
241+ child_s ,child_e = 26 , 100
242+ adult_e = 25
241243 else
242244 child_s , child_e = 61 , 100
243245 adult_e = 60
@@ -267,14 +269,16 @@ function npc.initialize(entity, pos, is_lua_entity, npc_stats)
267269 }
268270 ent .collisionbox = {- 0.10 ,- 0.50 ,- 0.10 , 0.10 ,0.40 ,0.10 }
269271 ent .is_child = true
272+ ent .child = true
270273 end
271274 -- Set texture accordingly
272275 local selected_texture = get_random_texture (selected_sex , selected_age )
273276 -- minetest.log("Selected texture: "..dump(selected_texture))
277+ -- Store selected texture due to the need to restore it later
278+ ent .selected_texture = selected_texture
279+ -- Set texture and base texture
274280 ent .textures = {selected_texture }
275- if selected_age == npc .age .child then
276- ent .base_texture = selected_texture
277- end
281+ ent .base_texture = {selected_texture }
278282 else
279283 -- Get sex based on texture. This is a 50% chance for
280284 -- each sex as there's same amount of textures for male and female.
@@ -444,7 +448,9 @@ function npc.initialize(entity, pos, is_lua_entity, npc_stats)
444448 table.insert (ent .trader_data .custom_trades , offer2 )
445449
446450 -- minetest.log(dump(ent))
447- npc .log (" INFO" , " Successfully initialized NPC with name " .. dump (ent .npc_name ))
451+ npc .log (" INFO" , " Successfully initialized NPC with name " .. dump (ent .npc_name )
452+ .. " , sex: " .. ent .sex .. " , is child: " .. dump (ent .is_child )
453+ .. " , texture: " .. dump (ent .textures ))
448454 -- Refreshes entity
449455 ent .object :set_properties (ent )
450456end
@@ -968,10 +974,24 @@ mobs:register_mob("advanced_npc:npc", {
968974 -- favor of a better manual spawning method with customization
969975 npc .log (" WARNING" , " Initializing NPC from entity step. This message should only be appearing if an NPC is being spawned from inventory with egg!" )
970976 npc .initialize (self , self .object :getpos (), true )
971- else
972977 self .tamed = false
973978 self .owner = nil
979+ else
974980 -- NPC is initialized, check other variables
981+ -- Check child texture issues
982+ if self .is_child then
983+ npc .texture_check .timer = npc .texture_check .timer + dtime
984+ if npc .texture_check .timer > npc .texture_check .interval then
985+ -- Reset timer
986+ npc .texture_check .timer = 0
987+ -- Set correct textures
988+ self .texture = {self .selected_texture }
989+ self .base_texture = {self .selected_texture }
990+ -- Set interval to large interval so this code isn't called frequently
991+ npc .texture_check .interval = 60
992+ end
993+ end
994+
975995 -- Timer function for casual traders to reset their trade offers
976996 self .trader_data .change_offers_timer = self .trader_data .change_offers_timer + dtime
977997 -- Check if time has come to change offers
0 commit comments