use of net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket in project KahzerxMod by otakucraft.
the class KlonePlayerEntity method createKlone.
public static void createKlone(MinecraftServer server, ServerPlayerEntity player) {
ServerWorld world = player.getWorld();
GameProfile profile = player.getGameProfile();
server.getPlayerManager().remove(player);
player.networkHandler.disconnect(new LiteralText("A clone has been created.\nThe clone will leave once you rejoin.\nHappy AFK!"));
KlonePlayerEntity klonedPlayer = new KlonePlayerEntity(server, world, profile);
klonedPlayer.refreshPositionAndAngles(player.getX(), player.getY(), player.getZ(), player.getYaw(), player.getPitch());
server.getPlayerManager().onPlayerConnect(new KloneNetworkManager(NetworkSide.SERVERBOUND), klonedPlayer);
klonedPlayer.teleport(world, player.getX(), player.getY(), player.getZ(), player.getYaw(), player.getPitch());
klonedPlayer.setHealth(player.getHealth());
klonedPlayer.unsetRemoved();
klonedPlayer.stepHeight = 0.6F;
klonedPlayer.interactionManager.changeGameMode(player.interactionManager.getGameMode());
server.getPlayerManager().sendToDimension(new EntitySetHeadYawS2CPacket(klonedPlayer, (byte) (player.headYaw * 256 / 360)), klonedPlayer.world.getRegistryKey());
server.getPlayerManager().sendToDimension(new EntityPositionS2CPacket(klonedPlayer), klonedPlayer.world.getRegistryKey());
server.getPlayerManager().sendToAll(new PlayerListS2CPacket(PlayerListS2CPacket.Action.ADD_PLAYER, klonedPlayer));
player.getWorld().getChunkManager().updatePosition(klonedPlayer);
klonedPlayer.dataTracker.set(PLAYER_MODEL_PARTS, (byte) 0x7f);
klonedPlayer.getAbilities().flying = player.getAbilities().flying;
}
use of net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket in project meteor-rejects by AntiCope.
the class CoordLogger method onPacketReceive.
@EventHandler
private void onPacketReceive(PacketEvent.Receive event) {
// Teleports
if (event.packet instanceof EntityPositionS2CPacket) {
EntityPositionS2CPacket packet = (EntityPositionS2CPacket) event.packet;
try {
Entity entity = mc.world.getEntityById(packet.getId());
// Player teleport
if (entity.getType().equals(EntityType.PLAYER) && players.get()) {
Vec3d packetPosition = new Vec3d(packet.getX(), packet.getY(), packet.getZ());
Vec3d playerPosition = entity.getPos();
if (playerPosition.distanceTo(packetPosition) >= minDistance.get()) {
info(formatMessage("Player '" + entity.getEntityName() + "' has teleported to ", packetPosition));
}
} else // World teleport
if (entity.getType().equals(EntityType.WOLF) && wolves.get()) {
Vec3d packetPosition = new Vec3d(packet.getX(), packet.getY(), packet.getZ());
Vec3d wolfPosition = entity.getPos();
UUID ownerUuid = ((TameableEntity) entity).getOwnerUuid();
if (ownerUuid != null && wolfPosition.distanceTo(packetPosition) >= minDistance.get()) {
info(formatMessage("Wolf has teleported to ", packetPosition));
}
}
} catch (NullPointerException ignored) {
}
// World events
} else if (event.packet instanceof WorldEventS2CPacket) {
WorldEventS2CPacket worldEventS2CPacket = (WorldEventS2CPacket) event.packet;
if (worldEventS2CPacket.isGlobal()) {
// Min distance
if (PlayerUtils.distanceTo(worldEventS2CPacket.getPos()) <= minDistance.get())
return;
switch(worldEventS2CPacket.getEventId()) {
case 1023:
if (withers.get())
info(formatMessage("Wither spawned at ", worldEventS2CPacket.getPos()));
break;
case 1038:
if (endPortals.get())
info(formatMessage("End portal opened at ", worldEventS2CPacket.getPos()));
break;
case 1028:
if (enderDragons.get())
info(formatMessage("Ender dragon killed at ", worldEventS2CPacket.getPos()));
break;
default:
if (otherEvents.get())
info(formatMessage("Unknown global event at ", worldEventS2CPacket.getPos()));
}
}
}
}
Aggregations