ArrowDodge module

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

1 implementationCOMBAT

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.

OfflineClientCOMBATsrc/main/java/com/jellypudding/offlineclient/modules/combat/ArrowDodge.javaJava · 225 lines · 8.4 KB

Sidesteps arrows and other projectiles aimed at you.

SettingsRangeStepsMarginMoveSpeedAll projectilesIgnore ownIgnore friendsGround checkDraw paths
ArrowDodge.javaJava · Minecraft 26.2 · 225 lines · 8.4 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.combat;
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.Module;
8
import com.jellypudding.offlineclient.render.DrawBatch;
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.ProjectileUtil;
14
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
15
import net.minecraft.world.entity.Entity;
16
import net.minecraft.world.entity.player.Player;
17
import net.minecraft.world.entity.projectile.Projectile;
18
import net.minecraft.world.entity.projectile.arrow.AbstractArrow;
19
import net.minecraft.world.level.ClipContext;
20
import net.minecraft.world.phys.AABB;
21
import net.minecraft.world.phys.HitResult;
22
import net.minecraft.world.phys.Vec3;
23
24
import java.util.ArrayList;
25
import java.util.List;
26
27
// Flies every projectile in range forward and takes the first sidestep
28
// that clears them all.
29
public final class ArrowDodge extends Module {
30
31
    // Each axis of a sidestep at forty five degrees.
32
    private static final double DIAGONAL = Math.sqrt(0.5);
33
34
    private static final Vec3[] DIRECTIONS = {
35
        new Vec3(1, 0, 0), new Vec3(-1, 0, 0), new Vec3(0, 0, 1), new Vec3(0, 0, -1),
36
        new Vec3(DIAGONAL, 0, DIAGONAL), new Vec3(-DIAGONAL, 0, DIAGONAL),
37
        new Vec3(DIAGONAL, 0, -DIAGONAL), new Vec3(-DIAGONAL, 0, -DIAGONAL)
38
    };
39
40
    private static final int GROWTH_TRIES = 6;
41
42
    private record Segment(Vec3 from, Vec3 to) {
43
    }
44
45
    public enum Move { VELOCITY, PACKET }
46
47
    private final NumberSetting range = new NumberSetting("Range",
48
        "How far away a projectile is still watched.", 32, 8, 64, 4, " blocks").min(1);
49
    private final NumberSetting steps = new NumberSetting("Steps",
50
        "How many ticks of flight to predict.", 40, 5, 120, 5, " ticks").min(1).max(400);
51
    private final NumberSetting margin = new NumberSetting("Margin",
52
        "Extra space kept around you.", 0.4, 0, 2, 0.1);
53
    private final EnumSetting<Move> move = new EnumSetting<>("Move",
54
        "How the sidestep is made.", Move.VELOCITY)
55
        .describe(Move.VELOCITY, "Pushes you sideways and lets the game carry you.")
56
        .describe(Move.PACKET, "Steps sideways at once with a position packet.");
57
    private final NumberSetting speed = new NumberSetting("Speed",
58
        "How far each sidestep goes.", 0.35, 0.05, 1.5, 0.05).min(0.01);
59
    private final BoolSetting everything = new BoolSetting("All projectiles",
60
        "Dodge thrown items and fireballs as well as arrows.", false);
61
    private final BoolSetting ignoreOwn = new BoolSetting("Ignore own",
62
        "Never dodge what you fired yourself.", true);
63
    private final BoolSetting ignoreFriends = new BoolSetting("Ignore friends",
64
        "Never dodge what a friend fired.", true);
65
    private final BoolSetting groundCheck = new BoolSetting("Ground check",
66
        "Only step onto blocks that will hold you up.", true);
67
    private final BoolSetting draw = new BoolSetting("Draw paths",
68
        "Show the predicted flight of every watched projectile.", false);
69
70
    private final List<Segment> paths = new ArrayList<>();
71
    private boolean dodging;
72
73
    public ArrowDodge() {
74
        super("ArrowDodge", "Sidesteps arrows and other projectiles aimed at you.", Category.COMBAT);
75
        addSettings(range, steps, margin, move, speed, everything, ignoreOwn, ignoreFriends,
76
            groundCheck, draw);
77
        searchTags("dodge", "arrow", "projectile");
78
    }
79
80
    @Override
81
    public String getSuffix() {
82
        return dodging ? "dodging" : null;
83
    }
84
85
    @Override
86
    protected void onDisable() {
87
        paths.clear();
88
        dodging = false;
89
    }
90
91
    @Subscribe
92
    private void onTick(TickEvent event) {
93
        paths.clear();
94
        dodging = false;
95
        if (!inGame() || mc.player.isSpectator()) {
96
            return;
97
        }
98
99
        double watch = range.getValue();
100
        for (Entity entity : mc.level.entitiesForRendering()) {
101
            if (!(entity instanceof Projectile projectile) || !watches(projectile)) {
102
                continue;
103
            }
104
            if (mc.player.distanceTo(projectile) > watch) {
105
                continue;
106
            }
107
            predict(projectile);
108
        }
109
        if (paths.isEmpty()) {
110
            return;
111
        }
112
113
        AABB body = mc.player.getBoundingBox().inflate(margin.getValue());
114
        if (!hits(body)) {
115
            return;
116
        }
117
118
        double push = speed.getValue();
119
        for (int attempt = 0; attempt < GROWTH_TRIES; attempt++) {
120
            for (Vec3 direction : DIRECTIONS) {
121
                Vec3 offset = direction.scale(push);
122
                AABB moved = body.move(offset);
123
                if (hits(moved) || !isClear(offset)) {
124
                    continue;
125
                }
126
                step(offset);
127
                dodging = true;
128
                return;
129
            }
130
            push += speed.getValue();
131
        }
132
    }
133
134
    private boolean watches(Projectile projectile) {
135
        if (!everything.isOn() && !(projectile instanceof AbstractArrow)) {
136
            return false;
137
        }
138
        // A stuck arrow is not going anywhere.
139
        if (projectile.getDeltaMovement().lengthSqr() < 0.01) {
140
            return false;
141
        }
142
        Entity owner = projectile.getOwner();
143
        if (owner == null) {
144
            return true;
145
        }
146
        if (ignoreOwn.isOn() && owner == mc.player) {
147
            return false;
148
        }
149
        return !ignoreFriends.isOn() || !(owner instanceof Player player)
150
            || !EntityUtil.isFriend(player);
151
    }
152
153
    private void predict(Projectile projectile) {
154
        double gravity = projectile instanceof AbstractArrow
155
            ? ProjectileUtil.ARROW_GRAVITY : ProjectileUtil.THROWN_GRAVITY;
156
        Vec3 pos = projectile.position();
157
        Vec3 velocity = projectile.getDeltaMovement();
158
        int limit = steps.getInt();
159
        int minY = mc.level.getMinY();
160
161
        for (int i = 0; i < limit; i++) {
162
            Vec3 previous = pos;
163
            pos = pos.add(velocity);
164
            velocity = velocity.scale(ProjectileUtil.ARROW_DRAG).subtract(0, gravity, 0);
165
            if (pos.y < minY) {
166
                break;
167
            }
168
            // A projectile that buries itself in a wall is no longer a threat.
169
            HitResult wall = mc.level.clip(new ClipContext(previous, pos,
170
                ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, projectile));
171
            if (wall.getType() != HitResult.Type.MISS) {
172
                paths.add(new Segment(previous, wall.getLocation()));
173
                break;
174
            }
175
            paths.add(new Segment(previous, pos));
176
        }
177
    }
178
179
    private boolean hits(AABB box) {
180
        for (Segment segment : paths) {
181
            if (box.clip(segment.from(), segment.to()).isPresent()) {
182
                return true;
183
            }
184
        }
185
        return false;
186
    }
187
188
    // A packet step lands at once. The velocity keeps whatever rise or fall was under way.
189
    private void step(Vec3 offset) {
190
        Vec3 motion = mc.player.getDeltaMovement();
191
        if (move.is(Move.VELOCITY)) {
192
            mc.player.setDeltaMovement(offset.x, motion.y, offset.z);
193
            return;
194
        }
195
        Vec3 landing = mc.player.position().add(offset);
196
        mc.player.connection.send(new ServerboundMovePlayerPacket.Pos(landing,
197
            mc.player.onGround(), mc.player.horizontalCollision));
198
        mc.player.setPos(landing);
199
        mc.player.setDeltaMovement(0, motion.y, 0);
200
    }
201
202
    private boolean isClear(Vec3 offset) {
203
        AABB destination = mc.player.getBoundingBox().move(offset);
204
        if (!mc.level.noCollision(mc.player, destination)) {
205
            return false;
206
        }
207
        if (!groundCheck.isOn() || !mc.player.onGround()) {
208
            return true;
209
        }
210
        AABB floor = destination.move(0, -0.6, 0);
211
        return !mc.level.noCollision(mc.player, floor);
212
    }
213
214
    @Subscribe
215
    private void onRender3D(Render3DEvent event) {
216
        if (!draw.isOn()) {
217
            return;
218
        }
219
        DrawBatch batch = event.getBatch();
220
        for (Segment segment : paths) {
221
            batch.line(segment.from(), segment.to(), 0xFFFF6040, true);
222
        }
223
    }
224
}
225