Search in sources :

Example 1 with EntityPositionS2CPacket

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;
}
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)

Example 2 with EntityPositionS2CPacket

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()));
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) TameableEntity(net.minecraft.entity.passive.TameableEntity) EntityPositionS2CPacket(net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket) WorldEventS2CPacket(net.minecraft.network.packet.s2c.play.WorldEventS2CPacket) UUID(java.util.UUID) Vec3d(net.minecraft.util.math.Vec3d) EventHandler(meteordevelopment.orbit.EventHandler)

Aggregations

EntityPositionS2CPacket (net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket)2 GameProfile (com.mojang.authlib.GameProfile)1 UUID (java.util.UUID)1 EventHandler (meteordevelopment.orbit.EventHandler)1 Entity (net.minecraft.entity.Entity)1 TameableEntity (net.minecraft.entity.passive.TameableEntity)1 EntitySetHeadYawS2CPacket (net.minecraft.network.packet.s2c.play.EntitySetHeadYawS2CPacket)1 PlayerListS2CPacket (net.minecraft.network.packet.s2c.play.PlayerListS2CPacket)1 WorldEventS2CPacket (net.minecraft.network.packet.s2c.play.WorldEventS2CPacket)1 ServerWorld (net.minecraft.server.world.ServerWorld)1 LiteralText (net.minecraft.text.LiteralText)1 Vec3d (net.minecraft.util.math.Vec3d)1