use of net.minecraft.server.v1_14_R1.EntityInsentient in project Citizens2 by CitizensDev.
the class NMSImpl method look.
@Override
public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, boolean immediate) {
Entity handle = NMSImpl.getHandle(entity);
if (immediate || headOnly || BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType()) || (!(handle instanceof EntityInsentient) && !(handle instanceof EntityHumanNPC))) {
Location fromLocation = entity.getLocation(FROM_LOCATION);
double xDiff, yDiff, zDiff;
xDiff = to.getX() - fromLocation.getX();
yDiff = to.getY() - fromLocation.getY();
zDiff = to.getZ() - fromLocation.getZ();
double distanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
double distanceY = Math.sqrt(distanceXZ * distanceXZ + yDiff * yDiff);
double yaw = Math.toDegrees(Math.acos(xDiff / distanceXZ));
double pitch = Math.toDegrees(Math.acos(yDiff / distanceY)) - (handle.getBukkitEntity().getType() == EntityType.PHANTOM ? 45 : 90);
if (zDiff < 0.0)
yaw += Math.abs(180 - yaw) * 2;
if (handle.getBukkitEntity().getType() == EntityType.ENDER_DRAGON) {
yaw = Util.getDragonYaw(handle.getBukkitEntity(), xDiff, zDiff);
} else {
yaw = yaw - 90;
}
if (headOnly) {
setHeadYaw(entity, (float) yaw);
} else {
look(entity, (float) yaw, (float) pitch);
}
return;
}
if (handle instanceof EntityInsentient) {
((EntityInsentient) handle).getControllerLook().a(to.getX(), to.getY(), to.getZ(), ((EntityInsentient) handle).ep(), ((EntityInsentient) handle).O());
while (((EntityLiving) handle).aC >= 180F) {
((EntityLiving) handle).aC -= 360F;
}
while (((EntityLiving) handle).aC < -180F) {
((EntityLiving) handle).aC += 360F;
}
} else if (handle instanceof EntityHumanNPC) {
((EntityHumanNPC) handle).setTargetLook(to);
}
}
use of net.minecraft.server.v1_14_R1.EntityInsentient in project Citizens2 by CitizensDev.
the class NMSImpl method setNoGravity.
@Override
public void setNoGravity(org.bukkit.entity.Entity entity, boolean enabled) {
Entity handle = getHandle(entity);
handle.setNoGravity(enabled);
if (!(handle instanceof EntityInsentient) || !(entity instanceof NPCHolder))
return;
EntityInsentient mob = (EntityInsentient) handle;
NPC npc = ((NPCHolder) entity).getNPC();
if (!(mob.getControllerMove() instanceof ControllerMoveFlying) || npc.data().has("flying-nogravity-float"))
return;
try {
if (enabled) {
boolean old = (boolean) FLYING_MOVECONTROL_FLOAT_GETTER.invoke(mob.getControllerMove());
FLYING_MOVECONTROL_FLOAT_SETTER.invoke(mob.getControllerMove(), true);
npc.data().set("flying-nogravity-float", old);
} else if (npc.data().has("flying-nogravity-float")) {
FLYING_MOVECONTROL_FLOAT_SETTER.invoke(mob.getControllerMove(), npc.data().get("flying-nogravity-float"));
npc.data().remove("flying-nogravity-float");
}
} catch (Throwable t) {
t.printStackTrace();
}
}
use of net.minecraft.server.v1_14_R1.EntityInsentient in project Citizens2 by CitizensDev.
the class NMSImpl method updateAI.
public static void updateAI(EntityLiving entity) {
if (entity instanceof EntityInsentient) {
EntityInsentient handle = (EntityInsentient) entity;
handle.getEntitySenses().a();
NMSImpl.updateNavigation(handle.getNavigation());
handle.getControllerMove().a();
handle.getControllerLook().a();
handle.getControllerJump().b();
} else if (entity instanceof EntityHumanNPC) {
((EntityHumanNPC) entity).updateAI();
}
}
use of net.minecraft.server.v1_14_R1.EntityInsentient in project Citizens2 by CitizensDev.
the class PlayerPathfinder method a.
@Override
public PathEntity a(ChunkCache var0, EntityInsentient var1, Set<BlockPosition> var2, float var3, int var4, float var5) {
this.a.a();
this.e.a(var0, var1);
PathPoint var6 = this.e.b();
Map<PathDestination, BlockPosition> var7 = var2.stream().collect(Collectors.toMap((var0x) -> {
return this.e.a((double) var0x.getX(), (double) var0x.getY(), (double) var0x.getZ());
}, Function.identity()));
PathEntity var8 = this.a(var6, var7, var3, var4, var5);
this.e.a();
return var8;
}
use of net.minecraft.server.v1_14_R1.EntityInsentient in project Citizens2 by CitizensDev.
the class NMSImpl method look.
@Override
public void look(org.bukkit.entity.Entity entity, Location to, boolean headOnly, boolean immediate) {
Entity handle = NMSImpl.getHandle(entity);
if (immediate || headOnly || BAD_CONTROLLER_LOOK.contains(handle.getBukkitEntity().getType()) || (!(handle instanceof EntityInsentient) && !(handle instanceof EntityHumanNPC))) {
Location fromLocation = entity.getLocation(FROM_LOCATION);
double xDiff, yDiff, zDiff;
xDiff = to.getX() - fromLocation.getX();
yDiff = to.getY() - fromLocation.getY();
zDiff = to.getZ() - fromLocation.getZ();
double distanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
double distanceY = Math.sqrt(distanceXZ * distanceXZ + yDiff * yDiff);
double yaw = Math.toDegrees(Math.acos(xDiff / distanceXZ));
double pitch = Math.toDegrees(Math.acos(yDiff / distanceY)) - 90;
if (zDiff < 0.0)
yaw += Math.abs(180 - yaw) * 2;
if (handle instanceof EntityEnderDragon) {
yaw = Util.getDragonYaw(handle.getBukkitEntity(), xDiff, zDiff);
} else {
yaw = yaw - 90;
}
if (headOnly) {
setHeadYaw(entity, (float) yaw);
} else {
look(entity, (float) yaw, (float) pitch);
}
return;
}
if (handle instanceof EntityInsentient) {
((EntityInsentient) handle).getControllerLook().a(to.getX(), to.getY(), to.getZ(), ((EntityInsentient) handle).cL(), ((EntityInsentient) handle).N());
while (((EntityLiving) handle).aP >= 180F) {
((EntityLiving) handle).aP -= 360F;
}
while (((EntityLiving) handle).aP < -180F) {
((EntityLiving) handle).aP += 360F;
}
} else if (handle instanceof EntityHumanNPC) {
((EntityHumanNPC) handle).setTargetLook(to);
}
}
Aggregations