FreeLook module

FreeLook: Minecraft 26.3 cheat module, full source for every implementation (3 clients: OfflineClient, Nicotine, LiquidBounce (Kotlin)).

3 implementationsRENDERPlayer

Full module source: 3 implementations

Every implementation below is the complete module file, verbatim. Expand a client to read its code.

OfflineClientRENDERsrc/main/java/com/jellypudding/offlineclient/modules/render/FreeLook.javaJava · 192 lines · 6.9 KB

Look around without turning your body.

SettingsHoldModePerspectiveSensitivityArrow keysArrow speed
FreeLook.javaJava · Minecraft 26.2 · 192 lines · 6.9 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.render;
2
3
import com.jellypudding.offlineclient.event.Subscribe;
4
import com.jellypudding.offlineclient.event.events.KeyPressEvent;
5
import com.jellypudding.offlineclient.event.events.TickEvent;
6
import com.jellypudding.offlineclient.module.Category;
7
import com.jellypudding.offlineclient.module.Module;
8
import com.jellypudding.offlineclient.setting.BoolSetting;
9
import com.jellypudding.offlineclient.setting.EnumSetting;
10
import com.jellypudding.offlineclient.setting.NumberSetting;
11
import com.jellypudding.offlineclient.util.InputUtil;
12
import com.jellypudding.offlineclient.util.Modules;
13
import com.mojang.blaze3d.platform.InputConstants;
14
import net.minecraft.client.CameraType;
15
import net.minecraft.util.Mth;
16
import net.minecraft.world.entity.Entity;
17
import org.lwjgl.glfw.GLFW;
18
19
// CameraMixin swaps the look angles around the camera alignment.
20
// MouseHandlerMixin sends the mouse here.
21
public final class FreeLook extends Module {
22
23
    public enum Perspective { KEEP, THIRD_PERSON, FRONT }
24
25
    public enum Mode { PLAYER, CAMERA }
26
27
    private static final float ARROW_STEP = 0.5f;
28
29
    private final BoolSetting hold = new BoolSetting("Hold",
30
        "Look around only whilst the bind is held down.", true);
31
    private final EnumSetting<Mode> mode = new EnumSetting<>("Mode",
32
        "What the mouse turns whilst the module is on.", Mode.PLAYER)
33
        .describe(Mode.PLAYER, "The mouse turns the camera and your body stays put.")
34
        .describe(Mode.CAMERA, "The camera freezes where it was and the mouse turns your body.");
35
    private final EnumSetting<Perspective> perspective = new EnumSetting<>("Perspective",
36
        "Camera to switch to whilst looking around.", Perspective.THIRD_PERSON)
37
        .describe(Perspective.KEEP, "Stays in whatever view you already had.")
38
        .describe(Perspective.THIRD_PERSON, "Switches to the view from behind.")
39
        .describe(Perspective.FRONT, "Switches to the view from the front.");
40
    private final NumberSetting sensitivity = new NumberSetting("Sensitivity",
41
        "Mouse speed whilst looking around.", 1, 0.1, 3, 0.1).min(0.05);
42
    private final BoolSetting arrows = new BoolSetting("Arrow keys",
43
        "The arrow keys turn whichever of your body or the camera the mouse does not.", true);
44
    private final NumberSetting arrowSpeed = new NumberSetting("Arrow speed",
45
        "Degrees the arrow keys turn each tick.", 4, 1, 20, 0.5, " degrees").min(0.5)
46
        .under(arrows);
47
48
    private float yaw;
49
    private float pitch;
50
    private float savedYaw;
51
    private float savedPitch;
52
    private float savedYawO;
53
    private float savedPitchO;
54
    private CameraType savedCamera;
55
    // Null whilst nothing is swapped.
56
    private Entity swapped;
57
    private boolean primed;
58
59
    public FreeLook() {
60
        super("FreeLook", "Look around without turning your body.", Category.RENDER, GLFW.GLFW_KEY_LEFT_ALT);
61
        addSettings(hold, mode, perspective, sensitivity, arrows, arrowSpeed);
62
        searchTags("free look", "perspective", "look behind");
63
    }
64
65
    @Override
66
    public boolean savesEnabledState() {
67
        return false;
68
    }
69
70
    @Override
71
    protected void onEnable() {
72
        swapped = null;
73
        if (mc.player == null) {
74
            setEnabled(false);
75
            return;
76
        }
77
        primed = true;
78
        yaw = mc.player.getYRot();
79
        pitch = mc.player.getXRot();
80
        savedCamera = mc.options.getCameraType();
81
        if (perspective.is(Perspective.THIRD_PERSON)) {
82
            mc.options.setCameraType(CameraType.THIRD_PERSON_BACK);
83
        } else if (perspective.is(Perspective.FRONT)) {
84
            mc.options.setCameraType(CameraType.THIRD_PERSON_FRONT);
85
        }
86
    }
87
88
    @Override
89
    protected void onDisable() {
90
        restoreRotation();
91
        if (savedCamera != null) {
92
            mc.options.setCameraType(savedCamera);
93
            savedCamera = null;
94
        }
95
    }
96
97
    @Subscribe
98
    private void onKeyPress(KeyPressEvent event) {
99
        if (hold.isOn() && event.getAction() == GLFW.GLFW_RELEASE
100
            && getKeybind().isBound() && event.getKey() == getKeybind().getValue()) {
101
            setEnabled(false);
102
        }
103
    }
104
105
    // Mouse movement lands here instead of turning the player.
106
    public void turn(double deltaYaw, double deltaPitch) {
107
        double factor = InputUtil.MOUSE_TURN * sensitivity.getValue();
108
        yaw += (float) (deltaYaw * factor);
109
        pitch = Mth.clamp(pitch + (float) (deltaPitch * factor), -90f, 90f);
110
    }
111
112
    // The arrow keys turn the camera in player mode and your body in camera mode.
113
    @Subscribe
114
    private void onTick(TickEvent event) {
115
        if (!arrows.isOn() || !isActive() || mc.gui.screen() != null) {
116
            return;
117
        }
118
        float step = 0;
119
        float pitchStep = 0;
120
        for (int i = 0; i < arrowSpeed.getValue() / ARROW_STEP; i++) {
121
            step += (held(GLFW.GLFW_KEY_RIGHT) ? ARROW_STEP : 0) - (held(GLFW.GLFW_KEY_LEFT) ? ARROW_STEP : 0);
122
            pitchStep += (held(GLFW.GLFW_KEY_DOWN) ? ARROW_STEP : 0) - (held(GLFW.GLFW_KEY_UP) ? ARROW_STEP : 0);
123
        }
124
        if (step == 0 && pitchStep == 0) {
125
            return;
126
        }
127
        if (mode.is(Mode.PLAYER)) {
128
            yaw += step;
129
            pitch = Mth.clamp(pitch + pitchStep, -90f, 90f);
130
        } else {
131
            mc.player.setYRot(mc.player.getYRot() + step);
132
            mc.player.setXRot(Mth.clamp(mc.player.getXRot() + pitchStep, -90f, 90f));
133
        }
134
    }
135
136
    private static boolean held(int key) {
137
        return InputConstants.isKeyDown(mc.getWindow(), key);
138
    }
139
140
    public boolean isActive() {
141
        if (!isEnabled() || mc.player == null) {
142
            return false;
143
        }
144
        return !Modules.enabled(Freecam.class);
145
    }
146
147
    // Only player mode takes the mouse away from your body.
148
    public boolean stealsMouse() {
149
        return isActive() && mode.is(Mode.PLAYER);
150
    }
151
152
    // Applied for one camera alignment and then restored.
153
    public void applyRotation() {
154
        if (swapped != null || !isActive()) {
155
            return;
156
        }
157
        Entity entity = target();
158
        if (!primed) {
159
            // The module can be enabled before a player exists.
160
            yaw = entity.getYRot();
161
            pitch = entity.getXRot();
162
            primed = true;
163
        }
164
        savedYaw = entity.getYRot();
165
        savedPitch = entity.getXRot();
166
        savedYawO = entity.yRotO;
167
        savedPitchO = entity.xRotO;
168
        entity.setYRot(yaw);
169
        entity.setXRot(pitch);
170
        entity.yRotO = yaw;
171
        entity.xRotO = pitch;
172
        swapped = entity;
173
    }
174
175
    public void restoreRotation() {
176
        if (swapped == null) {
177
            return;
178
        }
179
        Entity entity = swapped;
180
        swapped = null;
181
        entity.setYRot(savedYaw);
182
        entity.setXRot(savedPitch);
183
        entity.yRotO = savedYawO;
184
        entity.xRotO = savedPitchO;
185
    }
186
187
    private Entity target() {
188
        Entity entity = mc.getCameraEntity();
189
        return entity == null ? mc.player : entity;
190
    }
191
}
192
NicotinePlayersrc/client/java/nicotine/mod/mods/player/Freelook.javaJava · 71 lines · 1.8 KB
Freelook.javaJava · Minecraft 26.3 · 71 lines · 1.8 KB · complete file, verbatimOriginal ↗
1
package nicotine.mod.mods.player;
2
3
import net.minecraft.util.Mth;
4
import nicotine.events.AlignCameraWithEntityEvent;
5
import nicotine.events.TurnPlayerEvent;
6
import nicotine.mod.Mod;
7
import nicotine.mod.ModCategory;
8
import nicotine.util.EventBus;
9
10
import static nicotine.util.Common.*;
11
12
public class Freelook extends Mod {
13
14
    private float xRot, yRot, xRotO, yRotO = 0;
15
16
    public Freelook() {
17
        super(ModCategory.Player, "Freelook");
18
    }
19
20
    @Override
21
    public void toggle() {
22
        super.toggle();
23
24
        if (this.enabled && mc.level == null) {
25
            this.enabled = false;
26
            return;
27
        }
28
29
        if (this.enabled) {
30
            xRot = mc.player.getXRot();
31
            yRot = mc.player.getYRot();
32
33
            xRotO = mc.player.xRotO;
34
            yRotO = mc.player.yRotO;
35
        }
36
    }
37
38
    @Override
39
    public void init() {
40
        EventBus.register(TurnPlayerEvent.class, event -> {
41
            if (!this.enabled)
42
                return true;
43
44
            float xDelta = (float) event.yo * 0.15F;
45
            float yDelta = (float) event.xo * 0.15F;
46
47
            xRot += xDelta;
48
            yRot += yDelta;
49
            xRot = Mth.clamp(xRot, -90.0F, 90.0F);
50
51
            xRotO += xDelta;
52
            yRotO += yDelta;
53
            xRotO = Mth.clamp(this.xRotO, -90.0F, 90.0F);
54
55
            return false;
56
        });
57
58
        EventBus.register(AlignCameraWithEntityEvent.class, event -> {
59
            if (!this.enabled)
60
                return true;
61
62
            mc.gameRenderer.mainCamera().setRotation(
63
                    event.partialTicks == 1.0F ? yRot : Mth.rotLerp(event.partialTicks, yRotO, yRot),
64
                    event.partialTicks == 1.0F ? xRot : Mth.rotLerp(event.partialTicks, xRotO, xRot)
65
            );
66
67
            return true;
68
        });
69
    }
70
}
71
LiquidBounce (Kotlin)RENDERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleFreeLook.ktKotlin · 81 lines · 2.8 KB

Allows you to move the camera freely around your character.

SettingsPerspectiveSenseBoostNoPitchLimit
ModuleFreeLook.ktKotlin · Minecraft 26.2 · 81 lines · 2.8 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
3
 *
4
 * Copyright (c) 2015 - 2026 CCBlueX
5
 *
6
 * LiquidBounce is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * LiquidBounce is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
package net.ccbluex.liquidbounce.features.module.modules.render
21
22
import net.ccbluex.liquidbounce.config.types.list.Tagged
23
import net.ccbluex.liquidbounce.event.events.MouseRotationEvent
24
import net.ccbluex.liquidbounce.event.events.PerspectiveEvent
25
import net.ccbluex.liquidbounce.event.handler
26
import net.ccbluex.liquidbounce.features.module.ClientModule
27
import net.ccbluex.liquidbounce.features.module.ModuleCategories
28
import net.ccbluex.liquidbounce.utils.aiming.utils.RotationUtil
29
import net.ccbluex.liquidbounce.utils.input.InputBind
30
import net.minecraft.client.CameraType
31
import net.minecraft.client.CameraType.THIRD_PERSON_BACK
32
import net.minecraft.client.CameraType.THIRD_PERSON_FRONT
33
34
object ModuleFreeLook : ClientModule(
35
    "FreeLook", ModuleCategories.RENDER, disableOnQuit = true, bindAction = InputBind.BindAction.HOLD
36
) {
37
38
    private val perspective by enumChoice("Perspective", PerspectiveChoice.BACK)
39
    private val senseBoost by float("SenseBoost", 1f, 0.1f..2f)
40
    private val noPitchLimit by boolean("NoPitchLimit", true)
41
42
    var cameraYaw = 0f
43
    var cameraPitch = 0f
44
45
    @get:JvmName("isInvertedView")
46
    val invertedView get() = perspective.perspective == THIRD_PERSON_FRONT
47
48
    override fun onEnabled() {
49
        cameraYaw = player.yRot
50
        cameraPitch = player.xRot
51
    }
52
53
    @Suppress("unused")
54
    private val handlePerspective = handler<PerspectiveEvent> { event ->
55
        event.perspective = perspective.perspective
56
    }
57
58
    @Suppress("unused")
59
    private val mouseRotationInputHandler = handler<MouseRotationEvent> { event ->
60
        val delta = RotationUtil.mouseTurnDelta(event.cursorDeltaX, event.cursorDeltaY)
61
62
        cameraYaw += delta.deltaYaw * senseBoost
63
        cameraPitch += delta.deltaPitch * senseBoost
64
65
        if (!noPitchLimit) {
66
            cameraPitch = cameraPitch.coerceIn(-90f, 90f)
67
        }
68
69
        event.cancelEvent()
70
    }
71
72
    @Suppress("unused")
73
    private enum class PerspectiveChoice(
74
        override val tag: String,
75
        val perspective: CameraType
76
    ) : Tagged {
77
        FRONT("Front", THIRD_PERSON_FRONT),
78
        BACK("Back", THIRD_PERSON_BACK)
79
    }
80
}
81