Advertisement
GamingLVScripts

attackTargetEntityWithCurrentItem

Apr 1st, 2024
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.99 KB | None | 0 0
  1. /**
  2.      * Attacks for the player the targeted entity with the currently equipped item.  The equipped item has hitEntity
  3.      * called on it. Args: targetEntity
  4.      */
  5.     public void attackTargetEntityWithCurrentItem(Entity targetEntity)
  6.     {
  7.         if (targetEntity.canAttackWithItem())
  8.         {
  9.             if (!targetEntity.hitByEntity(this))
  10.             {
  11.                 float f = (float)this.getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue();
  12.                 int i = 0;
  13.                 float f1 = 0.0F;
  14.  
  15.                 if (targetEntity instanceof EntityLivingBase)
  16.                 {
  17.                     f1 = EnchantmentHelper.func_152377_a(this.getHeldItem(), ((EntityLivingBase)targetEntity).getCreatureAttribute());
  18.                 }
  19.                 else
  20.                 {
  21.                     f1 = EnchantmentHelper.func_152377_a(this.getHeldItem(), EnumCreatureAttribute.UNDEFINED);
  22.                 }
  23.  
  24.                 i = i + EnchantmentHelper.getKnockbackModifier(this);
  25.  
  26.                 if (this.isSprinting())
  27.                 {
  28.                     ++i;
  29.                 }
  30.  
  31.                 if (f > 0.0F || f1 > 0.0F)
  32.                 {
  33.                     boolean flag = this.fallDistance > 0.0F && !this.onGround && !this.isOnLadder() && !this.isInWater() && !this.isPotionActive(Potion.blindness) && this.ridingEntity == null && targetEntity instanceof EntityLivingBase;
  34.  
  35.                     if (flag && f > 0.0F)
  36.                     {
  37.                         f *= 1.5F;
  38.                     }
  39.  
  40.                     f = f + f1;
  41.                     boolean flag1 = false;
  42.                     int j = EnchantmentHelper.getFireAspectModifier(this);
  43.  
  44.                     if (targetEntity instanceof EntityLivingBase && j > 0 && !targetEntity.isBurning())
  45.                     {
  46.                         flag1 = true;
  47.                         targetEntity.setFire(1);
  48.                     }
  49.  
  50.                     double d0 = targetEntity.motionX;
  51.                     double d1 = targetEntity.motionY;
  52.                     double d2 = targetEntity.motionZ;
  53.                     boolean flag2 = targetEntity.attackEntityFrom(DamageSource.causePlayerDamage(this), f);
  54.  
  55.                     if (flag2) {
  56.                         final KnockbackModifierEvent knockbackModifierEvent = new KnockbackModifierEvent(i > 0).publishItself();
  57.                         float yaw = this.rotationYaw;
  58.                         if(this == Minecraft.getMinecraft().thePlayer)
  59.                             yaw = PlayerHandler.yaw;
  60.                         if (knockbackModifierEvent.isFlag()) {
  61.                             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));
  62.                             this.motionX *= 0.6D;
  63.                             this.motionZ *= 0.6D;
  64.                             this.setSprinting(false);
  65.                         }
  66.                         if (targetEntity instanceof EntityPlayerMP && targetEntity.velocityChanged)
  67.                         {
  68.                             ((EntityPlayerMP)targetEntity).playerNetServerHandler.sendPacket(new S12PacketEntityVelocity(targetEntity));
  69.                             targetEntity.velocityChanged = false;
  70.                             targetEntity.motionX = d0;
  71.                             targetEntity.motionY = d1;
  72.                             targetEntity.motionZ = d2;
  73.                         }
  74.  
  75.                         if (flag)
  76.                         {
  77.                             this.onCriticalHit(targetEntity);
  78.                         }
  79.  
  80.                         if (f1 > 0.0F)
  81.                         {
  82.                             this.onEnchantmentCritical(targetEntity);
  83.                         }
  84.  
  85.                         if (f >= 18.0F)
  86.                         {
  87.                             this.triggerAchievement(AchievementList.overkill);
  88.                         }
  89.  
  90.                         this.setLastAttacker(targetEntity);
  91.  
  92.                         if (targetEntity instanceof EntityLivingBase)
  93.                         {
  94.                             EnchantmentHelper.applyThornEnchantments((EntityLivingBase)targetEntity, this);
  95.                         }
  96.  
  97.                         EnchantmentHelper.applyArthropodEnchantments(this, targetEntity);
  98.                         ItemStack itemstack = this.getCurrentEquippedItem();
  99.                         Entity entity = targetEntity;
  100.  
  101.                         if (targetEntity instanceof EntityDragonPart)
  102.                         {
  103.                             IEntityMultiPart ientitymultipart = ((EntityDragonPart)targetEntity).entityDragonObj;
  104.  
  105.                             if (ientitymultipart instanceof EntityLivingBase)
  106.                             {
  107.                                 entity = (EntityLivingBase)ientitymultipart;
  108.                             }
  109.                         }
  110.  
  111.                         if (itemstack != null && entity instanceof EntityLivingBase)
  112.                         {
  113.                             itemstack.hitEntity((EntityLivingBase)entity, this);
  114.  
  115.                             if (itemstack.stackSize <= 0)
  116.                             {
  117.                                 this.destroyCurrentEquippedItem();
  118.                             }
  119.                         }
  120.  
  121.                         if (targetEntity instanceof EntityLivingBase)
  122.                         {
  123.                             this.addStat(StatList.damageDealtStat, Math.round(f * 10.0F));
  124.  
  125.                             if (j > 0)
  126.                             {
  127.                                 targetEntity.setFire(j * 4);
  128.                             }
  129.                         }
  130.  
  131.                         this.addExhaustion(0.3F);
  132.                     }
  133.                     else if (flag1)
  134.                     {
  135.                         targetEntity.extinguish();
  136.                     }
  137.                 }
  138.             }
  139.         }
  140.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement