NoKnockback module

NoKnockback: Minecraft 26.3 cheat module, full source for every implementation (2 clients: OfflineClient, Nicotine).

2 implementationsMOVEMENTCombat

Clients with this module

Full module source: 2 implementations

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

OfflineClientMOVEMENTsrc/main/java/com/jellypudding/offlineclient/modules/movement/NoKnockback.javaJava · 87 lines · 4.0 KB

Reduces or removes the knockback you take.

SettingsHorizontalVerticalSeparate explosionsExplosion horizontalExplosion verticalFishing rodsBlock push
NoKnockback.javaJava · Minecraft 26.2 · 87 lines · 4.0 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.KnockbackEvent;
5
import com.jellypudding.offlineclient.event.events.PacketReceiveEvent;
6
import com.jellypudding.offlineclient.module.Category;
7
import com.jellypudding.offlineclient.module.Module;
8
import com.jellypudding.offlineclient.setting.BoolSetting;
9
import com.jellypudding.offlineclient.setting.NumberSetting;
10
import net.minecraft.network.protocol.game.ClientboundExplodePacket;
11
import net.minecraft.world.phys.Vec3;
12
13
import java.util.Optional;
14
15
public final class NoKnockback extends Module {
16
17
    private final NumberSetting horizontal = new NumberSetting("Horizontal",
18
        "How much horizontal knockback to take. Over a hundred throws you further and under nought reverses it.", 0, -100, 200, 1, "%").min(-100).max(200);
19
    private final NumberSetting vertical = new NumberSetting("Vertical",
20
        "How much vertical knockback to take. Over a hundred throws you further and under nought reverses it.", 0, -100, 200, 1, "%").min(-100).max(200);
21
    private final BoolSetting separateExplosions = new BoolSetting("Separate explosions",
22
        "Give explosions their own pair of sliders.", false);
23
    private final NumberSetting explosionHorizontal = new NumberSetting("Explosion horizontal",
24
        "How much sideways push to take from explosions.", 100, -100, 200, 1, "%").min(-100).max(200)
25
        .under(separateExplosions);
26
    private final NumberSetting explosionVertical = new NumberSetting("Explosion vertical",
27
        "How much upward push to take from explosions.", 100, -100, 200, 1, "%").min(-100).max(200)
28
        .under(separateExplosions);
29
    private final BoolSetting fishingRods = new BoolSetting("Fishing rods",
30
        "A rod hooked into you cannot reel you in.", true);
31
    private final BoolSetting blockPush = new BoolSetting("Block push",
32
        "Standing inside a block no longer shoves you out.", false);
33
34
    public NoKnockback() {
35
        super("NoKnockback", "Reduces or removes the knockback you take.", Category.MOVEMENT);
36
        addSettings(horizontal, vertical, separateExplosions, explosionHorizontal,
37
            explosionVertical, fishingRods, blockPush);
38
        searchTags("velocity", "knockback", "antikb");
39
    }
40
41
    @Override
42
    public String getSuffix() {
43
        return horizontal.getInt() + "/" + vertical.getInt();
44
    }
45
46
    public boolean blocksFishingRods() {
47
        return isEnabled() && fishingRods.isOn();
48
    }
49
50
    public boolean blocksBlockPush() {
51
        return isEnabled() && blockPush.isOn();
52
    }
53
54
    @Subscribe
55
    private void onKnockback(KnockbackEvent event) {
56
        if (!inGame()) {
57
            return;
58
        }
59
        Vec3 current = mc.player.getDeltaMovement();
60
        double h = horizontal.getValue() / 100.0;
61
        double v = vertical.getValue() / 100.0;
62
        event.setX(current.x + (event.getX() - current.x) * h);
63
        event.setY(current.y + (event.getY() - current.y) * v);
64
        event.setZ(current.z + (event.getZ() - current.z) * h);
65
    }
66
67
    // Explosions push the player through their own packet instead of the usual knockback path.
68
    @Subscribe
69
    private void onPacketReceive(PacketReceiveEvent event) {
70
        if (!(event.getPacket() instanceof ClientboundExplodePacket packet)
71
            || packet.playerKnockback().isEmpty()) {
72
            return;
73
        }
74
        double h = (separateExplosions.isOn() ? explosionHorizontal : horizontal).getValue() / 100.0;
75
        double v = (separateExplosions.isOn() ? explosionVertical : vertical).getValue() / 100.0;
76
        if (h == 1 && v == 1) {
77
            return;
78
        }
79
        Vec3 push = packet.playerKnockback().get();
80
        // Scaling the packet keeps the particles and the sound.
81
        event.setPacket(new ClientboundExplodePacket(
82
            packet.center(), packet.radius(), packet.blockCount(),
83
            Optional.of(new Vec3(push.x * h, push.y * v, push.z * h)),
84
            packet.explosionParticle(), packet.explosionSound(), packet.blockParticles()));
85
    }
86
}
87
NicotineCombatsrc/client/java/nicotine/mod/mods/combat/NoKnockback.javaJava · 58 lines · 1.4 KB

Adjusts knockback from entities and explosions

SettingsEntityExplosion
NoKnockback.javaJava · Minecraft 26.3 · 58 lines · 1.4 KB · complete file, verbatimOriginal ↗
1
package nicotine.mod.mods.combat;
2
3
import nicotine.events.ExplosionKnockbackEvent;
4
import nicotine.events.KnockbackEvent;
5
import nicotine.mod.Mod;
6
import nicotine.mod.ModCategory;
7
import nicotine.mod.option.SliderOption;
8
import nicotine.util.EventBus;
9
10
import java.util.Arrays;
11
12
import static nicotine.util.Common.*;
13
14
public class NoKnockback extends Mod {
15
16
    private final SliderOption entity = new SliderOption(
17
            "Entity",
18
            0,
19
            0,
20
            1.0f,
21
            true
22
    );
23
24
    private final SliderOption explosion = new SliderOption(
25
            "Explosion",
26
            0,
27
            0,
28
            1.0f,
29
            true
30
    );
31
32
    public NoKnockback() {
33
        super(ModCategory.Combat, "NoKnockback", "Adjusts knockback from entities and explosions");
34
        this.addOptions(Arrays.asList(entity, explosion));
35
    }
36
37
    @Override
38
    protected void init() {
39
        EventBus.register(KnockbackEvent.class, event -> {
40
            if (!this.enabled)
41
                return true;
42
43
            mc.player.push(event.x * entity.value, event.y * entity.value, event.z * entity.value);
44
45
            return false;
46
        });
47
48
        EventBus.register(ExplosionKnockbackEvent.class, event -> {
49
            if (!this.enabled)
50
                return true;
51
52
            mc.player.push(event.x * explosion.value, event.y * explosion.value, event.z * explosion.value);
53
54
            return false;
55
        });
56
    }
57
}
58