use of net.minecraft.server.v1_16_R3.PacketPlayOutEntityTeleport in project DragonsOnline by UniverseCraft.
the class PlayerNPC116R3 method spawnFor.
public void spawnFor(Player player) {
if (isDestroyed)
return;
// resync
location = getEntity().getLocation();
location.setYaw(originalYaw);
handle.setCustomNameVisible(false);
sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, handle), player);
sync(() -> sendPacket(new PacketPlayOutNamedEntitySpawn(handle), player), 1);
PacketPlayOutEntityTeleport tp = new PacketPlayOutEntityTeleport();
setField(tp, "a", getEntityId());
setField(tp, "b", location.getX());
setField(tp, "c", location.getY());
setField(tp, "d", location.getZ());
setField(tp, "e", getPacketRotation(location.getYaw()));
setField(tp, "f", getPacketRotation(location.getPitch()));
setField(tp, "g", handle.isOnGround());
sync(() -> sendPacket(new PacketPlayOutEntityMetadata(handle.getId(), handle.getDataWatcher(), true), player), 2);
sync(() -> setTablistName(getTablistName()), 2);
sync(() -> sendPacket(tp, player), 3);
sync(() -> sendPacket(new PacketPlayOutEntityHeadRotation(handle, getPacketRotation(location.getYaw())), player), 6);
sync(() -> removeFromTablistFor(player), 20 + (int) Math.ceil(2 * bridge.getPing(player) * 20 / 1000));
lastSeenLocation.put(player, location.clone());
// https://www.spigotmc.org/threads/remove-nameplate-of-an-nms-player-entity.436099/ (Phaze)
ScoreboardTeam team = new ScoreboardTeam(((CraftScoreboard) Bukkit.getScoreboardManager().getMainScoreboard()).getHandle(), player.getName());
team.setNameTagVisibility(ScoreboardTeamBase.EnumNameTagVisibility.NEVER);
sendPacket(new PacketPlayOutScoreboardTeam(team, 1), player);
sendPacket(new PacketPlayOutScoreboardTeam(team, 0), player);
sendPacket(new PacketPlayOutScoreboardTeam(team, List.of(handle.getName()), 3), player);
}
use of net.minecraft.server.v1_16_R3.PacketPlayOutEntityTeleport in project DragonsOnline by UniverseCraft.
the class PlayerNPC116R3 method refreshRotationFor.
public void refreshRotationFor(Player player) {
// resync
location = getEntity().getLocation();
location.setYaw(originalYaw);
PacketPlayOutEntityTeleport tp = new PacketPlayOutEntityTeleport();
setField(tp, "a", getEntityId());
setField(tp, "b", location.getX());
setField(tp, "c", location.getY());
setField(tp, "d", location.getZ());
setField(tp, "e", getPacketRotation(location.getYaw()));
setField(tp, "f", getPacketRotation(location.getPitch()));
setField(tp, "g", handle.isOnGround());
PacketPlayOutEntityLook look = new PacketPlayOutEntityLook(getEntityId(), getPacketRotation(location.getYaw()), getPacketRotation(location.getPitch()), handle.isOnGround());
sync(() -> sendPacket(tp, player));
sync(() -> sendPacket(look, player));
sync(() -> sendPacket(new PacketPlayOutEntityHeadRotation(handle, getPacketRotation(location.getYaw())), player));
}
use of net.minecraft.server.v1_16_R3.PacketPlayOutEntityTeleport in project DragonsOnline by UniverseCraft.
the class PlayerNPC116R3 method teleport.
public void teleport(Location location, boolean onGround) {
PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport();
this.setField(packet, "a", handle.getId());
this.setField(packet, "b", location.getX());
this.setField(packet, "c", location.getY());
this.setField(packet, "d", location.getZ());
this.setField(packet, "e", getPacketRotation(location.getYaw()));
this.setField(packet, "f", getPacketRotation(location.getPitch()));
this.setField(packet, "g", onGround);
this.sendPacket(packet);
this.rotateHead(location.getPitch(), location.getYaw());
this.location = location;
}
use of net.minecraft.server.v1_16_R3.PacketPlayOutEntityTeleport in project DragonsOnline by UniverseCraft.
the class PlayerNPC116R3 method updateLocationFor.
public void updateLocationFor(Player player, float pitch, float yaw) {
if (!lastSeenLocation.containsKey(player)) {
spawnFor(player);
return;
}
// resync
location = getEntity().getLocation();
location.setYaw(originalYaw);
byte byaw = getPacketRotation(yaw);
byte bpitch = getPacketRotation(pitch);
Vector move = getEntity().getLocation().subtract(lastSeenLocation.get(player)).toVector();
// since error in the dx/dy/dz's can accumulate or get desynced with the client.
if (move.lengthSquared() > 63.996 || System.currentTimeMillis() - lastForceRefresh.getOrDefault(player, 0L) > FORCE_REFRESH_LOCATION_INTERVAL_MS) {
PacketPlayOutEntityTeleport tp = new PacketPlayOutEntityTeleport();
setField(tp, "a", getEntityId());
setField(tp, "b", location.getX());
setField(tp, "c", location.getY());
setField(tp, "d", location.getZ());
setField(tp, "e", byaw);
setField(tp, "f", bpitch);
setField(tp, "g", handle.isOnGround());
sync(() -> sendPacket(tp, player));
lastForceRefresh.put(player, System.currentTimeMillis());
} else // But usually we can just send dx/dy/dz, resulting in smoother movement
// and smaller packets
{
int dx = (int) move.getX() * 4096;
int dy = (int) move.getY() * 4096;
int dz = (int) move.getZ() * 4096;
boolean onGround = handle.isOnGround();
PacketPlayOutRelEntityMoveLook packet = new PacketPlayOutRelEntityMoveLook(getEntityId(), (short) dx, (short) dy, (short) dz, byaw, bpitch, onGround);
sendPacket(packet, player);
}
sync(() -> sendPacket(new PacketPlayOutEntityHeadRotation(handle, byaw), player));
lastSeenLocation.put(player, location);
}
Aggregations