//Gets rid of projectiles after 3 seconds. 
//This will prevent tnt from infinitely spawning through arrows and tridents.
import { system, world } from "@minecraft/server";
//clears projectiles after 3 seconds
system.runInterval(() => {
    for (let player of world.getAllPlayers()) {
        const entities = player?.dimension.getEntities({ maxDistance: 100, location: player.location })?.forEach(event => {
            const entity = event
            if (entity?.hasComponent("minecraft:projectile")) {
                entity.runCommandAsync("kill @s")
            }
        })
    }
}, 60);

//supposed to kill entities if it exceeds certain mob cap

// world.afterEvents.entityDie.subscribe(event => {
//     const entity = event.deadEntity
//     entity.runCommandAsync("scoreboard players set @e ecount 0")
// })
// world.afterEvents.entitySpawn.subscribe(event => {
//     const entity = event.entity
//     if (!entity.hasComponent("minecraft:projectile")) {
//         entity.runCommandAsync("execute as @e at @s unless entity @s[type=ender_dragon] unless entity @s[type=warden] unless entity @s[type=wither] unless entity @s[type=omni_science:mecha_giga_steve] unless entity @s[type=villager] unless entity @s[type=vex] unless entity @s[type=item] unless entity @s[type=wandering_trader] unless entity @s[family=inanimate] unless entity @s[type=evocation_illager] unless entity @s[type=xp_orb] unless entity @s[type=item] unless entity @s[type=witch] run scoreboard players add @e[type=!wither,type=!ender_dragon,type=!warden,type=!omni_science:mecha_giga_steve,type=!item,family=!inanimate,type=!evocation_illager,type=!villager,type=!vex,type=!wandering_trader,type=!witch] ecount 1")
//     }
// })
// system.runInterval(() => {
//     for (let player of world.getAllPlayers()) {
//         const entities = player?.dimension.getEntities({ maxDistance: 100, location: player.location })?.forEach(event => {
//             const entity = event
//             entity?.runCommandAsync("execute if entity @e[scores={ecount=50..}] run kill @s[scores={ecount=50..}]")
//         })
//     }
// }, 1);
