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

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

Introduction

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

Prototype

public DamageSource getSource() 

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);
        }//from   www.  j  av a 2s. com
    }
}

From source file:com.lothrazar.cyclicmagic.item.ItemFangs.java

License:Open Source License

@SubscribeEvent
public void onAttack(LivingHurtEvent event) {
    //true source is player that was holding the fang item
    //immediate source is the entity. and we check the boolean flag to make sure it was one of these, not from illager or some other spawn reason
    if (event.getSource().getImmediateSource() instanceof EntityEvokerFangs
            && UtilNBT.getEntityBoolean(event.getSource().getImmediateSource(), NBT_FANG_FROMPLAYER)) {
        event.setAmount(event.getAmount() * 2);
    }/*from w  ww . j a v  a 2  s . com*/
}

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 ww  w.ja  va 2 s . c om
    }
}

From source file:com.yyon.grapplinghook.items.LongFallBoots.java

License:Open Source License

@SubscribeEvent
public void onLivingHurtEvent(LivingHurtEvent event) {
    if (event.getEntity() != null && event.getEntity() instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.getEntity();

        for (ItemStack armor : player.getArmorInventoryList()) {
            if (armor != null && armor.getItem() instanceof LongFallBoots) {
                if (event.getSource() == DamageSource.flyIntoWall) {
                    System.out.println("Flew into wall");
                    // this cancels the fall event so you take no damage
                    event.setCanceled(true);
                }/*from  w w  w  . j a  va2 s  .c o m*/
            }
        }
    }
}

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   ww  w. java 2  s.  co  m

    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;// w  w w  .  j  a v a2  s.co  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   w  w w  .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.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:md.zazpro.mod.common.baubles.Pendant_Core.java

License:Open Source License

@SubscribeEvent(priority = EventPriority.LOWEST)
public void onHurt(LivingHurtEvent event) {
    if (event.getSource().getEntity() instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.getSource().getEntity();
        ItemStack itemStack = null;//  w  ww  .j av a2  s  .  c o m
        if (BaublesApi.getBaublesHandler(player).getStackInSlot(0) != null
                && BaublesApi.getBaublesHandler(player).getStackInSlot(0).hasTagCompound()) {
            itemStack = BaublesApi.getBaublesHandler(player).getStackInSlot(0);
            boolean Vampire = itemStack.getTagCompound().getBoolean("Vampire");
            if (Vampire) {
                if (player.getHealth() < player.getMaxHealth()
                        && this.getBSUStored(itemStack) >= ConfigurationHandler.Pendant_VAMPIRE) {
                    this.extractBSU(itemStack, ConfigurationHandler.Pendant_VAMPIRE, false);
                    player.heal(event.getAmount() / ConfigurationHandler.VampireAmount);
                }
            }
        }
    }
}

From source file:md.zazpro.mod.common.baubles.Ring_Core.java

License:Open Source License

@SubscribeEvent(priority = EventPriority.LOWEST)
public void onHurt(LivingHurtEvent event) {
    if (event.getSource().getEntity() instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.getSource().getEntity();
        ItemStack itemStack1 = BaublesApi.getBaublesHandler(player).getStackInSlot(1);
        ItemStack itemStack2 = BaublesApi.getBaublesHandler(player).getStackInSlot(2);
        if (RingUtils.isLegali(itemStack1, itemStack2, "Power")) {
            ItemStack itemStack3 = RingUtils.getStackFromBoolean(itemStack1, itemStack2, "Power");
            if (this.getBSUStored(itemStack3) >= ConfigurationHandler.Ring_POWER) {
                this.extractBSU(itemStack3, ConfigurationHandler.Ring_POWER, false);
                float power = (float) RingUtils.getIntFromBauble(itemStack1, itemStack2, "Power");
                float amount = event.getAmount() + power;
                event.setAmount(amount);
            }/*from  www  . j  a  va 2 s .  co m*/
        }
    }
}

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   w w  w . j  a  va  2 s  .  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);
}