Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void checkAndPerformAttack() {
- 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) {
- if(entity != null) {
- entity.setAttacking(true);
- }
- } else entity.setAttacking(false);
- }
- @Override
- public void tick() {
- super.tick();
- checkAndPerformAttack();
- if(entity.isAttacking()) {
- animCounter++;
- if(animCounter >= animTickLength) {
- /**you can add a second timer to damage at a specific time if you want to**/
- entity.getTarget().hurt(DamageSource.mobAttack(this.entity), (float) this.entity.getAttributeBaseValue(Attributes.ATTACK_DAMAGE));
- animCounter = 0;
- entity.setAttacking(false);
- }
- }
- this.ticksUntilNextAttack = Math.max(this.ticksUntilNextAttack - 1, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement