Advertisement
Scouter456

Untitled

Nov 10th, 2022
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1.     protected void checkAndPerformAttack() {
  2.         if (this.entity.position().distanceTo(new Vec3(this.entity.getTarget().getX(), this.entity.getTarget().getY(), this.entity.getTarget().getZ())) < this.entity.getBbWidth()+this.entity.getTarget().getBbWidth() && this.ticksUntilNextAttack <= 0) {
  3.             if(entity != null) {
  4.                 entity.setAttacking(true);
  5.             }
  6.         } else entity.setAttacking(false);
  7.     }
  8.  
  9.     @Override
  10.     public void tick() {
  11.         super.tick();
  12.         checkAndPerformAttack();
  13.         if(entity.isAttacking()) {
  14.             animCounter++;
  15.  
  16.             if(animCounter >= animTickLength) {
  17.                 /**you can add a second timer to damage at a specific time if you want to**/
  18.                 entity.getTarget().hurt(DamageSource.mobAttack(this.entity), (float) this.entity.getAttributeBaseValue(Attributes.ATTACK_DAMAGE));
  19.                 animCounter = 0;
  20.                 entity.setAttacking(false);
  21.             }
  22.         }
  23.         this.ticksUntilNextAttack = Math.max(this.ticksUntilNextAttack - 1, 0);
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement