EdgeGuard module

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

1 implementationMOVEMENT

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.

OfflineClientMOVEMENTsrc/main/java/com/jellypudding/offlineclient/modules/movement/EdgeGuard.javaJava · 217 lines · 8.3 KB

Stops you from going over edges without the sneak slowdown.

SettingsModeMax dropSafe sneakSneak when sprintingEdge distanceShow edge boxShow player box
EdgeGuard.javaJava · Minecraft 26.2 · 217 lines · 8.3 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.Render3DEvent;
5
import com.jellypudding.offlineclient.event.events.TickEvent;
6
import com.jellypudding.offlineclient.module.Category;
7
import com.jellypudding.offlineclient.module.ExclusivityGroup;
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.setting.NumberSetting;
12
import com.jellypudding.offlineclient.util.EntityUtil;
13
import com.jellypudding.offlineclient.util.InputUtil;
14
import com.jellypudding.offlineclient.util.MovementUtil;
15
import net.minecraft.world.phys.AABB;
16
import net.minecraft.world.phys.Vec3;
17
18
// Holds you on a ledge the way sneaking does but at full speed by simulating
19
// the run ahead a tick at a time. The clamp itself lives in LocalPlayerMixin and PlayerMixin.
20
public final class EdgeGuard extends Module {
21
22
    public enum Mode { HOLD, SNEAK }
23
24
    // Vanilla air physics for a player.
25
    private static final double GRAVITY = 0.08;
26
    private static final double AIR_DRAG = 0.98;
27
    private static final double AIR_FRICTION = 0.91;
28
    private static final double AIR_ACCELERATION = 0.02;
29
    private static final double SPRINT_AIR_BONUS = 1.3;
30
31
    // Ticks of flight to simulate. A ten block fall is over well inside this.
32
    private static final int LOOKAHEAD_TICKS = 40;
33
34
    // Depth probed under the feet to tell a supported box from a falling one.
35
    private static final double GROUND_PROBE = 0.05;
36
37
    // Lets a drop of exactly the allowed depth through.
38
    private static final double TOLERANCE = 1e-4;
39
40
    private static final int EDGE_BOX_COLOR = 0xFF4080FF;
41
    private static final int PLAYER_BOX_COLOR = 0xFF60E060;
42
43
    private final EnumSetting<Mode> mode = new EnumSetting<>("Mode",
44
        "What happens at an edge.", Mode.HOLD)
45
        .describe(Mode.HOLD, "Holds you at the edge at full speed.")
46
        .describe(Mode.SNEAK, "Presses sneak for you as you reach an edge the way a careful player would.");
47
    private final NumberSetting maxDrop = new NumberSetting("Max drop",
48
        "Edges you would fall further than this from stop you.",
49
        0.5, 0.5, 10, 0.5, " blocks");
50
    private final BoolSetting safeSneak = new BoolSetting("Safe sneak",
51
        "Also holds you at the edge in case the sneak comes too late.", true)
52
        .under(mode, Mode.SNEAK);
53
    private final BoolSetting sneakWhenSprinting = new BoolSetting("Sneak when sprinting",
54
        "Also sneaks whilst you hold the sprint key. Off lets a sprint run straight off.", true)
55
        .under(mode, Mode.SNEAK);
56
    private final NumberSetting edgeDistance = new NumberSetting("Edge distance",
57
        "How far before the edge the sneak starts.", 0.3, 0, 0.3, 0.01, " blocks")
58
        .min(0).max(0.3).under(mode, Mode.SNEAK);
59
    private final BoolSetting showEdgeBox = new BoolSetting("Show edge box",
60
        "Draws the box the edge check looks under.", false)
61
        .under(mode, Mode.SNEAK);
62
    private final BoolSetting showPlayerBox = new BoolSetting("Show player box",
63
        "Also draws your own box.", false)
64
        .under(showEdgeBox);
65
66
    private boolean sneaking;
67
68
    public EdgeGuard() {
69
        super("EdgeGuard", "Stops you from going over edges without the sneak slowdown.",
70
            Category.MOVEMENT);
71
        addSettings(mode, maxDrop, safeSneak, sneakWhenSprinting, edgeDistance, showEdgeBox,
72
            showPlayerBox);
73
        searchTags("safewalk", "safe walk", "edge", "ledge");
74
    }
75
76
    // Parkour leaps from the same lip EdgeGuard holds you at.
77
    @Override
78
    public ExclusivityGroup getExclusivityGroup() {
79
        return ExclusivityGroup.EDGE;
80
    }
81
82
    @Override
83
    public String getSuffix() {
84
        return maxDrop.getValueString();
85
    }
86
87
    @Override
88
    protected void onDisable() {
89
        letGoOfSneak();
90
    }
91
92
    // True when the run ahead ends in a drop deeper than allowed.
93
    public boolean shouldGuard() {
94
        if (!isEnabled() || !inGame()) {
95
            return false;
96
        }
97
        if (mode.is(Mode.SNEAK) && (!safeSneak.isOn() || sprintOverrides())) {
98
            return false;
99
        }
100
        AABB box = mc.player.getBoundingBox();
101
        double limitY = box.minY - maxDrop.getValue() - TOLERANCE;
102
        return landsBelow(box, mc.player.getDeltaMovement(), mc.player.onGround(), limitY);
103
    }
104
105
    @Subscribe
106
    private void onTick(TickEvent event) {
107
        if (!inGame() || !mode.is(Mode.SNEAK) || sprintOverrides()) {
108
            letGoOfSneak();
109
            return;
110
        }
111
        if (mc.player.onGround() && dropUnder(edgeBox())) {
112
            InputUtil.hold(mc.options.keyShift);
113
            sneaking = true;
114
        } else {
115
            letGoOfSneak();
116
        }
117
    }
118
119
    @Subscribe
120
    private void onRender3D(Render3DEvent event) {
121
        if (!showEdgeBox.isOn() || !mode.is(Mode.SNEAK) || !inGame()) {
122
            return;
123
        }
124
        AABB box = EntityUtil.lerpedBox(mc.player, event.getPartialTicks());
125
        event.getBatch().outlineBox(shrink(box), EDGE_BOX_COLOR, false);
126
        if (showPlayerBox.isOn()) {
127
            event.getBatch().outlineBox(box, PLAYER_BOX_COLOR, false);
128
        }
129
    }
130
131
    private boolean sprintOverrides() {
132
        return !sneakWhenSprinting.isOn() && mc.options.keySprint.isDown();
133
    }
134
135
    private void letGoOfSneak() {
136
        if (sneaking) {
137
            InputUtil.release(mc.options.keyShift);
138
            sneaking = false;
139
        }
140
    }
141
142
    // The player box pulled in from the sides. Standing with only the rim of the
143
    // feet over the drop leaves nothing under it.
144
    private AABB edgeBox() {
145
        return shrink(mc.player.getBoundingBox());
146
    }
147
148
    private AABB shrink(AABB box) {
149
        double edge = edgeDistance.getValue();
150
        return box.inflate(-edge, 0, -edge);
151
    }
152
153
    // True when the fall under the box would be deeper than allowed.
154
    private boolean dropUnder(AABB box) {
155
        double depth = maxDrop.getValue() + TOLERANCE;
156
        return mc.level.noCollision(mc.player, box.expandTowards(0, -depth, 0));
157
    }
158
159
    // Plays the movement forward until the player lands or passes the limit. A
160
    // supported run keeps its speed then vanilla drag and gravity take over once airborne.
161
    private boolean landsBelow(AABB box, Vec3 velocity, boolean supported, double limitY) {
162
        double vx = velocity.x;
163
        double vy = velocity.y;
164
        double vz = velocity.z;
165
        Vec3 push = airPush();
166
167
        for (int tick = 0; tick < LOOKAHEAD_TICKS; tick++) {
168
            AABB ahead = box.move(vx, 0, vz);
169
            if (!mc.level.noCollision(mc.player, ahead)) {
170
                // A wall ends the run. On a ledge that means staying on it.
171
                if (supported) {
172
                    return false;
173
                }
174
                vx = 0;
175
                vz = 0;
176
                ahead = box;
177
            }
178
            box = ahead;
179
            if (supported) {
180
                if (hasGround(box)) {
181
                    continue;
182
                }
183
                // The edge is passed. The first fall tick carries the gravity already stored.
184
                supported = false;
185
                vy = -GRAVITY * AIR_DRAG;
186
            }
187
188
            AABB dropped = box.move(0, vy, 0);
189
            if (vy < 0 && !mc.level.noCollision(mc.player, dropped)) {
190
                // Landed within this tick's drop. Fine if that ground is above the limit.
191
                if (box.minY + vy >= limitY) {
192
                    return false;
193
                }
194
                return mc.level.noCollision(mc.player, box.expandTowards(0, limitY - box.minY, 0));
195
            }
196
            box = dropped;
197
            if (box.minY < limitY) {
198
                return true;
199
            }
200
            vx = vx * AIR_FRICTION + push.x;
201
            vz = vz * AIR_FRICTION + push.z;
202
            vy = (vy - GRAVITY) * AIR_DRAG;
203
        }
204
        return false;
205
    }
206
207
    private boolean hasGround(AABB box) {
208
        return !mc.level.noCollision(mc.player, box.expandTowards(0, -GROUND_PROBE, 0));
209
    }
210
211
    // What the held keys add to the speed each tick in the air.
212
    private Vec3 airPush() {
213
        double strength = AIR_ACCELERATION * (mc.player.isSprinting() ? SPRINT_AIR_BONUS : 1);
214
        return MovementUtil.inputDirection().scale(strength);
215
    }
216
}
217