2011-01-17 04:03:19 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2011-01-21 06:54:30 +01:00
|
|
|
// CraftBukkit start
|
2011-01-26 20:26:24 +01:00
|
|
|
import org.bukkit.craftbukkit.entity.CraftEntity;
|
|
|
|
import org.bukkit.event.entity.EntityTargetEvent;
|
2011-01-21 06:54:30 +01:00
|
|
|
// CraftBukkit end
|
2011-01-17 09:17:16 +01:00
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
public abstract class EntityCreature extends EntityLiving {
|
2011-04-20 19:05:14 +02:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public PathEntity pathEntity; // CraftBukkit - private -> public
|
|
|
|
public Entity target; // CraftBukkit - protected -> public
|
2012-07-29 09:33:13 +02:00
|
|
|
protected boolean b = false;
|
|
|
|
protected int c = 0;
|
2011-01-17 04:03:19 +01:00
|
|
|
|
|
|
|
public EntityCreature(World world) {
|
|
|
|
super(world);
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
protected boolean h() {
|
2011-03-31 22:40:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
protected void bk() {
|
2012-09-10 06:19:28 +02:00
|
|
|
this.world.methodProfiler.a("ai");
|
2012-07-29 09:33:13 +02:00
|
|
|
if (this.c > 0) {
|
|
|
|
--this.c;
|
2011-09-15 02:23:52 +02:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
this.b = this.h();
|
2011-01-29 22:50:29 +01:00
|
|
|
float f = 16.0F;
|
2011-01-17 04:03:19 +01:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (this.target == null) {
|
2011-01-26 20:26:24 +01:00
|
|
|
// CraftBukkit start
|
2011-04-20 19:05:14 +02:00
|
|
|
Entity target = this.findTarget();
|
2011-01-29 22:50:29 +01:00
|
|
|
if (target != null) {
|
2011-06-27 00:25:01 +02:00
|
|
|
EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), target.getBukkitEntity(), EntityTargetEvent.TargetReason.CLOSEST_PLAYER);
|
|
|
|
this.world.getServer().getPluginManager().callEvent(event);
|
2011-02-23 13:56:36 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (!event.isCancelled()) {
|
|
|
|
if (event.getTarget() == null) {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.target = null;
|
2011-01-26 20:26:24 +01:00
|
|
|
} else {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.target = ((CraftEntity) event.getTarget()).getHandle();
|
2011-01-26 20:26:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2011-05-14 16:29:42 +02:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (this.target != null) {
|
2012-03-01 11:49:23 +01:00
|
|
|
this.pathEntity = this.world.findPath(this, this.target, f, true, false, false, true);
|
2011-01-17 04:03:19 +01:00
|
|
|
}
|
2012-07-29 09:33:13 +02:00
|
|
|
} else if (this.target.isAlive()) {
|
|
|
|
float f1 = this.target.d((Entity) this);
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
if (this.m(this.target)) {
|
2012-07-29 09:33:13 +02:00
|
|
|
this.a(this.target, f1);
|
|
|
|
}
|
|
|
|
} else {
|
2011-01-26 20:26:24 +01:00
|
|
|
// CraftBukkit start
|
2011-06-27 00:25:01 +02:00
|
|
|
EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), null, EntityTargetEvent.TargetReason.TARGET_DIED);
|
|
|
|
this.world.getServer().getPluginManager().callEvent(event);
|
2011-02-23 13:56:36 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
if (!event.isCancelled()) {
|
|
|
|
if (event.getTarget() == null) {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.target = null;
|
2011-01-26 20:26:24 +01:00
|
|
|
} else {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.target = ((CraftEntity) event.getTarget()).getHandle();
|
2011-01-26 20:26:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2011-01-17 04:03:19 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2012-09-10 06:19:28 +02:00
|
|
|
this.world.methodProfiler.b();
|
2012-07-29 09:33:13 +02:00
|
|
|
if (!this.b && this.target != null && (this.pathEntity == null || this.random.nextInt(20) == 0)) {
|
2012-03-01 11:49:23 +01:00
|
|
|
this.pathEntity = this.world.findPath(this, this.target, f, true, false, false, true);
|
2012-10-25 05:53:23 +02:00
|
|
|
} else if (!this.b && (this.pathEntity == null && this.random.nextInt(180) == 0 || this.random.nextInt(120) == 0 || this.c > 0) && this.bC < 100) {
|
|
|
|
this.i();
|
2011-01-17 04:03:19 +01:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:02:25 +02:00
|
|
|
int i = MathHelper.floor(this.boundingBox.b + 0.5D);
|
2012-07-29 09:33:13 +02:00
|
|
|
boolean flag = this.H();
|
|
|
|
boolean flag1 = this.J();
|
2011-01-17 04:03:19 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
this.pitch = 0.0F;
|
2011-04-20 19:05:14 +02:00
|
|
|
if (this.pathEntity != null && this.random.nextInt(100) != 0) {
|
2012-09-10 06:19:28 +02:00
|
|
|
this.world.methodProfiler.a("followpath");
|
2012-03-01 11:49:23 +01:00
|
|
|
Vec3D vec3d = this.pathEntity.a((Entity) this);
|
2011-11-30 00:17:43 +01:00
|
|
|
double d0 = (double) (this.width * 2.0F);
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
while (vec3d != null && vec3d.d(this.locX, vec3d.d, this.locZ) < d0 * d0) {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.pathEntity.a();
|
|
|
|
if (this.pathEntity.b()) {
|
2011-01-29 22:50:29 +01:00
|
|
|
vec3d = null;
|
2011-04-20 19:05:14 +02:00
|
|
|
this.pathEntity = null;
|
2011-01-29 22:50:29 +01:00
|
|
|
} else {
|
2012-03-01 11:49:23 +01:00
|
|
|
vec3d = this.pathEntity.a((Entity) this);
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
2011-01-17 04:03:19 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
this.bG = false;
|
2011-01-29 22:50:29 +01:00
|
|
|
if (vec3d != null) {
|
2012-10-25 05:53:23 +02:00
|
|
|
double d1 = vec3d.c - this.locX;
|
|
|
|
double d2 = vec3d.e - this.locZ;
|
|
|
|
double d3 = vec3d.d - (double) i;
|
2011-05-14 16:29:42 +02:00
|
|
|
// CraftBukkit - Math -> TrigMath
|
2012-07-22 08:18:00 +02:00
|
|
|
float f2 = (float) (org.bukkit.craftbukkit.TrigMath.atan2(d2, d1) * 180.0D / 3.1415927410125732D) - 90.0F;
|
2012-07-29 09:33:13 +02:00
|
|
|
float f3 = MathHelper.g(f2 - this.yaw);
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
this.bE = this.bI;
|
2011-06-30 00:02:25 +02:00
|
|
|
if (f3 > 30.0F) {
|
|
|
|
f3 = 30.0F;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:02:25 +02:00
|
|
|
if (f3 < -30.0F) {
|
|
|
|
f3 = -30.0F;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:02:25 +02:00
|
|
|
this.yaw += f3;
|
2012-07-29 09:33:13 +02:00
|
|
|
if (this.b && this.target != null) {
|
2011-04-20 19:05:14 +02:00
|
|
|
double d4 = this.target.locX - this.locX;
|
|
|
|
double d5 = this.target.locZ - this.locZ;
|
2011-06-30 00:02:25 +02:00
|
|
|
float f4 = this.yaw;
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
this.yaw = (float) (Math.atan2(d5, d4) * 180.0D / 3.1415927410125732D) - 90.0F;
|
2011-06-30 00:02:25 +02:00
|
|
|
f3 = (f4 - this.yaw + 90.0F) * 3.1415927F / 180.0F;
|
2012-10-25 05:53:23 +02:00
|
|
|
this.bD = -MathHelper.sin(f3) * this.bE * 1.0F;
|
|
|
|
this.bE = MathHelper.cos(f3) * this.bE * 1.0F;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (d3 > 0.0D) {
|
2012-10-25 05:53:23 +02:00
|
|
|
this.bG = true;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
2011-01-17 04:03:19 +01:00
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (this.target != null) {
|
|
|
|
this.a(this.target, 30.0F, 30.0F);
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
2011-01-17 04:03:19 +01:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
if (this.positionChanged && !this.k()) {
|
|
|
|
this.bG = true;
|
2011-01-17 04:03:19 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-06-30 00:02:25 +02:00
|
|
|
if (this.random.nextFloat() < 0.8F && (flag || flag1)) {
|
2012-10-25 05:53:23 +02:00
|
|
|
this.bG = true;
|
2011-01-17 04:03:19 +01:00
|
|
|
}
|
2011-11-20 09:01:14 +01:00
|
|
|
|
2012-09-10 06:19:28 +02:00
|
|
|
this.world.methodProfiler.b();
|
2011-01-29 22:50:29 +01:00
|
|
|
} else {
|
2012-10-25 05:53:23 +02:00
|
|
|
super.bk();
|
2011-04-20 19:05:14 +02:00
|
|
|
this.pathEntity = null;
|
2011-01-17 04:03:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
protected void i() {
|
2012-09-10 06:19:28 +02:00
|
|
|
this.world.methodProfiler.a("stroll");
|
2011-06-30 00:02:25 +02:00
|
|
|
boolean flag = false;
|
|
|
|
int i = -1;
|
|
|
|
int j = -1;
|
|
|
|
int k = -1;
|
|
|
|
float f = -99999.0F;
|
|
|
|
|
|
|
|
for (int l = 0; l < 10; ++l) {
|
|
|
|
int i1 = MathHelper.floor(this.locX + (double) this.random.nextInt(13) - 6.0D);
|
|
|
|
int j1 = MathHelper.floor(this.locY + (double) this.random.nextInt(7) - 3.0D);
|
|
|
|
int k1 = MathHelper.floor(this.locZ + (double) this.random.nextInt(13) - 6.0D);
|
|
|
|
float f1 = this.a(i1, j1, k1);
|
|
|
|
|
|
|
|
if (f1 > f) {
|
|
|
|
f = f1;
|
|
|
|
i = i1;
|
|
|
|
j = j1;
|
|
|
|
k = k1;
|
|
|
|
flag = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flag) {
|
2012-03-01 11:49:23 +01:00
|
|
|
this.pathEntity = this.world.a(this, i, j, k, 10.0F, true, false, false, true);
|
2011-06-30 00:02:25 +02:00
|
|
|
}
|
2011-11-20 09:01:14 +01:00
|
|
|
|
2012-09-10 06:19:28 +02:00
|
|
|
this.world.methodProfiler.b();
|
2011-06-30 00:02:25 +02:00
|
|
|
}
|
|
|
|
|
2011-01-17 04:03:19 +01:00
|
|
|
protected void a(Entity entity, float f) {}
|
|
|
|
|
2012-01-12 23:10:13 +01:00
|
|
|
public float a(int i, int j, int k) {
|
2011-01-17 04:03:19 +01:00
|
|
|
return 0.0F;
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
protected Entity findTarget() {
|
2011-01-17 04:03:19 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-01-14 21:03:48 +01:00
|
|
|
public boolean canSpawn() {
|
2011-04-20 19:05:14 +02:00
|
|
|
int i = MathHelper.floor(this.locX);
|
|
|
|
int j = MathHelper.floor(this.boundingBox.b);
|
|
|
|
int k = MathHelper.floor(this.locZ);
|
2011-01-17 04:03:19 +01:00
|
|
|
|
2012-01-14 21:03:48 +01:00
|
|
|
return super.canSpawn() && this.a(i, j, k) >= 0.0F;
|
2011-01-17 04:03:19 +01:00
|
|
|
}
|
2011-03-31 22:40:00 +02:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public boolean k() {
|
2011-04-20 19:05:14 +02:00
|
|
|
return this.pathEntity != null;
|
2011-03-31 22:40:00 +02:00
|
|
|
}
|
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
public void setPathEntity(PathEntity pathentity) {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.pathEntity = pathentity;
|
2011-03-31 22:40:00 +02:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public Entity l() {
|
2011-04-20 19:05:14 +02:00
|
|
|
return this.target;
|
2011-03-31 22:40:00 +02:00
|
|
|
}
|
|
|
|
|
2011-06-27 00:25:01 +02:00
|
|
|
public void setTarget(Entity entity) {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.target = entity;
|
2011-03-31 22:40:00 +02:00
|
|
|
}
|
2011-09-15 02:23:52 +02:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public float by() {
|
|
|
|
float f = super.by();
|
2011-09-15 02:23:52 +02:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
if (this.c > 0 && !this.bb()) {
|
|
|
|
f *= 2.0F;
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
2012-10-25 05:53:23 +02:00
|
|
|
|
|
|
|
return f;
|
2011-09-15 02:23:52 +02:00
|
|
|
}
|
2011-01-17 04:03:19 +01:00
|
|
|
}
|