List of usage examples for net.minecraftforge.event.entity.living LivingAttackEvent getSource
public DamageSource getSource()
From source file:blusunrize.immersiveengineering.common.items.ItemIEShield.java
public void hitShield(ItemStack stack, EntityPlayer player, DamageSource source, float amount, LivingAttackEvent event) { if (getUpgrades(stack).getBoolean("flash") && getUpgrades(stack).getInteger("flash_cooldown") <= 0) { Vec3d look = player.getLookVec(); //Offsets Player position by look backwards, then truncates cone at 1 List<EntityLivingBase> targets = Utils.getTargetsInCone(player.getEntityWorld(), player.getPositionVector().subtract(look), player.getLookVec().scale(9), 1.57079f, .5f); for (EntityLivingBase t : targets) if (!player.equals(t)) { t.addPotionEffect(new PotionEffect(IEPotions.flashed, 100, 1)); if (t instanceof EntityLiving) ((EntityLiving) t).setAttackTarget(null); }// w w w . ja v a 2 s . c o m getUpgrades(stack).setInteger("flash_cooldown", 40); } if (getUpgrades(stack).getBoolean("shock") && getUpgrades(stack).getInteger("shock_cooldown") <= 0) { boolean b = false; if (event.getSource().isProjectile() && event.getSource().getImmediateSource() != null) { Entity projectile = event.getSource().getImmediateSource(); projectile.setDead(); event.setCanceled(true); b = true; } if (event.getSource().getTrueSource() != null && event.getSource().getTrueSource() instanceof EntityLivingBase && event.getSource().getTrueSource().getDistanceSq(player) < 4) { ElectricDamageSource dmgsrc = IEDamageSources.causeTeslaDamage(1, true); dmgsrc.apply(event.getSource().getTrueSource()); b = true; } if (b) { getUpgrades(stack).setInteger("shock_cooldown", 40); player.world.playSound(null, player.posX, player.posY, player.posZ, IESounds.spark, SoundCategory.BLOCKS, 2.5F, 0.5F + Utils.RAND.nextFloat()); } } }
From source file:com.crowsofwar.avatar.common.bending.air.AirbendingEvents.java
License:Open Source License
@SubscribeEvent public void airBubbleShield(LivingAttackEvent e) { World world = e.getEntity().worldObj; if (!world.isRemote && e.getEntity() instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) e.getEntity(); AvatarPlayerData data = AvatarPlayerData.fetcher().fetch(player); if (data.hasStatusControl(StatusControl.BUBBLE_CONTRACT)) { List<EntityAirBubble> entities = player.worldObj.getEntitiesWithinAABB(EntityAirBubble.class, player.getEntityBoundingBox(), bubble -> bubble.getOwner() == player); for (EntityAirBubble bubble : entities) { DamageSource source = e.getSource(); Entity entity = source.getEntity(); if (entity != null && (entity instanceof AvatarEntity || entity instanceof EntityArrow)) { entity.setDead();/*from w w w . j a va 2 s .co m*/ data.getAbilityData(ABILITY_AIR_BUBBLE).addXp(SKILLS_CONFIG.airbubbleProtect); bubble.setHealth(bubble.getHealth() - e.getAmount()); e.setCanceled(true); } } } } }
From source file:com.elytradev.thermionics.Thermionics.java
License:Open Source License
@SubscribeEvent(priority = EventPriority.LOWEST) public void onEntityAttack(LivingAttackEvent e) { if (e.getEntity().getEntityWorld().isRemote) return;/*from w w w.j a v a 2s .c o m*/ Entity attacker = e.getSource().getTrueSource(); if (attacker == null) return; //It's probably just some bat dying in lava if (attacker.hasCapability(CAPABILITY_WEAPONSKILL, EnumFacing.UP)) { IWeaponSkillInfo skillInfo = attacker.getCapability(CAPABILITY_WEAPONSKILL, EnumFacing.UP); if (skillInfo.getCooldown() <= 0) { //Search for activations if (attacker instanceof EntityLivingBase) { //Tool activations if (e.getSource().damageType.equals("player")) { ItemStack weapon = ((EntityLivingBase) attacker) .getHeldItem(((EntityLivingBase) attacker).getActiveHand()); if (weapon.getItem() instanceof ISkillActivating) { int activated = ((ISkillActivating) weapon.getItem()).activateSkill(skillInfo, (EntityLivingBase) attacker, weapon, e.getSource(), (EntityLiving) e.getEntityLiving()); if (activated > 0) { // TODO: Stats? Advancements? skillInfo.setCooldown(activated); } } } } } } //TODO: Check the defender for armor WeaponSkills }
From source file:daxum.temporalconvergence.EventHandler.java
License:Open Source License
@SubscribeEvent public static void LivingAttacked(LivingAttackEvent event) { if (!event.getEntity().world.isRemote && event.getEntity() instanceof EntityPlayer && ItemPhaseClothChest.isWearingArmor((EntityPlayer) event.getEntity())) { event.setCanceled(ItemPhaseClothChest.onHit((EntityPlayer) event.getEntityLiving(), event.getSource())); }/*from ww w .j a v a 2s . c om*/ }
From source file:jayavery.geomastery.main.PlayerEvents.java
License:Open Source License
/** Alters behaviour when the player takes damage. */ @SubscribeEvent/* w w w . j a v a2s. c o m*/ public void playerAttacked(LivingAttackEvent event) { if (!(event.getEntity() instanceof EntityPlayer)) { return; } EntityPlayer player = (EntityPlayer) event.getEntity(); DamageSource source = event.getSource(); // Copy vanilla shield functionality to allow for custom shields if (!source.isUnblockable() && player.isActiveItemStackBlocking() && player.getActiveItemStack().getItem() instanceof ItemShield) { Vec3d sourceVec = source.getDamageLocation(); if (sourceVec != null) { Vec3d playerVec = player.getLook(1.0F); Vec3d attackVec = sourceVec.subtractReverse(new Vec3d(player.posX, player.posY, player.posZ)) .normalize(); attackVec = new Vec3d(attackVec.xCoord, 0.0D, attackVec.zCoord); if (attackVec.dotProduct(playerVec) < 0.0D && event.getAmount() >= 3) { player.getActiveItemStack().damageItem(1 + MathHelper.floor(event.getAmount()), player); } } } }
From source file:vazkii.quark.tweaks.feature.ArrowSafeMobs.java
License:Creative Commons License
@SubscribeEvent public void onAttacked(LivingAttackEvent event) { if (event.getSource() != null) { Entity attacker = event.getSource().getEntity(); if (attacker != null && attacker.getRidingEntity() == event.getEntity()) event.setCanceled(true);/*from w w w . j a v a 2s. c o m*/ } }