List of usage examples for net.minecraftforge.event.entity.living LivingHurtEvent getEntity
public Entity getEntity()
From source file:com.gmail.socraticphoenix.forge.randore.RandoresInvulnerabilityListener.java
License:Open Source License
@SubscribeEvent public void onDamage(LivingHurtEvent ev) { synchronized (playerMap) { if (ev.getEntity() instanceof EntityPlayer && playerMap.containsKey(ev.getEntity().getUniqueID())) { ev.setCanceled(true);//from w ww . j a v a 2s . c o m } } }
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); }/* ww w. j av a 2s .com*/ } } } }
From source file:de.sanandrew.mods.turretmod.event.DamageEventHandler.java
License:Creative Commons License
@SubscribeEvent public void onDamage(LivingHurtEvent event) { if (event.getEntity() instanceof EntityTurret) { IUpgradeProcessor proc = ((EntityTurret) event.getEntity()).getUpgradeProcessor(); if (proc.hasUpgrade(Upgrades.SHIELD_PERSONAL)) { ShieldPersonal upgInst = proc.getUpgradeInstance(Upgrades.SHIELD_PERSONAL); float restDmg = upgInst.damage(event.getAmount()); if (restDmg <= 0.0F) { event.setCanceled(true); } else { event.setAmount(restDmg); }//from w ww . j av a 2s . c o m proc.syncUpgrade(Upgrades.SHIELD_PERSONAL); } } }
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;/* w w w. j av a2 s .com*/ 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: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. ja v a2 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); }
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 v a 2 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()); }