@Override public boolean attackEntityAsMob(Entity victim) { float attackDamage = (float) getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue(); int knockback = 0; if (victim instanceof EntityLivingBase) { attackDamage += EnchantmentHelper.getEnchantmentModifierLiving(this, (EntityLivingBase) victim); knockback += EnchantmentHelper.getKnockbackModifier(this, (EntityLivingBase) victim); } boolean attacked = victim.attackEntityFrom(DamageSource.causeMobDamage(this), attackDamage); if (attacked) { if (knockback > 0) { double vx = -Math.sin(Math.toRadians(rotationYaw)) * knockback * 0.5; double vy = 0.1; double vz = Math.cos(Math.toRadians(rotationYaw)) * knockback * 0.5; victim.addVelocity(vx, vy, vz); motionX *= 0.6; motionZ *= 0.6; } if (victim instanceof EntityLivingBase) { // EnchantmentThorns.func_92096_a(this, (EntityLivingBase) victim, rand); } setLastAttacker(victim); } return attacked; }
@Override public boolean attackEntityAsMob(Entity par1Entity) { float attackDamage = (float) this.getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue(); int knockback = 0; if (par1Entity instanceof EntityLivingBase) { attackDamage += EnchantmentHelper.getEnchantmentModifierLiving(this, (EntityLivingBase) par1Entity); knockback += EnchantmentHelper.getKnockbackModifier(this, (EntityLivingBase) par1Entity); } boolean flag = par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), attackDamage); if (flag) { if (knockback > 0) { par1Entity.addVelocity( (double) (-MathHelper.sin(this.rotationYaw * (float) Math.PI / 180.0F) * (float) knockback * 0.5F), 0.1D, (double) (MathHelper.cos(this.rotationYaw * (float) Math.PI / 180.0F) * (float) knockback * 0.5F)); this.motionX *= 0.6D; this.motionZ *= 0.6D; } int j = EnchantmentHelper.getFireAspectModifier(this); if (j > 0) par1Entity.setFire(j * 4); if (par1Entity instanceof EntityLivingBase) EnchantmentHelper.func_151384_a((EntityLivingBase) par1Entity, this); EnchantmentHelper.func_151385_b(this, par1Entity); } return flag; }
@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); }