@SubscribeEvent public void onAttackEntity(AttackEntityEvent event) { if (event.getTarget() instanceof EntityLivingBase == false) { return; } EntityLivingBase target = (EntityLivingBase) event.getTarget(); EntityPlayer attacker = event.getEntityPlayer(); ItemStack main = attacker.getHeldItemMainhand(); ItemStack off = attacker.getHeldItemOffhand(); int mainLevel = -1, offLevel = -1; if (main != null && EnchantmentHelper.getEnchantments(main).containsKey(this)) { mainLevel = EnchantmentHelper.getEnchantments(main).get(this); } if (off != null && EnchantmentHelper.getEnchantments(off).containsKey(this)) { offLevel = EnchantmentHelper.getEnchantments(off).get(this); } int level = Math.max(mainLevel, offLevel); if (level > 0) { // we -1 since potion level 1 is Poison II // so that means enchantment I giving poison I means this UtilEntity.addOrMergePotionEffect( target, new PotionEffect(MobEffects.POISON, durationTicksPerLevel * level, level - 1)); } }
@SubscribeEvent public void onAttackEntity(AttackEntityEvent event) { if (event.entityLiving.worldObj.isRemote) return; EntityLivingBase attacker = event.entityLiving; EntityPlayer player = event.entityPlayer; Entity target = event.target; ItemStack stack = attacker.getEquipmentInSlot(0); if (stack != null && stack.getItem().onLeftClickEntity(stack, player, target)) return; if (target.canAttackWithItem()) { if (!target.hitByEntity(target)) { float damageAmount = TFC_MobData.STEVE_DAMAGE; if (stack != null) { damageAmount = (float) player .getEntityAttribute(SharedMonsterAttributes.attackDamage) .getAttributeValue(); // player.addChatMessage("Damage: " + i); if (damageAmount == 1.0f) { damageAmount = TFC_MobData.STEVE_DAMAGE; // i = player.inventory.getCurrentItem().getItem().getDamageVsEntity(target, // player.inventory.getCurrentItem()); } } if (player.isPotionActive(Potion.damageBoost)) damageAmount += 3 << player.getActivePotionEffect(Potion.damageBoost).getAmplifier(); if (player.isPotionActive(Potion.weakness)) damageAmount -= 2 << player.getActivePotionEffect(Potion.weakness).getAmplifier(); int knockback = 0; float enchantmentDamage = 0; if (target instanceof EntityLiving) { enchantmentDamage = EnchantmentHelper.getEnchantmentModifierLiving(player, (EntityLiving) target); knockback += EnchantmentHelper.getKnockbackModifier(player, (EntityLiving) target); } if (player.isSprinting()) ++knockback; if (damageAmount > 0 || enchantmentDamage > 0) { boolean criticalHit = player.fallDistance > 0.0F && !player.onGround && !player.isOnLadder() && !player.isInWater() && !player.isPotionActive(Potion.blindness) && player.ridingEntity == null && target instanceof EntityLiving; if (criticalHit && damageAmount > 0) damageAmount += event.entity.worldObj.rand.nextInt((int) (damageAmount / 2 + 2)); damageAmount += enchantmentDamage; boolean onFire = false; int fireAspect = EnchantmentHelper.getFireAspectModifier(player); if (target instanceof EntityLiving && fireAspect > 0 && !target.isBurning()) { onFire = true; target.setFire(1); } boolean entityAttacked = target.attackEntityFrom(DamageSource.causePlayerDamage(player), damageAmount); if (entityAttacked) { if (knockback > 0) { target.addVelocity( -MathHelper.sin(player.rotationYaw * (float) Math.PI / 180.0F) * knockback * 0.5F, 0.1D, MathHelper.cos(player.rotationYaw * (float) Math.PI / 180.0F) * knockback * 0.5F); player.motionX *= 0.6D; player.motionZ *= 0.6D; player.setSprinting(false); } if (criticalHit) player.onCriticalHit(target); if (enchantmentDamage > 0) player.onEnchantmentCritical(target); if (damageAmount >= 18) player.triggerAchievement(AchievementList.overkill); player.setLastAttacker(target); if (target instanceof EntityLiving) target.attackEntityFrom(DamageSource.causeThornsDamage(attacker), damageAmount); } ItemStack itemstack = player.getCurrentEquippedItem(); Object object = target; if (target instanceof EntityDragonPart) { IEntityMultiPart ientitymultipart = ((EntityDragonPart) target).entityDragonObj; if (ientitymultipart instanceof EntityLiving) object = ientitymultipart; } if (itemstack != null && object instanceof EntityLiving) { itemstack.hitEntity((EntityLiving) object, player); if (itemstack.stackSize <= 0) player.destroyCurrentEquippedItem(); } if (target instanceof EntityLivingBase) { player.addStat(StatList.damageDealtStat, Math.round(damageAmount * 10.0f)); if (fireAspect > 0 && entityAttacked) target.setFire(fireAspect * 4); else if (onFire) target.extinguish(); } player.addExhaustion(0.3F); } } } event.setCanceled(true); }