Advertisement
GeradesoLukas

Untitled

Sep 27th, 2022
1,166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.25 KB | None | 0 0
  1.    public void attack(Entity pTarget) {
  2.       if (!net.minecraftforge.common.ForgeHooks.onPlayerAttackTarget(this, pTarget)) return;
  3.       if (pTarget.isAttackable()) {
  4.          if (!pTarget.skipAttackInteraction(this)) {
  5.             float f = (float)this.getAttributeValue(Attributes.ATTACK_DAMAGE);
  6.             float f1;
  7.             if (pTarget instanceof LivingEntity) {
  8.                f1 = EnchantmentHelper.getDamageBonus(this.getMainHandItem(), ((LivingEntity)pTarget).getMobType());
  9.             } else {
  10.                f1 = EnchantmentHelper.getDamageBonus(this.getMainHandItem(), MobType.UNDEFINED);
  11.             }
  12.  
  13.             float f2 = this.getAttackStrengthScale(0.5F);
  14.             f *= 0.2F + f2 * f2 * 0.8F;
  15.             f1 *= f2;
  16.             this.resetAttackStrengthTicker();
  17.             if (f > 0.0F || f1 > 0.0F) {
  18.                boolean flag = f2 > 0.9F;
  19.                boolean flag1 = false;
  20.                float i = (float)this.getAttributeValue(Attributes.ATTACK_KNOCKBACK); // Forge: Initialize this value to the attack knockback attribute of the player, which is by default 0
  21.                i += EnchantmentHelper.getKnockbackBonus(this);
  22.                if (this.isSprinting() && flag) {
  23.                   this.level.playSound((Player)null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_KNOCKBACK, this.getSoundSource(), 1.0F, 1.0F);
  24.                   ++i;
  25.                   flag1 = true;
  26.                }
  27.  
  28.                boolean flag2 = flag && this.fallDistance > 0.0F && !this.onGround && !this.onClimbable() && !this.isInWater() && !this.hasEffect(MobEffects.BLINDNESS) && !this.isPassenger() && pTarget instanceof LivingEntity;
  29.                flag2 = flag2 && !this.isSprinting();
  30.                net.minecraftforge.event.entity.player.CriticalHitEvent hitResult = net.minecraftforge.common.ForgeHooks.getCriticalHit(this, pTarget, flag2, flag2 ? 1.5F : 1.0F);
  31.                flag2 = hitResult != null;
  32.                if (flag2) {
  33.                   f *= hitResult.getDamageModifier();
  34.                }
  35.  
  36.                f += f1;
  37.                boolean flag3 = false;
  38.                double d0 = (double)(this.walkDist - this.walkDistO);
  39.                if (flag && !flag2 && !flag1 && this.onGround && d0 < (double)this.getSpeed()) {
  40.                   ItemStack itemstack = this.getItemInHand(InteractionHand.MAIN_HAND);
  41.                   flag3 = itemstack.canPerformAction(net.minecraftforge.common.ToolActions.SWORD_SWEEP);
  42.                }
  43.  
  44.                float f4 = 0.0F;
  45.                boolean flag4 = false;
  46.                int j = EnchantmentHelper.getFireAspect(this);
  47.                if (pTarget instanceof LivingEntity) {
  48.                   f4 = ((LivingEntity)pTarget).getHealth();
  49.                   if (j > 0 && !pTarget.isOnFire()) {
  50.                      flag4 = true;
  51.                      pTarget.setSecondsOnFire(1);
  52.                   }
  53.                }
  54.  
  55.                Vec3 vec3 = pTarget.getDeltaMovement();
  56.                boolean flag5 = pTarget.hurt(DamageSource.playerAttack(this), f);
  57.                if (flag5) {
  58.                   if (i > 0) {
  59.                      if (pTarget instanceof LivingEntity) {
  60.                         ((LivingEntity)pTarget).knockback((double)((float)i * 0.5F), (double)Mth.sin(this.getYRot() * ((float)Math.PI / 180F)), (double)(-Mth.cos(this.getYRot() * ((float)Math.PI / 180F))));
  61.                      } else {
  62.                         pTarget.push((double)(-Mth.sin(this.getYRot() * ((float)Math.PI / 180F)) * (float)i * 0.5F), 0.1D, (double)(Mth.cos(this.getYRot() * ((float)Math.PI / 180F)) * (float)i * 0.5F));
  63.                      }
  64.  
  65.                      this.setDeltaMovement(this.getDeltaMovement().multiply(0.6D, 1.0D, 0.6D));
  66.                      this.setSprinting(false);
  67.                   }
  68.  
  69.                   if (flag3) {
  70.                      float f3 = 1.0F + EnchantmentHelper.getSweepingDamageRatio(this) * f;
  71.  
  72.                      for(LivingEntity livingentity : this.level.getEntitiesOfClass(LivingEntity.class, this.getItemInHand(InteractionHand.MAIN_HAND).getSweepHitBox(this, pTarget))) {
  73.                         if (livingentity != this && livingentity != pTarget && !this.isAlliedTo(livingentity) && (!(livingentity instanceof ArmorStand) || !((ArmorStand)livingentity).isMarker()) && this.canHit(livingentity, 0)) { // Original check was dist < 3, range is 3, so vanilla used padding=0
  74.                            livingentity.knockback((double)0.4F, (double)Mth.sin(this.getYRot() * ((float)Math.PI / 180F)), (double)(-Mth.cos(this.getYRot() * ((float)Math.PI / 180F))));
  75.                            livingentity.hurt(DamageSource.playerAttack(this), f3);
  76.                         }
  77.                      }
  78.  
  79.                      this.level.playSound((Player)null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_SWEEP, this.getSoundSource(), 1.0F, 1.0F);
  80.                      this.sweepAttack();
  81.                   }
  82.  
  83.                   if (pTarget instanceof ServerPlayer && pTarget.hurtMarked) {
  84.                      ((ServerPlayer)pTarget).connection.send(new ClientboundSetEntityMotionPacket(pTarget));
  85.                      pTarget.hurtMarked = false;
  86.                      pTarget.setDeltaMovement(vec3);
  87.                   }
  88.  
  89.                   if (flag2) {
  90.                      this.level.playSound((Player)null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_CRIT, this.getSoundSource(), 1.0F, 1.0F);
  91.                      this.crit(pTarget);
  92.                   }
  93.  
  94.                   if (!flag2 && !flag3) {
  95.                      if (flag) {
  96.                         this.level.playSound((Player)null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_STRONG, this.getSoundSource(), 1.0F, 1.0F);
  97.                      } else {
  98.                         this.level.playSound((Player)null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_WEAK, this.getSoundSource(), 1.0F, 1.0F);
  99.                      }
  100.                   }
  101.  
  102.                   if (f1 > 0.0F) {
  103.                      this.magicCrit(pTarget);
  104.                   }
  105.  
  106.                   this.setLastHurtMob(pTarget);
  107.                   if (pTarget instanceof LivingEntity) {
  108.                      EnchantmentHelper.doPostHurtEffects((LivingEntity)pTarget, this);
  109.                   }
  110.  
  111.                   EnchantmentHelper.doPostDamageEffects(this, pTarget);
  112.                   ItemStack itemstack1 = this.getMainHandItem();
  113.                   Entity entity = pTarget;
  114.                   if (pTarget instanceof net.minecraftforge.entity.PartEntity) {
  115.                      entity = ((net.minecraftforge.entity.PartEntity<?>) pTarget).getParent();
  116.                   }
  117.  
  118.                   if (!this.level.isClientSide && !itemstack1.isEmpty() && entity instanceof LivingEntity) {
  119.                      ItemStack copy = itemstack1.copy();
  120.                      itemstack1.hurtEnemy((LivingEntity)entity, this);
  121.                      if (itemstack1.isEmpty()) {
  122.                         net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this, copy, InteractionHand.MAIN_HAND);
  123.                         this.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY);
  124.                      }
  125.                   }
  126.  
  127.                   if (pTarget instanceof LivingEntity) {
  128.                      float f5 = f4 - ((LivingEntity)pTarget).getHealth();
  129.                      this.awardStat(Stats.DAMAGE_DEALT, Math.round(f5 * 10.0F));
  130.                      if (j > 0) {
  131.                         pTarget.setSecondsOnFire(j * 4);
  132.                      }
  133.  
  134.                      if (this.level instanceof ServerLevel && f5 > 2.0F) {
  135.                         int k = (int)((double)f5 * 0.5D);
  136.                         ((ServerLevel)this.level).sendParticles(ParticleTypes.DAMAGE_INDICATOR, pTarget.getX(), pTarget.getY(0.5D), pTarget.getZ(), k, 0.1D, 0.0D, 0.1D, 0.2D);
  137.                      }
  138.                   }
  139.  
  140.                   this.causeFoodExhaustion(0.1F);
  141.                } else {
  142.                   this.level.playSound((Player)null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_NODAMAGE, this.getSoundSource(), 1.0F, 1.0F);
  143.                   if (flag4) {
  144.                      pTarget.clearFire();
  145.                   }
  146.                }
  147.             }
  148.  
  149.          }
  150.       }
  151.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement