@SubscribeEvent(priority = EventPriority.HIGHEST) public void onLivingAttack(LivingAttackEvent event) { /* * Player attacks a monster OR another player */ if (event.getSource().getTrueSource() instanceof EntityPlayer && !event.getSource().getTrueSource().getEntityWorld().isRemote) { EntityPlayer player = (EntityPlayer) event.getSource().getTrueSource(); EntityLivingBase enemy = event.getEntityLiving(); ItemStack stack = player.inventory.getCurrentItem(); PlayerInformation playerInfo = (PlayerInformation) player.getCapability(CapabilityPlayerInformation.PLAYER_INFORMATION, null); if (playerInfo != null && stack != null && stack.getItem() instanceof ItemSword && !(stack.getItem() instanceof ItemLEAdvancedMelee)) { NBTTagCompound nbt = NBTHelper.loadStackNBT(stack); if (playerInfo.getPlayerLevel() >= nbt.getInteger("Level")) { useWeaponAttributes(event.getAmount(), player, enemy, stack, nbt); } } } }
@Override public void onAttack(LivingAttackEvent event, DamageSource source, EntityLivingBase affected, int amplifier) { if (amplifier >= 3) { if (!source.isExplosion()) { BrewStorageHandler.removeActiveBrew(affected, this); affected.world.createExplosion(source.getImmediateSource(), affected.posX, affected.posY + 1.2D, affected.posZ, amplifier + 3, true); } } if (amplifier == 2) { if (!source.isExplosion()) { BrewStorageHandler.removeActiveBrew(affected, this); affected.world.createExplosion(source.getImmediateSource(), affected.posX, affected.posY + 0.7D, affected.posZ, amplifier + 2, true); } } if (!source.isExplosion()) { BrewStorageHandler.removeActiveBrew(affected, this); affected.world.createExplosion(source.getImmediateSource(), affected.posX, affected.posY + 0.5D, affected.posZ, amplifier + 1, true); } }
@SubscribeEvent public void stopHurt(LivingAttackEvent event) { if (event.getSource().getTrueSource() != null && event.getSource().getTrueSource() instanceof EntityLivingBase && (event.getSource().damageType.equals("mob") || event.getSource().damageType.equals("player"))) { EntityLivingBase damageSource = (EntityLivingBase) event.getSource().getTrueSource(); if (!TF2Util.canInteract(damageSource)) { event.setCanceled(true); } if (damageSource.hasCapability(TF2weapons.WEAPONS_CAP, null) && WeaponsCapability.get(damageSource).isDisguised()) { disguise(damageSource, false); } } if (!event.isCanceled() && event.getAmount() > 0) { /* * if(event.getEntity().getEntityData().getByte("IsCloaked")!=0){ * event.getEntity().getEntityData().setInteger("VisTicks", * Math.min(10,event.getEntity().getEntityData().getInteger( * "VisTicks"))); event.getEntity().setInvisible(false); * //System.out.println("notInvisible"); } */ event.getEntityLiving().getEntityData().setInteger("lasthit", event.getEntityLiving().ticksExisted); } }
/** * When player is morphed, he can deal an damage or effect onto the enemy. * * For example, if player is morphed into the wither skeleton, he also * grants a target wither potion effect. Pretty realistic, however I don't * really know what that does. */ @SubscribeEvent public void onPlayerAttack(LivingAttackEvent event) { Entity source = event.getSource().getEntity(); Entity target = event.getEntity(); if (source instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) source; IMorphing capability = Morphing.get(player); if (capability == null || !capability.isMorphed()) { return; } capability.getCurrentMorph().attack(target, player); } }
@SubscribeEvent public void onLivingAttackEvent(LivingAttackEvent event) { if (event.getEntity() == null || event.getSource().getEntity() != Minecraft.getMinecraft().player) return; synchronized (this.damages) { for (MobWithReward mob : this.params.getMob()) { // Have we caught one of these mobs? for (EntityTypes et : mob.getType()) { String mobName = et.value(); if (event.getEntity().getName().equals(mobName)) { if (this.damages.containsKey(mob)) this.damages.put(mob, this.damages.get(mob) + event.getAmount()); else this.damages.put(mob, event.getAmount()); } } } } }
@SubscribeEvent public void onLivingHurt(LivingAttackEvent event) { if (event.getSource() == null) return; if (event.getSource().getTrueSource() == null) return; if (event.getSource().getTrueSource() instanceof EntityLivingBase) { PotionEffect effect = ((EntityLivingBase) event.getSource().getTrueSource()).getActivePotionEffect(PotionRegistry.REDSTONE_NEEDLE); if (effect == null) return; if (effect.getAmplifier() >= 4) event.setCanceled(true); } }
@SubscribeEvent(priority = EventPriority.BOTTOM) public void onLivingAttackCallback(LivingAttackEvent event) { if (Always.isServer()) { EntityLivingBase living = event.getEntityLiving(), attacker = event.getSource().getTrueSource() instanceof EntityLivingBase ? (EntityLivingBase) event.getSource().getTrueSource() : null; if (isEquipmented(living) && !(living instanceof EntityPlayer && ((EntityPlayer) living).isCreative())) { living.getCombatTracker().lastDamageTime = living.ticksExisted; if (living instanceof EntityPlayerMP && !(living instanceof FakePlayer)) AlchemyNetworkHandler.network_wrapper.sendTo(new MessageGuardCallback(-1), (EntityPlayerMP) living); } if (attacker != null && isEquipmented(attacker)) { attacker.setLastAttackedEntity(living); if (living instanceof EntityPlayerMP && !(living instanceof FakePlayer)) AlchemyNetworkHandler.network_wrapper.sendTo(new MessageGuardCallback(living.getEntityId()), (EntityPlayerMP) attacker); } } }
@SubscribeEvent public void attackEvent (LivingAttackEvent e) { if (e.getEntityLiving().getActiveItemStack() == null) return; final ItemStack stack = e.getEntityLiving().getActiveItemStack(); if (stack.getItem() instanceof ItemCustomShield && e.getAmount() > 0.0f) { final int i = 1 + MathHelper.floor(e.getAmount()); stack.damageItem(i, e.getEntityLiving()); if (stack.stackSize <= 0) { final EnumHand enumhand = e.getEntityLiving().getActiveHand(); if (e.getEntityLiving() instanceof EntityPlayer) ForgeEventFactory.onPlayerDestroyItem((EntityPlayer) e.getEntityLiving(), stack, enumhand); e.getEntityLiving().setItemStackToSlot(enumhand == EnumHand.MAIN_HAND ? EntityEquipmentSlot.MAINHAND : EntityEquipmentSlot.OFFHAND, null); if (e.getEntityLiving().getEntityWorld().isRemote) e.getEntityLiving().playSound(SoundEvents.BLOCK_ANVIL_BREAK, 0.8F, 0.8F + e.getEntityLiving().getEntityWorld().rand.nextFloat() * 0.4F); } } }
@SubscribeEvent public void onPlayerHurt(LivingAttackEvent event) { if(FMLCommonHandler.instance().getEffectiveSide().isClient()) { return; } if(!(event.entity instanceof EntityPlayer)) { return; } EntityPlayer player = (EntityPlayer)event.entity; ItemStack itemstack = player.inventory.armorItemInSlot(2); if(itemstack == null || event.source.equals(DamageSource.outOfWorld)) { event.setCanceled(false); return; } if(ElectricItem.manager.canUse(itemstack, 1000.0D)) { event.setCanceled(true); } }
@SubscribeEvent public void onLivingAttack(LivingAttackEvent evt) { if (evt.getEntity() instanceof EntityPlayer && evt.getSource() instanceof EntityDamageSource) { EntityDamageSource source = (EntityDamageSource) evt.getSource(); if (source.getEntity() instanceof EntityPlayer) { EntityPlayer attacker = (EntityPlayer) source.getEntity(); EntityPlayer damagee = (EntityPlayer) evt.getEntity(); ItemStack attackerBoots = attacker.inventory.armorItemInSlot(0); ItemStack damageeBoots = damagee.inventory.armorItemInSlot(0); if (attackerBoots != null && damageeBoots != null && attackerBoots == damageeBoots) { Item id = damageeBoots.getItem(); if (id == WarsItems.redBoots || id == WarsItems.greenBoots || id == WarsItems.blueBoots || id == WarsItems.yellowBoots) { evt.setCanceled(true); } } } } }
@SubscribeEvent public void onEntityAttacked(LivingAttackEvent event) { EntityLivingBase base = event.entityLiving; if(base.getEquipmentInSlot(4) != null && base.getEquipmentInSlot(4).getItem() instanceof ItemGasMask) { ItemGasMask mask = (ItemGasMask)base.getEquipmentInSlot(4).getItem(); if(base.getEquipmentInSlot(3) != null && base.getEquipmentInSlot(3).getItem() instanceof ItemScubaTank) { ItemScubaTank tank = (ItemScubaTank)base.getEquipmentInSlot(3).getItem(); if(tank.getFlowing(base.getEquipmentInSlot(3)) && tank.getGas(base.getEquipmentInSlot(3)) != null) { if(event.source == DamageSource.magic) { event.setCanceled(true); } } } } }
@SubscribeEvent public void onEntityAttacked(LivingAttackEvent event) { EntityLivingBase base = event.entityLiving; if(base.getEquipmentInSlot(1) != null && base.getEquipmentInSlot(1).getItem() instanceof ItemFreeRunners) { ItemStack stack = base.getEquipmentInSlot(1); ItemFreeRunners boots = (ItemFreeRunners)stack.getItem(); if(boots.getEnergy(stack) > 0 && event.source == DamageSource.fall) { boots.setEnergy(stack, boots.getEnergy(stack)-event.ammount*50); event.setCanceled(true); } } }
@SubscribeEvent public void attackedEntity(LivingAttackEvent event) { if (event.getSource().getEntity() instanceof EntityPlayerMP && event.getSource().damageType.equals("player") && Settings.Silly.moonPhasesOPPlzNerf) { EntityPlayerMP player = (EntityPlayerMP) event.getSource().getEntity(); if (player.getHeldItemMainhand() != null && player.getHeldItemMainhand().getItem() instanceof IMoonDamage && event.getEntityLiving().getHealth() > 0) { event.setCanceled(true); if (!player.worldObj.isRemote) { event.getEntity().attackEntityFrom(new MoonModifierDamageSource("moonModifier", player), getMoonDamage(player.worldObj.getCurrentMoonPhaseFactor(), event.getAmount())); int itemDamage = player.getHeldItemMainhand().getItemDamage() + 1; player.getHeldItemMainhand().getItem().setDamage(player.getHeldItemMainhand(), itemDamage); } } } }
@SubscribeEvent public void entityAttacked(LivingAttackEvent event) { if (event.source.getEntity() instanceof EntityPlayerMP) { EntityPlayerMP player = (EntityPlayerMP) event.source.getEntity(); if (!player.isEntityEqual(event.entity) && isWearingNincodiumArmorSet(player) && isHealingChanceSuccessful(player)) { EntityPlayerMP closestPlayer = getClosestPlayerToEntityWithLeastHealth(player, Settings.Armor.nincodiumArmorHealingRadius); if (closestPlayer != null && event.entityLiving.getHealth() > 0 && closestPlayer.getHealth() < closestPlayer.getMaxHealth()) { float healed = event.ammount * Settings.Armor.nincodiumArmorHealingPercentage; closestPlayer.setHealth(closestPlayer.getHealth() + (healed)); if (!closestPlayer.worldObj.isRemote) { closestPlayer.worldObj.playSoundEffect(closestPlayer.posX, closestPlayer.posY, closestPlayer.posZ, Names.Sounds.HEALING, 1, 2); } } } } }
@ForgeSubscribe public void onAttack(LivingAttackEvent event) { Entity source = event.source.getSourceOfDamage(); if(source != null && source instanceof EntityLiving && !event.source.isProjectile()) { EntityLiving attacker = (EntityLiving)source; PotionEffect affliction = attacker.getActivePotionEffect(Potion.confusion); if(affliction != null) { Random rand = attacker.getRNG(); int tier = affliction.getAmplifier(); if(rand.nextInt(5) <= tier) { event.setCanceled(true); } } } }
@SubscribeEvent public void onLivingAttack(LivingAttackEvent event) { if (stoppedDamageSources.keySet().contains(event.source.damageType) && SprinklesForVanilla.isOnServer) { int value = stoppedDamageSources.get(event.source.damageType); switch(value) { case 1: if (!(event.entity instanceof EntityPlayer)) break; case 2: event.setCanceled(true); break; default: LogHelper.warn("Found incorrect value in stoppedDamageSources: " + event.source.damageType + ", " + value); break; } } }
@SubscribeEvent public void RandomTeleport(LivingAttackEvent event) { if (event.source.getEntity() instanceof EntityPlayer) { EntityPlayer attacker = (EntityPlayer) event.source.getEntity(); Entity defender = event.entity; World world = event.entity.worldObj; if (world.isRemote) return; if (event.source.getEntity() == null) return; if (!(event.source.getEntity() instanceof EntityPlayer)) return; if (attacker.getHeldItem() == null) return; if (!attacker.getHeldItem().isItemEnchanted()) ; if (!(EnchantmentHelper.getEnchantments(attacker.getHeldItem()).containsKey(EnchantRegistry.randTeleEnchant.effectId))) return; teleport(world, defender); } }
@SubscribeEvent public void onLivingAttack(LivingAttackEvent event) { if (event.entity.worldObj.isRemote) { return; } Entity damagesource = event.source.getSourceOfDamage(); EntityLivingBase damager = null; if (damagesource instanceof EntityLivingBase) { damager = (EntityLivingBase)damagesource; } if (damager != null) { if (damager instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer)damager; if (player.getHeldItem() != null) { doTriggerOnDealDamage(player.getHeldItem(), event.entityLiving, player); } } else { ItemStack stack = damager.getEquipmentInSlot(0); if (stack != null) { doTriggerOnDealDamage(stack, event.entityLiving, damager); } } } }
@SubscribeEvent public void onLivingAttack(LivingAttackEvent event) { EntityLivingBase entityLiving = event.entityLiving; if ((event.source != null && event.source == DamageSource.lava || event.source == DamageSource.inFire || event.source == DamageSource.onFire) && (hasEquippedSet(entityLiving, ModArmor.fireHelmet, ModArmor.fireChest, ModArmor.fireLeggings, ModArmor.fireBoots) || hasEquippedSet(entityLiving, ModArmor.chaosHelmet, ModArmor.chaosChest, ModArmor.chaosLeggings, ModArmor.chaosBoots) || hasEquippedSet( entityLiving, ModArmor.orderHelmet, ModArmor.orderChest, ModArmor.orderLeggings, ModArmor.orderBoots))) { event.setCanceled(true); entityLiving.extinguish(); } }
@SubscribeEvent public void onLivingAttackEvent(LivingAttackEvent event) { if (spidersApplySlowness) { if (event.getSource().getDamageType().equals("mob") && event.getSource().getEntity() instanceof EntitySpider) { event.getEntityLiving() .addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 200, 1)); } } if (replaceCaveSpiderPoison) { if (event.getSource().getDamageType().equals("mob") && event.getSource().getEntity() instanceof EntityCaveSpider) { poisonedEntities.add(event.getEntityLiving()); } } }
@SubscribeEvent public void onLivingAttack(LivingAttackEvent event){ if(DifficultyManager.enabled) { Entity causeMob = event.getSource().getTrueSource(); if (causeMob instanceof EntityLiving && event.getEntity() instanceof EntityPlayer && MobNBTHandler.isModifiedMob((EntityLiving) causeMob)) { Map<String, Integer> changes = MobNBTHandler.getChangeMap((EntityLiving) causeMob); String regionName = MobNBTHandler.getEntityRegion((EntityLiving) causeMob); Region mobRegion = DifficultyManager.getRegionByName(regionName); String mobId = EntityList.getEntityString(causeMob); for (String change : changes.keySet()) { try { DifficultyModifier modifier = mobRegion.getModifierForMobById(mobId, change); if (modifier != null) { modifier.handleDamageEvent(event); } } catch (Exception e) { LOG.warn("Error applying modifier at onLivingAttack. Mob was " + causeMob.getName() + ", Modifier was " + change + ". Please report to Progressive Difficulty Developer!"); LOG.warn("\tCaught Exception had message " + e.getMessage()); } } } else if (event.getSource().getImmediateSource() instanceof PotionCloudModifier.PlayerEffectingOnlyEntityAreaEffectCloud && !(event.getEntity() instanceof EntityPlayer)) { event.setCanceled(true); } } }
@Override public void handleDamageEvent(LivingAttackEvent event) { super.handleDamageEvent(event); if(!(event.getEntity() instanceof EntityLivingBase)) return; EntityLivingBase hitEntity = (EntityLivingBase)event.getEntity(); EntityLiving cause = (EntityLiving)event.getSource().getTrueSource(); int level = MobNBTHandler.getModifierLevel(cause,identifier); hitEntity.addPotionEffect(new PotionEffect(effect, duration,level,false,false)); }
@Override public void handleDamageEvent(LivingAttackEvent event){ EntityLiving attackingMob = (EntityLiving)event.getSource().getTrueSource(); int level = MobNBTHandler.getModifierLevel(attackingMob,IDENTIFIER); float damage = event.getAmount(); float healDamage = damage * 0.2f * level; attackingMob.heal(healDamage); }
@SubscribeEvent public void livingAttack(LivingAttackEvent event) { if (event.source instanceof EntityDamageSourceIndirect) { EntityDamageSourceIndirect dmgSrc = (EntityDamageSourceIndirect) event.source; if (dmgSrc.getSourceOfDamage() instanceof EntityTippedArrow) { EntityTippedArrow tippedArrow = (EntityTippedArrow) dmgSrc.getSourceOfDamage(); if (!tippedArrow.worldObj.isRemote) event.entityLiving.addPotionEffect(tippedArrow.getEffect()); } } }
@SubscribeEvent(priority=EventPriority.LOWEST) public void onEntityAttack(LivingAttackEvent e) { if (e.getEntity().getEntityWorld().isRemote) return; 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 }
@SubscribeEvent public void autoShield(LivingAttackEvent event) { if (!(event.getEntityLiving() instanceof EntityPlayer)) return; if (!(event.getSource().getSourceOfDamage() instanceof EntityArrow)) return; ItemStack shield = ((EntityPlayer)event.getEntityLiving()).getHeldItemOffhand(); ItemStack emblem = BaublesApi.getBaublesHandler((EntityPlayer)event.getEntityLiving()).getStackInSlot(6); if (shield == null || emblem == null) return; if (emblem.getItem() != this || !(shield.getItem() instanceof ItemShield)) return; shield.attemptDamageItem(1, event.getEntityLiving().worldObj.rand); event.setCanceled(true); }
@SubscribeEvent public void onLivingAttack(LivingAttackEvent e) { EntityLivingBase attacked = e.getEntityLiving(); EntityLivingBase attacker = attacked.getAttackingEntity(); if(attacker == null) return; damageShield(attacked, attacker, e.getAmount()); doAxeStuff(attacked, attacker); }
/** Damage the advanced shield correctly, as vanilla code only works for the vanilla shield */ @SubscribeEvent public void onShieldedAttack(LivingAttackEvent e) { EntityLivingBase guy = e.getEntityLiving(); if(!guy.world.isRemote && guy instanceof EntityPlayer) { if(e.getAmount() > 0.0F && !guy.getActiveItemStack().isEmpty() && guy.getActiveItemStack().getItem() instanceof ItemShieldAdvanced) { if(this.canBlockDamageSource((EntityPlayer)guy, e.getSource())) { this.damageShield((EntityPlayer)guy, e.getAmount()); } } } }
@SubscribeEvent public void onLivingAttack(LivingAttackEvent event) { if (event.getSource() != null && event.getSource().getTrueSource() != null) { if (event.getSource().getTrueSource() instanceof EntityLivingBase && ((EntityLivingBase)event.getSource().getTrueSource()).isPotionActive(ExPPotions.stunned)) { event.setCanceled(true); } } }
@SubscribeEvent public void onAttack(LivingAttackEvent event) { if (event.getEntityLiving() instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) event.getEntityLiving(); PossessivePlayer possessivePlayer = PossessHandler.get(player); if (possessivePlayer != null) { if (event.getSource().isFireDamage()) { event.setCanceled(true); } else { possessivePlayer.getPossessing().attackEntityFrom(event.getSource(), event.getAmount()); event.setCanceled(true); if (!player.capabilities.isCreativeMode && !event.getSource().canHarmInCreative() && possessivePlayer.getPossessing().hurtTime <= 0) { this.playPossessedHurtAnimation(player); } } } } else { EntityPlayer possessor = PossessHandler.getPossesor(event.getEntityLiving()); if (possessor != null) { if (possessor.capabilities.isCreativeMode && !event.getSource().canHarmInCreative()) { event.setCanceled(true); } else if (possessor.hurtTime <= 0) { this.playPossessedHurtAnimation(possessor); } } } }
@SubscribeEvent public void livingAttacked(LivingAttackEvent event) { if (!event.getEntityLiving().world.isRemote) { if (!event.isCanceled() && event.getAmount() > 0) { EntityLivingBase living = event.getEntityLiving(); if (living.isPotionActive(ModPotions.cannonball) && (event.getSource().isExplosion() || event.getSource() == DamageSource.FALL)) { if (event.getSource() == DamageSource.FALL) //No you don't get to have superbuffs that make you immune to creepers and falldamage. living.removePotionEffect(ModPotions.cannonball); event.setCanceled(true); } } } }
@SubscribeEvent public void onPlayerDamaged(LivingAttackEvent event){ event.getEntityLiving().getEntityWorld(); EntityLivingBase attacked = event.getEntityLiving(); DamageSource source = event.getSource(); int pureCount = getArmorCount(attacked, "pure"); if(getArmorCount(attacked, "red") == 4 || pureCount == 4){ if(source == DamageSource.HOT_FLOOR){ event.setCanceled(true); } } if(getArmorCount(attacked, "dark") == 4 || pureCount == 4){ if(source.getSourceOfDamage() !=null){ Entity toAttack = source.getSourceOfDamage(); toAttack.attackEntityFrom(DamageSource.causeThornsDamage(attacked), EnchantmentThorns.getDamage(5, EntityUtil.rand)); if(toAttack instanceof EntityLivingBase){ EntityLivingBase living = (EntityLivingBase)toAttack; if(EntityUtil.rand.nextInt(10) == 0){ living.addPotionEffect(new PotionEffect(MobEffects.WITHER, MathHelper.getInt(EntityUtil.rand, 20*3, 20*6), 0)); } } } } /*if(source == DamageSource.FALL){ BlockPos pos = new BlockPos(attacked).down(); IBlockState state = world.getBlockState(pos); if (state.getBlock() instanceof BlockLiquid && attacked.posY > pos.getY() + 0.9 && !(world.getBlockState(pos.up()).getBlock().getMaterial(world.getBlockState(pos.up())) == Material.WATER)) { if(UpgradeItemRecipe.isWaterWalking(attacked.getItemStackFromSlot(EntityEquipmentSlot.FEET))){ world.playSound(null, pos, SoundEvents.ENTITY_PLAYER_SPLASH, SoundCategory.PLAYERS, 1.0F, 1.0F); event.setCanceled(true); } } }*/ }
@SubscribeEvent public void onAttacked(LivingAttackEvent event) { if(event.getSource() != null) { Entity attacker = event.getSource().getEntity(); if(attacker != null && attacker instanceof EntityMinionWarrior && attacker.getRidingEntity() == event.getEntityLiving()) event.setCanceled(true); } }
@SubscribeEvent public void onLivingAttack(LivingAttackEvent event) { if (event.getEntityLiving() instanceof EntityPlayer) { PlayerAether playerAether = PlayerAether.get((EntityPlayer) event.getEntityLiving()); if (playerAether != null) { event.setCanceled(playerAether.onPlayerAttacked(event.getSource())); } } }
@SubscribeEvent public void onLivingHurt(LivingAttackEvent event) { if (event.getSource() == null) return; if (event.getSource().getTrueSource() == null) return; if (event.getSource().getTrueSource() instanceof EntityLivingBase) { PotionEffect effect = ((EntityLivingBase) event.getSource().getTrueSource()).getActivePotionEffect(PotionRegistry.STUN); if (effect == null) return; event.setCanceled(true); } }
@SubscribeEvent(priority = EventPriority.HIGH) public void onLivingAttack(LivingAttackEvent event) { if (Always.isServer() && isEquipmented(event.getEntityLiving()) && isCDOver(event.getEntityLiving())) { AlchemyEventSystem.markEventCanceled(event); EntityLivingBase source = event.getSource().getTrueSource() instanceof EntityLivingBase ? (EntityLivingBase) event.getSource().getTrueSource() : null; if (source != null) source.attackEntityFrom(AlchemyDamageSourceLoader.dead_magic, event.getAmount()); EntityLivingBase living = event.getEntityLiving(); living.getCombatTracker().lastDamageTime = living.ticksExisted; if (living instanceof EntityPlayerMP && !(living instanceof FakePlayer)) AlchemyNetworkHandler.network_wrapper.sendTo(new MessageGuardCallback(-1), (EntityPlayerMP) living); } }
/** Alters behaviour when the player takes damage. */ @SubscribeEvent 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); } } } }
@SubscribeEvent public boolean onLivingAttackEvent(LivingAttackEvent event) { if ((event.entityLiving instanceof EntityPlayer) && (event.source == DamageSource.drown)) { event.entityLiving.setHealth(0.5F); return true; } return false; }
@SubscribeEvent public void onDamageRender(LivingAttackEvent e) { if (e.getEntityLiving() instanceof EntityPlayer) { if (e.getSource() == DamageSource.MAGIC) { e.setCanceled(false); return; } } }
@SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true) public void onLivingHurt(LivingAttackEvent event) { // if it's cancelled it got handled by the battlesign (or something else. but it's a prerequisite.) if(!event.isCanceled()) { return; } if(event.getSource().isUnblockable() || !event.getSource().isProjectile() || event.getSource().getTrueSource() == null) { return; } // hit entity is a player? if(!(event.getEntity() instanceof EntityPlayer)) { return; } EntityPlayer player = (EntityPlayer) event.getEntity(); // needs to be blocking with a battlesign if(!player.isActiveItemStackBlocking() || player.getActiveItemStack().getItem() != TinkerMeleeWeapons.battleSign) { return; } // broken battlesign. if(ToolHelper.isBroken(player.getActiveItemStack())) { return; } // at this point we duplicated all the logic if the battlesign should reflect a projectile.. bleh. int xp = Math.max(1, Math.round(event.getAmount())); addXp(player.getActiveItemStack(), xp, player); }