2012-03-09 01:22:09 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
2013-03-25 05:22:32 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
import org.bukkit.craftbukkit.entity.CraftEntity;
|
|
|
|
import org.bukkit.event.entity.EntityTargetEvent;
|
|
|
|
// CraftBukkit end
|
2012-03-09 22:40:59 +01:00
|
|
|
|
2012-03-09 01:22:09 +01:00
|
|
|
public abstract class PathfinderGoalTarget extends PathfinderGoal {
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
protected EntityCreature c;
|
|
|
|
protected boolean d;
|
2012-03-09 01:22:09 +01:00
|
|
|
private boolean a;
|
|
|
|
private int b;
|
2013-07-01 13:03:00 +02:00
|
|
|
private int e;
|
|
|
|
private int f;
|
2012-03-09 01:22:09 +01:00
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
public PathfinderGoalTarget(EntityCreature entitycreature, boolean flag) {
|
|
|
|
this(entitycreature, flag, false);
|
2012-03-09 01:22:09 +01:00
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
public PathfinderGoalTarget(EntityCreature entitycreature, boolean flag, boolean flag1) {
|
|
|
|
this.c = entitycreature;
|
|
|
|
this.d = flag;
|
2012-03-09 01:22:09 +01:00
|
|
|
this.a = flag1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean b() {
|
2013-07-01 13:03:00 +02:00
|
|
|
EntityLiving entityliving = this.c.getGoalTarget();
|
2012-03-09 01:22:09 +01:00
|
|
|
|
|
|
|
if (entityliving == null) {
|
|
|
|
return false;
|
|
|
|
} else if (!entityliving.isAlive()) {
|
|
|
|
return false;
|
|
|
|
} else {
|
2013-07-01 13:03:00 +02:00
|
|
|
double d0 = this.f();
|
|
|
|
|
|
|
|
if (this.c.e(entityliving) > d0 * d0) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
if (this.d) {
|
|
|
|
if (this.c.getEntitySenses().canSee(entityliving)) {
|
|
|
|
this.f = 0;
|
|
|
|
} else if (++this.f > 60) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-09 01:22:09 +01:00
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
return true;
|
|
|
|
}
|
2012-03-09 01:22:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
protected double f() {
|
2013-07-09 01:43:37 +02:00
|
|
|
AttributeInstance attributeinstance = this.c.getAttributeInstance(GenericAttributes.b);
|
2013-07-01 13:03:00 +02:00
|
|
|
|
2013-07-09 01:43:37 +02:00
|
|
|
return attributeinstance == null ? 16.0D : attributeinstance.getValue();
|
2013-07-01 13:03:00 +02:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public void c() {
|
2012-03-09 01:22:09 +01:00
|
|
|
this.b = 0;
|
2013-07-01 13:03:00 +02:00
|
|
|
this.e = 0;
|
|
|
|
this.f = 0;
|
2012-03-09 01:22:09 +01:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public void d() {
|
2013-07-01 13:03:00 +02:00
|
|
|
this.c.setGoalTarget((EntityLiving) null);
|
2012-03-09 01:22:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean a(EntityLiving entityliving, boolean flag) {
|
|
|
|
if (entityliving == null) {
|
|
|
|
return false;
|
2013-07-01 13:03:00 +02:00
|
|
|
} else if (entityliving == this.c) {
|
2012-03-09 01:22:09 +01:00
|
|
|
return false;
|
|
|
|
} else if (!entityliving.isAlive()) {
|
|
|
|
return false;
|
2013-07-01 13:03:00 +02:00
|
|
|
} else if (!this.c.a(entityliving.getClass())) {
|
2012-10-25 05:53:23 +02:00
|
|
|
return false;
|
|
|
|
} else {
|
2013-07-01 13:03:00 +02:00
|
|
|
if (this.c instanceof EntityOwnable && StringUtils.isNotEmpty(((EntityOwnable) this.c).getOwnerName())) {
|
|
|
|
if (entityliving instanceof EntityOwnable && ((EntityOwnable) this.c).getOwnerName().equals(((EntityOwnable) entityliving).getOwnerName())) {
|
2012-10-25 05:53:23 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
if (entityliving == ((EntityOwnable) this.c).getOwner()) {
|
2012-10-25 05:53:23 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (entityliving instanceof EntityHuman && !flag && ((EntityHuman) entityliving).abilities.isInvulnerable) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
if (!this.c.b(MathHelper.floor(entityliving.locX), MathHelper.floor(entityliving.locY), MathHelper.floor(entityliving.locZ))) {
|
2012-10-25 05:53:23 +02:00
|
|
|
return false;
|
2013-07-01 13:03:00 +02:00
|
|
|
} else if (this.d && !this.c.getEntitySenses().canSee(entityliving)) {
|
2012-03-09 01:22:09 +01:00
|
|
|
return false;
|
|
|
|
} else {
|
2012-10-25 05:53:23 +02:00
|
|
|
if (this.a) {
|
2013-07-01 13:03:00 +02:00
|
|
|
if (--this.e <= 0) {
|
2012-10-25 05:53:23 +02:00
|
|
|
this.b = 0;
|
2012-03-09 01:22:09 +01:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
if (this.b == 0) {
|
|
|
|
this.b = this.a(entityliving) ? 1 : 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.b == 2) {
|
2012-03-09 01:22:09 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-25 05:22:32 +01:00
|
|
|
// CraftBukkit start - Check all the different target goals for the reason, default to RANDOM_TARGET
|
2012-10-25 05:53:23 +02:00
|
|
|
EntityTargetEvent.TargetReason reason = EntityTargetEvent.TargetReason.RANDOM_TARGET;
|
2012-03-09 01:22:09 +01:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
if (this instanceof PathfinderGoalDefendVillage) {
|
|
|
|
reason = EntityTargetEvent.TargetReason.DEFEND_VILLAGE;
|
|
|
|
} else if (this instanceof PathfinderGoalHurtByTarget) {
|
|
|
|
reason = EntityTargetEvent.TargetReason.TARGET_ATTACKED_ENTITY;
|
|
|
|
} else if (this instanceof PathfinderGoalNearestAttackableTarget) {
|
|
|
|
if (entityliving instanceof EntityHuman) {
|
|
|
|
reason = EntityTargetEvent.TargetReason.CLOSEST_PLAYER;
|
2012-03-09 22:40:59 +01:00
|
|
|
}
|
2012-10-25 05:53:23 +02:00
|
|
|
} else if (this instanceof PathfinderGoalOwnerHurtByTarget) {
|
|
|
|
reason = EntityTargetEvent.TargetReason.TARGET_ATTACKED_OWNER;
|
|
|
|
} else if (this instanceof PathfinderGoalOwnerHurtTarget) {
|
|
|
|
reason = EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET;
|
|
|
|
}
|
2012-03-09 22:40:59 +01:00
|
|
|
|
2013-07-01 13:03:00 +02:00
|
|
|
org.bukkit.event.entity.EntityTargetLivingEntityEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTargetLivingEvent(this.c, entityliving, reason);
|
2012-10-25 05:53:23 +02:00
|
|
|
if (event.isCancelled() || event.getTarget() == null) {
|
2013-07-01 13:03:00 +02:00
|
|
|
this.c.setGoalTarget(null);
|
2012-10-25 05:53:23 +02:00
|
|
|
return false;
|
|
|
|
} else if (entityliving.getBukkitEntity() != event.getTarget()) {
|
2013-07-01 13:03:00 +02:00
|
|
|
this.c.setGoalTarget((EntityLiving) ((CraftEntity) event.getTarget()).getHandle());
|
2012-10-25 05:53:23 +02:00
|
|
|
}
|
2013-07-01 13:03:00 +02:00
|
|
|
if (this.c instanceof EntityCreature) {
|
|
|
|
((EntityCreature) this.c).target = ((CraftEntity) event.getTarget()).getHandle();
|
2012-03-09 01:22:09 +01:00
|
|
|
}
|
2012-10-25 05:53:23 +02:00
|
|
|
// CraftBukkit end
|
|
|
|
|
|
|
|
return true;
|
2012-03-09 01:22:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean a(EntityLiving entityliving) {
|
2013-07-09 01:43:37 +02:00
|
|
|
this.e = 10 + this.c.aC().nextInt(5);
|
2013-07-01 13:03:00 +02:00
|
|
|
PathEntity pathentity = this.c.getNavigation().a(entityliving);
|
2012-03-09 01:22:09 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|