2011-01-17 04:03:19 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2011-01-21 06:54:30 +01:00
|
|
|
// CraftBukkit start
|
2011-01-17 09:17:16 +01:00
|
|
|
import org.bukkit.craftbukkit.CraftServer;
|
2011-01-26 20:26:24 +01:00
|
|
|
import org.bukkit.craftbukkit.entity.CraftEntity;
|
2011-02-20 23:22:28 +01:00
|
|
|
import org.bukkit.craftbukkit.TrigMath;
|
2011-01-26 20:26:24 +01:00
|
|
|
import org.bukkit.event.entity.EntityTargetEvent;
|
|
|
|
import org.bukkit.event.entity.EntityTargetEvent.TargetReason;
|
2011-01-21 06:54:30 +01:00
|
|
|
// CraftBukkit end
|
2011-01-17 09:17:16 +01:00
|
|
|
|
2011-01-17 04:03:19 +01:00
|
|
|
public class EntityCreature extends EntityLiving {
|
2011-04-20 19:05:14 +02:00
|
|
|
|
|
|
|
public PathEntity pathEntity; // CraftBukkit - public
|
|
|
|
public Entity target; // CraftBukkit - public
|
2011-01-29 22:50:29 +01:00
|
|
|
protected boolean e = false;
|
2011-01-17 04:03:19 +01:00
|
|
|
|
|
|
|
public EntityCreature(World world) {
|
|
|
|
super(world);
|
|
|
|
}
|
|
|
|
|
2011-04-20 22:47:26 +02:00
|
|
|
protected boolean w() {
|
2011-03-31 22:40:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-23 03:37:56 +01:00
|
|
|
protected void c_() {
|
2011-04-20 22:47:26 +02:00
|
|
|
this.e = this.w();
|
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-01-26 20:26:24 +01:00
|
|
|
EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), target.getBukkitEntity(), TargetReason.CLOSEST_PLAYER);
|
2011-01-29 22:50:29 +01:00
|
|
|
CraftServer server = ((WorldServer) this.world).getServer();
|
2011-01-26 20:26:24 +01:00
|
|
|
server.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) {
|
|
|
|
this.pathEntity = this.world.findPath(this, this.target, f);
|
2011-01-17 04:03:19 +01:00
|
|
|
}
|
2011-05-28 22:50:08 +02:00
|
|
|
} else if (!this.target.S()) {
|
2011-01-26 20:26:24 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
EntityTargetEvent event = new EntityTargetEvent(this.getBukkitEntity(), null, TargetReason.TARGET_DIED);
|
2011-01-29 22:50:29 +01:00
|
|
|
CraftServer server = ((WorldServer) this.world).getServer();
|
2011-01-26 20:26:24 +01:00
|
|
|
server.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
|
|
|
} else {
|
2011-04-20 19:05:14 +02:00
|
|
|
float f1 = this.target.f(this);
|
2011-01-17 04:03:19 +01:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (this.e(this.target)) {
|
|
|
|
this.a(this.target, f1);
|
2011-05-26 14:48:22 +02:00
|
|
|
} else {
|
|
|
|
this.b(this.target, f1);
|
2011-01-17 04:03:19 +01:00
|
|
|
}
|
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (!this.e && this.target != null && (this.pathEntity == null || this.random.nextInt(20) == 0)) {
|
|
|
|
this.pathEntity = this.world.findPath(this, this.target, f);
|
|
|
|
} else if (!this.e && (this.pathEntity == null && this.random.nextInt(80) == 0 || this.random.nextInt(80) == 0)) {
|
2011-01-17 04:03:19 +01:00
|
|
|
boolean flag = false;
|
2011-01-29 22:50:29 +01:00
|
|
|
int i = -1;
|
2011-01-17 04:03:19 +01:00
|
|
|
int j = -1;
|
|
|
|
int k = -1;
|
2011-01-29 22:50:29 +01:00
|
|
|
float f2 = -99999.0F;
|
2011-01-17 04:03:19 +01:00
|
|
|
|
2011-01-29 22:50:29 +01:00
|
|
|
for (int l = 0; l < 10; ++l) {
|
2011-04-20 19:05:14 +02:00
|
|
|
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);
|
2011-01-29 22:50:29 +01:00
|
|
|
float f3 = this.a(i1, j1, k1);
|
2011-01-17 04:03:19 +01:00
|
|
|
|
|
|
|
if (f3 > f2) {
|
|
|
|
f2 = f3;
|
2011-01-29 22:50:29 +01:00
|
|
|
i = i1;
|
|
|
|
j = j1;
|
|
|
|
k = k1;
|
2011-01-17 04:03:19 +01:00
|
|
|
flag = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flag) {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.pathEntity = this.world.a(this, i, j, k, 10.0F);
|
2011-01-17 04:03:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 22:47:26 +02:00
|
|
|
int l1 = MathHelper.floor(this.boundingBox.b + 0.5D);
|
2011-05-28 22:50:08 +02:00
|
|
|
boolean flag1 = this.ac();
|
|
|
|
boolean flag2 = this.ad();
|
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) {
|
|
|
|
Vec3D vec3d = this.pathEntity.a(this);
|
2011-01-29 22:50:29 +01:00
|
|
|
double d0 = (double) (this.length * 2.0F);
|
|
|
|
|
|
|
|
while (vec3d != null && vec3d.d(this.locX, vec3d.b, 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 {
|
2011-04-20 19:05:14 +02:00
|
|
|
vec3d = this.pathEntity.a(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
|
|
|
|
2011-05-28 22:50:08 +02:00
|
|
|
this.aC = false;
|
2011-01-29 22:50:29 +01:00
|
|
|
if (vec3d != null) {
|
|
|
|
double d1 = vec3d.a - this.locX;
|
|
|
|
double d2 = vec3d.c - this.locZ;
|
|
|
|
double d3 = vec3d.b - (double) l1;
|
2011-05-14 16:29:42 +02:00
|
|
|
// CraftBukkit - Math -> TrigMath
|
2011-02-23 13:56:36 +01:00
|
|
|
float f4 = (float) (TrigMath.atan2(d2, d1) * 180.0D / 3.1415927410125732D) - 90.0F;
|
2011-01-29 22:50:29 +01:00
|
|
|
float f5 = f4 - this.yaw;
|
|
|
|
|
2011-05-28 22:50:08 +02:00
|
|
|
for (this.aA = this.aE; f5 < -180.0F; f5 += 360.0F) {
|
2011-01-29 22:50:29 +01:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (f5 >= 180.0F) {
|
|
|
|
f5 -= 360.0F;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (f5 > 30.0F) {
|
|
|
|
f5 = 30.0F;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (f5 < -30.0F) {
|
|
|
|
f5 = -30.0F;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.yaw += f5;
|
2011-04-20 19:05:14 +02:00
|
|
|
if (this.e && this.target != null) {
|
|
|
|
double d4 = this.target.locX - this.locX;
|
|
|
|
double d5 = this.target.locZ - this.locZ;
|
2011-01-29 22:50:29 +01:00
|
|
|
float f6 = this.yaw;
|
|
|
|
|
|
|
|
this.yaw = (float) (Math.atan2(d5, d4) * 180.0D / 3.1415927410125732D) - 90.0F;
|
|
|
|
f5 = (f6 - this.yaw + 90.0F) * 3.1415927F / 180.0F;
|
2011-05-28 22:50:08 +02:00
|
|
|
this.az = -MathHelper.sin(f5) * this.aA * 1.0F;
|
|
|
|
this.aA = MathHelper.cos(f5) * this.aA * 1.0F;
|
2011-01-29 22:50:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (d3 > 0.0D) {
|
2011-05-28 22:50:08 +02:00
|
|
|
this.aC = 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
|
|
|
|
2011-05-28 22:50:08 +02:00
|
|
|
if (this.positionChanged && !this.B()) {
|
|
|
|
this.aC = true;
|
2011-01-17 04:03:19 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
|
|
|
|
if (this.random.nextFloat() < 0.8F && (flag1 || flag2)) {
|
2011-05-28 22:50:08 +02:00
|
|
|
this.aC = true;
|
2011-01-17 04:03:19 +01:00
|
|
|
}
|
2011-01-29 22:50:29 +01:00
|
|
|
} else {
|
2011-02-23 03:37:56 +01:00
|
|
|
super.c_();
|
2011-04-20 19:05:14 +02:00
|
|
|
this.pathEntity = null;
|
2011-01-17 04:03:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void a(Entity entity, float f) {}
|
|
|
|
|
2011-05-26 14:48:22 +02:00
|
|
|
protected void b(Entity entity, float f) {}
|
|
|
|
|
2011-01-17 04:03:19 +01:00
|
|
|
protected float a(int i, int j, int k) {
|
|
|
|
return 0.0F;
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
protected Entity findTarget() {
|
2011-01-17 04:03:19 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-04-20 22:47:26 +02:00
|
|
|
public boolean d() {
|
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
|
|
|
|
2011-04-20 22:47:26 +02:00
|
|
|
return super.d() && this.a(i, j, k) >= 0.0F;
|
2011-01-17 04:03:19 +01:00
|
|
|
}
|
2011-03-31 22:40:00 +02:00
|
|
|
|
2011-05-28 22:50:08 +02:00
|
|
|
public boolean B() {
|
2011-04-20 19:05:14 +02:00
|
|
|
return this.pathEntity != null;
|
2011-03-31 22:40:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(PathEntity pathentity) {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.pathEntity = pathentity;
|
2011-03-31 22:40:00 +02:00
|
|
|
}
|
|
|
|
|
2011-05-28 22:50:08 +02:00
|
|
|
public Entity E() {
|
2011-04-20 19:05:14 +02:00
|
|
|
return this.target;
|
2011-03-31 22:40:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void c(Entity entity) {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.target = entity;
|
2011-03-31 22:40:00 +02:00
|
|
|
}
|
2011-01-17 04:03:19 +01:00
|
|
|
}
|