Search in sources :

Example 1 with PositionRotation

use of net.minecraft.network.play.client.CPacketPlayer.PositionRotation in project nebula by Sxmurai.

the class PacketFly method sendPacket.

private void sendPacket(double x, double y, double z, boolean bounds) {
    mc.player.connection.sendPacket(new CPacketConfirmTeleport(tpId++));
    mc.player.connection.sendPacket(new PositionRotation(x, y, z, mc.player.rotationYaw, mc.player.rotationPitch, false));
    if (bounds) {
        mc.player.connection.sendPacket(new PositionRotation(x, y - 1337.0, z, mc.player.rotationYaw, mc.player.rotationPitch, false));
    }
}
Also used : PositionRotation(net.minecraft.network.play.client.CPacketPlayer.PositionRotation) CPacketConfirmTeleport(net.minecraft.network.play.client.CPacketConfirmTeleport)

Example 2 with PositionRotation

use of net.minecraft.network.play.client.CPacketPlayer.PositionRotation in project nebula by Sxmurai.

the class MixinEntityPlayerSP method spoofUpdateWalkingPlayer.

/**
 * This is taken from minecraft's source and modified to allow us to spoof rotation / position values
 *
 * @see EntityPlayerSP#onUpdateWalkingPlayer()
 * @param event The motion update event marked as PRE
 */
private void spoofUpdateWalkingPlayer(MotionUpdateEvent event) {
    if (!event.getEra().equals(Era.PRE)) {
        return;
    }
    // sync sprint state with the server
    if (isSprinting() != serverSprintState) {
        serverSprintState = isSprinting();
        connection.sendPacket(new CPacketEntityAction(this, isSprinting() ? Action.START_SPRINTING : Action.STOP_SPRINTING));
    }
    // sync sneak state with the server
    if (isSneaking() != serverSneakState) {
        serverSneakState = isSneaking();
        connection.sendPacket(new CPacketEntityAction(this, isSneaking() ? Action.START_SNEAKING : Action.STOP_SNEAKING));
    }
    // if we are currently viewing this entity
    if (isCurrentViewEntity()) {
        // update our position update ticks
        ++positionUpdateTicks;
        // find differences in our x, y, and z values
        double diffX = event.getX() - lastReportedPosX;
        double diffY = event.getY() - lastReportedPosY;
        double diffZ = event.getZ() - lastReportedPosZ;
        // if we have moved at all
        boolean moved = diffX * diffX + diffY * diffY + diffZ * diffZ > 9.0E-4 || positionUpdateTicks >= 20;
        // differences in our yaw & pitch
        float diffYaw = event.getYaw() - lastReportedYaw;
        float diffPitch = event.getPitch() - lastReportedPitch;
        // if we have rotated at all
        boolean rotated = diffYaw != 0.0f || diffPitch != 0.0f;
        // if we are riding, we send a packet with our motion x and z and then -999 for our y value, with our rotations
        if (isRiding()) {
            connection.sendPacket(new PositionRotation(motionX, -999.0, motionZ, event.getYaw(), event.getPitch(), event.isOnGround()));
            moved = false;
        } else {
            // sync our position with the server
            if (moved && rotated) {
                connection.sendPacket(new PositionRotation(event.getX(), event.getY(), event.getZ(), event.getYaw(), event.getPitch(), event.isOnGround()));
            } else if (moved) {
                connection.sendPacket(new Position(event.getX(), event.getY(), event.getZ(), event.isOnGround()));
            } else if (rotated) {
                connection.sendPacket(new Rotation(event.getYaw(), event.getPitch(), event.isOnGround()));
            } else if (prevOnGround != onGround) {
                connection.sendPacket(new CPacketPlayer(onGround));
            }
        }
        // cache our current x, y, and z values and reset position update ticks
        if (moved) {
            lastReportedPosX = event.getX();
            lastReportedPosY = event.getY();
            lastReportedPosZ = event.getZ();
            positionUpdateTicks = 0;
        }
        // cache our current yaw and pitch
        if (rotated) {
            lastReportedYaw = event.getYaw();
            lastReportedPitch = event.getPitch();
        }
        // make sure we cache our onGround state as well
        prevOnGround = onGround;
    }
}
Also used : PositionRotation(net.minecraft.network.play.client.CPacketPlayer.PositionRotation) CPacketEntityAction(net.minecraft.network.play.client.CPacketEntityAction) Position(net.minecraft.network.play.client.CPacketPlayer.Position) CPacketPlayer(net.minecraft.network.play.client.CPacketPlayer) Rotation(net.minecraft.network.play.client.CPacketPlayer.Rotation) PositionRotation(net.minecraft.network.play.client.CPacketPlayer.PositionRotation)

Aggregations

PositionRotation (net.minecraft.network.play.client.CPacketPlayer.PositionRotation)2 CPacketConfirmTeleport (net.minecraft.network.play.client.CPacketConfirmTeleport)1 CPacketEntityAction (net.minecraft.network.play.client.CPacketEntityAction)1 CPacketPlayer (net.minecraft.network.play.client.CPacketPlayer)1 Position (net.minecraft.network.play.client.CPacketPlayer.Position)1 Rotation (net.minecraft.network.play.client.CPacketPlayer.Rotation)1