Search in sources :

Example 6 with CPacketConfirmTeleport

use of net.minecraft.network.play.client.CPacketConfirmTeleport in project cosmos by momentumdevelopment.

the class PacketFlightModule method onMotionUpdate.

@SubscribeEvent
public void onMotionUpdate(MotionUpdateEvent event) {
    // vanilla packet data
    event.setX(mc.player.posX);
    event.setY(mc.player.getEntityBoundingBox().minY);
    event.setZ(mc.player.posZ);
    event.setYaw(mc.player.rotationYaw);
    event.setPitch(mc.player.rotationPitch);
    event.setOnGround(false);
    // vertical movement
    double motionY = 0;
    // non-phase movement, allowed to move faster and more freely
    if (!isPhased()) {
        if (mc.gameSettings.keyBindJump.isKeyDown()) {
            // float up
            motionY = 0.031;
            // fall
            if (mc.player.ticksExisted % 18 == 0 && antiKick.getValue()) {
                motionY = -0.04;
            }
        }
        // float down
        if (mc.gameSettings.keyBindSneak.isKeyDown() && !mc.gameSettings.keyBindJump.isKeyDown()) {
            motionY = -0.031;
        }
    } else // phase movement, no need to apply vanilla anticheat gravity here
    {
        if (mc.gameSettings.keyBindJump.isKeyDown()) {
            // float up, slower
            motionY = 0.017;
        }
        if (mc.gameSettings.keyBindSneak.isKeyDown() && !mc.gameSettings.keyBindJump.isKeyDown()) {
            // float down, slower
            motionY = -0.017;
        }
    }
    // frozen movement
    if (motionY == 0 && !isPhased()) {
        // fall
        if (mc.player.ticksExisted % 4 == 0 && antiKick.getValue()) {
            motionY = -0.0325;
        }
    }
    // the current movement input values of the user
    float forward = mc.player.movementInput.moveForward;
    float strafe = mc.player.movementInput.moveStrafe;
    float yaw = mc.player.rotationYaw;
    // if we're not inputting any movements, then we shouldn't be adding any motion
    if (!MotionUtil.isMoving()) {
        mc.player.motionX = 0;
        mc.player.motionZ = 0;
    } else if (forward != 0) {
        if (strafe >= 1) {
            yaw += (forward > 0 ? -45 : 45);
            strafe = 0;
        } else if (strafe <= -1) {
            yaw += (forward > 0 ? 45 : -45);
            strafe = 0;
        }
        if (forward > 0) {
            forward = 1;
        } else if (forward < 0) {
            forward = -1;
        }
    }
    // our facing values, according to movement not rotations
    double cos = Math.cos(Math.toRadians(yaw + 90));
    double sin = Math.sin(Math.toRadians(yaw + 90));
    double moveSpeed;
    if (motionY != 0) {
        moveSpeed = 0.026;
    } else // we can move faster while not moving up
    {
        moveSpeed = 0.040;
        if (mode.getValue().equals(Mode.FACTOR)) {
            moveSpeed *= factor.getValue();
        }
    }
    // horizontal motion
    double motionX = (forward * moveSpeed * cos) + (strafe * moveSpeed * sin);
    double motionZ = (forward * moveSpeed * sin) - (strafe * moveSpeed * cos);
    if (!isPhased()) {
        if (motionY != 0 && motionY != -0.0325) {
            motionX = 0;
            motionZ = 0;
        } else {
            motionX *= 3.59125;
            motionZ *= 3.59125;
        }
    } else // apply block friction when moving through blocks
    {
        if (friction.getValue().equals(Friction.STRICT)) {
            motionX *= 0.75;
            motionY *= 0.75;
        }
    }
    // update the movements
    mc.player.motionX = motionX;
    mc.player.motionY = motionY;
    mc.player.motionZ = motionZ;
    // if we're not inputting any movements, then we shouldn't be adding any motion
    if (!MotionUtil.isMoving()) {
        mc.player.motionX = 0;
        mc.player.motionZ = 0;
    }
    // allow the player to clip through blocks
    mc.player.noClip = true;
    // vectors
    Vec3d motionVector = new Vec3d(motionX, motionY, motionZ);
    Vec3d playerVector = new Vec3d(mc.player.posX, mc.player.getEntityBoundingBox().minY, mc.player.posZ);
    // slightly overshoot positions
    if (overshoot.getValue()) {
        playerVector.addVector(ThreadLocalRandom.current().nextDouble(-0.5, 0.5), ThreadLocalRandom.current().nextDouble(-0.5, 0.5), ThreadLocalRandom.current().nextDouble(-0.5, 0.5));
    }
    // bounds
    Vec3d boundVector = motionVector.add(playerVector.add(motionVector)).add(bounds.getValue().getAddition());
    // process packets
    if (mc.getConnection() != null) {
        // send packets
        if (mode.getValue().equals(Mode.FACTOR)) {
            if (motionY == 0) {
                // percent chance to round
                double factorize = factor.getValue() - StrictMath.floor(factor.getValue());
                // (factorize)% chance of factorizing
                double factorScaled = StrictMath.floor(factor.getValue());
                if (StrictMath.random() <= factorize) {
                    factorScaled++;
                }
                // send factored packets
                for (int i = 0; i < factorScaled; i++) {
                    double motionFactorX = (motionX / factorScaled) * (i + 1);
                    double motionFactorZ = (motionZ / factorScaled) * (i + 1);
                    // 
                    mc.getConnection().getNetworkManager().sendPacket(new CPacketPlayer.Position(playerVector.x + motionFactorX, playerVector.add(motionVector).y, playerVector.z + motionFactorZ, false));
                }
            } else {
                // we can just move instantly
                mc.getConnection().getNetworkManager().sendPacket(new CPacketPlayer.Position(playerVector.add(motionVector).x, playerVector.add(motionVector).y, playerVector.add(motionVector).z, false));
            }
        } else {
            // we can just move instantly
            mc.getConnection().getNetworkManager().sendPacket(new CPacketPlayer.Position(playerVector.add(motionVector).x, playerVector.add(motionVector).y, playerVector.add(motionVector).z, false));
        }
        mc.getConnection().getNetworkManager().sendPacket(new CPacketPlayer.Position(boundVector.x, boundVector.y, boundVector.z, false));
        // predict teleport packet
        if (type.getValue().equals(Type.JITTER) || type.getValue().equals(Type.LIMIT_JITTER)) {
            if (!packetMap.containsKey(teleportID)) {
                teleportID++;
                // confirm predicted teleport
                mc.player.connection.sendPacket(new CPacketConfirmTeleport(teleportID));
                packetMap.put(teleportID, playerVector);
                // teleport player since we know where they are going
                mc.player.setPosition(playerVector.x, playerVector.y, playerVector.z);
            }
        }
    }
}
Also used : CPacketConfirmTeleport(net.minecraft.network.play.client.CPacketConfirmTeleport) 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)

Example 7 with CPacketConfirmTeleport

use of net.minecraft.network.play.client.CPacketConfirmTeleport in project 3arthh4ck by 3arthqu4ke.

the class ListenerPosLook method invoke.

@Override
public void invoke(PacketEvent.Receive<SPacketPlayerPosLook> event) {
    if (event.isCancelled() || mc.player == null || PACKET_FLY.isEnabled() || FREE_CAM.isEnabled() || !module.fastTeleports.getValue()) {
        return;
    }
    event.setCancelled(true);
    SPacketPlayerPosLook packet = event.getPacket();
    boolean xFlag = packet.getFlags().contains(SPacketPlayerPosLook.EnumFlags.X);
    boolean yFlag = packet.getFlags().contains(SPacketPlayerPosLook.EnumFlags.Y);
    boolean zFlag = packet.getFlags().contains(SPacketPlayerPosLook.EnumFlags.Z);
    boolean yawFlag = packet.getFlags().contains(SPacketPlayerPosLook.EnumFlags.Y_ROT);
    boolean pitFlag = packet.getFlags().contains(SPacketPlayerPosLook.EnumFlags.X_ROT);
    double x = packet.getX() + (xFlag ? mc.player.posX : 0);
    double y = packet.getY() + (yFlag ? mc.player.posY : 0);
    double z = packet.getZ() + (zFlag ? mc.player.posZ : 0);
    float yaw = packet.getYaw() + (yawFlag ? mc.player.rotationYaw : 0);
    float pit = packet.getPitch() + (pitFlag ? mc.player.rotationPitch : 0);
    mc.player.connection.sendPacket(new CPacketConfirmTeleport(packet.getTeleportId()));
    Managers.ROTATION.setBlocking(true);
    mc.player.connection.sendPacket(new CPacketPlayer.PositionRotation(MathHelper.clamp(x, -3.0E7D, 3.0E7D), y, MathHelper.clamp(z, -3.0E7D, 3.0E7D), yaw, pit, false));
    Managers.ROTATION.setBlocking(false);
    if (module.asyncTeleports.getValue()) {
        execute(x, y, z, yaw, pit, xFlag, yFlag, zFlag);
    }
    mc.addScheduledTask(() -> execute(x, y, z, yaw, pit, xFlag, yFlag, zFlag));
    PacketUtil.loadTerrain();
}
Also used : CPacketConfirmTeleport(net.minecraft.network.play.client.CPacketConfirmTeleport) SPacketPlayerPosLook(net.minecraft.network.play.server.SPacketPlayerPosLook) CPacketPlayer(net.minecraft.network.play.client.CPacketPlayer)

Aggregations

CPacketConfirmTeleport (net.minecraft.network.play.client.CPacketConfirmTeleport)7 CPacketPlayer (net.minecraft.network.play.client.CPacketPlayer)5 Vec3d (net.minecraft.util.math.Vec3d)3 ICPacketPlayer (cope.cosmos.asm.mixins.accessor.ICPacketPlayer)2 SPacketPlayerPosLook (net.minecraft.network.play.server.SPacketPlayerPosLook)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 ISPacketPlayerPosLook (cope.cosmos.asm.mixins.accessor.ISPacketPlayerPosLook)1 Pair (me.wallhacks.spark.util.objects.Pair)1 CPacketEntityAction (net.minecraft.network.play.client.CPacketEntityAction)1 PositionRotation (net.minecraft.network.play.client.CPacketPlayer.PositionRotation)1