Example usage for net.minecraftforge.event.entity.living LivingHurtEvent getEntityLiving

List of usage examples for net.minecraftforge.event.entity.living LivingHurtEvent getEntityLiving

Introduction

In this page you can find the example usage for net.minecraftforge.event.entity.living LivingHurtEvent getEntityLiving.

Prototype

public LivingEntity getEntityLiving() 

Source Link

Usage

From source file:com.gmail.socraticphoenix.forge.randore.component.ability.EmpoweredArmorListener.java

License:Open Source License

@SubscribeEvent
public void onHurt(LivingHurtEvent ev) {
    DamageSource source = ev.getSource();
    Entity root = source.getEntity();
    if (root instanceof EntityLivingBase) {
        EntityLivingBase cause = (EntityLivingBase) root;
        EntityLivingBase hurt = ev.getEntityLiving();
        if (EmpoweredEnchantment.appliedTo(hurt)) {
            EmpoweredEnchantment.doArmor(hurt, cause);
        }/* w ww  . j ava 2s  . c  o  m*/
    }
}

From source file:com.lothrazar.cyclicmagic.potion.effect.PotionEnder.java

License:Open Source License

@SubscribeEvent
public void onHurt(LivingHurtEvent event) {
    if (event.getEntityLiving().isPotionActive(this) && event.getSource() == DamageSource.IN_WALL) {
        event.setAmount(0);/*from  w w w .j  av  a 2  s  .c om*/
    }
}

From source file:de.canitzp.rarmor.module.protection.ItemModuleProtection.java

@SubscribeEvent
public void onHurt(LivingHurtEvent event) {
    EntityLivingBase entity = event.getEntityLiving();
    if (!entity.getEntityWorld().isRemote && entity instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) entity;
        IRarmorData data = RarmorAPI.methodHandler.getDataForChestplate(player, false);
        if (data != null) {
            float damageReduct = 0F;

            for (ActiveRarmorModule module : data.getCurrentModules()) {
                if (module instanceof ActiveModuleProtection) {
                    damageReduct = ((ActiveModuleProtection) module).getDamageReduction();
                    break;
                }// ww w  .j  av  a2 s .c  o  m
            }

            if (damageReduct > 0F) {
                int neededEnergy = (int) (damageReduct * 200);

                if (data.getEnergyStored() >= neededEnergy) {
                    event.setAmount(Math.max(0, event.getAmount() / damageReduct));
                    data.extractEnergy(neededEnergy, false);
                }
            }
        }
    }
}

From source file:hellfirepvp.astralsorcery.common.event.listener.EventHandlerEntity.java

License:Open Source License

@SubscribeEvent(priority = EventPriority.LOW)
public void onAttack(LivingHurtEvent event) {
    if (event.getEntity().getEntityWorld().isRemote)
        return;/*from   www . ja v a  2 s.c om*/

    DamageSource source = event.getSource();
    if (source.getTrueSource() != null) {
        EntityLivingBase entitySource = null;
        if (source.getTrueSource() instanceof EntityLivingBase) {
            entitySource = (EntityLivingBase) source.getTrueSource();
        } else if (source.getTrueSource() instanceof EntityArrow) {
            Entity shooter = ((EntityArrow) source.getTrueSource()).shootingEntity;
            if (shooter != null && shooter instanceof EntityLivingBase) {
                entitySource = (EntityLivingBase) shooter;
            }
        }
        if (entitySource != null) {
            WandAugment foundAugment = null;
            ItemStack stack = entitySource.getHeldItemMainhand();
            if (!stack.isEmpty() && stack.getItem() instanceof ItemWand) {
                foundAugment = ItemWand.getAugment(stack);
            }
            stack = entitySource.getHeldItemOffhand();
            if (foundAugment == null && !stack.isEmpty() && stack.getItem() instanceof ItemWand) {
                foundAugment = ItemWand.getAugment(stack);
            }
            if (foundAugment != null && foundAugment.equals(WandAugment.DISCIDIA)) {
                EntityAttackStack attack = attackStack.get(entitySource.getEntityId());
                if (attack == null) {
                    attack = new EntityAttackStack();
                    attackStack.put(entitySource.getEntityId(), attack);
                }
                EntityLivingBase entity = event.getEntityLiving();
                float multiplier = attack.getAndUpdateMultipler(entity);
                event.setAmount(event.getAmount() * (1F + multiplier));
                PktParticleEvent ev = new PktParticleEvent(
                        PktParticleEvent.ParticleEventType.DISCIDIA_ATTACK_STACK, entity.posX, entity.posY,
                        entity.posZ);
                ev.setAdditionalData(multiplier);
                PacketChannel.CHANNEL.sendToAllAround(ev, PacketChannel.pointFromPos(event.getEntity().world,
                        event.getEntity().getPosition(), 64));
            }
        }
    }
}

From source file:hellfirepvp.astralsorcery.common.event.listener.EventHandlerEntity.java

License:Open Source License

@SubscribeEvent
public void onDamage(LivingHurtEvent event) {
    EntityLivingBase living = event.getEntityLiving();
    if (living == null || living.getEntityWorld().isRemote)
        return;//from w ww . j  a  va  2s  .  c  o  m

    if (!living.isDead && living instanceof EntityPlayer) {
        if (invulnerabilityCooldown.contains((EntityPlayer) living)) {
            event.setCanceled(true);
            return;
        }
    }

    DamageSource source = event.getSource();
    lblIn: if (source.getTrueSource() != null) {
        EntityPlayer p;
        if (source.getTrueSource() instanceof EntityPlayer) {
            p = (EntityPlayer) source.getTrueSource();
        } else if (source.getTrueSource() instanceof EntityArrow) {
            Entity shooter = ((EntityArrow) source.getTrueSource()).shootingEntity;
            if (shooter != null && shooter instanceof EntityPlayer) {
                p = (EntityPlayer) shooter;
            } else {
                break lblIn;
            }
        } else {
            break lblIn;
        }
        PlayerProgress prog = ResearchManager.getProgress(p);
        if (prog != null) {
            float dmg = event.getAmount();
            Map<ConstellationPerk, Integer> perks = prog.getAppliedPerks();
            for (ConstellationPerk perk : perks.keySet()) {
                if (!prog.isPerkActive(perk))
                    continue;
                if (perk.mayExecute(ConstellationPerk.Target.ENTITY_ATTACK)) {
                    dmg = perk.onEntityAttack(p, event.getEntityLiving(), dmg);
                }
            }
            event.setAmount(dmg);
        }
    }
    EntityLivingBase entity = event.getEntityLiving();
    if (entity != null) {
        if (entity instanceof EntityPlayer) {
            EntityPlayer hurt = (EntityPlayer) entity;
            PlayerProgress prog = ResearchManager.getProgress(hurt);
            if (prog != null) {
                float dmg = event.getAmount();
                Map<ConstellationPerk, Integer> perks = prog.getAppliedPerks();
                for (ConstellationPerk perk : perks.keySet()) {
                    if (!prog.isPerkActive(perk))
                        continue;
                    if (perk.mayExecute(ConstellationPerk.Target.ENTITY_HURT)) {
                        dmg = perk.onEntityHurt(hurt, source, dmg);
                    }
                }
                event.setAmount(dmg);
            }
        }

        ItemStack active = entity.getActiveItemStack();
        if (!active.isEmpty() && active.getItem() instanceof ItemWand) {
            WandAugment wa = ItemWand.getAugment(active);
            if (wa != null && wa.equals(WandAugment.ARMARA)) {
                PotionEffect potion = new PotionEffect(MobEffects.RESISTANCE, 100, 0);
                if (entity.isPotionApplicable(potion)) {
                    entity.addPotionEffect(potion);
                }
                potion = new PotionEffect(MobEffects.ABSORPTION, 100, 1);
                if (entity.isPotionApplicable(potion)) {
                    entity.addPotionEffect(potion);
                }
            }
        }
    }
}

From source file:hellfirepvp.astralsorcery.common.event.listener.EventHandlerServer.java

License:Open Source License

@SubscribeEvent
public void onDamage(LivingHurtEvent event) {
    EntityLivingBase living = event.getEntityLiving();
    if (living == null || living.getEntityWorld().isRemote)
        return;/*from   www  . j a v  a2s . c o m*/

    if (!living.isDead && living instanceof EntityPlayer) {
        if (invulnerabilityCooldown.contains((EntityPlayer) living)) {
            event.setCanceled(true);
            return;
        }
    }

    DamageSource source = event.getSource();
    lblIn: if (source.getSourceOfDamage() != null) {
        EntityPlayer p;
        if (source.getSourceOfDamage() instanceof EntityPlayer) {
            p = (EntityPlayer) source.getSourceOfDamage();
        } else if (source.getSourceOfDamage() instanceof EntityArrow) {
            Entity shooter = ((EntityArrow) source.getSourceOfDamage()).shootingEntity;
            if (shooter != null && shooter instanceof EntityPlayer) {
                p = (EntityPlayer) shooter;
            } else {
                break lblIn;
            }
        } else {
            break lblIn;
        }
        PlayerProgress prog = ResearchManager.getProgress(p);
        if (prog != null) {
            float dmg = event.getAmount();
            Map<ConstellationPerk, Integer> perks = prog.getAppliedPerks();
            for (ConstellationPerk perk : perks.keySet()) {
                if (!prog.isPerkActive(perk))
                    continue;
                if (perk.mayExecute(ConstellationPerk.Target.ENTITY_ATTACK)) {
                    dmg = perk.onEntityAttack(p, event.getEntityLiving(), dmg);
                }
            }
            event.setAmount(dmg);
        }
    }
    if (event.getEntityLiving() != null && event.getEntityLiving() instanceof EntityPlayer) {
        EntityPlayer hurt = (EntityPlayer) event.getEntityLiving();
        PlayerProgress prog = ResearchManager.getProgress(hurt);
        if (prog != null) {
            float dmg = event.getAmount();
            Map<ConstellationPerk, Integer> perks = prog.getAppliedPerks();
            for (ConstellationPerk perk : perks.keySet()) {
                if (!prog.isPerkActive(perk))
                    continue;
                if (perk.mayExecute(ConstellationPerk.Target.ENTITY_HURT)) {
                    dmg = perk.onEntityHurt(hurt, source, dmg);
                }
            }
            event.setAmount(dmg);
        }
    }
}

From source file:org.blockartistry.DynSurround.server.services.HealthEffectService.java

License:MIT License

@SubscribeEvent(priority = EventPriority.LOW)
public void onLivingHurt(@Nonnull final LivingHurtEvent event) {
    if (!ModOptions.enableDamagePopoffs)
        return;//from   ww w .  j  a va  2s . c  o m

    if (event == null || event.getEntity() == null || event.getEntity().world == null
            || event.getEntity().world.isRemote)
        return;

    // Living heal should handle heals - I think..
    if (event.getAmount() <= 0 || event.getEntityLiving() == null)
        return;

    // A bit hokey - may work.
    boolean isCrit = false;
    if (event.getSource() instanceof EntityDamageSourceIndirect) {
        final EntityDamageSourceIndirect dmgSource = (EntityDamageSourceIndirect) event.getSource();
        if (dmgSource.getSourceOfDamage() instanceof EntityArrow) {
            final EntityArrow arrow = (EntityArrow) dmgSource.getSourceOfDamage();
            isCrit = arrow.getIsCritical();
        }
    } else if (event.getSource() instanceof EntityDamageSource) {
        final EntityDamageSource dmgSource = (EntityDamageSource) event.getSource();
        if (dmgSource.getSourceOfDamage() instanceof EntityPlayer) {
            final EntityPlayer player = (EntityPlayer) dmgSource.getSourceOfDamage();
            isCrit = isCritical(player, event.getEntityLiving());
        }
    }

    final Entity entity = event.getEntityLiving();
    final Locus point = new Locus(entity, RANGE);
    final PacketHealthChange packet = new PacketHealthChange(entity.getEntityId(), (float) entity.posX,
            (float) entity.posY + (entity.height / 2.0F), (float) entity.posZ, isCrit, (int) event.getAmount());
    Network.sendToAllAround(point, packet);
}

From source file:org.blockartistry.mod.DynSurround.client.HealthEffectHandler.java

License:MIT License

@SubscribeEvent(priority = EventPriority.LOW)
public void onLivingHurt(final LivingHurtEvent event) {
    if (event == null || event.getEntity() == null || event.getEntity().worldObj == null
            || event.getEntity().worldObj.isRemote)
        return;/*from w  w  w.  j a va2 s.c  om*/

    // Living heal should handle heals - I think..
    if (event.getAmount() <= 0 || event.getEntityLiving() == null)
        return;

    // A bit hokey - may work.
    boolean isCrit = false;
    if (event.getSource() instanceof EntityDamageSourceIndirect) {
        final EntityDamageSourceIndirect dmgSource = (EntityDamageSourceIndirect) event.getSource();
        if (dmgSource.getSourceOfDamage() instanceof EntityArrow) {
            final EntityArrow arrow = (EntityArrow) dmgSource.getSourceOfDamage();
            isCrit = arrow.getIsCritical();
        }
    } else if (event.getSource() instanceof EntityDamageSource) {
        final EntityDamageSource dmgSource = (EntityDamageSource) event.getSource();
        if (dmgSource.getSourceOfDamage() instanceof EntityPlayer) {
            final EntityPlayer player = (EntityPlayer) dmgSource.getSourceOfDamage();
            isCrit = isCritical(player, event.getEntityLiving());
        }
    }

    final HealthData data = new HealthData(event.getEntityLiving(), isCrit, (int) event.getAmount());
    Network.sendHealthUpdate(data, event.getEntity().worldObj.provider.getDimension());
}

From source file:vazkii.quark.vanity.feature.WitchHat.java

License:Creative Commons License

@SubscribeEvent
public void onDamage(LivingHurtEvent event) {
    if (halveDamage && event.getSource().getTrueSource() != null
            && event.getSource().getTrueSource() instanceof EntityWitch) {
        ItemStack hat = event.getEntityLiving().getItemStackFromSlot(EntityEquipmentSlot.HEAD);
        if (!hat.isEmpty() && hat.getItem() == witch_hat)
            event.setAmount(event.getAmount() / 2);
    }//w w  w  .  jav  a  2s.com
}