Search in sources :

Example 1 with SoldierDeathEvent

use of de.sanandrew.mods.claysoldiers.api.event.SoldierDeathEvent in project ClaySoldiersMod by SanAndreasP.

the class EntityClaySoldier method onDeath.

@Override
public void onDeath(DamageSource damageSource) {
    super.onDeath(damageSource);
    if (!this.world.isRemote) {
        NonNullList<ItemStack> drops = NonNullList.create();
        if (ItemStackUtils.isValid(this.doll)) {
            if (damageSource.isFireDamage()) {
                ItemStack brickDoll = new ItemStack(ItemRegistry.DOLL_BRICK_SOLDIER, 1);
                drops.add(brickDoll);
            } else {
                drops.add(this.doll);
            }
        }
        this.callUpgradeFunc(EnumUpgFunctions.ON_DEATH, inst -> inst.getUpgrade().onDeath(this, inst, damageSource, drops));
        SoldierDeathEvent event = new SoldierDeathEvent(this, damageSource, drops);
        ClaySoldiersMod.EVENT_BUS.post(event);
        drops.removeIf(stack -> !ItemStackUtils.isValid(stack));
        for (ItemStack drop : drops) {
            this.entityDropItem(drop, 0.5F);
        }
    } else {
        ClaySoldiersMod.proxy.spawnParticle(EnumParticle.TEAM_BREAK, this.world.provider.getDimension(), this.posX, this.posY + this.getEyeHeight(), this.posZ, this.getSoldierTeam().getId());
    }
}
Also used : SoldierDeathEvent(de.sanandrew.mods.claysoldiers.api.event.SoldierDeathEvent) ItemStack(net.minecraft.item.ItemStack)

Aggregations

SoldierDeathEvent (de.sanandrew.mods.claysoldiers.api.event.SoldierDeathEvent)1 ItemStack (net.minecraft.item.ItemStack)1