InvWalk module

InvWalk: Minecraft 26.3 cheat module, full source for every implementation (1 client: OfflineClient).

1 implementationPLAYER

Clients with this module

Full module source: 1 implementation

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

OfflineClientPLAYERsrc/main/java/com/jellypudding/offlineclient/modules/player/InvWalk.javaJava · 147 lines · 5.5 KB

Lets you walk about whilst a screen is open.

SettingsScreensSneakSprintJump
InvWalk.javaJava · Minecraft 26.2 · 147 lines · 5.5 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.player;
2
3
import com.jellypudding.offlineclient.event.Subscribe;
4
import com.jellypudding.offlineclient.event.events.ClientTickEvent;
5
import com.jellypudding.offlineclient.gui.GuiScreenBase;
6
import com.jellypudding.offlineclient.gui.ListPickerScreen;
7
import com.jellypudding.offlineclient.module.Category;
8
import com.jellypudding.offlineclient.module.Module;
9
import com.jellypudding.offlineclient.setting.BoolSetting;
10
import com.jellypudding.offlineclient.setting.EnumSetting;
11
import com.jellypudding.offlineclient.util.InputUtil;
12
import net.minecraft.client.KeyMapping;
13
import net.minecraft.client.gui.components.EditBox;
14
import net.minecraft.client.gui.components.events.GuiEventListener;
15
import net.minecraft.client.gui.screens.ChatScreen;
16
import net.minecraft.client.gui.screens.Screen;
17
import net.minecraft.client.gui.screens.inventory.AbstractSignEditScreen;
18
import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen;
19
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
20
21
import java.util.ArrayList;
22
import java.util.List;
23
24
// The real keyboard state is fed into the movement key mappings every tick.
25
public final class InvWalk extends Module {
26
27
    public enum Screens { INVENTORY, GAME, CLIENT, BOTH }
28
29
    private final EnumSetting<Screens> screens = new EnumSetting<>("Screens",
30
        "Which open screens let you keep walking.", Screens.GAME)
31
        .describe(Screens.INVENTORY, "Only your own inventory and the creative menu.")
32
        .describe(Screens.GAME, "Inventories and chests and other game screens.")
33
        .describe(Screens.CLIENT, "Only the ClickGUI and the other screens of this client.")
34
        .describe(Screens.BOTH, "Every screen that does not take typing.");
35
    private final BoolSetting sneak = new BoolSetting("Sneak",
36
        "Also let the sneak key work.", true);
37
    private final BoolSetting sprint = new BoolSetting("Sprint",
38
        "Also let the sprint key work.", true);
39
    private final BoolSetting jump = new BoolSetting("Jump",
40
        "Also let the jump key work.", true);
41
42
    public InvWalk() {
43
        super("InvWalk", "Lets you walk about whilst a screen is open.", Category.PLAYER);
44
        addSettings(screens, sneak, sprint, jump);
45
        searchTags("inventory walk", "inv move", "menu walk", "gui move");
46
    }
47
48
    @Override
49
    protected void onDisable() {
50
        release();
51
    }
52
53
    // Read by Sprint. True whilst the sprint key still works in a screen.
54
    public boolean allowsSprint() {
55
        return sprint.isOn();
56
    }
57
58
    // Read by ScreenMixin. A space press should jump rather than press a focused button.
59
    public boolean takesSpace() {
60
        return isEnabled() && jump.isOn() && mc.options.keyJump.isDefault()
61
            && mc.gui.screen() != null && allows(mc.gui.screen());
62
    }
63
64
    @Subscribe
65
    private void onClientTick(ClientTickEvent event) {
66
        if (!inGame()) {
67
            return;
68
        }
69
        Screen screen = mc.gui.screen();
70
        if (screen == null) {
71
            return;
72
        }
73
        if (!allows(screen)) {
74
            release();
75
            return;
76
        }
77
        for (KeyMapping mapping : keys()) {
78
            mapping.setDown(InputUtil.physicallyHeld(mapping));
79
        }
80
    }
81
82
    // True whilst the screen is one the setting covers and nothing on it is typing.
83
    public boolean allows(Screen screen) {
84
        if (!walkable(screen)) {
85
            return false;
86
        }
87
        boolean own = isClientScreen(screen);
88
        return switch (screens.getValue()) {
89
            case INVENTORY -> !own && isInventory(screen);
90
            case GAME -> !own;
91
            case CLIENT -> own;
92
            case BOTH -> true;
93
        };
94
    }
95
96
    // Screens that take typing keep the keyboard to themselves.
97
    public static boolean walkable(Screen screen) {
98
        if (screen instanceof ChatScreen || screen instanceof AbstractSignEditScreen
99
            || screen instanceof ListPickerScreen) {
100
            return false;
101
        }
102
        if (screen instanceof GuiScreenBase own) {
103
            return !own.isTyping();
104
        }
105
        // The creative screen carries its search box in every tab and only shows it in the search one.
106
        boolean creative = screen instanceof CreativeModeInventoryScreen;
107
        for (GuiEventListener child : screen.children()) {
108
            if (child instanceof EditBox box && (!creative || box.isVisible())) {
109
                return false;
110
            }
111
        }
112
        return true;
113
    }
114
115
    private static boolean isInventory(Screen screen) {
116
        return screen instanceof InventoryScreen || screen instanceof CreativeModeInventoryScreen;
117
    }
118
119
    private static boolean isClientScreen(Screen screen) {
120
        return screen instanceof GuiScreenBase || screen instanceof ListPickerScreen;
121
    }
122
123
    private List<KeyMapping> keys() {
124
        List<KeyMapping> keys = new ArrayList<>(List.of(mc.options.keyUp,
125
            mc.options.keyDown, mc.options.keyLeft, mc.options.keyRight));
126
        if (sneak.isOn()) {
127
            keys.add(mc.options.keyShift);
128
        }
129
        if (sprint.isOn()) {
130
            keys.add(mc.options.keySprint);
131
        }
132
        if (jump.isOn()) {
133
            keys.add(mc.options.keyJump);
134
        }
135
        return keys;
136
    }
137
138
    private void release() {
139
        List<KeyMapping> all = List.of(mc.options.keyUp, mc.options.keyDown,
140
            mc.options.keyLeft, mc.options.keyRight, mc.options.keyShift,
141
            mc.options.keySprint, mc.options.keyJump);
142
        for (KeyMapping mapping : all) {
143
            InputUtil.release(mapping);
144
        }
145
    }
146
}
147