criticals module

criticals: Minecraft 26.3 cheat module, full source for every implementation (6 clients: Meteor Client, MelaHack (ThunderHack fork), OfflineClient, …).

6 implementationsCombatCOMBAT

Full module source: 6 implementations

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

Meteor ClientCombatsrc/main/java/meteordevelopment/meteorclient/systems/modules/combat/Criticals.javaJava · 205 lines · 7.0 KB

Performs critical attacks when you hit your target.

Settingsmodeonly-killaurasmash-attackadditional-height
Criticals.javaJava · Minecraft 26.2 · 205 lines · 7.0 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
3
 * Copyright (c) Meteor Development.
4
 */
5
6
package meteordevelopment.meteorclient.systems.modules.combat;
7
8
9
import meteordevelopment.meteorclient.events.packets.PacketEvent;
10
import meteordevelopment.meteorclient.events.world.TickEvent;
11
import meteordevelopment.meteorclient.mixininterface.IServerboundMovePlayerPacket;
12
import meteordevelopment.meteorclient.mixininterface.IVec3;
13
import meteordevelopment.meteorclient.settings.*;
14
import meteordevelopment.meteorclient.systems.modules.Categories;
15
import meteordevelopment.meteorclient.systems.modules.Module;
16
import meteordevelopment.meteorclient.systems.modules.Modules;
17
import meteordevelopment.meteorclient.utils.entity.EntityUtils;
18
import meteordevelopment.orbit.EventHandler;
19
import net.minecraft.network.protocol.game.ServerboundAttackPacket;
20
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
21
import net.minecraft.network.protocol.game.ServerboundSwingPacket;
22
import net.minecraft.world.entity.Entity;
23
import net.minecraft.world.entity.LivingEntity;
24
import net.minecraft.world.item.MaceItem;
25
26
public class Criticals extends Module {
27
28
    private final SettingGroup sgGeneral = settings.getDefaultGroup();
29
    private final SettingGroup sgMace = settings.createGroup("Mace");
30
31
    private final Setting<Mode> mode = sgGeneral.add(new EnumSetting.Builder<Mode>()
32
        .name("mode")
33
        .description("The mode on how Criticals will function.")
34
        .defaultValue(Mode.Packet)
35
        .build()
36
    );
37
38
    private final Setting<Boolean> ka = sgGeneral.add(new BoolSetting.Builder()
39
        .name("only-killaura")
40
        .description("Only performs crits when using killaura.")
41
        .defaultValue(false)
42
        .visible(() -> mode.get() != Mode.None)
43
        .build()
44
    );
45
46
    private final Setting<Boolean> mace = sgMace.add(new BoolSetting.Builder()
47
        .name("smash-attack")
48
        .description("Will always perform smash attacks when using a mace.")
49
        .defaultValue(true)
50
        .build()
51
    );
52
53
    private final Setting<Double> extraHeight = sgMace.add(new DoubleSetting.Builder()
54
        .name("additional-height")
55
        .description("The amount of additional height to spoof. More height means more damage.")
56
        .defaultValue(0.0)
57
        .min(0)
58
        .sliderRange(0, 100)
59
        .visible(mace::get)
60
        .build()
61
    );
62
63
    private ServerboundAttackPacket attackPacket;
64
    private ServerboundSwingPacket swingPacket;
65
    private boolean sendPackets;
66
    private int sendTimer;
67
    private double lastY;
68
    private boolean waitingForPeak;
69
70
    public Criticals() {
71
        super(Categories.Combat, "criticals", "Performs critical attacks when you hit your target.");
72
    }
73
74
    @Override
75
    public void onActivate() {
76
        attackPacket = null;
77
        swingPacket = null;
78
        sendPackets = false;
79
        sendTimer = 0;
80
        lastY = 0;
81
        waitingForPeak = false;
82
    }
83
84
    @EventHandler
85
    private void onSendPacket(PacketEvent.Send event) {
86
        if (event.packet instanceof ServerboundAttackPacket(int entityId)) {
87
            if (mace.get() && mc.player.getMainHandItem().getItem() instanceof MaceItem) {
88
                if (mc.player.isFallFlying()) return;
89
90
                sendPacket(0);
91
                sendPacket(1.501 + extraHeight.get());
92
                sendPacket(0);
93
            } else {
94
                if (skipCrit()) return;
95
96
                Entity entity = mc.level.getEntity(entityId);
97
98
                if (!(entity instanceof LivingEntity) || (entity != Modules.get().get(KillAura.class).getTarget() && ka.get()))
99
                    return;
100
101
                switch (mode.get()) {
102
                    case Packet -> {
103
                        sendPacket(0.0625);
104
                        sendPacket(0);
105
                    }
106
                    case UpdatedNCP -> {
107
                        sendPacket(0.0000008);
108
                        sendPacket(0);
109
                    }
110
                    case OldNCP -> {
111
                        sendPacket(0.11);
112
                        sendPacket(0.1100013579);
113
                        sendPacket(0.0000013579);
114
                    }
115
                    case Jump, MiniJump -> {
116
                        if (!sendPackets) {
117
                            sendPackets = true;
118
                            attackPacket = (ServerboundAttackPacket) event.packet;
119
120
                            if (mode.get() == Mode.Jump) {
121
                                mc.player.jumpFromGround();
122
                                waitingForPeak = true;
123
                                lastY = mc.player.getY();
124
                            } else {
125
                                ((IVec3) mc.player.getDeltaMovement()).meteor$setY(0.25);
126
                                sendTimer = 4;
127
                            }
128
                            event.cancel();
129
                        }
130
                    }
131
                }
132
            }
133
        } else if (event.packet instanceof ServerboundSwingPacket serverboundSwingPacket && mode.get() != Mode.Packet) {
134
            if (skipCrit()) return;
135
136
            if (sendPackets && swingPacket == null) {
137
                swingPacket = serverboundSwingPacket;
138
                event.cancel();
139
            }
140
        }
141
    }
142
143
    @EventHandler
144
    private void onTick(TickEvent.Pre event) {
145
        if (sendPackets) {
146
            if (mode.get() == Mode.Jump && waitingForPeak) {
147
                double currentY = mc.player.getY();
148
                if (currentY <= lastY) {
149
                    waitingForPeak = false;
150
                    sendTimer = 0; // Attack on next tick after reaching peak
151
                }
152
                lastY = currentY;
153
                return;
154
            }
155
156
            if (sendTimer <= 0) {
157
                if (attackPacket == null || swingPacket == null) {
158
                    sendPackets = false;
159
                    return;
160
                }
161
                mc.getConnection().send(attackPacket);
162
                mc.getConnection().send(swingPacket);
163
164
                attackPacket = null;
165
                swingPacket = null;
166
167
                sendPackets = false;
168
            } else {
169
                sendTimer--;
170
            }
171
        }
172
    }
173
174
    private void sendPacket(double height) {
175
        double x = mc.player.getX();
176
        double y = mc.player.getY();
177
        double z = mc.player.getZ();
178
179
        ServerboundMovePlayerPacket packet = new ServerboundMovePlayerPacket.Pos(x, y + height, z, false, false);
180
        ((IServerboundMovePlayerPacket) packet).meteor$setTag(1337);
181
        mc.player.connection.send(packet);
182
    }
183
184
    private boolean skipCrit() {
185
        if (EntityUtils.isInCobweb(mc.player) && (mode.get() == Mode.Jump || mode.get() == Mode.MiniJump))
186
            return true;
187
188
        return !mc.player.onGround() || mc.player.isInWater() || mc.player.isInLava() || mc.player.onClimbable();
189
    }
190
191
    @Override
192
    public String getInfoString() {
193
        return mode.get().name();
194
    }
195
196
    public enum Mode {
197
        None,
198
        Packet,
199
        UpdatedNCP,
200
        OldNCP,
201
        Jump,
202
        MiniJump
203
    }
204
}
205
MelaHack (ThunderHack fork)COMBATsrc/main/java/thunder/hack/features/modules/combat/Criticals.javaJava · 89 lines · 3.4 KB

Makes every hit critical.

SettingsMode
Criticals.javaJava · Minecraft 26.2 · 89 lines · 3.4 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.combat;
2
3
import meteordevelopment.orbit.EventHandler;
4
import net.minecraft.network.protocol.game.ServerboundAttackPacket;
5
import net.minecraft.network.protocol.game.ServerboundInteractPacket;
6
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
7
import net.minecraft.world.entity.Entity;
8
import net.minecraft.world.entity.boss.enderdragon.EndCrystal;
9
import org.jetbrains.annotations.NotNull;
10
import thunder.hack.events.impl.PacketEvent;
11
import thunder.hack.injection.accesors.IClientPlayerEntity;
12
import thunder.hack.injection.accesors.IEntity;
13
import thunder.hack.features.modules.Module;
14
import thunder.hack.setting.Setting;
15
16
public final class Criticals extends Module {
17
    public final Setting<Mode> mode = new Setting<>("Mode", Mode.UpdatedNCP);
18
19
    public static boolean cancelCrit;
20
21
    public Criticals() {
22
        super("Criticals", Category.COMBAT);
23
    }
24
25
    @EventHandler
26
    public void onPacketSend(PacketEvent.@NotNull Send event) {
27
        if (event.getPacket() instanceof ServerboundAttackPacket attackPacket) {
28
            Entity ent = mc.level.getEntity(attackPacket.entityId());
29
            if (ent == null || ent instanceof EndCrystal || cancelCrit)
30
                return;
31
            doCrit();
32
        }
33
    }
34
35
    public void doCrit() {
36
        if (isDisabled() || mc.player == null || mc.level == null)
37
            return;
38
        if ((mc.player.onGround() || mc.player.getAbilities().flying || mode.is(Mode.Grim)) && !mc.player.isInLava() && !mc.player.isUnderWater()) {
39
            switch (mode.getValue()) {
40
                case OldNCP -> {
41
                    critPacket(0.00001058293536, false);
42
                    critPacket(0.00000916580235, false);
43
                    critPacket(0.00000010371854, false);
44
                }
45
                case Ncp -> {
46
                    critPacket(0.0625D, false);
47
                    critPacket(0., false);
48
                }
49
                case UpdatedNCP -> {
50
                    critPacket(0.000000271875, false);
51
                    critPacket(0., false);
52
                }
53
                case Strict -> {
54
                    critPacket(0.062600301692775, false);
55
                    critPacket(0.07260029960661, false);
56
                    critPacket(0., false);
57
                    critPacket(0., false);
58
                }
59
                case Grim -> {
60
                    if (!mc.player.onGround())
61
                        critPacket(-0.000001, true);
62
63
                }
64
            }
65
        }
66
    }
67
68
    private void critPacket(double yDelta, boolean full) {
69
        if (!full)
70
            sendPacket(new ServerboundMovePlayerPacket.Pos(mc.player.getX(), mc.player.getY() + yDelta, mc.player.getZ(), false, mc.player.horizontalCollision));
71
        else
72
            sendPacket(new ServerboundMovePlayerPacket.PosRot(mc.player.getX(), mc.player.getY() + yDelta, mc.player.getZ(), ((IEntity) mc.player).getLastYaw(), ((IEntity) mc.player).getLastPitch(), false, mc.player.horizontalCollision));
73
    }
74
75
    public static Entity getEntity(@NotNull ServerboundInteractPacket packet) {
76
        return mc.level.getEntity(packet.entityId());
77
    }
78
79
    public static InteractType getInteractType(@NotNull ServerboundInteractPacket packet) {
80
        return packet.location() == null ? InteractType.INTERACT : InteractType.INTERACT_AT;
81
    }
82
83
    public enum InteractType { INTERACT, ATTACK, INTERACT_AT }
84
85
    public enum Mode {
86
        Ncp, Strict, OldNCP, UpdatedNCP, Grim
87
    }
88
}
89
OfflineClientCOMBATsrc/main/java/com/jellypudding/offlineclient/modules/combat/Criticals.javaJava · 293 lines · 10.1 KB

Makes every melee hit a critical hit.

SettingsModeOnly KillAura targetsMace smashExtra heightStop sprinting
Criticals.javaJava · Minecraft 26.2 · 293 lines · 10.1 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.PacketSendEvent;
5
import com.jellypudding.offlineclient.event.events.PostMotionEvent;
6
import com.jellypudding.offlineclient.event.events.TickEvent;
7
import com.jellypudding.offlineclient.module.Category;
8
import com.jellypudding.offlineclient.module.Module;
9
import com.jellypudding.offlineclient.setting.BoolSetting;
10
import com.jellypudding.offlineclient.setting.EnumSetting;
11
import com.jellypudding.offlineclient.setting.NumberSetting;
12
import com.jellypudding.offlineclient.util.Modules;
13
import com.jellypudding.offlineclient.util.SprintPause;
14
import net.minecraft.network.protocol.game.ServerboundAttackPacket;
15
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
16
import net.minecraft.network.protocol.game.ServerboundSwingPacket;
17
import net.minecraft.world.entity.Entity;
18
import net.minecraft.world.entity.LivingEntity;
19
import net.minecraft.world.item.Items;
20
import net.minecraft.world.level.block.Blocks;
21
import net.minecraft.world.phys.Vec3;
22
23
// A critical hit needs the server to believe the player is falling.
24
// Packet modes fake that with position packets while the jump modes really jump.
25
public final class Criticals extends Module {
26
27
    // The server rebuilds fall distance from the gap between position packets.
28
    // A sixteenth of a block is the smallest drop that banks any fall at all.
29
    private static final double CRIT_LIFT = 0.0625;
30
31
    // The packet that settles back down has to stay above zero for the drop to hold.
32
    private static final double CRIT_SETTLE = 1.1e-5;
33
34
    // Each of the first five position packets in a tick buys a hundred squared
35
    // blocks of allowed movement. Three settling packets bank four hundred for the lift.
36
    private static final int MACE_SETTLE_PACKETS = 3;
37
38
    // The fourth packet allows four hundred squared blocks which is twenty of travel.
39
    private static final double MACE_LIFT = 19.9;
40
41
    private static final double MINI_JUMP_SPEED = 0.25;
42
    private static final int MINI_JUMP_TICKS = 4;
43
44
    public enum Mode {
45
        NONE, PACKET, NEW_NCP("New NCP"), OLD_NCP("Old NCP"), MINI_JUMP, FULL_JUMP;
46
47
        private final String label;
48
49
        Mode() {
50
            this.label = null;
51
        }
52
53
        Mode(String label) {
54
            this.label = label;
55
        }
56
57
        @Override
58
        public String toString() {
59
            return label == null ? name() : label;
60
        }
61
    }
62
63
    private final EnumSetting<Mode> mode = new EnumSetting<>("Mode",
64
        "How to get the fall a critical hit needs.", Mode.PACKET)
65
        .describe(Mode.NONE, "No critical hits. Mace smash still works.")
66
        .describe(Mode.PACKET, "Sends the tiny fall the server checks for without moving you.")
67
        .describe(Mode.NEW_NCP, "A fall too small to notice for newer anti cheats.")
68
        .describe(Mode.OLD_NCP, "Three small climbs that older anti cheats let through.")
69
        .describe(Mode.MINI_JUMP, "A small hop and the hit waits four ticks for the fall.")
70
        .describe(Mode.FULL_JUMP, "A normal jump and the hit waits for the peak.");
71
72
    private final BoolSetting onlyKillAura = new BoolSetting("Only KillAura targets",
73
        "Only makes hits on the KillAura target critical.", false)
74
        .visibleWhen(() -> !mode.is(Mode.NONE));
75
76
    private final BoolSetting mace = new BoolSetting("Mace smash",
77
        "Fakes a long fall whilst holding a mace to land every swing as a smash attack.", false);
78
79
    private final NumberSetting extraHeight = new NumberSetting("Extra height",
80
        "Extra fall on top of the twenty blocks vanilla allows. Only looser servers accept more.",
81
        0, 0, 100, 1, " blocks").under(mace);
82
83
    private final BoolSetting stopSprint = new BoolSetting("Stop sprinting",
84
        "Drops sprint for the hit and takes it straight back. A sprinting player cannot crit.",
85
        true);
86
87
    // Drops the sprint for a hit and hands it back afterwards.
88
    private final SprintPause sprintPause = new SprintPause();
89
90
    // The hit held back by a jump mode until the fall exists.
91
    private ServerboundAttackPacket heldAttack;
92
    private ServerboundSwingPacket heldSwing;
93
    private boolean holding;
94
    private boolean waitingForPeak;
95
    private double lastY;
96
    private int sendTimer;
97
98
    // Packets sent by release come straight back through the send handler.
99
    private boolean releasing;
100
101
    public Criticals() {
102
        super("Criticals", "Makes every melee hit a critical hit.", Category.COMBAT);
103
        addSettings(mode, onlyKillAura, mace, extraHeight, stopSprint);
104
        searchTags("crit", "mace", "smash");
105
    }
106
107
    @Override
108
    public String getSuffix() {
109
        return mode.getValueString();
110
    }
111
112
    @Override
113
    protected void onEnable() {
114
        clearHeld();
115
    }
116
117
    @Override
118
    protected void onDisable() {
119
        clearHeld();
120
        // Leaving mid hit would leave the server believing the sprint had ended.
121
        sprintPause.resume();
122
    }
123
124
    @Subscribe
125
    private void onPacketSend(PacketSendEvent event) {
126
        if (releasing || !inGame() || mc.player.isSpectator()) {
127
            return;
128
        }
129
        if (event.getPacket() instanceof ServerboundAttackPacket attack) {
130
            onAttackPacket(event, attack);
131
        } else if (event.getPacket() instanceof ServerboundSwingPacket swing
132
            && holding && heldSwing == null) {
133
            heldSwing = swing;
134
            event.cancel();
135
        }
136
    }
137
138
    private void onAttackPacket(PacketSendEvent event, ServerboundAttackPacket attack) {
139
        if (mace.isOn() && mc.player.getMainHandItem().is(Items.MACE)) {
140
            if (!mc.player.isFallFlying() && !mc.player.isInWater() && !mc.player.isInLava()) {
141
                dropSprint();
142
                smash();
143
            }
144
            return;
145
        }
146
        if (mode.is(Mode.NONE) || skipCrit() || !wantsCrit(attack.entityId())) {
147
            return;
148
        }
149
        switch (mode.getValue()) {
150
            case PACKET -> {
151
                dropSprint();
152
                sendFakeY(CRIT_LIFT, true);
153
                sendFakeY(0, false);
154
                sendFakeY(CRIT_SETTLE, false);
155
                sendFakeY(0, false);
156
            }
157
            case NEW_NCP -> {
158
                dropSprint();
159
                sendFakeY(0.0000008, false);
160
                sendFakeY(0, false);
161
            }
162
            case OLD_NCP -> {
163
                dropSprint();
164
                sendFakeY(0.11, false);
165
                sendFakeY(0.1100013579, false);
166
                sendFakeY(0.0000013579, false);
167
            }
168
            case MINI_JUMP, FULL_JUMP -> {
169
                if (holding) {
170
                    return;
171
                }
172
                hold(attack);
173
                event.cancel();
174
            }
175
            case NONE -> {
176
            }
177
        }
178
    }
179
180
    private boolean wantsCrit(int entityId) {
181
        Entity target = mc.level.getEntity(entityId);
182
        if (!(target instanceof LivingEntity)) {
183
            return false;
184
        }
185
        if (!onlyKillAura.isOn()) {
186
            return true;
187
        }
188
        KillAura killAura = Modules.get(KillAura.class);
189
        return killAura != null && target == killAura.getTarget();
190
    }
191
192
    // A jump cannot start from a ladder or a web. The packet modes only need solid ground.
193
    private boolean skipCrit() {
194
        if (!mc.player.onGround() || mc.player.isInWater() || mc.player.isInLava()
195
            || mc.player.onClimbable()) {
196
            return true;
197
        }
198
        return mode.isAny(Mode.MINI_JUMP, Mode.FULL_JUMP) && inCobweb();
199
    }
200
201
    private boolean inCobweb() {
202
        return mc.level.getBlockStates(mc.player.getBoundingBox())
203
            .anyMatch(state -> state.is(Blocks.COBWEB));
204
    }
205
206
    private void hold(ServerboundAttackPacket attack) {
207
        holding = true;
208
        heldAttack = attack;
209
        heldSwing = null;
210
        if (mode.is(Mode.FULL_JUMP)) {
211
            mc.player.jumpFromGround();
212
            waitingForPeak = true;
213
            lastY = mc.player.getY();
214
        } else {
215
            Vec3 motion = mc.player.getDeltaMovement();
216
            mc.player.setDeltaMovement(motion.x, MINI_JUMP_SPEED, motion.z);
217
            sendTimer = MINI_JUMP_TICKS;
218
        }
219
    }
220
221
    @Subscribe
222
    private void onTick(TickEvent event) {
223
        if (!holding || !inGame()) {
224
            return;
225
        }
226
        if (waitingForPeak) {
227
            double y = mc.player.getY();
228
            // The first tick that fails to climb is the peak.
229
            waitingForPeak = y > lastY;
230
            lastY = y;
231
            return;
232
        }
233
        if (sendTimer > 0) {
234
            sendTimer--;
235
            return;
236
        }
237
        release();
238
    }
239
240
    // Sends the held hit now that the server sees a fall.
241
    private void release() {
242
        ServerboundAttackPacket attack = heldAttack;
243
        ServerboundSwingPacket swing = heldSwing;
244
        clearHeld();
245
        releasing = true;
246
        try {
247
            dropSprint();
248
            mc.player.connection.send(attack);
249
            if (swing != null) {
250
                mc.player.connection.send(swing);
251
            }
252
        } finally {
253
            releasing = false;
254
        }
255
    }
256
257
    private void clearHeld() {
258
        holding = false;
259
        waitingForPeak = false;
260
        heldAttack = null;
261
        heldSwing = null;
262
        sendTimer = 0;
263
    }
264
265
    // The server refuses a critical hit to anyone it believes is sprinting.
266
    // Dropping sprint for the swing keeps the client from stuttering.
267
    private void dropSprint() {
268
        if (stopSprint.isOn()) {
269
            sprintPause.pause();
270
        }
271
    }
272
273
    // The attack packet has gone out by this point.
274
    @Subscribe
275
    private void onPostMotion(PostMotionEvent event) {
276
        sprintPause.resume();
277
    }
278
279
    private void smash() {
280
        for (int i = 0; i < MACE_SETTLE_PACKETS; i++) {
281
            sendFakeY(0, false);
282
        }
283
        sendFakeY(MACE_LIFT + extraHeight.getValue(), false);
284
        sendFakeY(0, false);
285
    }
286
287
    private void sendFakeY(double offset, boolean onGround) {
288
        mc.player.connection.send(new ServerboundMovePlayerPacket.Pos(
289
            mc.player.getX(), mc.player.getY() + offset, mc.player.getZ(),
290
            onGround, mc.player.horizontalCollision));
291
    }
292
}
293
CombatantCOMBATsrc/main/java/combatant/client/features/module/modules/combat/Criticals.javaJava · 767 lines · 28.0 KB
Settingsmodeselection_modewhen_sprintingstop_sprinting_modejump_heightjump_rangeoptimize_for_cooldowncan_be_seenpacket_modepacket_typetimer_speedtimer_range
Criticals.javaJava · Minecraft 26.2 · 767 lines · 28.0 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.combat;
9
10
import combatant.client.util.combat.AttackUtil;
11
import net.minecraft.client.Minecraft;
12
import net.minecraft.client.player.LocalPlayer;
13
import net.minecraft.core.BlockPos;
14
import net.minecraft.network.protocol.Packet;
15
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
16
import net.minecraft.tags.FluidTags;
17
import net.minecraft.world.effect.MobEffects;
18
import net.minecraft.world.entity.Entity;
19
import net.minecraft.world.entity.vehicle.boat.Boat;
20
import net.minecraft.world.level.block.Blocks;
21
import net.minecraft.world.level.block.state.BlockState;
22
import net.minecraft.world.level.material.FluidState;
23
import net.minecraft.world.phys.AABB;
24
import combatant.client.config.common.CommonSettingSchemas;
25
import combatant.client.config.values.BooleanValue;
26
import combatant.client.config.values.EnumValue;
27
import combatant.client.config.values.NumberValue;
28
import combatant.client.events.EventHandler;
29
import combatant.client.events.impl.MovementInputEvent;
30
import combatant.client.events.impl.PacketEvent;
31
import combatant.client.events.impl.PlayerJumpEvent;
32
import combatant.client.events.impl.SprintControlEvent;
33
import combatant.client.features.module.Module;
34
import combatant.client.features.module.ModuleCategory;
35
import combatant.client.features.module.ModuleInfo;
36
import combatant.client.features.module.Modules;
37
import combatant.client.features.module.modules.movement.Flight;
38
import combatant.client.features.module.modules.movement.Timer;
39
import combatant.client.mixins.accessors.ServerboundMovePlayerPacketAccessor;
40
import combatant.client.util.click.ClickScheduler;
41
import combatant.client.util.target.TargetManager;
42
43
//todo Description
44
@ModuleInfo(
45
        id = "criticals",
46
        displayName = "Criticals",
47
        category = ModuleCategory.COMBAT
48
)
49
public final class Criticals extends Module {
50
51
    private static final float VANILLA_JUMP_MOTION = 0.42f;
52
    private static final int JUMP_CRIT_LEAD_TICKS = 4;
53
    private static final int VULCAN_297_JUMP_RECOVERY_TICKS = 8;
54
    private static final int VULCAN_297_LANDING_RECOVERY_TICKS = 2;
55
    private final Minecraft mc = Minecraft.getInstance();
56
    private final EnumValue<Mode> mode =
57
            enumMode(
58
                    "mode",
59
                    Mode.JUMP,
60
                    Mode.values()
61
            );
62
    private final EnumValue<SelectionMode> selectionMode =
63
            enumCommon(
64
                    "selection_mode",
65
                    "selection_mode",
66
                    CommonSettingSchemas.COMBAT_CRITICALS,
67
                    SelectionMode.SMART,
68
                    SelectionMode.values()
69
            );
70
    private final BooleanValue whenSprinting =
71
            boolCommon(
72
                    "when_sprinting",
73
                    "when_sprinting",
74
                    CommonSettingSchemas.COMBAT_WHEN_SPRINTING,
75
                    false
76
            );
77
    private final EnumValue<StopSprintingMode> stopSprintingMode =
78
            visibleWhen(enumCommon(
79
                    "stop_sprinting_mode",
80
                    "stop_sprinting_mode",
81
                    CommonSettingSchemas.COMBAT_STOP_SPRINTING,
82
                    StopSprintingMode.LEGIT,
83
                    StopSprintingMode.values()
84
            ), whenSprinting::get);
85
    private final NumberValue<Float> jumpHeight =
86
            visibleWhen(num(
87
                    "jump_height",
88
                    "jump_height",
89
                    0.42f,
90
                    0.1f,
91
                    0.42f
92
            ), () -> mode.get() == Mode.JUMP);
93
    private final NumberValue<Float> jumpRange =
94
            visibleWhen(numCommon(
95
                    "jump_range",
96
                    "range",
97
                    CommonSettingSchemas.COMBAT_RANGE,
98
                    4.0f,
99
                    1.0f,
100
                    6.0f
101
            ), () -> mode.get() == Mode.JUMP);
102
    private final BooleanValue optimizeForCooldown =
103
            visibleWhen(bool(
104
                    "optimize_for_cooldown",
105
                    "optimize_for_cooldown",
106
                    true
107
            ), () -> mode.get() == Mode.JUMP);
108
    private final BooleanValue canBeSeen =
109
            visibleWhen(bool(
110
                    "can_be_seen",
111
                    "can_be_seen",
112
                    true
113
            ), () -> mode.get() == Mode.JUMP);
114
    private final EnumValue<PacketMode> packetMode =
115
            visibleWhen(enumMode(
116
                    "packet_mode",
117
                    PacketMode.NO_CHEAT_PLUS,
118
                    PacketMode.values()
119
            ), () -> mode.get() == Mode.PACKET);
120
    private final EnumValue<PacketType> packetType =
121
            visibleWhen(enumMode(
122
                    "packet_type",
123
                    PacketType.FULL,
124
                    PacketType.values()
125
            ), () -> mode.get() == Mode.PACKET);
126
    private final NumberValue<Float> timerSpeed =
127
            visibleWhen(num(
128
                    "timer_speed",
129
                    "timer_speed",
130
                    0.8f,
131
                    0.1f,
132
                    1.0f
133
            ), () -> mode.get() == Mode.TIMER);
134
    private final NumberValue<Float> timerRange =
135
            visibleWhen(num(
136
                    "timer_range",
137
                    "timer_range",
138
                    4.0f,
139
                    0.0f,
140
                    10.0f
141
            ), () -> mode.get() == Mode.TIMER);
142
    private Mode killAuraModeOverride;
143
    private SelectionMode killAuraSelectionOverride;
144
    private boolean adjustNextJump;
145
    private int lastJumpInputAge = -1;
146
    private int lastPreparedAttackAge = -1;
147
    private int lastPreparedTargetId = Integer.MIN_VALUE;
148
    private int vulcan297JumpRecoveryTicks;
149
    private int vulcan297LandingRecoveryTicks;
150
    private boolean vulcan297WasAirborne;
151
152
    @Override
153
    public void onEnable() {
154
        adjustNextJump = false;
155
        lastJumpInputAge = -1;
156
        resetVulcan297State();
157
        resetPreparedAttack();
158
        Timer.clearExternalTickTimer();
159
    }
160
161
    @Override
162
    public void onDisable() {
163
        adjustNextJump = false;
164
        lastJumpInputAge = -1;
165
        resetVulcan297State();
166
        resetPreparedAttack();
167
        Timer.clearExternalTickTimer();
168
    }
169
170
    public void setKillAuraOverrides(Mode modeOverride, SelectionMode selectionOverride) {
171
        killAuraModeOverride = modeOverride;
172
        killAuraSelectionOverride = selectionOverride;
173
    }
174
175
    public void clearKillAuraOverrides() {
176
        killAuraModeOverride = null;
177
        killAuraSelectionOverride = null;
178
    }
179
180
    @Override
181
    public void onTick() {
182
        if (!isEnabled()) return;
183
184
        if (getMode() == Mode.TIMER) {
185
            Entity target = getTargetInRange(timerRange.get());
186
            if (target != null && wouldDoCriticalHit(shouldAttemptCritWhileSprinting())) {
187
                Timer.setExternalTickTimer(timerSpeed.get());
188
            } else {
189
                Timer.clearExternalTickTimer();
190
            }
191
        } else {
192
            Timer.clearExternalTickTimer();
193
        }
194
195
        updateVulcan297State(currentPlayer());
196
    }
197
198
    @EventHandler
199
    private void onMovementInput(MovementInputEvent event) {
200
        if (!isEnabled() || getMode() != Mode.JUMP) return;
201
202
        LocalPlayer player = currentPlayer();
203
        if (player == null) return;
204
        Entity target = getTargetInRange();
205
206
        if (target != null && shouldAutoJumpCrit(target) && player.onGround()) {
207
            event.setJump(true);
208
            adjustNextJump = true;
209
        }
210
211
        if (event.isJump()) {
212
            lastJumpInputAge = player.tickCount;
213
        }
214
    }
215
216
    @EventHandler
217
    private void onPlayerJump(PlayerJumpEvent event) {
218
        if (isEnabled() && getMode() == Mode.VULCAN_297) {
219
            vulcan297JumpRecoveryTicks = VULCAN_297_JUMP_RECOVERY_TICKS;
220
            vulcan297LandingRecoveryTicks = VULCAN_297_LANDING_RECOVERY_TICKS;
221
            vulcan297WasAirborne = true;
222
            return;
223
        }
224
225
        if (!isEnabled() || getMode() != Mode.JUMP) return;
226
227
        if (adjustNextJump && Math.abs(event.getMotion() - VANILLA_JUMP_MOTION) < 1.0E-4f) {
228
            event.setMotion(jumpHeight.get());
229
        }
230
        adjustNextJump = false;
231
    }
232
233
    @EventHandler
234
    private void onSprintControl(SprintControlEvent event) {
235
        if (!shouldStopSprintingNow()) return;
236
237
        StopSprintingMode stopMode = stopSprintingMode.get();
238
        if (stopMode == StopSprintingMode.LEGIT) {
239
            if (event.getSource() == SprintControlEvent.Source.MOVEMENT_TICK
240
                    || event.getSource() == SprintControlEvent.Source.INPUT) {
241
                event.setSprint(false);
242
            }
243
        } else if (stopMode == StopSprintingMode.ON_NETWORK) {
244
            if (event.getSource() == SprintControlEvent.Source.NETWORK
245
                    || event.getSource() == SprintControlEvent.Source.INPUT) {
246
                event.setSprint(false);
247
            }
248
        }
249
    }
250
251
    public boolean isCriticalHit(Entity target) {
252
        return isCriticalHitInternal(target, false);
253
    }
254
255
    private boolean isCriticalHitInternal(Entity target, boolean ignoreEnabledState) {
256
        if (!ignoreEnabledState && !isEnabled()) return true;
257
        boolean ignoreSprint = shouldAttemptCritWhileSprinting();
258
        return switch (getSelectionMode()) {
259
            case IGNORE -> true;
260
            case SMART -> switch (getMode()) {
261
                case PACKET, NO_GROUND, VULCAN_297 -> canDoCriticalHit(true, ignoreSprint);
262
                case JUMP, TIMER -> !shouldWaitForCrit(target, true);
263
                case OFF -> true;
264
            };
265
            case ALWAYS -> switch (getMode()) {
266
                case PACKET, NO_GROUND, VULCAN_297 -> canDoCriticalHit(true, ignoreSprint);
267
                case JUMP, TIMER -> wouldDoCriticalHit(ignoreSprint);
268
                case OFF -> true;
269
            };
270
        };
271
    }
272
273
    public boolean shouldStopSprinting(ClickScheduler clicker, Entity target) {
274
        if (!shouldStopSprintingBase()) return false;
275
        if (getSelectionMode() == SelectionMode.IGNORE) return false;
276
277
        LocalPlayer player = currentPlayer();
278
        if (player == null) return false;
279
        if (target == null) return false;
280
        if (!canAttemptCriticalAttack(target)) return false;
281
        if (usesNaturalCriticalState() && player.onGround()) return false;
282
283
        return clicker != null && clicker.willClickAt(1);
284
    }
285
286
    public boolean shouldStopSprintingOnAttack(ClickScheduler clicker, Entity target) {
287
        return shouldStopSprinting(clicker, target)
288
                && stopSprintingMode.get() == StopSprintingMode.ON_ATTACK;
289
    }
290
291
    public boolean shouldAttack(Entity target) {
292
        return shouldAttack(null, target);
293
    }
294
295
    public boolean shouldAttack(ClickScheduler clicker, Entity target) {
296
        return shouldAttackInternal(clicker, target, false);
297
    }
298
299
    private boolean shouldAttackInternal(ClickScheduler clicker,
300
                                         Entity target,
301
                                         boolean ignoreEnabledState) {
302
        if (target == null) return false;
303
        LocalPlayer player = currentPlayer();
304
        if (player == null) return false;
305
306
        if (getMode() == Mode.JUMP && getSelectionMode() != SelectionMode.IGNORE && canUseJumpCriticalState(target)) {
307
            if (player.onGround()) return false;
308
            if (player.getDeltaMovement().y > 0.0) return false;
309
            if (clicker != null && !clicker.willClickAt(2) && player.fallDistance <= 0.0f) return false;
310
        }
311
312
        return isCriticalHitInternal(target, ignoreEnabledState);
313
    }
314
315
    /**
316
     * Runs attack gate with temporary KillAura-specific selection override.
317
     * Keeps Criticals internals (mode checks, jump state checks, click lookahead) intact.
318
     */
319
    public boolean shouldAttackForKillAura(ClickScheduler clicker,
320
                                           Entity target,
321
                                           SelectionMode selectionOverride,
322
                                           boolean ignoreSprintAfterReset) {
323
        if (target == null) return false;
324
        LocalPlayer player = currentPlayer();
325
        if (player == null) return false;
326
327
        SelectionMode selection = selectionOverride != null ? selectionOverride : selectionMode.get();
328
        if (selection == SelectionMode.IGNORE) {
329
            return true;
330
        }
331
332
        boolean ignoreSprint = ignoreSprintAfterReset || shouldAttemptCritWhileSprinting();
333
        if (canUseKillAuraJumpCriticalState(target)) {
334
            if (selection == SelectionMode.ALWAYS) {
335
                return isNaturalCriticalReady(ignoreSprint);
336
            }
337
            if (selection == SelectionMode.SMART
338
                    && player.onGround()
339
                    && hasJumpIntent(player)
340
                    && shouldForceJumpCrit(target)) {
341
                return false;
342
            }
343
            if (shouldHoldKillAuraForNaturalCrit(player, ignoreSprint)) {
344
                return isNaturalCriticalReady(ignoreSprint);
345
            }
346
        }
347
348
        return switch (selection) {
349
            case SMART -> !shouldWaitForCrit(target, true);
350
            case ALWAYS -> wouldDoCriticalHit(ignoreSprint);
351
            case IGNORE -> true;
352
        };
353
    }
354
355
    public boolean shouldControlTargetStrafeJump(Entity target) {
356
        if (!isEnabled() || target == null) {
357
            return false;
358
        }
359
        if (getSelectionMode() == SelectionMode.IGNORE) {
360
            return false;
361
        }
362
        return canUseJumpCriticalState(target);
363
    }
364
365
    public void beforeAttack(Minecraft mc, LocalPlayer player, Entity target) {
366
        if (mc == null || player == null || target == null || !isEnabled()) return;
367
        if (isAttackAlreadyPrepared(player, target)) return;
368
        markAttackPrepared(player, target);
369
370
        if (stopSprintingMode.get() == StopSprintingMode.ON_ATTACK
371
                && whenSprinting.get()
372
                && getSelectionMode() != SelectionMode.IGNORE
373
                && canAttemptCriticalAttack(target)) {
374
            AttackUtil.sendStopSprinting(mc, player);
375
        }
376
377
        if (getMode() == Mode.PACKET && canDoCriticalHit(true, shouldAttemptCritWhileSprinting())) {
378
            performPacketCritical(mc, player, target);
379
        } else if (getMode() == Mode.VULCAN_297
380
                && canDoCriticalHit(true, shouldAttemptCritWhileSprinting())
381
                && canPerformVulcan297Critical(player)) {
382
            performVulcan297Critical(mc, player);
383
        }
384
    }
385
386
    public boolean shouldStopSprinting() {
387
        return shouldStopSprintingBase();
388
    }
389
390
    @EventHandler
391
    private void onPacketSend(PacketEvent.Send event) {
392
        if (!isEnabled()) return;
393
394
        if (getMode() == Mode.NO_GROUND && event.getPacket() instanceof ServerboundMovePlayerPacket move) {
395
            ((ServerboundMovePlayerPacketAccessor) move).combatant$setOnGround(false);
396
        }
397
    }
398
399
    private boolean shouldStopSprintingBase() {
400
        if (!isEnabled() || !whenSprinting.get()) return false;
401
        if (stopSprintingMode.get() == StopSprintingMode.NONE) return false;
402
        if (getSelectionMode() == SelectionMode.IGNORE) return false;
403
        return canAttemptCriticalAttack(getTargetInRange());
404
    }
405
406
    private boolean shouldStopSprintingNow() {
407
        if (!shouldStopSprintingBase()) return false;
408
409
        Entity target = getTargetInRange();
410
        if (target == null) return false;
411
412
        KillAura killAura = Modules.get(KillAura.class);
413
        if (killAura != null && killAura.isEnabled()) {
414
            return shouldStopSprinting(killAura.getClickScheduler(), target);
415
        }
416
417
        return false;
418
    }
419
420
    public boolean allowsCriticalHit(boolean ignoreOnGround) {
421
        LocalPlayer player = currentPlayer();
422
        if (player == null) return false;
423
424
        Flight flight = Modules.get(Flight.class);
425
        if (flight != null && flight.isEnabled()) return false;
426
        if (player.isFallFlying()) return false;
427
        if (player.isInWater() || player.isUnderWater() || player.isInLava()) return false;
428
        if (player.isPassenger() || player.getVehicle() instanceof Boat) return false;
429
        if (player.onClimbable() || player.isNoGravity()) return false;
430
        if (player.getAbilities().flying) return false;
431
        if (player.isUsingItem()) return false;
432
        if (player.hasEffect(MobEffects.BLINDNESS)
433
                || player.hasEffect(MobEffects.LEVITATION)
434
                || player.hasEffect(MobEffects.SLOW_FALLING)) return false;
435
        if (!ignoreOnGround && player.onGround()) return false;
436
        AABB box = player.getBoundingBox();
437
        BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();
438
        int minX = (int) Math.floor(box.minX);
439
        int maxX = (int) Math.floor(box.maxX);
440
        int minY = (int) Math.floor(box.minY);
441
        int maxY = (int) Math.floor(box.maxY);
442
        int minZ = (int) Math.floor(box.minZ);
443
        int maxZ = (int) Math.floor(box.maxZ);
444
        for (int x = minX; x <= maxX; x++) {
445
            for (int y = minY; y <= maxY; y++) {
446
                for (int z = minZ; z <= maxZ; z++) {
447
                    pos.set(x, y, z);
448
                    BlockState state = player.level().getBlockState(pos);
449
                    if (state.is(Blocks.COBWEB)) return false;
450
                    FluidState fluid = player.level().getFluidState(pos);
451
                    if (fluid.is(FluidTags.WATER) || fluid.is(FluidTags.LAVA)) return false;
452
                }
453
            }
454
        }
455
456
        return true;
457
    }
458
459
    public boolean canDoCriticalHit(boolean ignoreOnGround, boolean ignoreSprint) {
460
        LocalPlayer player = currentPlayer();
461
        if (player == null) return false;
462
463
        return allowsCriticalHit(ignoreOnGround)
464
                && player.getAttackStrengthScale(0.5f) > 0.9f
465
                && (!player.isSprinting() || ignoreSprint);
466
    }
467
468
    public boolean wouldDoCriticalHit(boolean ignoreSprint) {
469
        LocalPlayer player = currentPlayer();
470
        if (player == null) return false;
471
472
        return isNaturalCriticalReady(ignoreSprint);
473
    }
474
475
    private boolean isNaturalCriticalReady(boolean ignoreSprint) {
476
        LocalPlayer player = currentPlayer();
477
        if (player == null) return false;
478
479
        return canDoCriticalHit(false, ignoreSprint)
480
                && player.fallDistance > 0.0f
481
                && player.getDeltaMovement().y <= 0.0;
482
    }
483
484
    private boolean shouldHoldKillAuraForNaturalCrit(LocalPlayer player, boolean ignoreSprint) {
485
        if (player == null || player.onGround()) return false;
486
        return ignoreSprint || !player.isSprinting();
487
    }
488
489
    private boolean hasJumpIntent(LocalPlayer player) {
490
        if (player == null) return false;
491
        if (mc.options != null && mc.options.keyJump.isDown()) return true;
492
        return lastJumpInputAge >= 0 && player.tickCount - lastJumpInputAge <= 1;
493
    }
494
495
    public boolean shouldWaitForCrit(Entity target, boolean ignoreState) {
496
        LocalPlayer player = currentPlayer();
497
        if (player == null || target == null) return false;
498
        if (!ignoreState && (!isEnabled() || getMode() != Mode.JUMP)) return false;
499
        if (player.isFallFlying()) return false;
500
        if (!allowsCriticalHit(false) || player.getDeltaMovement().y < -0.08) return false;
501
        if (player.fallDistance > 0.0f) return false;
502
        if (player.distanceToSqr(target) > jumpRange.get() * jumpRange.get()) return false;
503
504
        return player.getDeltaMovement().y > 0.0
505
                && player.getAttackStrengthScale(0.5f) > 0.9f;
506
    }
507
508
    private boolean shouldWaitForJump() {
509
        LocalPlayer player = currentPlayer();
510
        if (player == null || !allowsCriticalHit(true) || getMode() != Mode.JUMP) return false;
511
        return player.getAttackStrengthScale(0.5f) < 0.9f;
512
    }
513
514
    private Entity getTargetInRange() {
515
        return getTargetInRange(jumpRange.get());
516
    }
517
518
    private Entity getTargetInRange(float rangeValue) {
519
        LocalPlayer player = currentPlayer();
520
        Entity target = getPreferredTarget();
521
        if (player == null || target == null || !target.isAlive()) return null;
522
        if (player.distanceToSqr(target) > rangeValue * rangeValue) return null;
523
        if (canBeSeen.get() && !player.hasLineOfSight(target)) return null;
524
        return target;
525
    }
526
527
    private LocalPlayer currentPlayer() {
528
        return mc != null ? mc.player : null;
529
    }
530
531
    private boolean usesNaturalCriticalState() {
532
        return getMode() == Mode.JUMP || getMode() == Mode.TIMER;
533
    }
534
535
    private boolean shouldForceJumpCrit(Entity target) {
536
        LocalPlayer player = currentPlayer();
537
        if (player == null || target == null) return false;
538
        if (getMode() != Mode.JUMP) return false;
539
        if (!allowsCriticalHit(true)) return false;
540
        if (player.distanceToSqr(target) > jumpRange.get() * jumpRange.get()) return false;
541
        if (canBeSeen.get() && !player.hasLineOfSight(target)) return false;
542
        return !optimizeForCooldown.get() || !shouldWaitForJump();
543
    }
544
545
    private boolean shouldAttemptCritWhileSprinting() {
546
        return isEnabled() && whenSprinting.get() && stopSprintingMode.get() == StopSprintingMode.NONE;
547
    }
548
549
    private boolean canAttemptCriticalAttack(Entity target) {
550
        if (target == null) return false;
551
        boolean ignoreSprint = shouldAttemptCritWhileSprinting();
552
        return switch (getMode()) {
553
            case PACKET, NO_GROUND, VULCAN_297 -> canDoCriticalHit(true, ignoreSprint);
554
            case JUMP, TIMER -> getTargetInRange() != null;
555
            case OFF -> false;
556
        };
557
    }
558
559
    private boolean canUseJumpCriticalState(Entity target) {
560
        LocalPlayer player = currentPlayer();
561
        if (player == null || target == null) return false;
562
        if (getMode() != Mode.JUMP) return false;
563
        if (!allowsCriticalHit(true)) return false;
564
        if (player.distanceToSqr(target) > jumpRange.get() * jumpRange.get()) return false;
565
        return !canBeSeen.get() || player.hasLineOfSight(target);
566
    }
567
568
    private boolean canUseKillAuraJumpCriticalState(Entity target) {
569
        LocalPlayer player = currentPlayer();
570
        if (player == null || target == null) return false;
571
        if (!allowsCriticalHit(true)) return false;
572
        if (player.distanceToSqr(target) > jumpRange.get() * jumpRange.get()) return false;
573
        return !canBeSeen.get() || player.hasLineOfSight(target);
574
    }
575
576
    private boolean shouldAutoJumpCrit(Entity target) {
577
        if (!shouldForceJumpCrit(target)) return false;
578
579
        KillAura killAura = Modules.get(KillAura.class);
580
        if (killAura == null || !killAura.isEnabled()) return true;
581
        return killAura.willAttackInTicks(JUMP_CRIT_LEAD_TICKS);
582
    }
583
584
    private Mode getMode() {
585
        return killAuraModeOverride != null ? killAuraModeOverride : mode.get();
586
    }
587
588
    private SelectionMode getSelectionMode() {
589
        return killAuraSelectionOverride != null ? killAuraSelectionOverride : selectionMode.get();
590
    }
591
592
    private Entity getPreferredTarget() {
593
        KillAura killAura = Modules.get(KillAura.class);
594
        if (killAura != null && killAura.isEnabled() && killAura.getCurrentTarget() != null) {
595
            return killAura.getCurrentTarget();
596
        }
597
        return TargetManager.getTarget();
598
    }
599
600
    private void performPacketCritical(Minecraft mc, LocalPlayer player, Entity target) {
601
        if (mc.getConnection() == null) return;
602
603
        switch (packetMode.get()) {
604
            case VANILLA -> {
605
                sendCriticalPacket(player, 0.2, false);
606
                sendCriticalPacket(player, 0.01, false);
607
            }
608
            case NO_CHEAT_PLUS -> {
609
                sendCriticalPacket(player, 0.11, false);
610
                sendCriticalPacket(player, 0.1100013579, false);
611
                sendCriticalPacket(player, 0.0000013579, false);
612
            }
613
            case FALLING -> {
614
                sendCriticalPacket(player, 0.0625, false);
615
                sendCriticalPacket(player, 0.0625013579, false);
616
                sendCriticalPacket(player, 0.0000013579, false);
617
            }
618
            case LOW -> {
619
                sendCriticalPacket(player, 1.0E-9, false);
620
                sendCriticalPacket(player, 0.0, false);
621
            }
622
            case DOWN -> sendCriticalPacket(player, -1.0E-9, false);
623
            case GRIM -> {
624
                if (!player.onGround()) {
625
                    sendCriticalPacket(player, -1.0E-6, false);
626
                }
627
            }
628
            case BLOCKSMC -> {
629
                if (player.tickCount % 4 == 0) {
630
                    sendCriticalPacket(player, 0.0011, true);
631
                    sendCriticalPacket(player, 0.0, false);
632
                }
633
            }
634
        }
635
    }
636
637
    private void performVulcan297Critical(Minecraft mc, LocalPlayer player) {
638
        if (mc.getConnection() == null) return;
639
640
        sendCriticalPacket(player, 0.021, false, PacketType.FULL);
641
        sendCriticalPacket(player, 0.011, false, PacketType.FULL);
642
    }
643
644
    private void updateVulcan297State(LocalPlayer player) {
645
        if (getMode() != Mode.VULCAN_297) {
646
            resetVulcan297State();
647
            return;
648
        }
649
650
        if (vulcan297JumpRecoveryTicks > 0) {
651
            vulcan297JumpRecoveryTicks--;
652
        }
653
654
        if (player == null) {
655
            resetVulcan297State();
656
            return;
657
        }
658
659
        if (!player.onGround()) {
660
            vulcan297WasAirborne = true;
661
            vulcan297LandingRecoveryTicks = VULCAN_297_LANDING_RECOVERY_TICKS;
662
            return;
663
        }
664
665
        if (vulcan297WasAirborne && vulcan297LandingRecoveryTicks > 0) {
666
            vulcan297LandingRecoveryTicks--;
667
            return;
668
        }
669
670
        vulcan297WasAirborne = false;
671
        vulcan297LandingRecoveryTicks = 0;
672
    }
673
674
    private boolean canPerformVulcan297Critical(LocalPlayer player) {
675
        if (player == null || !player.onGround()) return false;
676
        if (vulcan297JumpRecoveryTicks > 0) return false;
677
        return vulcan297LandingRecoveryTicks <= 0;
678
    }
679
680
    private void sendCriticalPacket(LocalPlayer player, double yOffset, boolean onGround) {
681
        sendCriticalPacket(player, yOffset, onGround, packetType.get());
682
    }
683
684
    private void sendCriticalPacket(LocalPlayer player, double yOffset, boolean onGround, PacketType type) {
685
        if (mc == null || mc.getConnection() == null || player == null) return;
686
687
        Packet<?> packet = switch (type) {
688
            case POSITION -> new ServerboundMovePlayerPacket.Pos(
689
                    player.getX(),
690
                    player.getY() + yOffset,
691
                    player.getZ(),
692
                    onGround,
693
                    player.horizontalCollision
694
            );
695
            case FULL -> new ServerboundMovePlayerPacket.PosRot(
696
                    player.getX(),
697
                    player.getY() + yOffset,
698
                    player.getZ(),
699
                    player.getYRot(),
700
                    player.getXRot(),
701
                    onGround,
702
                    player.horizontalCollision
703
            );
704
        };
705
706
        mc.getConnection().send(packet);
707
    }
708
709
    private boolean isAttackAlreadyPrepared(LocalPlayer player, Entity target) {
710
        return player.tickCount == lastPreparedAttackAge && target.getId() == lastPreparedTargetId;
711
    }
712
713
    private void markAttackPrepared(LocalPlayer player, Entity target) {
714
        lastPreparedAttackAge = player.tickCount;
715
        lastPreparedTargetId = target.getId();
716
    }
717
718
    private void resetPreparedAttack() {
719
        lastPreparedAttackAge = -1;
720
        lastPreparedTargetId = Integer.MIN_VALUE;
721
    }
722
723
    private void resetVulcan297State() {
724
        vulcan297JumpRecoveryTicks = 0;
725
        vulcan297LandingRecoveryTicks = 0;
726
        vulcan297WasAirborne = false;
727
    }
728
729
    public enum Mode {
730
        OFF,
731
        JUMP,
732
        PACKET,
733
        NO_GROUND,
734
        TIMER,
735
        VULCAN_297
736
    }
737
738
    public enum SelectionMode {
739
        SMART,
740
        IGNORE,
741
        ALWAYS
742
    }
743
744
    public enum StopSprintingMode {
745
        NONE,
746
        LEGIT,
747
        ON_NETWORK,
748
        ON_ATTACK
749
    }
750
751
    public enum PacketMode {
752
        VANILLA,
753
        NO_CHEAT_PLUS,
754
        FALLING,
755
        LOW,
756
        DOWN,
757
        GRIM,
758
        BLOCKSMC
759
    }
760
761
    public enum PacketType {
762
        POSITION,
763
        FULL
764
    }
765
766
}
767
KiwiClientCOMBATsrc/main/java/com/tangykiwi/kiwiclient/module/combat/Criticals.javaJava · 47 lines · 1.6 KB

Forces critical hits

Criticals.javaJava · Minecraft 26.2 · 47 lines · 1.6 KB · complete file, verbatimOriginal ↗
1
package com.tangykiwi.kiwiclient.module.combat;
2
3
import static com.tangykiwi.kiwiclient.KiwiClient.mc;
4
5
import com.google.common.eventbus.Subscribe;
6
import com.tangykiwi.kiwiclient.event.PacketEvent;
7
import com.tangykiwi.kiwiclient.mixininterface.IServerboundMovePlayerPacket;
8
import com.tangykiwi.kiwiclient.module.Category;
9
import com.tangykiwi.kiwiclient.module.Module;
10
11
import net.minecraft.network.protocol.game.ServerboundAttackPacket;
12
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
13
import net.minecraft.world.entity.Entity;
14
import net.minecraft.world.entity.LivingEntity;
15
16
public class Criticals extends Module {
17
    public Criticals() {
18
        super("Criticals", "Forces critical hits", KEY_UNBOUND, Category.COMBAT);
19
    }
20
21
    @Subscribe
22
    public void onSendPacket(PacketEvent.Send event) {
23
        if (event.packet instanceof ServerboundAttackPacket(int entityId)) {
24
            Entity entity = mc.level.getEntity(entityId);
25
            
26
            doCritical(entity);
27
        }
28
    }
29
30
    public void doCritical(Entity entity) {
31
        if (!(entity instanceof LivingEntity) || !  mc.player.onGround() || mc.player.isInWater() || mc.player.isInLava() || mc.player.onClimbable()) return;
32
33
        sendPacket(0.0625);
34
        sendPacket(0);
35
    }
36
37
    private void sendPacket(double height) {
38
        double x = mc.player.getX();
39
        double y = mc.player.getY();
40
        double z = mc.player.getZ();
41
42
        ServerboundMovePlayerPacket packet = new ServerboundMovePlayerPacket.Pos(x, y + height, z, false, false);
43
        ((IServerboundMovePlayerPacket) packet).setTag(1337);
44
        mc.player.connection.send(packet);
45
    }
46
}
47
LiquidBounce (Kotlin)COMBATsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/criticals/ModuleCriticals.ktKotlin · 227 lines · 8.2 KB

Automatically deals critical damage every time you attack an entity.

SettingsStopSprintingRangeFakeCriticalMagic
ModuleCriticals.ktKotlin · Minecraft 26.2 · 227 lines · 8.2 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.combat.criticals
20
21
import net.ccbluex.liquidbounce.config.types.group.NoneMode
22
import net.ccbluex.liquidbounce.config.types.group.ToggleableValueGroup
23
import net.ccbluex.liquidbounce.config.types.list.Tagged
24
import net.ccbluex.liquidbounce.event.events.AttackEntityEvent
25
import net.ccbluex.liquidbounce.event.events.SprintEvent
26
import net.ccbluex.liquidbounce.event.handler
27
import net.ccbluex.liquidbounce.features.module.ClientModule
28
import net.ccbluex.liquidbounce.features.module.ModuleCategories
29
import net.ccbluex.liquidbounce.features.module.modules.combat.criticals.modes.CriticalsBlink
30
import net.ccbluex.liquidbounce.features.module.modules.combat.criticals.modes.CriticalsJump
31
import net.ccbluex.liquidbounce.features.module.modules.combat.criticals.modes.CriticalsNoGround
32
import net.ccbluex.liquidbounce.features.module.modules.combat.criticals.modes.CriticalsPacket
33
import net.ccbluex.liquidbounce.features.module.modules.combat.criticals.modes.CriticalsTimer
34
import net.ccbluex.liquidbounce.features.module.modules.movement.fly.ModuleFly
35
import net.ccbluex.liquidbounce.features.module.modules.movement.liquidwalk.ModuleLiquidWalk
36
import net.ccbluex.liquidbounce.utils.block.collideBlockIntersects
37
import net.ccbluex.liquidbounce.utils.clicking.Clicker
38
import net.ccbluex.liquidbounce.utils.network.sendStopSprinting
39
import net.ccbluex.liquidbounce.utils.combat.findEnemy
40
import net.ccbluex.liquidbounce.utils.entity.box
41
import net.ccbluex.liquidbounce.utils.kotlin.EventPriorityConvention.CRITICAL_MODIFICATION
42
import net.minecraft.world.effect.MobEffects.BLINDNESS
43
import net.minecraft.world.effect.MobEffects.LEVITATION
44
import net.minecraft.world.effect.MobEffects.SLOW_FALLING
45
import net.minecraft.world.entity.Entity
46
import net.minecraft.world.entity.LivingEntity
47
import net.minecraft.world.level.block.WebBlock
48
49
/**
50
 * Criticals module
51
 *
52
 * Automatically crits every time you attack someone.
53
 */
54
object ModuleCriticals : ClientModule("Criticals", ModuleCategories.COMBAT) {
55
56
    val modes = choices("Mode", 1) {
57
        arrayOf(
58
            NoneMode(it),
59
            CriticalsPacket,
60
            CriticalsNoGround,
61
            CriticalsJump,
62
            CriticalsBlink,
63
            CriticalsTimer
64
        )
65
    }.apply(::tagBy)
66
67
    object WhenSprinting : ToggleableValueGroup(ModuleCriticals, "WhenSprinting", false) {
68
69
        enum class StopSprintingMode(override val tag: String) : Tagged {
70
            NONE("None"),
71
            LEGIT("Legit"),
72
            ON_NETWORK("OnNetwork"),
73
            ON_ATTACK("OnAttack")
74
        }
75
76
        override val running: Boolean
77
            get() = super.running && wouldDoCriticalHit(true)
78
                && world.findEnemy(0.0f, enemyInRange) != null
79
80
        val stopSprinting by enumChoice("StopSprinting", StopSprintingMode.LEGIT)
81
        private val enemyInRange by float("Range", 4.0f, 0.0f..10.0f)
82
83
        @Suppress("unused")
84
        private val attackHandler = handler<AttackEntityEvent>(
85
            priority = CRITICAL_MODIFICATION
86
        ) { event ->
87
            if (stopSprinting == StopSprintingMode.ON_ATTACK && player.wasSprinting) {
88
                network.sendStopSprinting()
89
                player.wasSprinting = false
90
            }
91
        }
92
93
        @Suppress("unused")
94
        private val sprintHandler = handler<SprintEvent> { event ->
95
            when (stopSprinting) {
96
                StopSprintingMode.LEGIT ->
97
                    if (event.source == SprintEvent.Source.MOVEMENT_TICK || event.source == SprintEvent.Source.INPUT) {
98
                        event.sprint = false
99
                    }
100
                StopSprintingMode.ON_NETWORK ->
101
                    if (event.source == SprintEvent.Source.NETWORK || event.source == SprintEvent.Source.INPUT) {
102
                        event.sprint = false
103
                    }
104
                else -> {}
105
            }
106
        }
107
108
        fun shouldAttemptCritWhileSprinting(): Boolean {
109
            return this.running && this.stopSprinting == StopSprintingMode.NONE
110
        }
111
    }
112
113
    /**
114
     * Just some visuals.
115
     */
116
    object VisualsValueGroup : ToggleableValueGroup(this, "Visuals", false) {
117
118
        val fake by boolean("Fake", false)
119
120
        private val critical by int("Critical", 1, 0..20)
121
        private val magic by int("Magic", 0, 0..20)
122
123
        @Suppress("unused")
124
        private val attackHandler = handler<AttackEntityEvent> { event ->
125
            if (event.entity !is LivingEntity) {
126
                return@handler
127
            }
128
129
            if (!fake && !wouldDoCriticalHit()) {
130
                return@handler
131
            }
132
133
            showCriticals(event.entity)
134
        }
135
136
        fun showCriticals(entity: Entity) {
137
            if (!enabled) {
138
                return
139
            }
140
141
            repeat(critical) {
142
                player.crit(entity)
143
            }
144
145
            repeat(magic) {
146
                player.magicCrit(entity)
147
            }
148
        }
149
150
    }
151
152
    init {
153
        tree(WhenSprinting)
154
        tree(VisualsValueGroup)
155
    }
156
157
    /**
158
     * The Criticals selection mode
159
     */
160
    enum class CriticalsSelectionMode(override val tag: String) : Tagged {
161
162
        SMART("Smart"),
163
        IGNORE("Ignore"),
164
        ALWAYS("Always");
165
166
        fun isCriticalHit(target: Entity): Boolean {
167
            return when (this) {
168
                IGNORE -> true
169
                SMART -> !shouldWaitForCrit(target, ignoreState = true)
170
                ALWAYS -> wouldDoCriticalHit()
171
            }
172
        }
173
174
        fun shouldStopSprinting(clicker: Clicker<*>, target: Entity?): Boolean {
175
            // If we don't care about critical hits we don't have to stop sprinting.
176
            if (this == IGNORE) {
177
                return false
178
            }
179
180
            // On ground, we cannot do critical hits anyway.
181
            if (player.onGround()) {
182
                return false
183
            }
184
185
            // If we are about to do a critical hit, we should stop sprinting.
186
            return target != null && clicker.willClickAt(1)
187
        }
188
189
    }
190
191
    fun shouldWaitForCrit(target: Entity, ignoreState: Boolean = false) = when {
192
        CriticalsBlink.running && CriticalsBlink.isInState -> false
193
        else -> CriticalsJump.shouldWaitForCrit(target, ignoreState)
194
    }
195
196
    private val blockingEffects = arrayOf(LEVITATION, BLINDNESS, SLOW_FALLING)
197
198
    fun allowsCriticalHit(ignoreOnGround: Boolean = false): Boolean {
199
        val blockingConditions = booleanArrayOf(
200
            // Modules
201
            ModuleFly.running,
202
            ModuleLiquidWalk.running && ModuleLiquidWalk.standingOnWater(),
203
            player.isInLiquid, player.isPassenger,
204
            // Cobwebs
205
            player.box.collideBlockIntersects(checkCollisionShape = false) { it is WebBlock },
206
            // Effects
207
            blockingEffects.any(player::hasEffect),
208
            // Disabling conditions
209
            player.onClimbable(), player.isNoGravity, player.isHandsBusy,
210
            player.abilities.flying,
211
            // On Ground
212
            player.onGround() && !ignoreOnGround
213
        )
214
215
        // Do not replace this with .none() since it is equivalent to .isEmpty()
216
        return blockingConditions.none { it }
217
    }
218
219
    fun canDoCriticalHit(ignoreOnGround: Boolean = false, ignoreSprint: Boolean = false) =
220
        allowsCriticalHit(ignoreOnGround) && player.getAttackStrengthScale(0.5f) > 0.9f &&
221
            (!player.isSprinting || ignoreSprint)
222
223
    fun wouldDoCriticalHit(ignoreSprint: Boolean = false) =
224
        canDoCriticalHit(false, ignoreSprint) && player.fallDistance > 0.0
225
226
}
227