use of net.minecraft.server.v1_16_R2.Entity 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).O(), ((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);
}
}
use of net.minecraft.server.v1_16_R2.Entity in project Citizens2 by CitizensDev.
the class NMSImpl method look.
@Override
public void look(org.bukkit.entity.Entity entity, float yaw, float pitch) {
Entity handle = NMSImpl.getHandle(entity);
if (handle == null)
return;
yaw = Util.clampYaw(yaw);
handle.yaw = yaw;
setHeadYaw(entity, yaw);
handle.pitch = pitch;
}
use of net.minecraft.server.v1_16_R2.Entity in project Citizens2 by CitizensDev.
the class PlayerlistTrackerEntry method updateLastPlayer.
public void updateLastPlayer() {
if (lastUpdatedPlayer == null)
return;
final Entity tracker = getTracker(this);
final EntityPlayer entityplayer = lastUpdatedPlayer;
NMS.sendTabListAdd(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
lastUpdatedPlayer = null;
if (!Setting.DISABLE_TABLIST.asBoolean())
return;
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override
public void run() {
NMS.sendTabListRemove(entityplayer.getBukkitEntity(), (Player) tracker.getBukkitEntity());
}
}, Setting.TABLIST_REMOVE_PACKET_DELAY.asInt());
}
use of net.minecraft.server.v1_16_R2.Entity in project Citizens2 by CitizensDev.
the class NMSImpl method removeFromWorld.
@Override
public void removeFromWorld(org.bukkit.entity.Entity entity) {
Preconditions.checkNotNull(entity);
Entity nmsEntity = ((CraftEntity) entity).getHandle();
((WorldServer) nmsEntity.world).removeEntity(nmsEntity);
}
use of net.minecraft.server.v1_16_R2.Entity in project Citizens2 by CitizensDev.
the class NMSImpl method registerEntityClass.
@Override
public void registerEntityClass(Class<?> clazz) {
if (ENTITY_REGISTRY == null)
return;
Class<?> search = clazz;
while ((search = search.getSuperclass()) != null && Entity.class.isAssignableFrom(search)) {
EntityTypes<?> type = ENTITY_REGISTRY.findType(search);
MinecraftKey key = ENTITY_REGISTRY.getKey(type);
if (key == null || type == null)
continue;
CITIZENS_ENTITY_TYPES.put(clazz, type);
int code = ENTITY_REGISTRY.a(type);
ENTITY_REGISTRY.put(code, key, type);
return;
}
throw new IllegalArgumentException("unable to find valid entity superclass for class " + clazz.toString());
}
Aggregations