Added PathfinderGoalTarget, PathfinderGoalArrowAttack, PathfinderGoalMeleeAttack for diff visibility.

This commit is contained in:
feildmaster 2012-03-08 18:22:09 -06:00 committed by EvilSeph
parent 08bd33a3ed
commit a967d6e371
3 changed files with 293 additions and 0 deletions

View file

@ -0,0 +1,87 @@
package net.minecraft.server;
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() {
EntityLiving entityliving = this.b.as();
if (entityliving == null) {
return false;
} else {
this.c = entityliving;
return true;
}
}
public boolean b() {
return this.a() || !this.b.ak().e();
}
public void d() {
this.c = null;
}
public void e() {
double d0 = 100.0D;
double d1 = this.b.e(this.c.locX, this.c.boundingBox.b, this.c.locZ);
boolean flag = this.b.al().canSee(this.c);
if (flag) {
++this.f;
} else {
this.f = 0;
}
if (d1 <= d0 && this.f >= 20) {
this.b.ak().f();
} else {
this.b.ak().a(this.c, this.e);
}
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);
this.a.makeSound(this.b, "random.bow", 1.0F, 1.0F / (this.b.am().nextFloat() * 0.4F + 0.8F));
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;
entitysnowball.a(d0, d1 + (double) f, d2, 1.6F, 12.0F);
this.a.makeSound(this.b, "random.bow", 1.0F, 1.0F / (this.b.am().nextFloat() * 0.4F + 0.8F));
this.a.addEntity(entitysnowball);
}
}
}

View file

@ -0,0 +1,76 @@
package net.minecraft.server;
public class PathfinderGoalMeleeAttack extends PathfinderGoal {
World a;
EntityLiving b;
EntityLiving c;
int d;
float e;
boolean f;
PathEntity g;
Class h;
private int i;
public PathfinderGoalMeleeAttack(EntityLiving entityliving, Class oclass, float f, boolean flag) {
this(entityliving, f, flag);
this.h = oclass;
}
public PathfinderGoalMeleeAttack(EntityLiving entityliving, float f, boolean flag) {
this.d = 0;
this.b = entityliving;
this.a = entityliving.world;
this.e = f;
this.f = flag;
this.a(3);
}
public boolean a() {
EntityLiving entityliving = this.b.as();
if (entityliving == null) {
return false;
} else if (this.h != null && !this.h.isAssignableFrom(entityliving.getClass())) {
return false;
} else {
this.c = entityliving;
this.g = this.b.ak().a(this.c);
return this.g != null;
}
}
public boolean b() {
EntityLiving entityliving = this.b.as();
return entityliving == null ? false : (!this.c.isAlive() ? false : (!this.f ? !this.b.ak().e() : this.b.e(MathHelper.floor(this.c.locX), MathHelper.floor(this.c.locY), MathHelper.floor(this.c.locZ))));
}
public void c() {
this.b.ak().a(this.g, this.e);
this.i = 0;
}
public void d() {
this.c = null;
this.b.ak().f();
}
public void e() {
this.b.getControllerLook().a(this.c, 30.0F, 30.0F);
if ((this.f || this.b.al().canSee(this.c)) && --this.i <= 0) {
this.i = 4 + this.b.am().nextInt(7);
this.b.ak().a(this.c, this.e);
}
this.d = Math.max(this.d - 1, 0);
double d0 = (double) (this.b.width * 2.0F * this.b.width * 2.0F);
if (this.b.e(this.c.locX, this.c.boundingBox.b, this.c.locZ) <= d0) {
if (this.d <= 0) {
this.d = 20;
this.b.a((Entity) this.c);
}
}
}
}

View file

@ -0,0 +1,130 @@
package net.minecraft.server;
public abstract class PathfinderGoalTarget extends PathfinderGoal {
protected EntityLiving c;
protected float d;
protected boolean e;
private boolean a;
private int b;
private int f;
private int g;
public PathfinderGoalTarget(EntityLiving entityliving, float f, boolean flag) {
this(entityliving, f, flag, false);
}
public PathfinderGoalTarget(EntityLiving entityliving, float f, boolean flag, boolean flag1) {
this.b = 0;
this.f = 0;
this.g = 0;
this.c = entityliving;
this.d = f;
this.e = flag;
this.a = flag1;
}
public boolean b() {
EntityLiving entityliving = this.c.as();
if (entityliving == null) {
return false;
} else if (!entityliving.isAlive()) {
return false;
} else if (this.c.j(entityliving) > (double) (this.d * this.d)) {
return false;
} else {
if (this.e) {
if (!this.c.al().canSee(entityliving)) {
if (++this.g > 60) {
return false;
}
} else {
this.g = 0;
}
}
return true;
}
}
public void c() {
this.b = 0;
this.f = 0;
this.g = 0;
}
public void d() {
this.c.b((EntityLiving) null);
}
protected boolean a(EntityLiving entityliving, boolean flag) {
if (entityliving == null) {
return false;
} else if (entityliving == this.c) {
return false;
} else if (!entityliving.isAlive()) {
return false;
} else if (entityliving.boundingBox.e > this.c.boundingBox.b && entityliving.boundingBox.b < this.c.boundingBox.e) {
if (!this.c.a(entityliving.getClass())) {
return false;
} else {
if (this.c instanceof EntityTameableAnimal && ((EntityTameableAnimal) this.c).isTamed()) {
if (entityliving instanceof EntityTameableAnimal && ((EntityTameableAnimal) entityliving).isTamed()) {
return false;
}
if (entityliving == ((EntityTameableAnimal) this.c).getOwner()) {
return false;
}
} else if (entityliving instanceof EntityHuman && !flag && ((EntityHuman) entityliving).abilities.isInvulnerable) {
return false;
}
if (!this.c.e(MathHelper.floor(entityliving.locX), MathHelper.floor(entityliving.locY), MathHelper.floor(entityliving.locZ))) {
return false;
} else if (this.e && !this.c.al().canSee(entityliving)) {
return false;
} else {
if (this.a) {
if (--this.f <= 0) {
this.b = 0;
}
if (this.b == 0) {
this.b = this.a(entityliving) ? 1 : 2;
}
if (this.b == 2) {
return false;
}
}
return true;
}
}
} else {
return false;
}
}
private boolean a(EntityLiving entityliving) {
this.f = 10 + this.c.am().nextInt(5);
PathEntity pathentity = this.c.ak().a(entityliving);
if (pathentity == null) {
return false;
} else {
PathPoint pathpoint = pathentity.c();
if (pathpoint == null) {
return false;
} else {
int i = pathpoint.a - MathHelper.floor(entityliving.locX);
int j = pathpoint.c - MathHelper.floor(entityliving.locZ);
return (double) (i * i + j * j) <= 2.25D;
}
}
}
}