NoFall module

NoFall: Minecraft 26.3 cheat module, full source for every implementation (5 clients: MelaHack (ThunderHack fork), OfflineClient, Combatant, …).

5 implementationsMOVEMENTPLAYER

Full module source: 5 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/NoFall.javaJava · 199 lines · 9.8 KB

Prevents fall damage.

SettingsModeFallDistanceFallDistanceValPowderSnowBucketWaterBucketRetrieveEnderPearlCobwebTwistingVines
NoFall.javaJava · Minecraft 26.2 · 199 lines · 9.8 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.movement;
2
3
import meteordevelopment.orbit.EventHandler;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
6
import net.minecraft.world.InteractionHand;
7
import net.minecraft.world.item.Items;
8
import thunder.hack.events.impl.EventSync;
9
import thunder.hack.events.impl.EventTick;
10
import thunder.hack.events.impl.PacketEvent;
11
import thunder.hack.features.modules.Module;
12
import thunder.hack.injection.accesors.IPlayerMoveC2SPacket;
13
import thunder.hack.setting.Setting;
14
import thunder.hack.utility.player.InteractionUtility;
15
import thunder.hack.utility.player.InventoryUtility;
16
import thunder.hack.utility.player.SearchInvResult;
17
18
public class NoFall extends Module {
19
    public NoFall() {
20
        super("NoFall", Category.MOVEMENT);
21
    }
22
23
    public final Setting<Mode> mode = new Setting<>("Mode", Mode.Rubberband);
24
    public final Setting<FallDistance> fallDistance = new Setting<>("FallDistance", FallDistance.Calc);
25
    public final Setting<Integer> fallDistanceValue = new Setting<>("FallDistanceVal", 10, 2, 100, v -> fallDistance.getValue() == FallDistance.Custom);
26
    private final Setting<Boolean> powderSnowBucket = new Setting<>("PowderSnowBucket", true, v -> mode.getValue() == Mode.Items);
27
    private final Setting<Boolean> waterBucket = new Setting<>("WaterBucket", true, v -> mode.getValue() == Mode.Items);
28
    private final Setting<Boolean> retrieve = new Setting<>("Retrieve", true, v -> mode.getValue() == Mode.Items && waterBucket.getValue());
29
    private final Setting<Boolean> enderPearl = new Setting<>("EnderPearl", true, v -> mode.getValue() == Mode.Items);
30
    private final Setting<Boolean> cobweb = new Setting<>("Cobweb", true, v -> mode.getValue() == Mode.Items);
31
    private final Setting<Boolean> twistingVines = new Setting<>("TwistingVines", true, v -> mode.getValue() == Mode.Items);
32
33
    private thunder.hack.utility.Timer pearlCooldown = new thunder.hack.utility.Timer();
34
35
    private boolean retrieveFlag;
36
    private boolean cancelGround = false;
37
38
    @EventHandler
39
    public void onSync(EventSync e) {
40
        if (fullNullCheck())
41
            return;
42
43
        if (isFalling()) {
44
            switch (mode.getValue()) {
45
                case MatrixOffGround, Vanilla -> cancelGround = true;
46
                case Rubberband -> sendPacket(new ServerboundMovePlayerPacket.StatusOnly(true, mc.player.horizontalCollision));
47
                case Items -> {
48
                    BlockPos playerPos = BlockPos.containing(mc.player.position());
49
50
                    SearchInvResult snowResult = InventoryUtility.findItemInHotBar(Items.POWDER_SNOW_BUCKET);
51
                    SearchInvResult pearlResult = InventoryUtility.findItemInHotBar(Items.ENDER_PEARL);
52
                    SearchInvResult webResult = InventoryUtility.findItemInHotBar(Items.COBWEB);
53
                    SearchInvResult vinesResult = InventoryUtility.findItemInHotBar(Items.TWISTING_VINES);
54
                    SearchInvResult waterResult = InventoryUtility.findItemInHotBar(Items.WATER_BUCKET);
55
56
                    if (waterResult.found() && waterBucket.getValue()) {
57
                        mc.player.setXRot(90);
58
                        doWaterDrop(waterResult, playerPos);
59
                    } else if (pearlResult.found() && enderPearl.getValue()) {
60
                        mc.player.setXRot(90);
61
                        doPearlDrop(pearlResult);
62
                    } else if (webResult.found() && cobweb.getValue()) {
63
                        mc.player.setXRot(90);
64
                        doWebDrop(webResult, playerPos);
65
                    } else if (vinesResult.found() && twistingVines.getValue()) {
66
                        mc.player.setXRot(90);
67
                        doVinesDrop(vinesResult, playerPos);
68
                    } else if (snowResult.found() && powderSnowBucket.getValue()) {
69
                        mc.player.setXRot(90);
70
                        doSnowDrop(snowResult, playerPos);
71
                    }
72
                }
73
            }
74
        } else if (retrieveFlag) {
75
            InventoryUtility.saveSlot();
76
            SearchInvResult waterResult = InventoryUtility.findItemInHotBar(Items.BUCKET);
77
            waterResult.switchTo();
78
            mc.player.setXRot(90);
79
            mc.gameMode.useItem(mc.player, InteractionHand.MAIN_HAND);
80
            mc.player.swing(InteractionHand.MAIN_HAND);
81
            InventoryUtility.returnSlot();
82
            retrieveFlag = false;
83
        }
84
    }
85
86
    @EventHandler
87
    public void onTick(EventTick e) {
88
        if (mode.is(Mode.Grim2b2t) && isFalling()) {
89
            sendPacket(new ServerboundMovePlayerPacket.PosRot(mc.player.getX(), mc.player.getY() + 0.000000001, mc.player.getZ(), mc.player.getYRot(), mc.player.getXRot(), false, mc.player.horizontalCollision));
90
            mc.player.resetFallDistance();
91
        }
92
    }
93
94
    private void doWaterDrop(SearchInvResult waterResult, BlockPos playerPos) {
95
        if (mc.level.getBlockState(playerPos.below()).isRedstoneConductor(mc.level, playerPos.below()) || mc.level.getBlockState(playerPos.below().below()).isRedstoneConductor(mc.level, playerPos.below().below())) {
96
            InventoryUtility.saveSlot();
97
            waterResult.switchTo();
98
            mc.gameMode.useItem(mc.player, InteractionHand.MAIN_HAND);
99
            mc.player.swing(InteractionHand.MAIN_HAND);
100
            InventoryUtility.returnSlot();
101
            retrieveFlag = retrieve.getValue();
102
        }
103
    }
104
105
    private void doPearlDrop(SearchInvResult pearlResult) {
106
        if (pearlCooldown.passedMs(5000)) {
107
            InventoryUtility.saveSlot();
108
            pearlResult.switchTo();
109
            mc.gameMode.useItem(mc.player, InteractionHand.MAIN_HAND);
110
            mc.player.swing(InteractionHand.MAIN_HAND);
111
            InventoryUtility.returnSlot();
112
            pearlCooldown.reset();
113
        }
114
    }
115
116
    private void doWebDrop(SearchInvResult webResult, BlockPos playerPos) {
117
        if (mc.level.getBlockState(playerPos.below()).isRedstoneConductor(mc.level, playerPos.below()) || mc.level.getBlockState(playerPos.below().below()).isRedstoneConductor(mc.level, playerPos.below().below())) {
118
            InventoryUtility.saveSlot();
119
            if (mc.level.getBlockState(playerPos.below()).isRedstoneConductor(mc.level, playerPos.below()))
120
                InteractionUtility.placeBlock(playerPos, InteractionUtility.Rotate.None, InteractionUtility.Interact.Vanilla, InteractionUtility.PlaceMode.Normal, webResult.slot(), false, true);
121
            else
122
                InteractionUtility.placeBlock(playerPos.below(), InteractionUtility.Rotate.None, InteractionUtility.Interact.Vanilla, InteractionUtility.PlaceMode.Normal, webResult.slot(), false, true);
123
            mc.player.swing(InteractionHand.MAIN_HAND);
124
            InventoryUtility.returnSlot();
125
        }
126
    }
127
128
    private void doVinesDrop(SearchInvResult vinesResult, BlockPos playerPos) {
129
        if (mc.level.getBlockState(playerPos.below()).isRedstoneConductor(mc.level, playerPos.below()) || mc.level.getBlockState(playerPos.below().below()).isRedstoneConductor(mc.level, playerPos.below().below())) {
130
            InventoryUtility.saveSlot();
131
            if (mc.level.getBlockState(playerPos.below()).isRedstoneConductor(mc.level, playerPos.below()))
132
                InteractionUtility.placeBlock(playerPos, InteractionUtility.Rotate.None, InteractionUtility.Interact.Vanilla, InteractionUtility.PlaceMode.Normal, vinesResult.slot(), false, true);
133
            else
134
                InteractionUtility.placeBlock(playerPos.below(), InteractionUtility.Rotate.None, InteractionUtility.Interact.Vanilla, InteractionUtility.PlaceMode.Normal, vinesResult.slot(), false, true);
135
            mc.player.swing(InteractionHand.MAIN_HAND);
136
            InventoryUtility.returnSlot();
137
        }
138
    }
139
140
    private void doSnowDrop(SearchInvResult snowResult, BlockPos playerPos) {
141
        if (mc.level.getBlockState(playerPos.below()).isRedstoneConductor(mc.level, playerPos.below()) || mc.level.getBlockState(playerPos.below().below()).isRedstoneConductor(mc.level, playerPos.below().below())) {
142
            InventoryUtility.saveSlot();
143
            if (mc.level.getBlockState(playerPos.below()).isRedstoneConductor(mc.level, playerPos.below()))
144
                InteractionUtility.placeBlock(playerPos, InteractionUtility.Rotate.None, InteractionUtility.Interact.Vanilla, InteractionUtility.PlaceMode.Normal, snowResult.slot(), false, true);
145
            else
146
                InteractionUtility.placeBlock(playerPos.below(), InteractionUtility.Rotate.None, InteractionUtility.Interact.Vanilla, InteractionUtility.PlaceMode.Normal, snowResult.slot(), false, true);
147
            mc.player.swing(InteractionHand.MAIN_HAND);
148
            InventoryUtility.returnSlot();
149
        }
150
    }
151
152
    public boolean isFalling() {
153
        if (mc == null || mc.player == null || mc.level == null)
154
            return false;
155
156
        if (mc.player.isFallFlying())
157
            return false;
158
159
        if (mode.is(Mode.Grim2b2t))
160
            return mc.player.fallDistance > 3f;
161
162
        switch (fallDistance.getValue()) {
163
            case Custom -> {
164
                return mc.player.fallDistance > fallDistanceValue.getValue();
165
            }
166
            case Calc -> {
167
                return (((mc.player.fallDistance - 3) / 2F) + 3.5F) > mc.player.getHealth() / 3f;
168
            }
169
        }
170
        return false;
171
    }
172
173
    @Override
174
    public String getDisplayInfo() {
175
        return mode.getValue().toString() + " " + (isFalling() ? "Ready" : "");
176
    }
177
178
    @EventHandler
179
    public void onPacketSend(PacketEvent.Send e) {
180
        if (e.getPacket() instanceof ServerboundMovePlayerPacket pac) {
181
            if (cancelGround)
182
                ((IPlayerMoveC2SPacket) pac).setOnGround(false);
183
        }
184
    }
185
186
    @Override
187
    public void onEnable() {
188
        cancelGround = false;
189
    }
190
191
    private enum Mode {
192
        Rubberband, Items, MatrixOffGround, Vanilla, Grim2b2t
193
    }
194
195
    private enum FallDistance {
196
        Calc, Custom
197
    }
198
}
199
OfflineClientMOVEMENTsrc/main/java/com/jellypudding/offlineclient/modules/movement/NoFall.javaJava · 520 lines · 18.8 KB

Stops fall damage.

SettingsModePlaced itemCollectAir place whenAnchorMin fallWhilst glidingGlide min fallAnti bouncePause on mace
NoFall.javaJava · Minecraft 26.2 · 520 lines · 18.8 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.PreMotionEvent;
7
import com.jellypudding.offlineclient.event.events.TickEvent;
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.util.BlockUtil;
14
import com.jellypudding.offlineclient.util.EntityUtil;
15
import com.jellypudding.offlineclient.util.InventoryUtil;
16
import net.minecraft.client.player.LocalPlayer;
17
import net.minecraft.core.BlockPos;
18
import net.minecraft.core.Direction;
19
import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket;
20
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
21
import net.minecraft.world.InteractionHand;
22
import net.minecraft.world.attribute.EnvironmentAttributes;
23
import net.minecraft.world.item.Item;
24
import net.minecraft.world.item.Items;
25
import net.minecraft.world.level.ClipContext;
26
import net.minecraft.world.level.block.Block;
27
import net.minecraft.world.level.block.Blocks;
28
import net.minecraft.world.phys.BlockHitResult;
29
import net.minecraft.world.phys.HitResult;
30
import net.minecraft.world.phys.Vec3;
31
32
import java.util.function.BooleanSupplier;
33
34
// The server counts your fall and hurts on the packet that claims ground.
35
// Packet mode climbs first and never fakes ground. Place mode softens the landing.
36
public final class NoFall extends Module {
37
38
    public enum Mode { PACKET, PLACE, AIR_PLACE, BOTH }
39
    public enum AirPlaceWhen { BEFORE_DAMAGE, BEFORE_DEATH }
40
41
    public enum PlacedItem {
42
        BUCKET(Items.WATER_BUCKET, Blocks.WATER),
43
        POWDER_SNOW(Items.POWDER_SNOW_BUCKET, Blocks.POWDER_SNOW),
44
        HAY_BALE(Items.HAY_BLOCK, Blocks.HAY_BLOCK),
45
        COBWEB(Items.COBWEB, Blocks.COBWEB),
46
        SLIME_BLOCK(Items.SLIME_BLOCK, Blocks.SLIME_BLOCK);
47
48
        private final Item item;
49
        private final Block block;
50
51
        PlacedItem(Item item, Block block) {
52
            this.item = item;
53
            this.block = block;
54
        }
55
56
        // Poured from a bucket and taken back with an empty one.
57
        boolean fromBucket() {
58
            return this == BUCKET || this == POWDER_SNOW;
59
        }
60
    }
61
62
    // A jump between dimensions moves the player further than any fall.
63
    private static final double TELEPORT_DROP = 64;
64
65
    // Blocks of fall the game forgives before it hurts.
66
    private static final float SAFE_FALL = 3;
67
68
    // Air place goes down before this much fall would hurt at all.
69
    private static final float DAMAGE_FALL = 2;
70
71
    // How far the wiping packet climbs. Any climb at all does it.
72
    private static final double CLIMB = 0.001;
73
74
    // A landing pauses this far above the ground for its wipe.
75
    private static final double LANDING_STEP = 0.02;
76
77
    // Ticks to leave the water alone before collecting it and the longest wait.
78
    private static final int PICKUP_DELAY = 2;
79
    private static final int PICKUP_TIMEOUT = 20;
80
81
    private final EnumSetting<Mode> mode = new EnumSetting<>("Mode",
82
        "How the fall is stopped.", Mode.PACKET)
83
        .describe(Mode.PACKET, "Wipes the fall the server has counted with a tiny climb before it can hurt.")
84
        .describe(Mode.PLACE, "Drops water or another soft landing under you. Survives a strict server.")
85
        .describe(Mode.AIR_PLACE, "Puts any block from your hotbar under your feet just before the fall would hurt.")
86
        .describe(Mode.BOTH, "Wipes the count and drops the soft landing as well.");
87
    private final EnumSetting<PlacedItem> placedItem = new EnumSetting<>("Placed item",
88
        "What is dropped under you. A bucket turns into powder snow where water boils away.", PlacedItem.BUCKET)
89
        .under(mode, Mode.PLACE, Mode.BOTH);
90
    private final BoolSetting pickUp = new BoolSetting("Collect",
91
        "Picks the water or powder snow back up once it has broken your fall.", true)
92
        .under(mode, Mode.PLACE, Mode.BOTH);
93
    private final EnumSetting<AirPlaceWhen> airPlaceWhen = new EnumSetting<>("Air place when",
94
        "How far you fall before the block goes down.", AirPlaceWhen.BEFORE_DEATH)
95
        .describe(AirPlaceWhen.BEFORE_DAMAGE, "Before the fall would hurt at all.")
96
        .describe(AirPlaceWhen.BEFORE_DEATH, "Only once the fall would kill you.")
97
        .under(mode, Mode.AIR_PLACE);
98
    private final BoolSetting anchor = new BoolSetting("Anchor",
99
        "Centres you on the block first so the landing goes under you and not beside you.", true)
100
        .under(mode, Mode.PLACE, Mode.AIR_PLACE, Mode.BOTH);
101
    private final NumberSetting minFall = new NumberSetting("Min fall",
102
        "Small drops are left alone until the fall passes this. Anything over three blocks will hurt.",
103
        2.5, 0, 10, 0.1, " blocks").min(0).max(10);
104
    private final BoolSetting whilstGliding = new BoolSetting("Whilst gliding",
105
        "Keep working whilst you fly with an elytra.", true);
106
    private final NumberSetting glideMinFall = new NumberSetting("Glide min fall",
107
        "The same minimum applied whilst you glide.", 2.5, 0, 10, 0.1, " blocks")
108
        .min(0).max(10)
109
        .under(whilstGliding);
110
    private final BoolSetting antiBounce = new BoolSetting("Anti bounce",
111
        "Landing on a slime block or a bed never bounces you.", true);
112
    private final BoolSetting pauseOnMace = new BoolSetting("Pause on mace",
113
        "Leaves the fall alone whilst you hold a mace. The smash still lands.", true);
114
115
    // The count the server holds. Every movement packet that goes out is mirrored here.
116
    // Unknown after a teleport until a climb has wiped it.
117
    private double bank;
118
    private volatile boolean bankKnown;
119
120
    // The last position that went out. The climb packet starts from it.
121
    private double sentX;
122
    private double sentY;
123
    private double sentZ;
124
    private volatile boolean sentKnown;
125
126
    // A module such as Blink is holding the movement packets back.
127
    private boolean heldBack;
128
129
    // The fall as the client sees it. Place modes read this.
130
    private double descent;
131
    private double lastY;
132
    private boolean tracking;
133
134
    private final InventoryUtil.HotbarLoan loan = new InventoryUtil.HotbarLoan();
135
    // Where the soft landing went and what it was. Null once collected or given up.
136
    private BlockPos placedAt;
137
    private PlacedItem placedKind;
138
    private int pickupTimer;
139
    private int placedTicks;
140
141
    public NoFall() {
142
        super("NoFall", "Stops fall damage.", Category.MOVEMENT);
143
        addSettings(mode, placedItem, pickUp, airPlaceWhen, anchor, minFall, whilstGliding,
144
            glideMinFall, antiBounce, pauseOnMace);
145
        searchTags("fall damage", "water bucket", "clutch", "air place");
146
    }
147
148
    @Override
149
    public String getSuffix() {
150
        return placedKind == null ? null : EnumSetting.label(placedKind);
151
    }
152
153
    // Read by EntityMixin. Slime and beds check this before they bounce.
154
    public boolean suppressesBounce() {
155
        return isEnabled() && antiBounce.isOn();
156
    }
157
158
    @Override
159
    protected void onEnable() {
160
        reset();
161
        if (inGame()) {
162
            // The server may already hold a count. The first climb clears it.
163
            sentX = mc.player.getX();
164
            sentY = mc.player.getY();
165
            sentZ = mc.player.getZ();
166
            sentKnown = true;
167
        }
168
    }
169
170
    @Override
171
    protected void onDisable() {
172
        reset();
173
    }
174
175
    private void reset() {
176
        bank = 0;
177
        bankKnown = false;
178
        sentKnown = false;
179
        heldBack = false;
180
        descent = 0;
181
        tracking = false;
182
        placedAt = null;
183
        placedKind = null;
184
        pickupTimer = 0;
185
        placedTicks = 0;
186
        loan.giveBack();
187
    }
188
189
    private boolean packetMode() {
190
        return mode.isAny(Mode.PACKET, Mode.BOTH);
191
    }
192
193
    private boolean placeMode() {
194
        return mode.isAny(Mode.PLACE, Mode.BOTH);
195
    }
196
197
    // Runs once per tick just before the movement packet is built.
198
    @Subscribe
199
    private void onPreMotion(PreMotionEvent event) {
200
        if (!inGame()) {
201
            reset();
202
            return;
203
        }
204
        trackDescent();
205
        if (!packetMode() || !protecting()) {
206
            return;
207
        }
208
        if (!sentKnown || heldBack || mc.player.isInWater()) {
209
            return;
210
        }
211
        double y = mc.player.getY();
212
        double drop = sentY - y;
213
        // A climb wipes the count on its own.
214
        if (drop < 0) {
215
            return;
216
        }
217
        double counted = bankKnown ? bank + drop : Double.MAX_VALUE;
218
        if (counted <= wipeAt()) {
219
            return;
220
        }
221
        // A landing after a real drop pauses just above the ground.
222
        // Anything else is one climb.
223
        if (landingThisTick() && drop > LANDING_STEP) {
224
            sendLanding(mc.player.getX(), y, mc.player.getZ());
225
        } else {
226
            sendClimb();
227
        }
228
    }
229
230
    // The packet about to go out will carry a ground flag.
231
    private boolean landingThisTick() {
232
        if (mc.player.onGround()) {
233
            return true;
234
        }
235
        // FastBreak claims ground whilst a block is being mined.
236
        return mc.gameMode.isDestroying();
237
    }
238
239
    // A tiny climb from the last sent spot. The server wipes its count on it.
240
    private void sendClimb() {
241
        mc.player.connection.send(new ServerboundMovePlayerPacket.Pos(
242
            sentX, sentY + CLIMB, sentZ, false, mc.player.horizontalCollision));
243
    }
244
245
    // The count is wiped and the fall carried on to just above the ground.
246
    // The real landing packet that follows only counts that last step.
247
    private void sendLanding(double x, double y, double z) {
248
        sendClimb();
249
        boolean collided = mc.player.horizontalCollision;
250
        mc.player.connection.send(new ServerboundMovePlayerPacket.Pos(
251
            x, y + LANDING_STEP, z, false, collided));
252
        mc.player.connection.send(new ServerboundMovePlayerPacket.Pos(
253
            x, y + LANDING_STEP + CLIMB, z, false, collided));
254
    }
255
256
    // How much fall the server may hold before a climb wipes it.
257
    private double wipeAt() {
258
        return mc.player.isFallFlying() ? glideMinFall.getValue() : minFall.getValue();
259
    }
260
261
    private boolean protecting() {
262
        LocalPlayer player = mc.player;
263
        if (player.getAbilities().invulnerable || player.isPassenger()) {
264
            return false;
265
        }
266
        if (player.isFallFlying() && !whilstGliding.isOn()) {
267
            return false;
268
        }
269
        return !pauseOnMace.isOn() || !holdingMace();
270
    }
271
272
    private void trackDescent() {
273
        double y = mc.player.getY();
274
        if (!tracking) {
275
            lastY = y;
276
            tracking = true;
277
        }
278
        double drop = lastY - y;
279
        lastY = y;
280
        if (mc.player.onGround() || mc.player.isInWater() || mc.player.isPassenger()) {
281
            descent = 0;
282
        } else if (drop > TELEPORT_DROP || drop < 0) {
283
            // A climb or a teleport wipes what the server was tracking.
284
            descent = 0;
285
        } else {
286
            descent += drop;
287
        }
288
    }
289
290
    private boolean holdingMace() {
291
        return mc.player.getMainHandItem().is(Items.MACE)
292
            || mc.player.getOffhandItem().is(Items.MACE);
293
    }
294
295
    // Mirrors what the server will hold after each movement packet.
296
    // Runs after every other rewrite. The packet seen here is the one sent.
297
    @Subscribe(priority = -100)
298
    private void onPacketSend(PacketSendEvent event) {
299
        if (!(event.getPacket() instanceof ServerboundMovePlayerPacket packet)) {
300
            return;
301
        }
302
        if (event.isCancelled()) {
303
            heldBack = true;
304
            return;
305
        }
306
        heldBack = false;
307
        // The packet thread can lose the player mid handler.
308
        LocalPlayer player = mc.player;
309
        if (player == null) {
310
            return;
311
        }
312
        if (packet.hasPosition()) {
313
            double y = packet.getY(player.getY());
314
            if (sentKnown && y > sentY) {
315
                bank = 0;
316
                bankKnown = true;
317
            } else if (sentKnown && bankKnown) {
318
                bank += sentY - y;
319
            }
320
            sentX = packet.getX(player.getX());
321
            sentY = y;
322
            sentZ = packet.getZ(player.getZ());
323
            sentKnown = true;
324
        }
325
        // Water and a ground flag both wipe the count on the server.
326
        if (packet.isOnGround() || player.isInWater()) {
327
            bank = 0;
328
            bankKnown = true;
329
        }
330
    }
331
332
    // Fired on the netty thread. The server moved the player and the count with it.
333
    @Subscribe
334
    private void onPacketReceive(PacketReceiveEvent event) {
335
        if (event.getPacket() instanceof ClientboundPlayerPositionPacket) {
336
            bankKnown = false;
337
            sentKnown = false;
338
        }
339
    }
340
341
    @Subscribe
342
    private void onTick(TickEvent event) {
343
        if (!inGame()) {
344
            return;
345
        }
346
        if (pickupTimer > 0) {
347
            pickupTimer--;
348
        }
349
        // A mode change mid clutch still has to clear up what is already down.
350
        if (placedAt != null) {
351
            collect();
352
            return;
353
        }
354
        if (mode.is(Mode.AIR_PLACE)) {
355
            airPlaceTick();
356
            return;
357
        }
358
        if (!placeMode()) {
359
            return;
360
        }
361
        if (!falling() || descent <= SAFE_FALL || groundBelow() == null) {
362
            loan.giveBack();
363
            return;
364
        }
365
        placeLanding();
366
    }
367
368
    // True whilst a fall is running that the module ought to be watching.
369
    private boolean falling() {
370
        LocalPlayer player = mc.player;
371
        if (player.getAbilities().invulnerable || player.onGround() || player.isInWater()
372
            || player.getDeltaMovement().y >= 0) {
373
            return false;
374
        }
375
        if (player.isFallFlying() && !whilstGliding.isOn()) {
376
            return false;
377
        }
378
        return !pauseOnMace.isOn() || !holdingMace();
379
    }
380
381
    // The ground straight below within reach or null.
382
    private BlockPos groundBelow() {
383
        Vec3 eye = mc.player.getEyePosition();
384
        Vec3 end = eye.subtract(0, mc.player.blockInteractionRange(), 0);
385
        BlockHitResult hit = mc.level.clip(new ClipContext(eye, end,
386
            ClipContext.Block.OUTLINE, ClipContext.Fluid.SOURCE_ONLY, mc.player));
387
        return hit.getType() == HitResult.Type.BLOCK ? hit.getBlockPos() : null;
388
    }
389
390
    // The item chosen with the bucket swapped for powder snow where water boils away.
391
    private PlacedItem chosenItem() {
392
        if (placedItem.is(PlacedItem.BUCKET) && mc.level.environmentAttributes()
393
            .getValue(EnvironmentAttributes.WATER_EVAPORATES, mc.player.blockPosition())) {
394
            return PlacedItem.POWDER_SNOW;
395
        }
396
        return placedItem.getValue();
397
    }
398
399
    // A bucket raycasts from the live client rotation and the packet carries it.
400
    // Pointing down for the call is enough. A block is clicked onto the ground.
401
    private void placeLanding() {
402
        PlacedItem kind = chosenItem();
403
        int slot = InventoryUtil.findSlot(kind.item, InventoryUtil.WHOLE_INVENTORY);
404
        BlockPos ground = groundBelow();
405
        if (slot == -1 || ground == null || !loan.select(slot)) {
406
            return;
407
        }
408
        if (anchor.isOn()) {
409
            BlockUtil.centerPlayer();
410
        }
411
        BlockPos target = ground.above();
412
        boolean placed = kind.fromBucket()
413
            ? lookingDown(() -> useHeld())
414
            : BlockUtil.place(target, Direction.DOWN, true, true);
415
        if (!placed) {
416
            return;
417
        }
418
        if (kind.fromBucket()) {
419
            placedAt = target;
420
            placedKind = kind;
421
            pickupTimer = PICKUP_DELAY;
422
            placedTicks = 0;
423
        } else {
424
            loan.giveBack();
425
        }
426
    }
427
428
    private boolean useHeld() {
429
        if (!mc.gameMode.useItem(mc.player, InteractionHand.MAIN_HAND).consumesAction()) {
430
            return false;
431
        }
432
        mc.player.swing(InteractionHand.MAIN_HAND);
433
        return true;
434
    }
435
436
    private boolean lookingDown(BooleanSupplier action) {
437
        float pitch = mc.player.getXRot();
438
        mc.player.setXRot(90f);
439
        try {
440
            return action.getAsBoolean();
441
        } finally {
442
            mc.player.setXRot(pitch);
443
        }
444
    }
445
446
    // Any block from the hotbar goes under the feet once the fall is deep enough.
447
    // The fall is paused for the click. The block lands where the feet are.
448
    private void airPlaceTick() {
449
        if (!falling() || descent <= airPlaceThreshold()) {
450
            loan.giveBack();
451
            return;
452
        }
453
        BlockPos below = mc.player.blockPosition().below();
454
        int slot = BlockUtil.findBlockSlot();
455
        if (slot == -1 || !BlockUtil.isReplaceable(below) || !loan.select(slot)) {
456
            return;
457
        }
458
        if (anchor.isOn()) {
459
            BlockUtil.centerPlayer();
460
        }
461
        Vec3 velocity = mc.player.getDeltaMovement();
462
        mc.player.setDeltaMovement(velocity.x, 0, velocity.z);
463
        try {
464
            BlockUtil.placeAny(below, true, true);
465
        } finally {
466
            mc.player.setDeltaMovement(velocity);
467
        }
468
    }
469
470
    // Before any damage or only once the fall would take every heart.
471
    private float airPlaceThreshold() {
472
        if (airPlaceWhen.is(AirPlaceWhen.BEFORE_DAMAGE)) {
473
            return DAMAGE_FALL;
474
        }
475
        return Math.max(EntityUtil.totalHealth(mc.player), DAMAGE_FALL);
476
    }
477
478
    // Takes the water or snow back once the landing is done with it.
479
    private void collect() {
480
        if (!pickUp.isOn() || !placeMode() || ++placedTicks > PICKUP_TIMEOUT) {
481
            forgetPlaced();
482
            return;
483
        }
484
        if (pickupTimer > 0 || !landedOnPlaced()) {
485
            return;
486
        }
487
        if (!placedStillThere()) {
488
            // Something else already took it.
489
            forgetPlaced();
490
            return;
491
        }
492
        int bucket = InventoryUtil.findSlot(Items.BUCKET, InventoryUtil.WHOLE_INVENTORY);
493
        if (bucket != -1 && loan.select(bucket)) {
494
            lookingDown(this::useHeld);
495
        }
496
        forgetPlaced();
497
    }
498
499
    // Water is collected once the player is in it and snow once they have sunk to its floor.
500
    private boolean landedOnPlaced() {
501
        if (placedKind == PlacedItem.BUCKET) {
502
            return mc.player.isInWater();
503
        }
504
        return mc.player.onGround() && mc.player.fallDistance == 0;
505
    }
506
507
    private boolean placedStillThere() {
508
        if (placedKind == PlacedItem.BUCKET) {
509
            return !mc.level.getFluidState(placedAt).isEmpty();
510
        }
511
        return mc.level.getBlockState(placedAt).is(placedKind.block);
512
    }
513
514
    private void forgetPlaced() {
515
        placedAt = null;
516
        placedKind = null;
517
        loan.giveBack();
518
    }
519
}
520
CombatantMOVEMENTsrc/main/java/combatant/client/features/module/modules/movement/NoFall.javaJava · 718 lines · 25.4 KB
Settingsmodepacket_jump_fall_distancepacket_jump_timingpacket_jump_reset_fall_distancevulcan_fall_distancemlg_min_fall_distancemlg_no_rotations
NoFall.javaJava · Minecraft 26.2 · 718 lines · 25.4 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Combatant Client distribution.
3
 * Copyright (c) 2026 pivosos2007.
4
 *
5
 * Licensed under the GNU General Public License v3.0.
6
 */
7
8
package combatant.client.features.module.modules.movement;
9
10
import net.minecraft.client.Minecraft;
11
import net.minecraft.client.player.LocalPlayer;
12
import net.minecraft.core.BlockPos;
13
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
14
import net.minecraft.network.protocol.game.ServerboundUseItemPacket;
15
import net.minecraft.world.InteractionHand;
16
import net.minecraft.world.InteractionResult;
17
import net.minecraft.world.item.Item;
18
import net.minecraft.world.item.ItemStack;
19
import net.minecraft.world.item.Items;
20
import net.minecraft.world.level.ClipContext;
21
import net.minecraft.world.level.Level;
22
import net.minecraft.world.level.block.Blocks;
23
import net.minecraft.world.phys.BlockHitResult;
24
import net.minecraft.world.phys.HitResult;
25
import net.minecraft.world.phys.Vec3;
26
import combatant.client.config.values.BooleanValue;
27
import combatant.client.config.values.EnumValue;
28
import combatant.client.config.values.NumberValue;
29
import combatant.client.events.EventHandler;
30
import combatant.client.events.impl.GameTickEvent;
31
import combatant.client.events.impl.MovementInputEvent;
32
import combatant.client.events.impl.PacketEvent;
33
import combatant.client.events.impl.RotationUpdateEvent;
34
import combatant.client.features.module.Module;
35
import combatant.client.features.module.ModuleCategory;
36
import combatant.client.features.module.ModuleInfo;
37
import combatant.client.mixins.accessors.PlayerInventoryAccessor;
38
import combatant.client.mixins.accessors.ServerboundMovePlayerPacketAccessor;
39
import combatant.client.util.aiming.RotationManager;
40
import combatant.client.util.aiming.RotationTarget;
41
import combatant.client.util.aiming.data.Rotation;
42
import combatant.client.util.aiming.features.MovementCorrection;
43
import combatant.client.util.block.scaffold.ScaffoldFacePositionFactory;
44
import combatant.client.util.block.scaffold.ScaffoldPlacementTarget;
45
import combatant.client.util.block.scaffold.ScaffoldTargetFinder;
46
import combatant.client.util.player.InteractionUtil;
47
import combatant.client.util.player.inventory.InventorySwap;
48
import combatant.client.util.player.simulation.PlayerSimulationCache;
49
50
import java.util.ArrayList;
51
import java.util.List;
52
import java.util.Objects;
53
import java.util.Set;
54
55
//todo Description
56
@ModuleInfo(
57
        id = "nofall",
58
        displayName = "NoFall",
59
        category = ModuleCategory.MOVEMENT
60
)
61
public class NoFall extends Module {
62
63
    private static final int MLG_COLLISION_PREDICTION_TICKS = 20;
64
    private static final int MLG_SCAFFOLDING_SNEAK_TICKS = 3;
65
    private static final int MLG_HOTBAR_RESET_TICKS = 1;
66
    private static final long MLG_PICKUP_WATER_MIN_DELAY_MS = 200L;
67
    private static final long MLG_PICKUP_WATER_MAX_DELAY_MS = 1000L;
68
    private static final Set<Item> NETHER_MLG_ITEMS = Set.of(
69
            Items.SCAFFOLDING,
70
            Items.COBWEB,
71
            Items.POWDER_SNOW_BUCKET,
72
            Items.HAY_BLOCK,
73
            Items.SLIME_BLOCK,
74
            Items.HONEY_BLOCK,
75
            Items.TWISTING_VINES
76
    );
77
    private static final Set<Item> NORMAL_MLG_ITEMS;
78
79
    static {
80
        java.util.LinkedHashSet<Item> items = new java.util.LinkedHashSet<>(NETHER_MLG_ITEMS);
81
        items.add(Items.WATER_BUCKET);
82
        NORMAL_MLG_ITEMS = Set.copyOf(items);
83
    }
84
85
    private final EnumValue<Mode> mode =
86
            enumSetting("mode", "mode", Mode.GROUD_SPOOF, Mode.values());
87
    private final NumberValue<Float> packetJumpFallDistance =
88
            visibleWhen(num("packet_jump_fall_distance", 3.0f, 0.0f, 20.0f), () -> mode.get() == Mode.PACKET_JUMP);
89
    private final EnumValue<PacketJumpTiming> packetJumpTiming =
90
            visibleWhen(enumSetting("packet_jump_timing", "packet_jump_timing", PacketJumpTiming.LANDING, PacketJumpTiming.values()),
91
                    () -> mode.get() == Mode.PACKET_JUMP);
92
    private final BooleanValue packetJumpResetFallDistance =
93
            visibleWhen(bool("packet_jump_reset_fall_distance", true),
94
                    () -> mode.get() == Mode.PACKET_JUMP && packetJumpTiming.get() == PacketJumpTiming.FALLING);
95
    private final NumberValue<Float> vulcanFallDistance =
96
            visibleWhen(num("vulcan_fall_distance", 7.0f, 3.0f, 40.0f), () -> mode.get() == Mode.VULCAN);
97
    private final NumberValue<Float> mlgMinFallDistance =
98
            visibleWhen(num("mlg_min_fall_distance", 4.0f, 3.0f, 50.0f), () -> mode.get() == Mode.MLG);
99
    private final BooleanValue mlgNoRotations =
100
            visibleWhen(bool("mlg_no_rotations", false), () -> mode.get() == Mode.MLG);
101
    private final List<PlacedWater> lastWaterPlacements = new ArrayList<>();
102
    private boolean packetJumpFalling;
103
    private boolean packetJumpInternalSend;
104
    private int lastPacketJumpTick = Integer.MIN_VALUE;
105
    private double lastMoveX = Double.NaN;
106
    private double lastMoveY = Double.NaN;
107
    private double lastMoveZ = Double.NaN;
108
    private MlgPlan currentMlgPlan;
109
    private int mlgSneakTicks;
110
111
    {
112
        setDefaultBind("GRAVE_ACCENT");
113
    }
114
115
    @Override
116
    public void onEnable() {
117
        resetState();
118
    }
119
120
    @Override
121
    public void onDisable() {
122
        resetState();
123
    }
124
125
    @EventHandler
126
    private void onGameTick(GameTickEvent event) {
127
        Minecraft client = Minecraft.getInstance();
128
        if (client == null || client.player == null || client.getConnection() == null) return;
129
130
        LocalPlayer player = client.player;
131
        if (mode.get() == Mode.MLG) {
132
            tickMlg(client, player);
133
            return;
134
        }
135
136
        if (player.onGround()) {
137
            packetJumpFalling = false;
138
        }
139
        if (player.isShiftKeyDown()) return;
140
141
        switch (mode.get()) {
142
            case GROUD_SPOOF -> {
143
                if (isDangerousFall(player)) {
144
                    client.getConnection().send(
145
                            new ServerboundMovePlayerPacket.StatusOnly(true, player.horizontalCollision)
146
                    );
147
                }
148
            }
149
            case PACKET_JUMP -> {
150
                packetJumpFalling = !player.onGround() && player.fallDistance > packetJumpFallDistance.get();
151
                if (packetJumpTiming.get() == PacketJumpTiming.FALLING
152
                        && packetJumpFalling
153
                        && player.tickCount != lastPacketJumpTick) {
154
                    sendPacketJumpSpoof(client, player, player.getX(), player.getY() + 1.0E-9, player.getZ());
155
                    lastPacketJumpTick = player.tickCount;
156
                    if (packetJumpResetFallDistance.get()) {
157
                        player.fallDistance = 0.0f;
158
                    }
159
                }
160
            }
161
            default -> {
162
            }
163
        }
164
    }
165
166
    @EventHandler
167
    private void onRotationUpdate(RotationUpdateEvent event) {
168
        if (event.getType() != RotationUpdateEvent.Type.PRE) {
169
            return;
170
        }
171
172
        if (mode.get() != Mode.MLG) {
173
            currentMlgPlan = null;
174
            return;
175
        }
176
177
        Minecraft client = Minecraft.getInstance();
178
        if (client == null || client.player == null || client.gameMode == null) {
179
            currentMlgPlan = null;
180
            return;
181
        }
182
183
        currentMlgPlan = getCurrentGoal(client.player);
184
        if (currentMlgPlan == null || mlgNoRotations.get()) {
185
            return;
186
        }
187
188
        RotationTarget target = new RotationTarget(
189
                currentMlgPlan.rotation(),
190
                client.player,
191
                List.of(),
192
                1,
193
                4.0f,
194
                false,
195
                MovementCorrection.SILENT,
196
                null
197
        );
198
        RotationManager.INSTANCE.setRotationTarget(target, 100, this);
199
    }
200
201
    @EventHandler
202
    private void onMovementInput(MovementInputEvent event) {
203
        if (mode.get() != Mode.MLG || mlgSneakTicks <= 0) {
204
            return;
205
        }
206
207
        mlgSneakTicks--;
208
        event.setSneak(true);
209
    }
210
211
    @EventHandler
212
    private void onPacketSend(PacketEvent.Send event) {
213
        if (packetJumpInternalSend) return;
214
        if (!(event.getPacket() instanceof ServerboundMovePlayerPacket packet)) return;
215
216
        Minecraft client = Minecraft.getInstance();
217
        if (client == null || client.player == null) return;
218
219
        LocalPlayer player = client.player;
220
        if (player.isShiftKeyDown()) {
221
            rememberMovePacket(packet, player);
222
            return;
223
        }
224
225
        switch (mode.get()) {
226
            case PACKET_JUMP -> {
227
                packetJumpFalling = !player.onGround() && player.fallDistance > packetJumpFallDistance.get();
228
                if (packetJumpTiming.get() == PacketJumpTiming.LANDING
229
                        && packet.isOnGround()
230
                        && packetJumpFalling) {
231
                    packetJumpFalling = false;
232
                    sendPacketJumpSpoof(
233
                            client,
234
                            player,
235
                            resolveTracked(lastMoveX, player.getX()),
236
                            resolveTracked(lastMoveY, player.getY()) + 1.0E-9,
237
                            resolveTracked(lastMoveZ, player.getZ())
238
                    );
239
                }
240
            }
241
            case VULCAN -> {
242
                if (player.fallDistance > vulcanFallDistance.get()) {
243
                    ((ServerboundMovePlayerPacketAccessor) packet).combatant$setOnGround(true);
244
                    player.fallDistance = 0.0f;
245
                    player.setDeltaMovement(player.getDeltaMovement().x, 0.0, player.getDeltaMovement().z);
246
                }
247
            }
248
            case NO_GROUND -> ((ServerboundMovePlayerPacketAccessor) packet).combatant$setOnGround(false);
249
            default -> {
250
            }
251
        }
252
253
        rememberMovePacket(packet, player);
254
    }
255
256
    private boolean isDangerousFall(LocalPlayer player) {
257
        return player != null
258
                && player.getDeltaMovement().y < -0.5
259
                && player.fallDistance > 2.0f;
260
    }
261
262
    private void sendPacketJumpSpoof(Minecraft client, LocalPlayer player, double x, double y, double z) {
263
        if (client.getConnection() == null || player == null) return;
264
265
        packetJumpInternalSend = true;
266
        try {
267
            client.getConnection().send(new ServerboundMovePlayerPacket.Pos(
268
                    x,
269
                    y,
270
                    z,
271
                    false,
272
                    player.horizontalCollision
273
            ));
274
        } finally {
275
            packetJumpInternalSend = false;
276
        }
277
    }
278
279
    private void rememberMovePacket(ServerboundMovePlayerPacket packet, LocalPlayer player) {
280
        lastMoveX = packet.getX(player.getX());
281
        lastMoveY = packet.getY(player.getY());
282
        lastMoveZ = packet.getZ(player.getZ());
283
    }
284
285
    private double resolveTracked(double value, double fallback) {
286
        return Double.isNaN(value) ? fallback : value;
287
    }
288
289
    private void resetState() {
290
        packetJumpFalling = false;
291
        packetJumpInternalSend = false;
292
        lastPacketJumpTick = Integer.MIN_VALUE;
293
        lastMoveX = Double.NaN;
294
        lastMoveY = Double.NaN;
295
        lastMoveZ = Double.NaN;
296
        currentMlgPlan = null;
297
        mlgSneakTicks = 0;
298
        lastWaterPlacements.clear();
299
        InventorySwap.INSTANCE.releaseHotbar(this);
300
    }
301
302
    private void tickMlg(Minecraft client, LocalPlayer player) {
303
        if (player == null || client.gameMode == null) {
304
            currentMlgPlan = null;
305
            return;
306
        }
307
308
        MlgPlan plan = currentMlgPlan;
309
        if (plan == null) {
310
            return;
311
        }
312
313
        if (plan.type() == MlgPlanType.PLACE
314
                && (player.onGround()
315
                || player.isInWater()
316
                || player.isInLava()
317
                || player.onClimbable()
318
                || player.getAbilities().flying)) {
319
            currentMlgPlan = null;
320
            return;
321
        }
322
323
        BlockHitResult hitResult;
324
        Rotation useRotation;
325
        if (mlgNoRotations.get()) {
326
            if (plan.type() == MlgPlanType.PICKUP_WATER) {
327
                Rotation playerRotation = new Rotation(player.getYRot(), player.getXRot(), true).normalize();
328
                hitResult = traceTarget(player, playerRotation, ClipContext.Fluid.SOURCE_ONLY);
329
                if (!plan.matches(hitResult)) {
330
                    return;
331
                }
332
                useRotation = playerRotation;
333
            } else {
334
                hitResult = plan.target().toHitResult();
335
                useRotation = plan.rotation();
336
            }
337
        } else {
338
            Rotation currentRotation = RotationManager.INSTANCE.getCurrentRotation();
339
            if (currentRotation == null) {
340
                return;
341
            }
342
343
            hitResult = traceTarget(
344
                    player,
345
                    currentRotation,
346
                    plan.type() == MlgPlanType.PICKUP_WATER ? ClipContext.Fluid.SOURCE_ONLY : ClipContext.Fluid.NONE
347
            );
348
            if (!plan.matches(hitResult)) {
349
                return;
350
            }
351
            useRotation = currentRotation;
352
        }
353
354
        executeMlgPlacement(player, plan, hitResult, useRotation);
355
        currentMlgPlan = null;
356
    }
357
358
    private MlgPlan getCurrentGoal(LocalPlayer player) {
359
        MlgPlan placement = getCurrentMlgPlacementPlan(player);
360
        if (placement != null) {
361
            return placement;
362
        }
363
        return getCurrentPickupPlan(player);
364
    }
365
366
    private MlgPlan getCurrentMlgPlacementPlan(LocalPlayer player) {
367
        if (player == null || player.fallDistance <= mlgMinFallDistance.get()) {
368
            return null;
369
        }
370
371
        MlgSource source = findClosestMlgSource(player);
372
        if (source == null) {
373
            return null;
374
        }
375
376
        BlockPos collision = findMlgCollision(player);
377
        if (collision == null || isFallDamageBlocking(collision)) {
378
            return null;
379
        }
380
381
        BlockPos targetPos = collision.above();
382
        ScaffoldPlacementTarget target = ScaffoldTargetFinder.findTarget(
383
                player,
384
                targetPos,
385
                source.stack(),
386
                List.of(BlockPos.ZERO),
387
                null,
388
                false,
389
                new ScaffoldFacePositionFactory(
390
                        player,
391
                        player.getEyePosition(),
392
                        ScaffoldFacePositionFactory.Mode.CENTER,
393
                        null,
394
                        0.0
395
                ),
396
                player.getEyePosition()
397
        );
398
        if (target == null) {
399
            return null;
400
        }
401
        if (!isWithinMlgBlockRange(player, target.getHitVec())) {
402
            return null;
403
        }
404
405
        return new MlgPlan(MlgPlanType.PLACE, targetPos, target, target.getRotation(), source.hand(), source.hotbarSlot(), source.item());
406
    }
407
408
    private MlgPlan getCurrentPickupPlan(LocalPlayer player) {
409
        if (player == null) {
410
            return null;
411
        }
412
413
        MlgSource source = findClosestSpecificItemSource(player, Items.BUCKET);
414
        if (source == null) {
415
            return null;
416
        }
417
418
        Minecraft client = Minecraft.getInstance();
419
        if (client == null || client.level == null) {
420
            return null;
421
        }
422
423
        long now = System.currentTimeMillis();
424
        lastWaterPlacements.removeIf(placement ->
425
                now - placement.timeMs() > MLG_PICKUP_WATER_MAX_DELAY_MS
426
                        || !client.level.getBlockState(placement.pos()).is(Blocks.WATER));
427
428
        for (PlacedWater placement : lastWaterPlacements) {
429
            if (now - placement.timeMs() < MLG_PICKUP_WATER_MIN_DELAY_MS) {
430
                continue;
431
            }
432
433
            Vec3 hitVec = Vec3.atCenterOf(placement.pos()).add(0.0, 0.45, 0.0);
434
            Rotation rotation = Rotation.lookingAt(hitVec, player.getEyePosition()).normalize();
435
            if (!isWithinMlgBlockRange(player, hitVec)) {
436
                continue;
437
            }
438
439
            return new MlgPlan(MlgPlanType.PICKUP_WATER, placement.pos(), null, rotation, source.hand(), source.hotbarSlot(), source.item());
440
        }
441
442
        return null;
443
    }
444
445
    private MlgSource findClosestMlgSource(LocalPlayer player) {
446
        if (player == null) {
447
            return null;
448
        }
449
450
        Set<Item> allowedItems = player.level().dimension() == Level.NETHER
451
                ? NETHER_MLG_ITEMS
452
                : NORMAL_MLG_ITEMS;
453
        ItemStack offhand = player.getOffhandItem();
454
        if (isAllowedMlgItem(offhand, allowedItems)) {
455
            return new MlgSource(InteractionHand.OFF_HAND, -1, offhand, offhand.getItem());
456
        }
457
458
        int selectedSlot = ((PlayerInventoryAccessor) player.getInventory()).combatant$getSelectedSlot();
459
        int bestSlot = -1;
460
        int bestDistance = Integer.MAX_VALUE;
461
        ItemStack bestStack = ItemStack.EMPTY;
462
463
        for (int slot = 0; slot < 9; slot++) {
464
            ItemStack stack = player.getInventory().getItem(slot);
465
            if (!isAllowedMlgItem(stack, allowedItems)) {
466
                continue;
467
            }
468
469
            int distance = hotbarDistance(selectedSlot, slot);
470
            if (distance < bestDistance) {
471
                bestDistance = distance;
472
                bestSlot = slot;
473
                bestStack = stack;
474
            }
475
        }
476
477
        if (bestSlot == -1) {
478
            return null;
479
        }
480
481
        return new MlgSource(InteractionHand.MAIN_HAND, bestSlot, bestStack, bestStack.getItem());
482
    }
483
484
    private MlgSource findClosestSpecificItemSource(LocalPlayer player, Item item) {
485
        if (player == null || item == null) {
486
            return null;
487
        }
488
489
        ItemStack offhand = player.getOffhandItem();
490
        if (!offhand.isEmpty() && offhand.is(item)) {
491
            return new MlgSource(InteractionHand.OFF_HAND, -1, offhand, item);
492
        }
493
494
        int selectedSlot = ((PlayerInventoryAccessor) player.getInventory()).combatant$getSelectedSlot();
495
        int bestSlot = -1;
496
        int bestDistance = Integer.MAX_VALUE;
497
        ItemStack bestStack = ItemStack.EMPTY;
498
499
        for (int slot = 0; slot < 9; slot++) {
500
            ItemStack stack = player.getInventory().getItem(slot);
501
            if (!stack.is(item)) {
502
                continue;
503
            }
504
505
            int distance = hotbarDistance(selectedSlot, slot);
506
            if (distance < bestDistance) {
507
                bestDistance = distance;
508
                bestSlot = slot;
509
                bestStack = stack;
510
            }
511
        }
512
513
        if (bestSlot == -1) {
514
            return null;
515
        }
516
517
        return new MlgSource(InteractionHand.MAIN_HAND, bestSlot, bestStack, item);
518
    }
519
520
    private boolean isAllowedMlgItem(ItemStack stack, Set<Item> allowedItems) {
521
        return stack != null && !stack.isEmpty() && allowedItems.contains(stack.getItem());
522
    }
523
524
    private int hotbarDistance(int from, int to) {
525
        int diff = Math.abs(from - to);
526
        return Math.min(diff, 9 - diff);
527
    }
528
529
    private BlockPos findMlgCollision(LocalPlayer player) {
530
        PlayerSimulationCache.SimulatedPlayerCache simulation = PlayerSimulationCache.getSimulationForLocalPlayer();
531
        if (simulation == null) {
532
            return null;
533
        }
534
535
        for (int tick = 1; tick <= MLG_COLLISION_PREDICTION_TICKS; tick++) {
536
            PlayerSimulationCache.SimulatedPlayerSnapshot snapshot = simulation.getSnapshotAt(tick);
537
            if (!snapshot.onGround()) {
538
                continue;
539
            }
540
541
            Vec3 pos = snapshot.pos();
542
            return BlockPos.containing(pos.x, pos.y - 0.2, pos.z);
543
        }
544
545
        return null;
546
    }
547
548
    private boolean isFallDamageBlocking(BlockPos pos) {
549
        if (pos == null) {
550
            return false;
551
        }
552
553
        Minecraft client = Minecraft.getInstance();
554
        if (client == null || client.level == null) {
555
            return false;
556
        }
557
558
        var state = client.level.getBlockState(pos);
559
        return state.is(Blocks.WATER)
560
                || state.is(Blocks.COBWEB)
561
                || state.is(Blocks.POWDER_SNOW)
562
                || state.is(Blocks.HAY_BLOCK)
563
                || state.is(Blocks.SLIME_BLOCK);
564
    }
565
566
    private BlockHitResult traceTarget(LocalPlayer player, Rotation rotation, ClipContext.Fluid fluidHandling) {
567
        if (player == null || rotation == null || player.level() == null) {
568
            return null;
569
        }
570
571
        double range = getMlgBlockRange(player);
572
        Vec3 eyes = player.getEyePosition();
573
        Vec3 end = eyes.add(rotation.directionVector().scale(range));
574
        HitResult hitResult = player.level().clip(new ClipContext(
575
                eyes,
576
                end,
577
                ClipContext.Block.OUTLINE,
578
                fluidHandling,
579
                player
580
        ));
581
        return hitResult instanceof BlockHitResult blockHitResult ? blockHitResult : null;
582
    }
583
584
    private void executeMlgPlacement(LocalPlayer player, MlgPlan plan, BlockHitResult hitResult, Rotation useRotation) {
585
        Minecraft client = Minecraft.getInstance();
586
        if (client == null || client.gameMode == null || player == null || plan == null || hitResult == null || useRotation == null) {
587
            return;
588
        }
589
        if (!canReachMlgTarget(player, plan, hitResult)) {
590
            return;
591
        }
592
593
        if (plan.hotbarSlot() >= 0) {
594
            InventorySwap.INSTANCE.leaseHotbar(this, plan.hotbarSlot(), MLG_HOTBAR_RESET_TICKS);
595
        }
596
597
        boolean success;
598
        if (plan.type() == MlgPlanType.PICKUP_WATER) {
599
            InteractionResult useResult = interactItemWithRotation(player, plan.hand(), useRotation);
600
            success = useResult != null && useResult.consumesAction();
601
        } else {
602
            InteractionResult result = client.gameMode.useItemOn(player, plan.hand(), hitResult);
603
            success = result != null && result.consumesAction();
604
605
            if (!success && result == InteractionResult.PASS) {
606
                InteractionResult useResult = interactItemWithRotation(player, plan.hand(), useRotation);
607
                success = useResult != null && useResult.consumesAction();
608
            }
609
        }
610
611
        if (success) {
612
            player.swing(plan.hand());
613
            if (plan.item() == Items.SCAFFOLDING) {
614
                mlgSneakTicks = MLG_SCAFFOLDING_SNEAK_TICKS;
615
            }
616
            if (plan.type() == MlgPlanType.PLACE && plan.item() == Items.WATER_BUCKET) {
617
                lastWaterPlacements.add(new PlacedWater(plan.targetPos(), System.currentTimeMillis()));
618
            } else if (plan.type() == MlgPlanType.PICKUP_WATER && plan.item() == Items.BUCKET) {
619
                lastWaterPlacements.removeIf(placement -> placement.pos().equals(plan.targetPos()));
620
            }
621
        }
622
    }
623
624
    private boolean canReachMlgTarget(LocalPlayer player, MlgPlan plan, BlockHitResult hitResult) {
625
        if (player == null || plan == null || hitResult == null) {
626
            return false;
627
        }
628
        if (!plan.matches(hitResult)) {
629
            return false;
630
        }
631
632
        return isWithinMlgBlockRange(player, hitResult.getLocation());
633
    }
634
635
    private boolean isWithinMlgBlockRange(LocalPlayer player, Vec3 point) {
636
        if (player == null || point == null) {
637
            return false;
638
        }
639
        double range = getMlgBlockRange(player);
640
        return player.getEyePosition().distanceToSqr(point) <= range * range;
641
    }
642
643
    private double getMlgBlockRange(LocalPlayer player) {
644
        return player != null ? player.blockInteractionRange() : 0.0;
645
    }
646
647
    private InteractionResult interactItemWithRotation(LocalPlayer player, InteractionHand hand, Rotation rotation) {
648
        Minecraft client = Minecraft.getInstance();
649
        if (client == null || client.gameMode == null || player == null || rotation == null) {
650
            return InteractionResult.FAIL;
651
        }
652
        Rotation normalized = rotation.normalize();
653
        ItemStack stack = player.getItemInHand(hand);
654
        if (stack.isEmpty() || player.getCooldowns().isOnCooldown(stack)) {
655
            return InteractionResult.PASS;
656
        }
657
658
        final InteractionResult[] resultHolder = {InteractionResult.PASS};
659
        InteractionUtil.sendSequencedPacket(id ->
660
                new ServerboundUseItemPacket(hand, id, normalized.yaw(), normalized.pitch()));
661
662
        InteractionResult result = stack.use(client.level, player, hand);
663
        if (result instanceof InteractionResult.Success success) {
664
            ItemStack newStack = Objects.requireNonNullElseGet(success.heldItemTransformedTo(), () -> player.getItemInHand(hand));
665
            if (newStack != stack) {
666
                player.setItemInHand(hand, newStack);
667
            }
668
        }
669
        resultHolder[0] = result;
670
        return resultHolder[0];
671
    }
672
673
    public enum Mode {
674
        GROUD_SPOOF,
675
        PACKET_JUMP,
676
        VULCAN,
677
        NO_GROUND,
678
        MLG
679
    }
680
681
    public enum PacketJumpTiming {
682
        LANDING,
683
        FALLING
684
    }
685
686
    private enum MlgPlanType {
687
        PLACE,
688
        PICKUP_WATER
689
    }
690
691
    private record MlgSource(InteractionHand hand, int hotbarSlot, ItemStack stack, Item item) {
692
    }
693
694
    private record MlgPlan(
695
            MlgPlanType type,
696
            BlockPos targetPos,
697
            ScaffoldPlacementTarget target,
698
            Rotation rotation,
699
            InteractionHand hand,
700
            int hotbarSlot,
701
            Item item
702
    ) {
703
        private boolean matches(BlockHitResult hitResult) {
704
            if (hitResult == null) {
705
                return false;
706
            }
707
708
            return switch (type) {
709
                case PLACE -> target != null && target.matches(hitResult);
710
                case PICKUP_WATER -> targetPos.equals(hitResult.getBlockPos());
711
            };
712
        }
713
    }
714
715
    private record PlacedWater(BlockPos pos, long timeMs) {
716
    }
717
}
718
KiwiClientMOVEMENTsrc/main/java/com/tangykiwi/kiwiclient/module/movement/NoFall.javaJava · 52 lines · 2.1 KB

Prevents fall damage

SettingsMode
NoFall.javaJava · Minecraft 26.2 · 52 lines · 2.1 KB · complete file, verbatimOriginal ↗
1
package com.tangykiwi.kiwiclient.module.movement;
2
3
import static com.tangykiwi.kiwiclient.KiwiClient.mc;
4
5
import com.google.common.eventbus.AllowConcurrentEvents;
6
import com.google.common.eventbus.Subscribe;
7
import com.tangykiwi.kiwiclient.KiwiClient;
8
import com.tangykiwi.kiwiclient.event.PacketEvent;
9
import com.tangykiwi.kiwiclient.event.TickEvent;
10
import com.tangykiwi.kiwiclient.mixin.ServerboundMovePlayerPacketAccessor;
11
import com.tangykiwi.kiwiclient.mixininterface.IServerboundMovePlayerPacket;
12
import com.tangykiwi.kiwiclient.module.Category;
13
import com.tangykiwi.kiwiclient.module.Module;
14
import com.tangykiwi.kiwiclient.module.setting.ModeSetting;
15
16
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
17
18
public class NoFall extends Module {
19
20
    public NoFall() {
21
        super("NoFall", "Prevents fall damage", Category.MOVEMENT,
22
            new ModeSetting("Mode", "NoFall mode", "Simple", "Packet"));
23
    }
24
25
    @Subscribe
26
    @AllowConcurrentEvents
27
    public void onTick(TickEvent.Pre e) {
28
        if (mc.player == null) return;
29
        if (mc.player.getAbilities().instabuild) return;
30
        if (getSetting(0).asMode().getValue() == 0) {
31
            if (mc.player.isFallFlying()) return;
32
            mc.player.connection.send(new ServerboundMovePlayerPacket.StatusOnly(true, mc.player.horizontalCollision));
33
        }
34
    }
35
36
    @Subscribe
37
    @AllowConcurrentEvents
38
    public void onPacketSend(PacketEvent.Send event) {
39
        if(getSetting(0).asMode().getValue() == 0 || !(event.packet instanceof ServerboundMovePlayerPacket) || ((IServerboundMovePlayerPacket) event.packet).getTag() == 1337) {
40
            return;
41
        }
42
        if(getSetting(0).asMode().getValue() == 1) {
43
            if(!KiwiClient.moduleManager.getModule(Fly.class).isEnabled()) {
44
                if (mc.player.isFallFlying()) return;
45
                if (mc.player.getDeltaMovement().y > -0.5) return;
46
                ((ServerboundMovePlayerPacketAccessor) event.packet).setOnGround(true);
47
            } else {
48
                ((ServerboundMovePlayerPacketAccessor) event.packet).setOnGround(true);
49
            }
50
        }
51
    }
52
}
LiquidBounce (Kotlin)PLAYERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/nofall/ModuleNoFall.ktKotlin · 112 lines · 4.7 KB

Protects you from taking fall damage.

ModuleNoFall.ktKotlin · Minecraft 26.2 · 112 lines · 4.7 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.nofall
20
21
import net.ccbluex.liquidbounce.config.types.list.Tagged
22
import net.ccbluex.liquidbounce.features.module.ClientModule
23
import net.ccbluex.liquidbounce.features.module.ModuleCategories
24
import net.ccbluex.liquidbounce.features.module.modules.player.nofall.modes.NoFallBlink
25
import net.ccbluex.liquidbounce.features.module.modules.player.nofall.modes.NoFallBlocksMC
26
import net.ccbluex.liquidbounce.features.module.modules.player.nofall.modes.NoFallCancel
27
import net.ccbluex.liquidbounce.features.module.modules.player.nofall.modes.NoFallForceJump
28
import net.ccbluex.liquidbounce.features.module.modules.player.nofall.modes.NoFallGrim2371
29
import net.ccbluex.liquidbounce.features.module.modules.player.nofall.modes.NoFallHypixel
30
import net.ccbluex.liquidbounce.features.module.modules.player.nofall.modes.NoFallHypixelPacket
31
import net.ccbluex.liquidbounce.features.module.modules.player.nofall.modes.NoFallMLG
32
import net.ccbluex.liquidbounce.features.module.modules.player.nofall.modes.NoFallNoGround
33
import net.ccbluex.liquidbounce.features.module.modules.player.nofall.modes.NoFallPacket
34
import net.ccbluex.liquidbounce.features.module.modules.player.nofall.modes.NoFallPacketJump
35
import net.ccbluex.liquidbounce.features.module.modules.player.nofall.modes.NoFallRettungsplatform
36
import net.ccbluex.liquidbounce.features.module.modules.player.nofall.modes.NoFallSpartan524Flag
37
import net.ccbluex.liquidbounce.features.module.modules.player.nofall.modes.NoFallSpoofGround
38
import net.ccbluex.liquidbounce.features.module.modules.player.nofall.modes.NoFallSpoofLanding
39
import net.ccbluex.liquidbounce.features.module.modules.player.nofall.modes.NoFallMount
40
import net.ccbluex.liquidbounce.features.module.modules.player.nofall.modes.NoFallVerus
41
import net.ccbluex.liquidbounce.features.module.modules.player.nofall.modes.NoFallVulcan
42
import net.ccbluex.liquidbounce.features.module.modules.player.nofall.modes.NoFallVulcanTP
43
import net.minecraft.world.entity.Pose
44
import net.minecraft.world.item.Items
45
import java.util.function.BooleanSupplier
46
47
/**
48
 * NoFall module
49
 *
50
 * Protects you from taking fall damage.
51
 */
52
object ModuleNoFall : ClientModule("NoFall", ModuleCategories.PLAYER) {
53
    internal val modes = choices(
54
        "Mode", NoFallSpoofGround, arrayOf(
55
            NoFallSpoofGround,
56
            NoFallSpoofLanding,
57
            NoFallNoGround,
58
            NoFallPacket,
59
            NoFallPacketJump,
60
            NoFallMLG,
61
            NoFallMount,
62
            NoFallRettungsplatform,
63
            NoFallSpartan524Flag,
64
            NoFallVulcan,
65
            NoFallVulcanTP,
66
            NoFallVerus,
67
            NoFallForceJump,
68
            NoFallCancel,
69
            NoFallBlink,
70
            NoFallHypixelPacket,
71
            NoFallHypixel,
72
            NoFallBlocksMC,
73
            NoFallGrim2371
74
        )
75
    ).apply(::tagBy)
76
77
    private val notConditions by multiEnumChoice<NotCondition>("Not")
78
79
    override val running: Boolean
80
        get() = when {
81
            !super.running -> false
82
83
            // In creative mode, we don't need to reduce fall damage
84
            player.isCreative || player.isSpectator -> false
85
86
            // Check if we are invulnerable or flying
87
            player.abilities.invulnerable || player.abilities.flying -> false
88
89
            // Test other conditions
90
            else -> notConditions.none { it.asBoolean }
91
        }
92
93
    @Suppress("unused")
94
    private enum class NotCondition(
95
        override val tag: String,
96
    ) : Tagged, BooleanSupplier {
97
        /**
98
         * With Elytra - we don't want to reduce fall damage.
99
         */
100
        WHILE_GLIDING("WhileGliding") {
101
            override fun getAsBoolean() = player.isFallFlying && player.hasPose(Pose.FALL_FLYING)
102
        },
103
104
        /**
105
         * Check if we are holding a mace
106
         */
107
        WITH_MACE("WithMace") {
108
            override fun getAsBoolean() = player.mainHandItem.item == Items.MACE
109
        };
110
    }
111
}
112