blink module

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

4 implementationsMovementMOVEMENTPLAYER

Full module source: 4 implementations

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

Meteor ClientMovementsrc/main/java/meteordevelopment/meteorclient/systems/modules/movement/Blink.javaJava · 167 lines · 5.0 KB

Allows you to essentially teleport while suspending motion updates.

Settingsrender-originalpulse-delaycancel-blink
Blink.javaJava · Minecraft 26.2 · 167 lines · 5.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.movement;
7
8
import meteordevelopment.meteorclient.events.game.GameJoinedEvent;
9
import meteordevelopment.meteorclient.events.game.GameLeftEvent;
10
import meteordevelopment.meteorclient.events.packets.PacketEvent;
11
import meteordevelopment.meteorclient.events.world.TickEvent;
12
import meteordevelopment.meteorclient.settings.*;
13
import meteordevelopment.meteorclient.systems.modules.Categories;
14
import meteordevelopment.meteorclient.systems.modules.Module;
15
import meteordevelopment.meteorclient.utils.Utils;
16
import meteordevelopment.meteorclient.utils.entity.fakeplayer.FakePlayerEntity;
17
import meteordevelopment.meteorclient.utils.misc.Keybind;
18
import meteordevelopment.orbit.EventHandler;
19
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
20
import net.minecraft.world.phys.Vec3;
21
import org.joml.Vector3d;
22
23
import java.util.ArrayList;
24
import java.util.List;
25
26
public class Blink extends Module {
27
    private final SettingGroup sgGeneral = settings.getDefaultGroup();
28
29
    private final Setting<Boolean> renderOriginal = sgGeneral.add(new BoolSetting.Builder()
30
        .name("render-original")
31
        .description("Renders your player model at the original position.")
32
        .defaultValue(true)
33
        .build()
34
    );
35
36
    private final Setting<Integer> delay = sgGeneral.add(new IntSetting.Builder()
37
        .name("pulse-delay")
38
        .description("After the duration in ticks has elapsed, send all packets and start blinking again. 0 to disable.")
39
        .defaultValue(0)
40
        .min(0)
41
        .sliderMax(60)
42
        .build()
43
    );
44
45
    @SuppressWarnings("unused")
46
    private final Setting<Keybind> cancelBlink = sgGeneral.add(new KeybindSetting.Builder()
47
        .name("cancel-blink")
48
        .description("Cancels sending packets and sends you back to your original position.")
49
        .defaultValue(Keybind.none())
50
        .action(() -> {
51
            cancelled = true;
52
            disable();
53
        })
54
        .build()
55
    );
56
57
    private final List<ServerboundMovePlayerPacket> packets = new ArrayList<>();
58
    private FakePlayerEntity model;
59
    private final Vector3d start = new Vector3d();
60
61
    private boolean cancelled, sending;
62
    private int timer = 0;
63
64
    public Blink() {
65
        super(Categories.Movement, "blink", "Allows you to essentially teleport while suspending motion updates.");
66
67
        runInMainMenu = true;
68
    }
69
70
    @Override
71
    public void onActivate() {
72
        if (!Utils.canUpdate()) return;
73
74
        if (renderOriginal.get()) {
75
            model = new FakePlayerEntity(mc.player, mc.player.getGameProfile().name(), 20, true);
76
            model.doNotPush = true;
77
            model.hideWhenInsideCamera = true;
78
            model.noHit = true;
79
            model.spawn();
80
        }
81
82
        Utils.set(start, mc.player.position());
83
    }
84
85
    @Override
86
    public void onDeactivate() {
87
        if (!Utils.canUpdate()) return;
88
89
        dumpPackets(!cancelled);
90
91
        if (cancelled) {
92
            mc.player.setPos(start.x, start.y, start.z);
93
            mc.player.setDeltaMovement(Vec3.ZERO);
94
        }
95
96
        cancelled = false;
97
    }
98
99
    @EventHandler
100
    private void onTick(TickEvent.Post event) {
101
        if (!Utils.canUpdate()) return;
102
103
        timer++;
104
105
        if (delay.get() != 0 && delay.get() <= timer) {
106
            onDeactivate();
107
            onActivate();
108
        }
109
    }
110
111
    @EventHandler
112
    private void onSendPacket(PacketEvent.Send event) {
113
        if (!Utils.canUpdate()) return;
114
115
        if (sending) return;
116
        if (!(event.packet instanceof ServerboundMovePlayerPacket p)) return;
117
        event.cancel();
118
119
        ServerboundMovePlayerPacket prev = packets.isEmpty() ? null : packets.getLast();
120
121
        if (prev != null &&
122
            p.isOnGround() == prev.isOnGround() &&
123
            p.getYRot(-1) == prev.getYRot(-1) &&
124
            p.getXRot(-1) == prev.getXRot(-1) &&
125
            p.getX(-1) == prev.getX(-1) &&
126
            p.getY(-1) == prev.getY(-1) &&
127
            p.getZ(-1) == prev.getZ(-1)
128
        ) return;
129
130
        synchronized (packets) {
131
            packets.add(p);
132
        }
133
    }
134
135
    @EventHandler
136
    private void onJoinGame(GameJoinedEvent event) {
137
        warning("Blink is currently enabled; you won't be able to interact with anything properly until you disable it!");
138
    }
139
140
    @EventHandler
141
    private void onLeaveGame(GameLeftEvent event) {
142
        dumpPackets(false);
143
        cancelled = false;
144
    }
145
146
    @Override
147
    public String getInfoString() {
148
        return String.format("%.1f", timer / 20f);
149
    }
150
151
    private void dumpPackets(boolean send) {
152
        sending = true;
153
        synchronized (packets) {
154
            if (send) packets.forEach(mc.player.connection::send);
155
            packets.clear();
156
        }
157
        sending = false;
158
159
        if (model != null) {
160
            model.despawn();
161
            model = null;
162
        }
163
164
        timer = 0;
165
    }
166
}
167
MelaHack (ThunderHack fork)MOVEMENTsrc/main/java/thunder/hack/features/modules/movement/Blink.javaJava · 246 lines · 9.8 KB

Delays movement packets.

SettingsPulsePulsePacketsAutoDisableDisableOnVelocityClearOnVelocityStopOnInteractionDisablePacketsRenderRender ModeColorCancel
Blink.javaJava · Minecraft 26.2 · 246 lines · 9.8 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.movement;
2
3
import meteordevelopment.orbit.EventHandler;
4
import net.minecraft.client.player.LocalPlayer;
5
import net.minecraft.network.protocol.Packet;
6
import net.minecraft.network.protocol.common.ServerboundKeepAlivePacket;
7
import net.minecraft.network.protocol.common.ServerboundPongPacket;
8
import net.minecraft.network.protocol.game.*;
9
import net.minecraft.world.phys.AABB;
10
import net.minecraft.world.phys.Vec3;
11
import org.lwjgl.glfw.GLFW;
12
import thunder.hack.events.impl.EventTick;
13
import thunder.hack.events.impl.PacketEvent;
14
import thunder.hack.features.modules.Module;
15
import thunder.hack.features.modules.client.HudEditor;
16
import thunder.hack.setting.Setting;
17
import thunder.hack.setting.impl.Bind;
18
import thunder.hack.setting.impl.ColorSetting;
19
import thunder.hack.utility.player.PlayerEntityCopy;
20
import thunder.hack.utility.render.Render3DEngine;
21
22
import java.awt.*;
23
import java.util.ArrayList;
24
import java.util.LinkedList;
25
import java.util.Queue;
26
import java.util.concurrent.atomic.AtomicBoolean;
27
28
import static thunder.hack.features.modules.client.ClientSettings.isRu;
29
30
import com.mojang.blaze3d.vertex.PoseStack;
31
32
public class Blink extends Module {
33
    public Blink() {
34
        super("Blink", Category.MOVEMENT);
35
    }
36
37
    private final Setting<Boolean> pulse = new Setting<>("Pulse", false);
38
    private final Setting<Integer> pulsePackets = new Setting<>("PulsePackets", 20, 1, 1000, v -> pulse.getValue());
39
    private final Setting<Boolean> autoDisable = new Setting<>("AutoDisable", false);
40
    private final Setting<Boolean> disableOnVelocity = new Setting<>("DisableOnVelocity", false);
41
    private final Setting<Boolean> clearOnVelocity = new Setting<>("ClearOnVelocity", true, v -> false);
42
    private final Setting<Boolean> stopOnInteraction = new Setting<>("StopOnInteraction", true);
43
    private final Setting<Integer> disablePackets = new Setting<>("DisablePackets", 17, 1, 1000, v -> autoDisable.getValue());
44
    private final Setting<Boolean> render = new Setting<>("Render", true);
45
    private final Setting<RenderMode> renderMode = new Setting<>("Render Mode", RenderMode.Circle, value -> render.getValue());
46
    private final Setting<ColorSetting> circleColor = new Setting<>("Color", new ColorSetting(0xFFda6464), value -> render.getValue() && renderMode.getValue() == RenderMode.Circle || renderMode.getValue() == RenderMode.CircleAndModel || renderMode.getValue() == RenderMode.Box);
47
    private final Setting<Bind> cancel = new Setting<>("Cancel", new Bind(GLFW.GLFW_KEY_LEFT_SHIFT, false, false));
48
49
    private enum RenderMode {
50
        Circle,
51
        Model,
52
        CircleAndModel,
53
        Box
54
    }
55
56
    private PlayerEntityCopy blinkPlayer;
57
    public static Vec3 lastPos = Vec3.ZERO;
58
    private Vec3 prevVelocity = Vec3.ZERO;
59
    private float prevYaw = 0;
60
    private boolean prevSprinting = false;
61
    private final Queue<Packet<?>> storedPackets = new LinkedList<>();
62
    private final Queue<Packet<?>> storedTransactions = new LinkedList<>();
63
    private final AtomicBoolean sending = new AtomicBoolean(false);
64
    private boolean need2SendBsAsap = false;
65
    private boolean need2CancelBsAsap = false;
66
    private AABB renderbox;
67
68
    @Override
69
    public void onEnable() {
70
        if (mc.player == null
71
                || mc.level == null
72
                || mc.hasSingleplayerServer()
73
                || mc.getConnection() == null) {
74
            disable();
75
            return;
76
        }
77
78
        storedTransactions.clear();
79
        lastPos = mc.player.position();
80
        prevVelocity = mc.player.getDeltaMovement();
81
        prevYaw = mc.player.getYRot();
82
        prevSprinting = mc.player.isSprinting();
83
        mc.level.addFreshEntity(new LocalPlayer(mc, mc.level, mc.getConnection(), mc.player.getStats(), mc.player.getRecipeBook(), mc.player.input.keyPresses, mc.player.wasSprinting, mc.player.chatAbilities()));
84
        sending.set(false);
85
        storedPackets.clear();
86
    }
87
88
    @Override
89
    public void onDisable() {
90
        if (mc.level == null || mc.player == null) return;
91
92
        while (!storedPackets.isEmpty())
93
            sendPacket(storedPackets.poll());
94
95
        if (blinkPlayer != null) blinkPlayer.deSpawn();
96
        blinkPlayer = null;
97
98
        storedPackets.clear(); // доверяй, но проверяй
99
    }
100
101
    @Override
102
    public String getDisplayInfo() {
103
        return Integer.toString(storedPackets.size());
104
    }
105
106
    @EventHandler
107
    public void onPacketReceive(PacketEvent.Receive event) {
108
        if (event.getPacket() instanceof ClientboundSetEntityMotionPacket vel && vel.id() == mc.player.getId() && disableOnVelocity.getValue())
109
            disable(isRu() ? "Выключенно из-за велосити!" : "Disabled due to velocity!");
110
    }
111
112
    @EventHandler
113
    public void onPacketSend(PacketEvent.Send event) {
114
        if (fullNullCheck()) return;
115
116
        Packet<?> packet = event.getPacket();
117
118
        if (sending.get()) {
119
            return;
120
        }
121
122
        if (need2CancelBsAsap) {
123
            storedPackets.clear();
124
        }
125
126
        if (packet instanceof ServerboundPongPacket) {
127
            storedTransactions.add(packet);
128
        }
129
130
        if (pulse.getValue()) {
131
            if (packet instanceof ServerboundMovePlayerPacket) {
132
                event.cancel();
133
                storedPackets.add(packet);
134
            }
135
        } else if (!(packet instanceof ServerboundChatPacket || packet instanceof ServerboundAcceptTeleportationPacket || packet instanceof ServerboundKeepAlivePacket || packet instanceof ServerboundSeenAdvancementsPacket || packet instanceof ServerboundClientCommandPacket)) {
136
            event.cancel();
137
            storedPackets.add(packet);
138
        }
139
140
        if (stopOnInteraction.getValue() && packet instanceof ServerboundInteractPacket)
141
            need2SendBsAsap = true;
142
    }
143
144
    @EventHandler
145
    public void onUpdate(EventTick event) {
146
        if (fullNullCheck()) return;
147
148
        if (clearOnVelocity.getValue()) clearOnVelocity.setValue(false);
149
150
        if (need2CancelBsAsap) storedPackets.clear();
151
152
        if (isKeyPressed(cancel)) {
153
            storedPackets.clear();
154
            mc.player.setPosRaw(lastPos.x(), lastPos.y(), lastPos.z());
155
            mc.player.setDeltaMovement(prevVelocity);
156
            mc.player.setYRot(prevYaw);
157
            mc.player.setSprinting(prevSprinting);
158
            mc.player.setShiftKeyDown(false);
159
            mc.options.keyShift.setDown(false);
160
            sending.set(true);
161
            while (!storedTransactions.isEmpty())
162
                sendPacket(storedTransactions.poll());
163
            sending.set(false);
164
            disable(isRu() ? "Отменяю.." : "Canceling..");
165
            return;
166
        }
167
168
        if (pulse.getValue()) {
169
            if (storedPackets.size() >= pulsePackets.getValue()) {
170
                sendPackets();
171
            }
172
        }
173
174
        if (autoDisable.getValue()) {
175
            if (storedPackets.size() >= disablePackets.getValue()) {
176
                disable();
177
            }
178
        }
179
180
        if (need2SendBsAsap) {
181
            sendPackets();
182
            need2SendBsAsap = false;
183
        }
184
185
    }
186
187
    private void sendPackets() {
188
        if (mc.player == null) return;
189
        sending.set(true);
190
191
        while (!storedPackets.isEmpty()) {
192
            Packet<?> packet = storedPackets.poll();
193
            sendPacket(packet);
194
            if (packet instanceof ServerboundMovePlayerPacket && !(packet instanceof ServerboundMovePlayerPacket.Rot)) {
195
                lastPos = new Vec3(((ServerboundMovePlayerPacket) packet).getX(mc.player.getX()), ((ServerboundMovePlayerPacket) packet).getY(mc.player.getY()), ((ServerboundMovePlayerPacket) packet).getZ(mc.player.getZ()));
196
197
                if (renderMode.getValue() == RenderMode.Model || renderMode.getValue() == RenderMode.CircleAndModel) {
198
                    blinkPlayer.deSpawn();
199
                    blinkPlayer = new PlayerEntityCopy();
200
                    blinkPlayer.spawn();
201
                }
202
203
                if (renderMode.getValue() == RenderMode.Box) renderbox = mc.player.getBoundingBox();
204
            }
205
        }
206
207
        sending.set(false);
208
        storedPackets.clear();
209
    }
210
211
    public void onRender3D(PoseStack stack) {
212
        if (mc.player == null || mc.level == null) return;
213
        if (render.getValue() && lastPos != null) {
214
            if (renderMode.getValue() == RenderMode.Circle || renderMode.getValue() == RenderMode.CircleAndModel) {
215
                float[] hsb = Color.RGBtoHSB(circleColor.getValue().getRed(), circleColor.getValue().getGreen(), circleColor.getValue().getBlue(), null);
216
                float hue = (float) (System.currentTimeMillis() % 7200L) / 7200F;
217
                int rgb = Color.getHSBColor(hue, hsb[1], hsb[2]).getRGB();
218
                ArrayList<Vec3> vecs = new ArrayList<>();
219
                double x = lastPos.x;
220
                double y = lastPos.y;
221
                double z = lastPos.z;
222
223
                for (int i = 0; i <= 360; ++i) {
224
                    Vec3 vec = new Vec3(x + Math.sin((double) i * Math.PI / 180.0) * 0.5D, y + 0.01, z + Math.cos((double) i * Math.PI / 180.0) * 0.5D);
225
                    vecs.add(vec);
226
                }
227
228
                for (int j = 0; j < vecs.size() - 1; ++j) {
229
                    Render3DEngine.drawLine(vecs.get(j), vecs.get(j + 1), new Color(rgb));
230
                    hue += (1F / 360F);
231
                    rgb = Color.getHSBColor(hue, hsb[1], hsb[2]).getRGB();
232
                }
233
            }
234
            if (renderMode.getValue() == RenderMode.Model || renderMode.getValue() == RenderMode.CircleAndModel) {
235
                if (blinkPlayer == null) {
236
                    blinkPlayer = new PlayerEntityCopy();
237
                    blinkPlayer.spawn();
238
                }
239
            }
240
            if (renderMode.getValue() == RenderMode.Box && renderbox != null) {
241
                 Render3DEngine.OUTLINE_QUEUE.add(new Render3DEngine.OutlineAction(renderbox, circleColor.getValue().getColorObject(), 1));
242
            }
243
        }
244
    }
245
}
246
OfflineClientMOVEMENTsrc/main/java/com/jellypudding/offlineclient/modules/movement/Blink.javaJava · 195 lines · 6.5 KB

Pauses your position updates until you turn it off.

SettingsShow copyPulse delayLimitCancel key
Blink.javaJava · Minecraft 26.2 · 195 lines · 6.5 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.KeyPressEvent;
5
import com.jellypudding.offlineclient.event.events.PacketSendEvent;
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.modules.misc.FakePlayer;
10
import com.jellypudding.offlineclient.setting.BoolSetting;
11
import com.jellypudding.offlineclient.setting.KeybindSetting;
12
import com.jellypudding.offlineclient.setting.NumberSetting;
13
import net.minecraft.client.player.LocalPlayer;
14
import net.minecraft.network.protocol.Packet;
15
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
16
import net.minecraft.world.entity.Entity;
17
import net.minecraft.world.phys.Vec3;
18
import org.lwjgl.glfw.GLFW;
19
20
import java.lang.ref.WeakReference;
21
import java.util.Queue;
22
import java.util.concurrent.LinkedBlockingQueue;
23
24
public final class Blink extends Module {
25
26
    private static final float COPY_HEALTH = 20;
27
28
    private final BoolSetting showCopy = new BoolSetting("Show copy",
29
        "Leaves a copy of you standing where the blink began.", true);
30
    private final NumberSetting pulseDelay = new NumberSetting("Pulse delay",
31
        "Sends the held packets and starts again after this many ticks. 0 never does.",
32
        0, 0, 60, 1, " ticks").min(0);
33
    private final NumberSetting limit = new NumberSetting("Limit",
34
        "Restarts after holding this many packets. Nought holds them for as long as you like.",
35
        200, 0, 1000, 10, " packets").min(0);
36
    private final KeybindSetting cancelKey = new KeybindSetting("Cancel key",
37
        "Drops every held packet and puts you back where the blink began.",
38
        KeybindSetting.UNBOUND);
39
40
    // Filled from the packet thread and read by the HUD.
41
    private final Queue<Packet<?>> held = new LinkedBlockingQueue<>();
42
43
    // The last packet queued. A repeat of it is not worth holding.
44
    private volatile ServerboundMovePlayerPacket lastHeld;
45
46
    // The player the held packets were captured from. Weak to avoid pinning a dead world.
47
    private volatile WeakReference<LocalPlayer> owner = new WeakReference<>(null);
48
49
    // Packets sent by release come straight back through this handler.
50
    private boolean releasing;
51
52
    private FakePlayer.Body copy;
53
    private Vec3 start;
54
    private int timer;
55
56
    public Blink() {
57
        super("Blink", "Pauses your position updates until you turn it off.",
58
            Category.MOVEMENT);
59
        addSettings(showCopy, pulseDelay, limit, cancelKey);
60
    }
61
62
    @Override
63
    public boolean savesEnabledState() {
64
        return false;
65
    }
66
67
    @Override
68
    public String getSuffix() {
69
        return held.size() + " held " + String.format("%.1fs", timer / 20f);
70
    }
71
72
    @Override
73
    protected void onEnable() {
74
        begin();
75
    }
76
77
    @Override
78
    protected void onDisable() {
79
        release();
80
    }
81
82
    private void begin() {
83
        held.clear();
84
        lastHeld = null;
85
        timer = 0;
86
        owner = new WeakReference<>(mc.player);
87
        if (!inGame()) {
88
            return;
89
        }
90
        start = mc.player.position();
91
        if (showCopy.isOn()) {
92
            copy = new FakePlayer.Body(mc.level, mc.player, COPY_HEALTH, true, true);
93
            mc.level.addEntity(copy);
94
        }
95
    }
96
97
    @Subscribe
98
    private void onTick(TickEvent event) {
99
        timer++;
100
        int delay = pulseDelay.getInt();
101
        if (delay > 0 && timer >= delay) {
102
            release();
103
            begin();
104
        }
105
    }
106
107
    @Subscribe
108
    private void onKeyPress(KeyPressEvent event) {
109
        if (event.getAction() != GLFW.GLFW_PRESS || mc.gui.screen() != null
110
            || !cancelKey.isBound() || event.getKey() != cancelKey.getValue()) {
111
            return;
112
        }
113
        cancel();
114
    }
115
116
    @Subscribe
117
    private void onPacketSend(PacketSendEvent event) {
118
        LocalPlayer player = mc.player;
119
        if (releasing || player == null
120
            || !(event.getPacket() instanceof ServerboundMovePlayerPacket packet)) {
121
            return;
122
        }
123
        if (player != owner.get()) {
124
            // A respawn or a new world means the held positions are worthless.
125
            held.clear();
126
            lastHeld = null;
127
            owner = new WeakReference<>(player);
128
        }
129
        if (limit.getInt() > 0 && held.size() >= limit.getInt()) {
130
            // Toggling the module from the packet thread would edit the bus mid dispatch.
131
            release();
132
            owner = new WeakReference<>(player);
133
            return;
134
        }
135
        event.cancel();
136
        if (sameAs(lastHeld, packet)) {
137
            return;
138
        }
139
        held.add(packet);
140
        lastHeld = packet;
141
    }
142
143
    // Standing still makes a stream of identical packets. One of them says it all.
144
    private static boolean sameAs(ServerboundMovePlayerPacket previous,
145
                                  ServerboundMovePlayerPacket next) {
146
        return previous != null
147
            && previous.isOnGround() == next.isOnGround()
148
            && previous.getYRot(-1) == next.getYRot(-1)
149
            && previous.getXRot(-1) == next.getXRot(-1)
150
            && previous.getX(-1) == next.getX(-1)
151
            && previous.getY(-1) == next.getY(-1)
152
            && previous.getZ(-1) == next.getZ(-1);
153
    }
154
155
    // Throws the held packets away and walks the player back to the start.
156
    private void cancel() {
157
        held.clear();
158
        lastHeld = null;
159
        if (inGame() && start != null) {
160
            mc.player.setPos(start);
161
            mc.player.setDeltaMovement(Vec3.ZERO);
162
        }
163
        setEnabled(false);
164
    }
165
166
    // Sends everything held on to the server. Positions of a dead player are dropped.
167
    private void release() {
168
        LocalPlayer player = mc.player;
169
        LocalPlayer captured = owner.get();
170
        owner = new WeakReference<>(null);
171
        boolean replay = player != null && player == captured;
172
        releasing = true;
173
        try {
174
            Packet<?> packet;
175
            while ((packet = held.poll()) != null) {
176
                if (replay) {
177
                    player.connection.send(packet);
178
                }
179
            }
180
        } finally {
181
            releasing = false;
182
        }
183
        lastHeld = null;
184
        removeCopy();
185
        timer = 0;
186
    }
187
188
    private void removeCopy() {
189
        if (copy != null && mc.level != null && copy.level() == mc.level) {
190
            mc.level.removeEntity(copy.getId(), Entity.RemovalReason.DISCARDED);
191
        }
192
        copy = null;
193
    }
194
}
195
LiquidBounce (Kotlin)PLAYERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/ModuleBlink.ktKotlin · 187 lines · 6.7 KB

Makes it look as if you were teleporting to other players.

SettingsDirectionsDummyAmbushAutoDisableResetAfterResetAction
ModuleBlink.ktKotlin · Minecraft 26.2 · 187 lines · 6.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
20
21
import net.ccbluex.liquidbounce.config.types.group.ToggleableValueGroup
22
import net.ccbluex.liquidbounce.config.types.list.Tagged
23
import net.ccbluex.liquidbounce.event.events.BlinkPacketEvent
24
import net.ccbluex.liquidbounce.event.events.NotificationEvent
25
import net.ccbluex.liquidbounce.event.events.PacketEvent
26
import net.ccbluex.liquidbounce.event.events.PlayerMovementTickEvent
27
import net.ccbluex.liquidbounce.event.events.TransferOrigin
28
import net.ccbluex.liquidbounce.event.handler
29
import net.ccbluex.liquidbounce.event.tickHandler
30
import net.ccbluex.liquidbounce.features.blink.BlinkManager
31
import net.ccbluex.liquidbounce.features.blink.BlinkManager.Action
32
import net.ccbluex.liquidbounce.features.blink.BlinkManager.positions
33
import net.ccbluex.liquidbounce.features.module.ClientModule
34
import net.ccbluex.liquidbounce.features.module.ModuleCategories
35
import net.ccbluex.liquidbounce.features.module.modules.movement.autododge.ModuleAutoDodge
36
import net.ccbluex.liquidbounce.features.module.modules.player.ModuleBlink.dummyPlayer
37
import net.ccbluex.liquidbounce.utils.client.notification
38
import net.ccbluex.liquidbounce.utils.kotlin.EventPriorityConvention
39
import net.ccbluex.liquidbounce.utils.world.nextLocalEntityId
40
import net.minecraft.client.player.RemotePlayer
41
import net.minecraft.network.protocol.game.ServerboundAttackPacket
42
import net.minecraft.network.protocol.game.ServerboundInteractPacket
43
import net.minecraft.network.protocol.game.ServerboundSpectatorActionPacket
44
import net.minecraft.world.entity.Entity
45
import net.minecraft.world.level.entity.EntityLookup
46
import java.util.UUID
47
48
/**
49
 * Blink module
50
 *
51
 * Suspends packets before they are sent to/received from the server.
52
 */
53
54
object ModuleBlink : ClientModule("Blink", ModuleCategories.PLAYER) {
55
56
    private val directions by multiEnumChoice("Directions", TransferOrigin.OUTGOING, canBeNone = false)
57
58
    private val dummy by boolean("Dummy", false)
59
    private val ambush by boolean("Ambush", false)
60
    private val autoDisable by boolean("AutoDisable", true)
61
62
    private object AutoResetOption : ToggleableValueGroup(this, "AutoReset", false) {
63
        val resetAfter by int("ResetAfter", 100, 1..1000)
64
        val action by enumChoice("ResetAction", ResetAction.RESET)
65
    }
66
67
    private var dummyPlayer: RemotePlayer? = null
68
    private var tickCounter = 0
69
70
    init {
71
        tree(AutoResetOption)
72
    }
73
74
    override fun onEnabled() {
75
        tickCounter = 0
76
        if (dummy) {
77
            val clone = RemotePlayer(world, player.gameProfile)
78
79
            clone.yHeadRot = player.yHeadRot
80
            clone.copyPosition(player)
81
            /**
82
             * A different UUID has to be set, to avoid [dummyPlayer] from being invisible to [player]
83
             * @see EntityLookup.add
84
             */
85
            clone.setUUID(UUID.randomUUID())
86
            clone.id = world.nextLocalEntityId()
87
            world.addEntity(clone)
88
89
            dummyPlayer = clone
90
        }
91
    }
92
93
    override fun onDisabled() {
94
        directions.forEach { BlinkManager.flush(it) }
95
        removeClone()
96
    }
97
98
    private fun removeClone() {
99
        val clone = dummyPlayer ?: return
100
101
        world.removeEntity(clone.id, Entity.RemovalReason.DISCARDED)
102
        dummyPlayer = null
103
    }
104
105
    val packetHandler = handler<PacketEvent>(priority = EventPriorityConvention.MODEL_STATE) { event ->
106
        val packet = event.packet
107
108
        if (event.isCancelled || !directions.contains(event.origin)) {
109
            return@handler
110
        }
111
112
        if (ambush &&
113
            (packet is ServerboundInteractPacket
114
                || packet is ServerboundAttackPacket
115
                || packet is ServerboundSpectatorActionPacket)) {
116
            enabled = false
117
            return@handler
118
        }
119
    }
120
121
    @Suppress("unused")
122
    private val tickTask = tickHandler {
123
        if (ModuleAutoDodge.enabled) {
124
            val playerPosition = positions.firstOrNull() ?: return@tickHandler
125
126
            if (ModuleAutoDodge.getInflictedHit(playerPosition) == null) {
127
                return@tickHandler
128
            }
129
130
            val evadingPacket = ModuleAutoDodge.findAvoidingArrowPosition()
131
132
            // We have found no packet that avoids getting hit? Then we default to blinking.
133
            // AutoDoge might save the situation...
134
            if (evadingPacket == null) {
135
                notification(
136
                    "Blink", "Unable to evade arrow. Blinking.",
137
                    NotificationEvent.Severity.INFO
138
                )
139
                enabled = false
140
            } else if (evadingPacket.ticksToImpact != null) {
141
                notification("Blink", "Trying to evade arrow...", NotificationEvent.Severity.INFO)
142
                BlinkManager.flush(evadingPacket.idx + 1)
143
            } else {
144
                notification("Blink", "Arrow evaded.", NotificationEvent.Severity.INFO)
145
                BlinkManager.flush(evadingPacket.idx + 1)
146
            }
147
        }
148
    }
149
150
    @Suppress("unused")
151
    private val playerMoveHandler = handler<PlayerMovementTickEvent> {
152
        tickCounter++
153
154
        if (AutoResetOption.enabled && tickCounter > AutoResetOption.resetAfter) {
155
            tickCounter = 0
156
            when (AutoResetOption.action) {
157
                ResetAction.RESET -> BlinkManager.cancel()
158
                ResetAction.BLINK -> {
159
                    directions.forEach { BlinkManager.flush(it) }
160
                    dummyPlayer?.copyPosition(player)
161
                }
162
            }
163
164
            notification("Blink", "Auto reset", NotificationEvent.Severity.INFO)
165
            if (autoDisable) {
166
                enabled = false
167
            }
168
        }
169
    }
170
171
    @Suppress("unused")
172
    private val fakeLagHandler = handler<BlinkPacketEvent> { event ->
173
        if (directions.contains(event.origin)) {
174
            event.action = Action.QUEUE
175
        }
176
    }
177
178
    enum class ResetAction(override val tag: String) : Tagged {
179
        RESET("Reset"),
180
        BLINK("Blink");
181
    }
182
183
    fun isDummyPlayer(entityId: Int): Boolean {
184
        return entityId == dummyPlayer?.id
185
    }
186
}
187