2012-03-09 01:22:09 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2012-03-09 22:40:59 +01:00
|
|
|
import org.bukkit.event.entity.EntityTargetEvent; // CraftBukkit
|
|
|
|
|
2012-03-09 01:22:09 +01:00
|
|
|
public class PathfinderGoalArrowAttack extends PathfinderGoal {
|
|
|
|
|
|
|
|
World a;
|
|
|
|
EntityLiving b;
|
|
|
|
EntityLiving c;
|
|
|
|
int d = 0;
|
|
|
|
float e;
|
|
|
|
int f = 0;
|
|
|
|
int g;
|
|
|
|
int h;
|
|
|
|
|
|
|
|
public PathfinderGoalArrowAttack(EntityLiving entityliving, float f, int i, int j) {
|
|
|
|
this.b = entityliving;
|
|
|
|
this.a = entityliving.world;
|
|
|
|
this.e = f;
|
|
|
|
this.g = i;
|
|
|
|
this.h = j;
|
|
|
|
this.a(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean a() {
|
2012-07-29 09:33:13 +02:00
|
|
|
EntityLiving entityliving = this.b.az();
|
2012-03-09 01:22:09 +01:00
|
|
|
|
|
|
|
if (entityliving == null) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
this.c = entityliving;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean b() {
|
2012-07-29 09:33:13 +02:00
|
|
|
return this.a() || !this.b.getNavigation().f();
|
2012-03-09 01:22:09 +01:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public void c() {
|
2012-03-09 22:40:59 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
EntityTargetEvent.TargetReason reason = this.c.isAlive() ? EntityTargetEvent.TargetReason.FORGOT_TARGET : EntityTargetEvent.TargetReason.TARGET_DIED;
|
|
|
|
org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTargetEvent(b, null, reason);
|
|
|
|
// CraftBukkit end
|
2012-03-09 01:22:09 +01:00
|
|
|
this.c = null;
|
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public void d() {
|
2012-03-09 01:22:09 +01:00
|
|
|
double d0 = 100.0D;
|
|
|
|
double d1 = this.b.e(this.c.locX, this.c.boundingBox.b, this.c.locZ);
|
2012-07-29 09:33:13 +02:00
|
|
|
boolean flag = this.b.at().canSee(this.c);
|
2012-03-09 01:22:09 +01:00
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
++this.f;
|
|
|
|
} else {
|
|
|
|
this.f = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d1 <= d0 && this.f >= 20) {
|
2012-07-29 09:33:13 +02:00
|
|
|
this.b.getNavigation().g();
|
2012-03-09 01:22:09 +01:00
|
|
|
} else {
|
2012-07-29 09:33:13 +02:00
|
|
|
this.b.getNavigation().a(this.c, this.e);
|
2012-03-09 01:22:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.b.getControllerLook().a(this.c, 30.0F, 30.0F);
|
|
|
|
this.d = Math.max(this.d - 1, 0);
|
|
|
|
if (this.d <= 0) {
|
|
|
|
if (d1 <= d0 && flag) {
|
|
|
|
this.f();
|
|
|
|
this.d = this.h;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void f() {
|
|
|
|
if (this.g == 1) {
|
|
|
|
EntityArrow entityarrow = new EntityArrow(this.a, this.b, this.c, 1.6F, 12.0F);
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
this.a.makeSound(this.b, "random.bow", 1.0F, 1.0F / (this.b.au().nextFloat() * 0.4F + 0.8F));
|
2012-03-09 01:22:09 +01:00
|
|
|
this.a.addEntity(entityarrow);
|
|
|
|
} else if (this.g == 2) {
|
|
|
|
EntitySnowball entitysnowball = new EntitySnowball(this.a, this.b);
|
|
|
|
double d0 = this.c.locX - this.b.locX;
|
|
|
|
double d1 = this.c.locY + (double) this.c.getHeadHeight() - 1.100000023841858D - entitysnowball.locY;
|
|
|
|
double d2 = this.c.locZ - this.b.locZ;
|
|
|
|
float f = MathHelper.sqrt(d0 * d0 + d2 * d2) * 0.2F;
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
entitysnowball.c(d0, d1 + (double) f, d2, 1.6F, 12.0F);
|
|
|
|
this.a.makeSound(this.b, "random.bow", 1.0F, 1.0F / (this.b.au().nextFloat() * 0.4F + 0.8F));
|
2012-03-09 01:22:09 +01:00
|
|
|
this.a.addEntity(entitysnowball);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|