3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-21 05:50:05 +01:00
Paper/src/main/java/net/minecraft/server/EntityCreature.java

240 Zeilen
7.3 KiB
Java

package net.minecraft.server;
// CraftBukkit start
2011-01-26 20:26:24 +01:00
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.craftbukkit.TrigMath;
2011-01-26 20:26:24 +01:00
import org.bukkit.event.entity.EntityTargetEvent;
// CraftBukkit end
2011-09-15 02:23:52 +02:00
public abstract class EntityCreature extends EntityLiving {
public PathEntity pathEntity; // CraftBukkit - public
public Entity target; // CraftBukkit - public
2011-01-29 22:50:29 +01:00
protected boolean e = false;
2011-09-15 02:23:52 +02:00
protected int f = 0;
public EntityCreature(World world) {
super(world);
}
2012-01-12 23:10:13 +01:00
protected boolean v() {
2011-03-31 22:40:00 +02:00
return false;
}
2011-11-20 09:01:14 +01:00
protected void m_() {
2012-01-12 12:02:39 +01:00
// MethodProfiler.a("ai"); // CraftBukkit - not in production code
2011-09-15 02:23:52 +02:00
if (this.f > 0) {
--this.f;
}
2012-01-12 23:10:13 +01:00
this.e = this.v();
2011-01-29 22:50:29 +01:00
float f = 16.0F;
if (this.target == null) {
2011-01-26 20:26:24 +01:00
// CraftBukkit start
Entity target = this.findTarget();
2011-01-29 22:50:29 +01:00
if (target != null) {
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) {
this.target = null;
2011-01-26 20:26:24 +01:00
} else {
this.target = ((CraftEntity) event.getTarget()).getHandle();
2011-01-26 20:26:24 +01:00
}
}
}
// CraftBukkit end
2011-05-14 16:29:42 +02:00
if (this.target != null) {
this.pathEntity = this.world.findPath(this, this.target, f);
}
} else if (!this.target.isAlive()) {
2011-01-26 20:26:24 +01:00
// CraftBukkit start
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) {
this.target = null;
2011-01-26 20:26:24 +01:00
} else {
this.target = ((CraftEntity) event.getTarget()).getHandle();
2011-01-26 20:26:24 +01:00
}
}
// CraftBukkit end
} else {
2011-11-20 09:01:14 +01:00
float f1 = this.target.h(this);
2011-11-20 09:01:14 +01:00
if (this.g(this.target)) {
this.a(this.target, f1);
2011-05-26 14:48:22 +02:00
} else {
this.b(this.target, f1);
}
}
2011-01-29 22:50:29 +01:00
2012-01-12 12:02:39 +01:00
// MethodProfiler.a(); // CraftBukkit - not in production code
if (!this.e && this.target != null && (this.pathEntity == null || this.random.nextInt(20) == 0)) {
this.pathEntity = this.world.findPath(this, this.target, f);
2012-01-12 23:10:13 +01:00
} else if (!this.e && (this.pathEntity == null && this.random.nextInt(180) == 0 || this.random.nextInt(120) == 0 || this.f > 0) && this.aV < 100) {
this.D();
}
2011-06-30 00:02:25 +02:00
int i = MathHelper.floor(this.boundingBox.b + 0.5D);
2012-01-12 23:10:13 +01:00
boolean flag = this.aK();
boolean flag1 = this.aL();
2011-01-29 22:50:29 +01:00
this.pitch = 0.0F;
if (this.pathEntity != null && this.random.nextInt(100) != 0) {
2012-01-12 12:02:39 +01:00
// MethodProfiler.a("followpath"); // CraftBukkit - not in production code
Vec3D vec3d = this.pathEntity.a(this);
double d0 = (double) (this.width * 2.0F);
2011-01-29 22:50:29 +01:00
while (vec3d != null && vec3d.d(this.locX, vec3d.b, this.locZ) < d0 * d0) {
this.pathEntity.a();
if (this.pathEntity.b()) {
2011-01-29 22:50:29 +01:00
vec3d = null;
this.pathEntity = null;
2011-01-29 22:50:29 +01:00
} else {
vec3d = this.pathEntity.a(this);
2011-01-29 22:50:29 +01:00
}
}
2011-01-29 22:50:29 +01:00
2012-01-12 23:10:13 +01:00
this.aZ = false;
2011-01-29 22:50:29 +01:00
if (vec3d != null) {
double d1 = vec3d.a - this.locX;
double d2 = vec3d.c - this.locZ;
2011-06-30 00:02:25 +02:00
double d3 = vec3d.b - (double) i;
2011-05-14 16:29:42 +02:00
// CraftBukkit - Math -> TrigMath
2011-06-30 00:02:25 +02:00
float f2 = (float) (TrigMath.atan2(d2, d1) * 180.0D / 3.1415927410125732D) - 90.0F;
float f3 = f2 - this.yaw;
2011-01-29 22:50:29 +01:00
2012-01-12 23:10:13 +01:00
for (this.aX = this.bb; f3 < -180.0F; f3 += 360.0F) {
2011-01-29 22:50:29 +01:00
;
}
2011-06-30 00:02:25 +02:00
while (f3 >= 180.0F) {
f3 -= 360.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
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;
if (this.e && this.target != null) {
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-01-12 23:10:13 +01:00
this.aW = -MathHelper.sin(f3) * this.aX * 1.0F;
this.aX = MathHelper.cos(f3) * this.aX * 1.0F;
2011-01-29 22:50:29 +01:00
}
if (d3 > 0.0D) {
2012-01-12 23:10:13 +01:00
this.aZ = true;
2011-01-29 22:50:29 +01:00
}
}
if (this.target != null) {
this.a(this.target, 30.0F, 30.0F);
2011-01-29 22:50:29 +01:00
}
2012-01-12 23:10:13 +01:00
if (this.positionChanged && !this.E()) {
this.aZ = true;
}
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-01-12 23:10:13 +01:00
this.aZ = true;
}
2011-11-20 09:01:14 +01:00
2012-01-12 12:02:39 +01:00
// MethodProfiler.a(); // CraftBukkit - not in production code
2011-01-29 22:50:29 +01:00
} else {
2011-11-20 09:01:14 +01:00
super.m_();
this.pathEntity = null;
}
}
2012-01-12 23:10:13 +01:00
protected void D() {
2012-01-12 12:02:39 +01:00
// MethodProfiler.a("stroll"); // CraftBukkit - not in production code
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) {
this.pathEntity = this.world.a(this, i, j, k, 10.0F);
}
2011-11-20 09:01:14 +01:00
2012-01-12 12:02:39 +01:00
// MethodProfiler.a(); // CraftBukkit - not in production code
2011-06-30 00:02:25 +02:00
}
protected void a(Entity entity, float f) {}
2011-05-26 14:48:22 +02:00
protected void b(Entity entity, float f) {}
2012-01-12 23:10:13 +01:00
public float a(int i, int j, int k) {
return 0.0F;
}
protected Entity findTarget() {
return null;
}
2011-11-20 09:01:14 +01:00
public boolean g() {
int i = MathHelper.floor(this.locX);
int j = MathHelper.floor(this.boundingBox.b);
int k = MathHelper.floor(this.locZ);
2011-11-20 09:01:14 +01:00
return super.g() && this.a(i, j, k) >= 0.0F;
}
2011-03-31 22:40:00 +02:00
2012-01-12 23:10:13 +01:00
public boolean E() {
return this.pathEntity != null;
2011-03-31 22:40:00 +02:00
}
public void setPathEntity(PathEntity pathentity) {
this.pathEntity = pathentity;
2011-03-31 22:40:00 +02:00
}
2012-01-12 23:10:13 +01:00
public Entity F() {
return this.target;
2011-03-31 22:40:00 +02:00
}
public void setTarget(Entity entity) {
this.target = entity;
2011-03-31 22:40:00 +02:00
}
2011-09-15 02:23:52 +02:00
2012-01-12 23:10:13 +01:00
protected float G() {
float f = super.G();
2011-09-15 02:23:52 +02:00
if (this.f > 0) {
f *= 2.0F;
}
return f;
}
}