VehicleFly module

VehicleFly: 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/VehicleFly.javaJava · 338 lines · 14.1 KB

Flies or speeds the boat or mount you are riding.

SettingsVehiclesFlyModeHorizontal speedInstant stopVertical speedFall speedFall protectionDismount safetySpeedGround speedOnly on groundIn waterFace viewMax jumpSpoof saddleIgnore server moves
VehicleFly.javaJava · Minecraft 26.2 · 338 lines · 14.1 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.PacketReceiveEvent;
5
import com.jellypudding.offlineclient.event.events.PacketSendEvent;
6
import com.jellypudding.offlineclient.event.events.TickEvent;
7
import com.jellypudding.offlineclient.event.events.VehicleTickEvent;
8
import com.jellypudding.offlineclient.module.Category;
9
import com.jellypudding.offlineclient.module.Module;
10
import com.jellypudding.offlineclient.setting.BoolSetting;
11
import com.jellypudding.offlineclient.setting.EnumSetting;
12
import com.jellypudding.offlineclient.setting.NumberSetting;
13
import com.jellypudding.offlineclient.setting.RegistryListSetting;
14
import com.jellypudding.offlineclient.util.MovementUtil;
15
import net.minecraft.core.registries.BuiltInRegistries;
16
import net.minecraft.network.protocol.game.ClientboundMoveVehiclePacket;
17
import net.minecraft.network.protocol.game.ServerboundMoveVehiclePacket;
18
import net.minecraft.network.protocol.game.ServerboundPlayerInputPacket;
19
import net.minecraft.world.entity.Entity;
20
import net.minecraft.world.entity.EntityType;
21
import net.minecraft.world.entity.ItemSteerable;
22
import net.minecraft.world.entity.PlayerRideableJumping;
23
import net.minecraft.world.entity.animal.equine.AbstractHorse;
24
import net.minecraft.world.entity.animal.equine.Llama;
25
import net.minecraft.world.entity.animal.happyghast.HappyGhast;
26
import net.minecraft.world.entity.animal.nautilus.AbstractNautilus;
27
import net.minecraft.world.entity.player.Input;
28
import net.minecraft.world.entity.vehicle.boat.AbstractBoat;
29
import net.minecraft.world.phys.AABB;
30
import net.minecraft.world.phys.Vec3;
31
32
import java.util.List;
33
34
// Flies and speeds whatever you ride since vehicles use a code path Flight cannot reach.
35
// Only a steerable vehicle can be driven and speed is set right before its tick.
36
public final class VehicleFly extends Module {
37
38
    public enum Mode { CONTROL, GLIDE }
39
40
    // A drop longer than this starts to hurt.
41
    private static final double SAFE_DROP = 3;
42
43
    // The physics never move a vehicle this far in one tick. The server did.
44
    private static final double RESYNC_DISTANCE = 4;
45
46
    // The server banks every drop a vehicle packet makes. Only a ground flag wipes it.
47
    // A tick with a big drop is sent as several packets. None crosses the hurt line.
48
    private static final double SAFE_PACKET_DROP = 2.5;
49
50
    private static final double TICKS_PER_SECOND = 20;
51
52
    private final RegistryListSetting<EntityType<?>> vehicles = new RegistryListSetting<>("Vehicles",
53
        "Which kinds of vehicle the module drives.", BuiltInRegistries.ENTITY_TYPE, rideableTypes());
54
    private final BoolSetting fly = new BoolSetting("Fly",
55
        "Lifts the vehicle with jump and lowers it with sprint.", true);
56
    private final EnumSetting<Mode> mode = new EnumSetting<>("Mode",
57
        "How much the flight takes over.", Mode.CONTROL)
58
        .describe(Mode.CONTROL, "Steers the vehicle from your keys.")
59
        .describe(Mode.GLIDE, "Only holds the vehicle up and leaves the steering alone.")
60
        .under(fly);
61
    private final NumberSetting flySpeed = new NumberSetting("Horizontal speed",
62
        "How hard your keys push the vehicle in flight. 1 matches creative flight.", 1, 0.1, 5, 0.1, "x")
63
        .min(0.1).max(20).under(mode, Mode.CONTROL);
64
    private final BoolSetting instantStop = new BoolSetting("Instant stop",
65
        "The vehicle stops dead the moment you let go of the keys. Off lets it coast to a halt.", true)
66
        .under(mode, Mode.CONTROL);
67
    private final NumberSetting verticalSpeed = new NumberSetting("Vertical speed",
68
        "Up and down speed with jump climbing and sprint sinking.", 1, 0.1, 5, 0.1, "x")
69
        .min(0.1).max(20).under(fly);
70
    private final NumberSetting fallSpeed = new NumberSetting("Fall speed",
71
        "Blocks a second the vehicle sinks whilst no key is held. 0 holds the height.", 0, 0, 10, 0.1, " blocks")
72
        .min(0).under(fly);
73
    private final BoolSetting fallProtection = new BoolSetting("Fall protection",
74
        "Tells the server the mount is on the ground. A landing after a long flight then never hurts it.", true)
75
        .under(fly);
76
    private final BoolSetting dismountSafety = new BoolSetting("Dismount safety",
77
        "Swallows the dismount key whilst the vehicle is too high to step off.", true)
78
        .under(fly);
79
    private final BoolSetting speed = new BoolSetting("Speed",
80
        "Drives the vehicle along the ground at a set speed. It takes over the steering from flight too.", false);
81
    private final NumberSetting groundSpeed = new NumberSetting("Ground speed",
82
        "Blocks a second the vehicle moves under speed.", 10, 0, 50, 0.5, " blocks")
83
        .min(0).under(speed);
84
    private final BoolSetting onlyOnGround = new BoolSetting("Only on ground",
85
        "Speed only applies whilst the vehicle stands on a block or is a flying kind.", false)
86
        .under(speed);
87
    private final BoolSetting inWater = new BoolSetting("In water",
88
        "Speed also applies whilst the vehicle is in water.", true)
89
        .under(speed);
90
    private final BoolSetting faceView = new BoolSetting("Face view",
91
        "Turns the vehicle to match where you are looking.", true);
92
    private final BoolSetting maxJump = new BoolSetting("Max jump",
93
        "A horse jump is always at full power without holding the key to charge it.", true);
94
    private final BoolSetting spoofSaddle = new BoolSetting("Spoof saddle",
95
        "Makes the game treat every mount as saddled. Only older servers accept the steering.", false);
96
    private final BoolSetting ignoreServerMoves = new BoolSetting("Ignore server moves",
97
        "Drops every vehicle position the server sends. A refused move then leaves you out of sync.", false);
98
99
    private boolean holding;
100
    private double holdY;
101
102
    // Read from the packet thread.
103
    private volatile boolean blockDismount;
104
    private volatile boolean protecting;
105
    // Height of the last vehicle packet. Not a number until one has gone out.
106
    private volatile double lastSentY = Double.NaN;
107
    // Packets sent by the split come straight back through the send hook.
108
    private boolean splitting;
109
110
    public VehicleFly() {
111
        super("VehicleFly", "Flies or speeds the boat or mount you are riding.", Category.MOVEMENT);
112
        addSettings(vehicles, fly, mode, flySpeed, instantStop, verticalSpeed, fallSpeed,
113
            fallProtection, dismountSafety, speed, groundSpeed, onlyOnGround, inWater, faceView,
114
            maxJump, spoofSaddle, ignoreServerMoves);
115
        searchTags("boat fly", "vehicle fly", "horse fly", "entity control", "entity speed",
116
            "minecart", "strider", "camel", "pig");
117
    }
118
119
    // Every kind a player can steer. Minecarts run on rails and llamas cannot be steered.
120
    private static List<EntityType<?>> rideableTypes() {
121
        return BuiltInRegistries.ENTITY_TYPE.stream().filter(type -> {
122
            Class<?> base = type.getBaseClass();
123
            if (Llama.class.isAssignableFrom(base)) {
124
                return false;
125
            }
126
            return AbstractBoat.class.isAssignableFrom(base)
127
                || AbstractHorse.class.isAssignableFrom(base)
128
                || ItemSteerable.class.isAssignableFrom(base)
129
                || HappyGhast.class.isAssignableFrom(base)
130
                || AbstractNautilus.class.isAssignableFrom(base);
131
        }).toList();
132
    }
133
134
    @Override
135
    public String getSuffix() {
136
        if (fly.isOn()) {
137
            return speed.isOn() ? mode.getValueString() + " and speed" : mode.getValueString();
138
        }
139
        return speed.isOn() ? "speed" : null;
140
    }
141
142
    @Override
143
    protected void onEnable() {
144
        stop();
145
    }
146
147
    @Override
148
    protected void onDisable() {
149
        stop();
150
    }
151
152
    // Read by MobMixin. True whilst every mount should read as saddled.
153
    public boolean spoofsSaddle() {
154
        return isEnabled() && spoofSaddle.isOn();
155
    }
156
157
    // Read by LocalPlayerMixin. True whilst a horse jump should always be full power.
158
    public boolean maxesJump() {
159
        return isEnabled() && maxJump.isOn();
160
    }
161
162
    // Read by LocalPlayerMixin. Whilst flying a jumping mount the jump key lifts
163
    // instead of charging its jump.
164
    public boolean takesJumpKey() {
165
        if (!isEnabled() || !fly.isOn() || mc.player == null) {
166
            return false;
167
        }
168
        Entity vehicle = mc.player.getControlledVehicle();
169
        return vehicle instanceof PlayerRideableJumping && wanted(vehicle);
170
    }
171
172
    private boolean wanted(Entity vehicle) {
173
        return vehicles.contains(vehicle.getType());
174
    }
175
176
    private void stop() {
177
        holding = false;
178
        blockDismount = false;
179
        protecting = false;
180
        lastSentY = Double.NaN;
181
    }
182
183
    // The vehicle event only fires whilst riding. A dismount is noticed here.
184
    @Subscribe
185
    private void onTick(TickEvent event) {
186
        if (!inGame() || !mc.player.isPassenger()) {
187
            stop();
188
        }
189
    }
190
191
    @Subscribe
192
    private void onVehicleTick(VehicleTickEvent event) {
193
        Entity vehicle = event.getVehicle();
194
        // Vanilla only sends vehicle movement for a vehicle the client owns.
195
        if (!inGame() || mc.player.isSpectator() || !vehicle.isLocalInstanceAuthoritative()
196
            || !wanted(vehicle)) {
197
            stop();
198
            return;
199
        }
200
201
        Vec3 velocity = vehicle.getDeltaMovement();
202
        double vx = velocity.x;
203
        double vy = velocity.y;
204
        double vz = velocity.z;
205
206
        if (fly.isOn()) {
207
            blockDismount = dismountSafety.isOn() && dropIsUnsafe(vehicle);
208
            protecting = fallProtection.isOn();
209
            vy = flightLift(vehicle);
210
            if (mode.is(Mode.CONTROL)) {
211
                Vec3 heading = MovementUtil.inputDirection();
212
                if (heading.lengthSqr() > 0 || instantStop.isOn()) {
213
                    double h = flySpeed.getValue() * MovementUtil.FLY_HORIZONTAL;
214
                    vx = heading.x * h;
215
                    vz = heading.z * h;
216
                }
217
            }
218
        } else {
219
            stop();
220
        }
221
222
        if (speedApplies(vehicle)) {
223
            Vec3 heading = MovementUtil.inputDirection();
224
            double h = groundSpeed.getValue() / TICKS_PER_SECOND;
225
            vx = heading.x * h;
226
            vz = heading.z * h;
227
        }
228
229
        if (faceView.isOn()) {
230
            vehicle.setYRot(mc.player.getYRot());
231
        }
232
        vehicle.setDeltaMovement(vx, vy, vz);
233
    }
234
235
    private double flightLift(Entity vehicle) {
236
        double limit = verticalSpeed.getValue() * MovementUtil.FLY_VERTICAL;
237
        if (mc.options.keyJump.isDown()) {
238
            holding = false;
239
            return limit;
240
        }
241
        if (mc.options.keySprint.isDown()) {
242
            holding = false;
243
            return -limit;
244
        }
245
        if (fallSpeed.getValue() > 0) {
246
            holding = false;
247
            return -fallSpeed.getValue() / TICKS_PER_SECOND;
248
        }
249
        return holdHeight(vehicle, limit);
250
    }
251
252
    private boolean speedApplies(Entity vehicle) {
253
        if (!speed.isOn()) {
254
            return false;
255
        }
256
        if (onlyOnGround.isOn() && !vehicle.onGround() && !vehicle.isFlyingVehicle()) {
257
            return false;
258
        }
259
        return inWater.isOn() || !vehicle.isInWater();
260
    }
261
262
    // Corrects back towards the height the vehicle was left at.
263
    // Vehicle physics keep pulling down. A flat zero would sink.
264
    private double holdHeight(Entity vehicle, double limit) {
265
        if (!holding || Math.abs(holdY - vehicle.getY()) > RESYNC_DISTANCE) {
266
            holdY = vehicle.getY();
267
            holding = true;
268
        }
269
        double correction = holdY - vehicle.getY() + vehicle.getGravity();
270
        return Math.clamp(correction, -limit, limit);
271
    }
272
273
    private boolean dropIsUnsafe(Entity vehicle) {
274
        AABB box = vehicle.getBoundingBox();
275
        return mc.level.noCollision(vehicle, box.minmax(box.move(0, -SAFE_DROP, 0)));
276
    }
277
278
    // The server moved the vehicle itself. The next drop is measured from there.
279
    @Subscribe
280
    private void onPacketReceive(PacketReceiveEvent event) {
281
        if (!(event.getPacket() instanceof ClientboundMoveVehiclePacket)) {
282
            return;
283
        }
284
        if (ignoreServerMoves.isOn()) {
285
            event.cancel();
286
            return;
287
        }
288
        lastSentY = Double.NaN;
289
    }
290
291
    // Fired on whichever thread sent the packet.
292
    @Subscribe
293
    private void onPacketSend(PacketSendEvent event) {
294
        if (event.getPacket() instanceof ServerboundPlayerInputPacket packet) {
295
            guardDismount(event, packet);
296
        } else if (event.getPacket() instanceof ServerboundMoveVehiclePacket packet) {
297
            protectLanding(event, packet);
298
        }
299
    }
300
301
    // A shift flag whilst riding makes the server dismount the player.
302
    private void guardDismount(PacketSendEvent event, ServerboundPlayerInputPacket packet) {
303
        Input input = packet.input();
304
        if (!blockDismount || !input.shift()) {
305
            return;
306
        }
307
        event.setPacket(new ServerboundPlayerInputPacket(new Input(input.forward(), input.backward(),
308
            input.left(), input.right(), input.jump(), false, input.sprint())));
309
    }
310
311
    private void protectLanding(PacketSendEvent event, ServerboundMoveVehiclePacket packet) {
312
        if (splitting || !protecting) {
313
            return;
314
        }
315
        Vec3 pos = packet.position();
316
        double from = lastSentY;
317
        lastSentY = pos.y;
318
        if (packet.onGround()) {
319
            return;
320
        }
321
        double drop = Double.isNaN(from) ? 0 : from - pos.y;
322
        if (drop > SAFE_PACKET_DROP && mc.player != null) {
323
            int steps = (int) Math.ceil(drop / SAFE_PACKET_DROP);
324
            splitting = true;
325
            try {
326
                for (int i = 1; i < steps; i++) {
327
                    Vec3 between = new Vec3(pos.x, from - drop * i / steps, pos.z);
328
                    mc.player.connection.send(new ServerboundMoveVehiclePacket(between,
329
                        packet.yRot(), packet.xRot(), true));
330
                }
331
            } finally {
332
                splitting = false;
333
            }
334
        }
335
        event.setPacket(new ServerboundMoveVehiclePacket(pos, packet.yRot(), packet.xRot(), true));
336
    }
337
}
338