/**
* Attacks for the player the targeted entity with the currently equipped item. The equipped item has hitEntity
* called on it. Args: targetEntity
*/
public void attackTargetEntityWithCurrentItem(Entity targetEntity)
{
if (targetEntity.canAttackWithItem())
{
if (!targetEntity.hitByEntity(this))
{
float f = (float)this.getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue();
int i = 0;
float f1 = 0.0F;
if (targetEntity instanceof EntityLivingBase)
{
f1 = EnchantmentHelper.func_152377_a(this.getHeldItem(), ((EntityLivingBase)targetEntity).getCreatureAttribute());
}
else
{
f1 = EnchantmentHelper.func_152377_a(this.getHeldItem(), EnumCreatureAttribute.UNDEFINED);
}
i = i + EnchantmentHelper.getKnockbackModifier(this);
if (this.isSprinting())
{
++i;
}
if (f > 0.0F || f1 > 0.0F)
{
boolean flag = this.fallDistance > 0.0F && !this.onGround && !this.isOnLadder() && !this.isInWater() && !this.isPotionActive(Potion.blindness) && this.ridingEntity == null && targetEntity instanceof EntityLivingBase;
if (flag && f > 0.0F)
{
f *= 1.5F;
}
f = f + f1;
boolean flag1 = false;
int j = EnchantmentHelper.getFireAspectModifier(this);
if (targetEntity instanceof EntityLivingBase && j > 0 && !targetEntity.isBurning())
{
flag1 = true;
targetEntity.setFire(1);
}
double d0 = targetEntity.motionX;
double d1 = targetEntity.motionY;
double d2 = targetEntity.motionZ;
boolean flag2 = targetEntity.attackEntityFrom(DamageSource.causePlayerDamage(this), f);
if (flag2) {
final KnockbackModifierEvent knockbackModifierEvent = new KnockbackModifierEvent(i > 0).publishItself();
float yaw = this.rotationYaw;
if(this == Minecraft.getMinecraft().thePlayer)
yaw = PlayerHandler.yaw;
if (knockbackModifierEvent.isFlag()) {
targetEntity.addVelocity((double) (-MathHelper.sin(yaw * (float) Math.PI / 180.0F) * (float) i * 0.5F), 0.1D, (double) (MathHelper.cos(yaw * (float) Math.PI / 180.0F) * (float) i * 0.5F));
this.motionX *= 0.6D;
this.motionZ *= 0.6D;
this.setSprinting(false);
}
if (targetEntity instanceof EntityPlayerMP && targetEntity.velocityChanged)
{
((EntityPlayerMP)targetEntity).playerNetServerHandler.sendPacket(new S12PacketEntityVelocity(targetEntity));
targetEntity.velocityChanged = false;
targetEntity.motionX = d0;
targetEntity.motionY = d1;
targetEntity.motionZ = d2;
}
if (flag)
{
this.onCriticalHit(targetEntity);
}
if (f1 > 0.0F)
{
this.onEnchantmentCritical(targetEntity);
}
if (f >= 18.0F)
{
this.triggerAchievement(AchievementList.overkill);
}
this.setLastAttacker(targetEntity);
if (targetEntity instanceof EntityLivingBase)
{
EnchantmentHelper.applyThornEnchantments((EntityLivingBase)targetEntity, this);
}
EnchantmentHelper.applyArthropodEnchantments(this, targetEntity);
ItemStack itemstack = this.getCurrentEquippedItem();
Entity entity = targetEntity;
if (targetEntity instanceof EntityDragonPart)
{
IEntityMultiPart ientitymultipart = ((EntityDragonPart)targetEntity).entityDragonObj;
if (ientitymultipart instanceof EntityLivingBase)
{
entity = (EntityLivingBase)ientitymultipart;
}
}
if (itemstack != null && entity instanceof EntityLivingBase)
{
itemstack.hitEntity((EntityLivingBase)entity, this);
if (itemstack.stackSize <= 0)
{
this.destroyCurrentEquippedItem();
}
}
if (targetEntity instanceof EntityLivingBase)
{
this.addStat(StatList.damageDealtStat, Math.round(f * 10.0F));
if (j > 0)
{
targetEntity.setFire(j * 4);
}
}
this.addExhaustion(0.3F);
}
else if (flag1)
{
targetEntity.extinguish();
}
}
}
}
}