use of net.minecraft.network.play.client.CPacketPlayer.Rotation 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;
}
}
Aggregations