AutoWalk module

AutoWalk: Minecraft 26.3 cheat module, full source for every implementation (4 clients: MelaHack (ThunderHack fork), OfflineClient, Nicotine, …).

4 implementationsMOVEMENTMovementPLAYER

Full module source: 4 implementations

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

MelaHack (ThunderHack fork)MOVEMENTsrc/main/java/thunder/hack/features/modules/movement/AutoWalk.javaJava · 39 lines · 1.1 KB

Going forward for you

SettingsMode
AutoWalk.javaJava · Minecraft 26.2 · 39 lines · 1.1 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.movement;
2
3
import meteordevelopment.orbit.EventHandler;
4
import thunder.hack.events.impl.EventKeyboardInput;
5
import thunder.hack.features.modules.Module;
6
import thunder.hack.setting.Setting;
7
import thunder.hack.utility.player.MovementUtility;
8
9
public class AutoWalk extends Module {
10
    public AutoWalk() {
11
        super("AutoWalk", Category.MOVEMENT);
12
    }
13
14
    private final Setting<AutoWalk.Mode> mode = new Setting<>("Mode", AutoWalk.Mode.Simple);
15
16
    public enum Mode {
17
        Simple, Baritone
18
    }
19
20
    @Override
21
    public void onEnable() {
22
        if (mode.getValue() == Mode.Baritone)
23
            mc.player.connection.sendChat("#goto " + 3000000 * Math.cos(Math.toRadians(mc.player.getYRot() + 90f)) + " " + 3000000 * Math.sin(Math.toRadians(mc.player.getYRot() + 90f)));
24
    }
25
26
    @Override
27
    public void onDisable() {
28
        if (mode.getValue() == AutoWalk.Mode.Baritone) {
29
            mc.player.connection.sendChat("#stop");
30
        }
31
    }
32
33
    @EventHandler
34
    public void onKey(EventKeyboardInput e) {
35
        if (mode.getValue() == Mode.Simple)
36
            MovementUtility.setMovementInputY(1f);
37
    }
38
}
39
OfflineClientMOVEMENTsrc/main/java/com/jellypudding/offlineclient/modules/movement/AutoWalk.javaJava · 209 lines · 7.5 KB

Walks for you.

SettingsModeDirectionAuto sprintStop on inputStop on height changeStay in loaded chunks
AutoWalk.javaJava · Minecraft 26.2 · 209 lines · 7.5 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.movement;
2
3
import com.jellypudding.offlineclient.event.Subscribe;
4
import com.jellypudding.offlineclient.event.events.ClientTickEvent;
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.modules.player.InvWalk;
9
import com.jellypudding.offlineclient.path.PathWalker;
10
import com.jellypudding.offlineclient.path.Trip;
11
import com.jellypudding.offlineclient.setting.BoolSetting;
12
import com.jellypudding.offlineclient.setting.EnumSetting;
13
import com.jellypudding.offlineclient.util.InputUtil;
14
import com.jellypudding.offlineclient.util.Modules;
15
import net.minecraft.client.KeyMapping;
16
import net.minecraft.client.gui.screens.Screen;
17
import net.minecraft.core.BlockPos;
18
import net.minecraft.world.phys.Vec3;
19
20
import java.util.List;
21
22
public final class AutoWalk extends Module {
23
24
    public enum Mode { SIMPLE, SMART }
25
26
    public enum Direction { FORWARDS, BACKWARDS, LEFT, RIGHT }
27
28
    // How far ahead the smart walk aims and how often it aims again.
29
    private static final int LOOK_AHEAD = 16;
30
    private static final int RETARGET_TICKS = 40;
31
    private static final double GOAL_RADIUS = 3;
32
33
    private final EnumSetting<Mode> mode = new EnumSetting<>("Mode",
34
        "How the walking is done.", Mode.SIMPLE)
35
        .describe(Mode.SIMPLE, "Holds the key and walks into whatever is in the way.")
36
        .describe(Mode.SMART, "Walks the way you face and finds a path round what is in the way.");
37
    private final EnumSetting<Direction> direction = new EnumSetting<>("Direction",
38
        "Which way you walk.", Direction.FORWARDS);
39
    private final BoolSetting autoSprint = new BoolSetting("Auto sprint",
40
        "Sprint instead of walking.", false);
41
    private final BoolSetting stopOnInput = new BoolSetting("Stop on input",
42
        "Switches off as soon as you press a movement key yourself.", false);
43
    private final BoolSetting stopOnHeightChange = new BoolSetting("Stop on height change",
44
        "Switches off as soon as you move up or down.", false)
45
        .under(mode, Mode.SIMPLE);
46
    private final BoolSetting stayInLoadedChunks = new BoolSetting("Stay in loaded chunks",
47
        "Stops walking whilst the chunk ahead has not loaded yet.", true);
48
49
    // Whether each movement key was physically down last tick.
50
    private final boolean[] wasHeld = new boolean[6];
51
    private KeyMapping held;
52
53
    private final Trip trip = new Trip();
54
    private int retarget;
55
56
    public AutoWalk() {
57
        super("AutoWalk", "Walks for you.", Category.MOVEMENT);
58
        addSettings(mode, direction, autoSprint, stopOnInput, stopOnHeightChange, stayInLoadedChunks);
59
        searchTags("auto walk", "path", "afk walk");
60
    }
61
62
    @Override
63
    public String getSuffix() {
64
        return direction.getValueString();
65
    }
66
67
    @Override
68
    protected void onEnable() {
69
        retarget = 0;
70
        if (!inGame()) {
71
            return;
72
        }
73
        List<KeyMapping> keys = movementKeys();
74
        for (int i = 0; i < keys.size(); i++) {
75
            wasHeld[i] = InputUtil.physicallyHeld(keys.get(i));
76
        }
77
    }
78
79
    // The key state only changes again on a real key event.
80
    @Override
81
    protected void onDisable() {
82
        letGo();
83
        trip.stop();
84
    }
85
86
    @Subscribe
87
    private void onTick(TickEvent event) {
88
        if (!inGame()) {
89
            return;
90
        }
91
        if (mode.is(Mode.SIMPLE) && stopOnHeightChange.isOn() && mc.player.yo != mc.player.getY()) {
92
            setEnabled(false);
93
            return;
94
        }
95
        boolean pressed = pressedMovementKey();
96
        if (stopOnInput.isOn() && pressed) {
97
            setEnabled(false);
98
            return;
99
        }
100
        if (stayInLoadedChunks.isOn() && chunkAheadMissing()) {
101
            letGo();
102
            trip.stop();
103
            Vec3 motion = mc.player.getDeltaMovement();
104
            mc.player.setDeltaMovement(0, motion.y, 0);
105
            return;
106
        }
107
        if (mode.is(Mode.SMART)) {
108
            letGo();
109
            smartTick();
110
            return;
111
        }
112
        trip.stop();
113
        KeyMapping wanted = keyFor(direction.getValue());
114
        if (held != wanted) {
115
            letGo();
116
        }
117
        held = wanted;
118
        held.setDown(true);
119
        if (autoSprint.isOn()) {
120
            return;
121
        }
122
        // A hand started sprint ends on key release.
123
        if (mc.player.isSprinting() && !InputUtil.physicallyHeld(mc.options.keyUp)
124
            && !Modules.enabled(Sprint.class)) {
125
            mc.player.setSprinting(false);
126
        }
127
    }
128
129
    // Aims a little way off in the chosen direction and lets the pathfinder get there.
130
    // The aim moves on as you turn. A blocked way just gets a new aim.
131
    private void smartTick() {
132
        if (--retarget <= 0 || !trip.active()) {
133
            retarget = RETARGET_TICKS;
134
            trip.walker().turn(PathWalker.Turn.NONE).sprint(autoSprint.isOn());
135
            trip.start(aheadOf(mc.player.position()), GOAL_RADIUS);
136
        }
137
        trip.tick();
138
    }
139
140
    private BlockPos aheadOf(Vec3 from) {
141
        float yaw = mc.player.getYRot() + switch (direction.getValue()) {
142
            case FORWARDS -> 0;
143
            case BACKWARDS -> 180;
144
            case LEFT -> -90;
145
            case RIGHT -> 90;
146
        };
147
        Vec3 heading = Vec3.directionFromRotation(0, yaw).scale(LOOK_AHEAD);
148
        return BlockPos.containing(from.add(heading));
149
    }
150
151
    // Sprint is set late in the tick. The player tick clears sprint set any earlier.
152
    @Subscribe
153
    private void onClientTick(ClientTickEvent event) {
154
        if (!inGame() || !autoSprint.isOn() || mode.is(Mode.SMART)) {
155
            return;
156
        }
157
        if (!mc.player.isUsingItem()) {
158
            mc.player.setSprinting(true);
159
        }
160
    }
161
162
    private KeyMapping keyFor(Direction direction) {
163
        return switch (direction) {
164
            case FORWARDS -> mc.options.keyUp;
165
            case BACKWARDS -> mc.options.keyDown;
166
            case LEFT -> mc.options.keyLeft;
167
            case RIGHT -> mc.options.keyRight;
168
        };
169
    }
170
171
    private void letGo() {
172
        if (held != null) {
173
            InputUtil.release(held);
174
            held = null;
175
        }
176
    }
177
178
    // True on the tick a movement key or button goes down. A screen only counts
179
    // whilst InvWalk lets the keys through it.
180
    private boolean pressedMovementKey() {
181
        Screen screen = mc.gui.screen();
182
        InvWalk invWalk = Modules.active(InvWalk.class);
183
        boolean listen = screen == null || (invWalk != null && invWalk.allows(screen));
184
        List<KeyMapping> keys = movementKeys();
185
        boolean pressed = false;
186
        for (int i = 0; i < keys.size(); i++) {
187
            boolean down = InputUtil.physicallyHeld(keys.get(i));
188
            if (down && !wasHeld[i] && listen) {
189
                pressed = true;
190
            }
191
            wasHeld[i] = down;
192
        }
193
        return pressed;
194
    }
195
196
    private List<KeyMapping> movementKeys() {
197
        return List.of(mc.options.keyUp, mc.options.keyDown, mc.options.keyLeft,
198
            mc.options.keyRight, mc.options.keyShift, mc.options.keyJump);
199
    }
200
201
    // Looks two ticks of travel ahead. The stop comes before the border.
202
    private boolean chunkAheadMissing() {
203
        Vec3 motion = mc.player.getDeltaMovement();
204
        int chunkX = (int) Math.floor((mc.player.getX() + motion.x * 2) / 16);
205
        int chunkZ = (int) Math.floor((mc.player.getZ() + motion.z * 2) / 16);
206
        return !mc.level.getChunkSource().hasChunk(chunkX, chunkZ);
207
    }
208
}
209
NicotineMovementsrc/client/java/nicotine/mod/mods/movement/AutoWalk.javaJava · 40 lines · 904 B
AutoWalk.javaJava · Minecraft 26.3 · 40 lines · 904 B · complete file, verbatimOriginal ↗
1
package nicotine.mod.mods.movement;
2
3
import com.mojang.blaze3d.platform.InputConstants;
4
import nicotine.events.ClientLevelTickEvent;
5
import nicotine.mod.Mod;
6
import nicotine.mod.ModCategory;
7
import nicotine.mod.option.KeybindOption;
8
import nicotine.util.EventBus;
9
10
import static nicotine.util.Common.mc;
11
12
public class AutoWalk extends Mod {
13
14
15
    public AutoWalk() {
16
        super(ModCategory.Movement, "AutoWalk");
17
        this.keybind.keyCode = InputConstants.KEY_U;
18
    }
19
20
    @Override
21
    public void toggle() {
22
        this.enabled = !this.enabled;
23
24
        if (!this.enabled) {
25
            mc.options.keyUp.setDown(false);
26
        }
27
    }
28
29
    @Override
30
    protected void init() {
31
        EventBus.register(ClientLevelTickEvent.class, event -> {
32
            if (!this.enabled)
33
                return true;
34
35
            mc.options.keyUp.setDown(true);
36
            return true;
37
        });
38
    }
39
}
40
LiquidBounce (Kotlin)PLAYERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/ModuleAutoWalk.ktKotlin · 40 lines · 1.5 KB

Automatically makes you walk in the direction you are facing.

ModuleAutoWalk.ktKotlin · Minecraft 26.2 · 40 lines · 1.5 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
package net.ccbluex.liquidbounce.features.module.modules.player
20
21
import net.ccbluex.liquidbounce.event.events.MovementInputEvent
22
import net.ccbluex.liquidbounce.event.handler
23
import net.ccbluex.liquidbounce.features.module.ClientModule
24
import net.ccbluex.liquidbounce.features.module.ModuleCategories
25
import net.ccbluex.liquidbounce.utils.kotlin.EventPriorityConvention.CRITICAL_MODIFICATION
26
27
/**
28
 * AutoWalk module
29
 *
30
 * Automatically makes you walk.
31
 */
32
object ModuleAutoWalk : ClientModule("AutoWalk", ModuleCategories.PLAYER) {
33
34
    @Suppress("unused")
35
    private val moveInputHandler = handler<MovementInputEvent>(priority = CRITICAL_MODIFICATION) { event ->
36
        event.directionalInput = event.directionalInput.copy(forwards = true)
37
    }
38
39
}
40