Paper/src/main/java/net/minecraft/server/PathfinderGoalArrowAttack.java

106 Zeilen
2.9 KiB
Java

package net.minecraft.server;
import org.bukkit.event.entity.EntityTargetEvent; // CraftBukkit
public class PathfinderGoalArrowAttack extends PathfinderGoal {
2013-07-01 13:03:00 +02:00
private final EntityInsentient a;
private final IRangedEntity b;
private EntityLiving c;
2013-03-13 23:33:27 +01:00
private int d;
2013-07-01 13:03:00 +02:00
private double e;
2013-03-13 23:33:27 +01:00
private int f;
private int g;
2013-03-13 23:33:27 +01:00
private int h;
private float i;
private float j;
2013-07-01 13:03:00 +02:00
public PathfinderGoalArrowAttack(IRangedEntity irangedentity, double d0, int i, float f) {
this(irangedentity, d0, i, i, f);
2013-03-13 23:33:27 +01:00
}
2013-07-01 13:03:00 +02:00
public PathfinderGoalArrowAttack(IRangedEntity irangedentity, double d0, int i, int j, float f) {
2013-03-13 23:33:27 +01:00
this.d = -1;
if (!(irangedentity instanceof EntityLiving)) {
throw new IllegalArgumentException("ArrowAttackGoal requires Mob implements RangedAttackMob");
} else {
this.b = irangedentity;
2013-07-01 13:03:00 +02:00
this.a = (EntityInsentient) irangedentity;
this.e = d0;
this.g = i;
2013-03-13 23:33:27 +01:00
this.h = j;
2013-07-01 13:03:00 +02:00
this.i = f;
this.j = f * f;
this.a(3);
}
}
public boolean a() {
2013-01-17 10:28:44 +01:00
EntityLiving entityliving = this.a.getGoalTarget();
if (entityliving == null) {
return false;
} else {
this.c = entityliving;
return true;
}
}
public boolean b() {
2013-07-01 13:03:00 +02:00
return this.a() || !this.a.getNavigation().g();
}
public void d() {
// CraftBukkit start
EntityTargetEvent.TargetReason reason = this.c.isAlive() ? EntityTargetEvent.TargetReason.FORGOT_TARGET : EntityTargetEvent.TargetReason.TARGET_DIED;
org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTargetEvent((Entity) b, null, reason);
// CraftBukkit end
this.c = null;
this.f = 0;
2013-03-13 23:33:27 +01:00
this.d = -1;
}
public void e() {
double d0 = this.a.e(this.c.locX, this.c.boundingBox.b, this.c.locZ);
2013-04-27 11:40:05 +02:00
boolean flag = this.a.getEntitySenses().canSee(this.c);
if (flag) {
++this.f;
} else {
this.f = 0;
}
2013-03-13 23:33:27 +01:00
if (d0 <= (double) this.j && this.f >= 20) {
2013-07-01 13:03:00 +02:00
this.a.getNavigation().h();
} else {
2013-07-01 13:03:00 +02:00
this.a.getNavigation().a((Entity) this.c, this.e);
}
this.a.getControllerLook().a(this.c, 30.0F, 30.0F);
2013-03-13 23:33:27 +01:00
float f;
if (--this.d == 0) {
if (d0 > (double) this.j || !flag) {
return;
}
f = MathHelper.sqrt(d0) / this.i;
float f1 = f;
if (f < 0.1F) {
f1 = 0.1F;
}
2013-03-13 23:33:27 +01:00
if (f1 > 1.0F) {
f1 = 1.0F;
}
this.b.a(this.c, f1);
this.d = MathHelper.d(f * (float) (this.h - this.g) + (float) this.g);
} else if (this.d < 0) {
f = MathHelper.sqrt(d0) / this.i;
this.d = MathHelper.d(f * (float) (this.h - this.g) + (float) this.g);
}
}
}