use of cope.cosmos.asm.mixins.accessor.ISPacketPlayerPosLook in project cosmos by momentumdevelopment.
the class PacketFlightModule method onPacketReceive.
@SubscribeEvent
public void onPacketReceive(PacketEvent.PacketReceiveEvent event) {
if (event.getPacket() instanceof SPacketPlayerPosLook) {
// packet vector associated with this rubberband
Vec3d packetVector = packetMap.remove(((SPacketPlayerPosLook) event.getPacket()).getTeleportId());
// server data
double serverX = ((SPacketPlayerPosLook) event.getPacket()).getX();
double serverY = ((SPacketPlayerPosLook) event.getPacket()).getY();
double serverZ = ((SPacketPlayerPosLook) event.getPacket()).getZ();
float serverYaw = ((SPacketPlayerPosLook) event.getPacket()).getYaw();
float serverPitch = ((SPacketPlayerPosLook) event.getPacket()).getPitch();
if (((SPacketPlayerPosLook) event.getPacket()).getFlags().contains(SPacketPlayerPosLook.EnumFlags.X)) {
serverX += mc.player.posX;
}
if (((SPacketPlayerPosLook) event.getPacket()).getFlags().contains(SPacketPlayerPosLook.EnumFlags.Y)) {
serverY += mc.player.getEntityBoundingBox().minY;
}
if (((SPacketPlayerPosLook) event.getPacket()).getFlags().contains(SPacketPlayerPosLook.EnumFlags.Z)) {
serverZ += mc.player.posZ;
}
if (((SPacketPlayerPosLook) event.getPacket()).getFlags().contains(SPacketPlayerPosLook.EnumFlags.X_ROT)) {
serverPitch += mc.player.rotationPitch;
}
if (((SPacketPlayerPosLook) event.getPacket()).getFlags().contains(SPacketPlayerPosLook.EnumFlags.Y_ROT)) {
serverYaw += mc.player.rotationYaw;
}
// quickly confirm the teleport
if (type.getValue().equals(Type.LIMIT) || type.getValue().equals(Type.LIMIT_JITTER)) {
mc.player.connection.sendPacket(new CPacketConfirmTeleport(((SPacketPlayerPosLook) event.getPacket()).getTeleportId()));
}
// accept server position
if (strict.getValue()) {
mc.player.setPosition(serverX, serverY, serverZ);
if (mc.getConnection() != null) {
mc.getConnection().sendPacket(new CPacketPlayer.PositionRotation(serverX, serverY, serverZ, serverYaw, serverPitch, false));
}
}
switch(mode.getValue()) {
// we already predicted this rubberband and have sent a packet to resolve it, so we can ignore the server request
case FAST:
if (packetVector.x == serverX && packetVector.y == serverY && packetVector.z == serverZ) {
event.setCanceled(true);
} else {
((ISPacketPlayerPosLook) event.getPacket()).setYaw(mc.player.rotationYaw);
((ISPacketPlayerPosLook) event.getPacket()).setPitch(mc.player.rotationPitch);
// remove packet flags
((SPacketPlayerPosLook) event.getPacket()).getFlags().remove(SPacketPlayerPosLook.EnumFlags.X_ROT);
((SPacketPlayerPosLook) event.getPacket()).getFlags().remove(SPacketPlayerPosLook.EnumFlags.Y_ROT);
}
break;
case CONCEAL:
event.setCanceled(true);
break;
case FACTOR:
((ISPacketPlayerPosLook) event.getPacket()).setYaw(mc.player.rotationYaw);
((ISPacketPlayerPosLook) event.getPacket()).setPitch(mc.player.rotationPitch);
// remove packet flags
((SPacketPlayerPosLook) event.getPacket()).getFlags().remove(SPacketPlayerPosLook.EnumFlags.X_ROT);
((SPacketPlayerPosLook) event.getPacket()).getFlags().remove(SPacketPlayerPosLook.EnumFlags.Y_ROT);
break;
}
// update our current teleport id
teleportID = ((SPacketPlayerPosLook) event.getPacket()).getTeleportId();
}
}
Aggregations