import { world, system, ItemStack, TicksPerSecond } from '@minecraft/server'
//player pooping sometimes when sneaking
system.runInterval(() => {
    world.getAllPlayers().filter(
        (data) => {
            const chance = Math.random()
            if (data.isSneaking && chance < 0.2) {
                system.run(() => {
                    data.dimension.spawnItem(new ItemStack('omni_science:poop', 1), data.location)
                    if (chance > 0.1) {
                        data.dimension.playSound('random.pooping', data.location, { volume: 50 })
                    }
                    else {
                        data.dimension.playSound('random.i_pooped_my_pants', data.location, { volume: 50 })
                    }
                })
            }
        }
    )
}, 20)
//when player eats poop, a sound plays and player gets nausea for 5 minutes(what did u expect from eating poop anyway?)
world.beforeEvents.worldInitialize.subscribe(event => {
    event.itemComponentRegistry.registerCustomComponent('omni_science:poop', {
        onConsume({ source }) {
            source.dimension.playSound('item.poop', source.location, { volume: 50 })
            source.addEffect('nausea', TicksPerSecond * 30, { amplifier: 10, showParticles: true })
        }
    })
})