Search in sources :

Example 1 with EntitySetHeadYawS2CPacket

use of net.minecraft.network.packet.s2c.play.EntitySetHeadYawS2CPacket 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;
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) EntityPositionS2CPacket(net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket) PlayerListS2CPacket(net.minecraft.network.packet.s2c.play.PlayerListS2CPacket) GameProfile(com.mojang.authlib.GameProfile) EntitySetHeadYawS2CPacket(net.minecraft.network.packet.s2c.play.EntitySetHeadYawS2CPacket) LiteralText(net.minecraft.text.LiteralText)

Aggregations

GameProfile (com.mojang.authlib.GameProfile)1 EntityPositionS2CPacket (net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket)1 EntitySetHeadYawS2CPacket (net.minecraft.network.packet.s2c.play.EntitySetHeadYawS2CPacket)1 PlayerListS2CPacket (net.minecraft.network.packet.s2c.play.PlayerListS2CPacket)1 ServerWorld (net.minecraft.server.world.ServerWorld)1 LiteralText (net.minecraft.text.LiteralText)1