From 544c6cbdb3c99dbc92bb4e5b8d690ad199ee18a5 Mon Sep 17 00:00:00 2001 From: cora Date: Wed, 17 Aug 2022 22:17:33 +0200 Subject: [PATCH] Use proper keyset for randomisation --- mods/ENTITIES/mobs_mc/parrot.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/parrot.lua b/mods/ENTITIES/mobs_mc/parrot.lua index d4b6c12e6..cc20dadb1 100644 --- a/mods/ENTITIES/mobs_mc/parrot.lua +++ b/mods/ENTITIES/mobs_mc/parrot.lua @@ -13,12 +13,20 @@ local shoulders = { right = vector.new(3.75,10.5,0) } +local function table_get_rand(tbl) + local keys = {} + for k in pairs(tbl) do + table.insert(keys, k) + end + return tbl[keys[math.random(#keys)]] +end + local function get_random_mob_sound() local t = table.copy(minetest.registered_entities) table.shuffle(t) for _,e in pairs(t) do - if e.is_mob and e.sounds then - return e.sounds[math.random(#e.sounds)] + if e.is_mob and e.sounds and #e.sounds > 0 then + return table_get_rand(e.sounds) end end return minetest.registered_entities["mobs_mc:parrot"].sounds.random