Search in sources :

Example 1 with EnderDragonEntity

use of net.minecraft.entity.boss.dragon.EnderDragonEntity in project BluePower by Qmunity.

the class BPEventHandler method onEntityAttack.

@SubscribeEvent
public void onEntityAttack(LivingAttackEvent event) {
    if (!isAttacking && event.getSource() instanceof EntityDamageSource) {
        // this event will be trigger recursively by EntityLiving#hurt,
        // so we need to stop the loop.
        EntityDamageSource entitySource = (EntityDamageSource) event.getSource();
        if (entitySource.getEntity() instanceof PlayerEntity) {
            PlayerEntity killer = (PlayerEntity) entitySource.getEntity();
            if (!killer.inventory.getSelected().isEmpty()) {
                if (EnchantmentHelper.getEnchantments(killer.inventory.getSelected()).containsKey(BPEnchantments.disjunction)) {
                    if (event.getEntityLiving() instanceof EndermanEntity || event.getEntityLiving() instanceof EnderDragonEntity) {
                        int level = EnchantmentHelper.getItemEnchantmentLevel(BPEnchantments.disjunction, killer.inventory.getSelected());
                        isAttacking = true;
                        event.getEntityLiving().hurt(event.getSource(), event.getAmount() * (level * 0.5F + 1));
                        isAttacking = false;
                    }
                }
            }
        }
    }
}
Also used : EnderDragonEntity(net.minecraft.entity.boss.dragon.EnderDragonEntity) EntityDamageSource(net.minecraft.util.EntityDamageSource) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

EnderDragonEntity (net.minecraft.entity.boss.dragon.EnderDragonEntity)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 EntityDamageSource (net.minecraft.util.EntityDamageSource)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1