import { world, system } from '@minecraft/server'

const EntityList = [
    'minecraft:armadillo',
    'minecraft:axolotl',
    'minecraft:pig',
    'minecraft:cow',
    'minecraft:sheep',
    'minecraft:llama',
    'minecraft:creeper',
    'minecraft:chicken',
    'minecraft:warden',
    'minecraft:zoglin',
    'minecraft:cat',
    'minecraft:wolf',
    'minecraft:frog',
    'minecraft:spider',
    'minecraft:fox',
    'minecraft:iron_golem',
    'minecraft:polar_bear',
    'minecraft:panda',
    'minecraft:goat',
    'minecraft:endermite',
    'minecraft:npc',
    'minecraft:zombie_horse',
    'minecraft:trader_llama',
    'minecraft:wandering_trader'
]
//plays a random sound for plyer and summons a random entity from the list above behind the player
system.runInterval(() => {
    world.getAllPlayers().filter(
        (data) => {
            const chance = Math.random()
            const entity = Math.floor(Math.random() * EntityList.length)
            if (chance < 0.1) {
                data.dimension.playSound('random.random_world_sound', data.location, { volume: 40 })
                data.runCommand(`summon ${entity, EntityList[entity]} ^ ^ ^-1`)

            }
        }
    )
}, 600)