import { world } from "@minecraft/server";
export function coloredSlimesDie() {
    world.afterEvents.entityDie.subscribe((event)=>{
        if (event.deadEntity.typeId != 'tvf_randev:colored_slime') return;
        const color = event.deadEntity.getProperty("property:color");
        const oldVariant = event.deadEntity.getComponent("minecraft:mark_variant").value;
        let newVariant = undefined;
        switch(oldVariant){
            case 4:
                newVariant = 'spawn_medium';
                break;
            case 2:
                newVariant = 'spawn_small';
                break;
        }
        const dimension = event.deadEntity.dimension;
        const count = Math.floor(Math.random() * 4) + 1;
        if (newVariant == undefined) return;
        for(let i = 0; i < count; i++){
            let newSlime = dimension.spawnEntity(event.deadEntity.typeId, event.deadEntity.location);
            newSlime.triggerEvent(newVariant);
            newSlime.setProperty("property:color", color);
        }
    });
}
