Search in sources :

Example 1 with ISPacketPlayerPosLook

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();
    }
}
Also used : CPacketConfirmTeleport(net.minecraft.network.play.client.CPacketConfirmTeleport) ISPacketPlayerPosLook(cope.cosmos.asm.mixins.accessor.ISPacketPlayerPosLook) ISPacketPlayerPosLook(cope.cosmos.asm.mixins.accessor.ISPacketPlayerPosLook) SPacketPlayerPosLook(net.minecraft.network.play.server.SPacketPlayerPosLook) ICPacketPlayer(cope.cosmos.asm.mixins.accessor.ICPacketPlayer) CPacketPlayer(net.minecraft.network.play.client.CPacketPlayer) Vec3d(net.minecraft.util.math.Vec3d) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

ICPacketPlayer (cope.cosmos.asm.mixins.accessor.ICPacketPlayer)1 ISPacketPlayerPosLook (cope.cosmos.asm.mixins.accessor.ISPacketPlayerPosLook)1 CPacketConfirmTeleport (net.minecraft.network.play.client.CPacketConfirmTeleport)1 CPacketPlayer (net.minecraft.network.play.client.CPacketPlayer)1 SPacketPlayerPosLook (net.minecraft.network.play.server.SPacketPlayerPosLook)1 Vec3d (net.minecraft.util.math.Vec3d)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1