import { world } from "@minecraft/server"
import { GOLEM } from "./specific/golem"
import { CUSTOM_CREEPERS } from "./common/customCreepers";
import { CUSTOM_SKELETON } from "./common/customSkeleton";
import { CUSTOM_ZOMBIES } from "./common/customZombies";

world.afterEvents.entityDie.subscribe(ev => {
    const {damageSource, deadEntity} = ev

    const deadEntityTypeId = deadEntity.typeId;
    const damageCause = damageSource.cause
    const damagingEntity = damageSource.damagingEntity

    if (GOLEM.isGolemKilledByCommand(deadEntityTypeId, damageCause)) GOLEM.onDeath(deadEntity)
    if (CUSTOM_CREEPERS.shouldDropHead(deadEntity, damagingEntity, damageCause)) CUSTOM_CREEPERS.dropHead(deadEntity)
    if (CUSTOM_SKELETON.shouldDropHead(deadEntity, damagingEntity, damageCause)) CUSTOM_SKELETON.dropHead(deadEntity)
    if (CUSTOM_ZOMBIES.shouldDropHead(deadEntity, damagingEntity, damageCause)) CUSTOM_ZOMBIES.dropHead(deadEntity)
})