Merge pull request 'Parrot mobimitate: Use proper keyset for randomisation' (#2574) from fix_parrot_crash into master

Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/2574
Reviewed-by: MysticTempest <mystictempest@noreply.git.minetest.land>
This commit is contained in:
cora 2022-08-18 21:53:34 +00:00
commit 4032cbe943

View file

@ -13,12 +13,20 @@ local shoulders = {
right = vector.new(3.75,10.5,0) 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 function get_random_mob_sound()
local t = table.copy(minetest.registered_entities) local t = table.copy(minetest.registered_entities)
table.shuffle(t) table.shuffle(t)
for _,e in pairs(t) do for _,e in pairs(t) do
if e.is_mob and e.sounds then if e.is_mob and e.sounds and #e.sounds > 0 then
return e.sounds[math.random(#e.sounds)] return table_get_rand(e.sounds)
end end
end end
return minetest.registered_entities["mobs_mc:parrot"].sounds.random return minetest.registered_entities["mobs_mc:parrot"].sounds.random