AntiAFK module

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

4 implementationsMISCMovementPLAYER

Full module source: 4 implementations

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

MelaHack (ThunderHack fork)MISCsrc/main/java/thunder/hack/features/modules/misc/AntiAFK.javaJava · 137 lines · 5.1 KB

Allows you to avoid being kicked for AFK.

SettingsModeOnlyWhenAFKCommandMoveSpinRotateSpeedJumpSwingAlwaysSneakRadius
AntiAFK.javaJava · Minecraft 26.2 · 137 lines · 5.1 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.misc;
2
3
import meteordevelopment.orbit.EventHandler;
4
import meteordevelopment.orbit.EventPriority;
5
import thunder.hack.core.Managers;
6
import thunder.hack.events.impl.EventKeyboardInput;
7
import thunder.hack.events.impl.EventSetting;
8
import thunder.hack.events.impl.PlayerUpdateEvent;
9
import thunder.hack.features.modules.Module;
10
import thunder.hack.setting.Setting;
11
import thunder.hack.utility.Timer;
12
import thunder.hack.utility.player.MovementUtility;
13
14
import java.util.concurrent.ThreadLocalRandom;
15
16
public class AntiAFK extends Module {
17
    public AntiAFK() {
18
        super("AntiAFK", Category.MISC);
19
    }
20
21
    private final Setting<Mode> mode = new Setting<>("Mode", Mode.Simple);
22
    private final Setting<Boolean> onlyWhenAfk = new Setting<>("OnlyWhenAFK", false);
23
    private final Setting<Boolean> command = new Setting<>("Command", false, v -> mode.getValue() == Mode.Simple);
24
    private final Setting<Boolean> move = new Setting<>("Move", false, v -> mode.getValue() == Mode.Simple);
25
    private final Setting<Boolean> spin = new Setting<>("Spin", false, v -> mode.getValue() == Mode.Simple);
26
    private final Setting<Float> rotateSpeed = new Setting<>("RotateSpeed", 5f, 1f, 7f, v -> mode.getValue() == Mode.Simple);
27
    private final Setting<Boolean> jump = new Setting<>("Jump", false, v -> mode.getValue() == Mode.Simple);
28
    private final Setting<Boolean> swing = new Setting<>("Swing", false, v -> mode.getValue() == Mode.Simple);
29
    private final Setting<Boolean> alwayssneak = new Setting<>("AlwaysSneak", false, v -> mode.getValue() == Mode.Simple);
30
    private final Setting<Integer> radius = new Setting<>("Radius", 64, 1, 128, v -> mode.getValue() == Mode.Baritone);
31
32
    private int step;
33
    private Timer inactiveTime = new Timer();
34
35
    private enum Mode {
36
        Simple, Baritone
37
    }
38
39
    @Override
40
    public void onEnable() {
41
        if (alwayssneak.getValue())
42
            mc.options.keyShift.setDown(true);
43
44
        step = 0;
45
    }
46
47
    @EventHandler
48
    public void onSettingChange(EventSetting e) {
49
        if (e.getSetting() == mode)
50
            step = 0;
51
    }
52
53
    @EventHandler
54
    @SuppressWarnings("unused")
55
    public void onKeyboardInput(EventKeyboardInput e) {
56
        if (mc.player != null && mode.is(Mode.Simple) && !MovementUtility.isMoving() && move.getValue() && isAfk()) {
57
            float angleToRad = (float) Math.toRadians(9 * (mc.player.tickCount % 40));
58
59
            float sin = (float) Math.clamp(Math.sin(angleToRad), -1, 1);
60
            float cos = (float) Math.clamp(Math.cos(angleToRad), -1, 1);
61
62
            MovementUtility.setMovementInput((float) Math.round(cos), (float) Math.round(sin));
63
        }
64
    }
65
66
    @EventHandler(priority = EventPriority.LOW)
67
    public void onUpdate(PlayerUpdateEvent e) {
68
        if (mode.is(Mode.Simple) ? isActive() : Managers.PLAYER.currentPlayerSpeed > 0.07)
69
            inactiveTime.reset();
70
71
        if (mode.getValue() == Mode.Simple) {
72
            if(!isAfk()) return;
73
74
            if(move.getValue())
75
                mc.player.setSprinting(false);
76
77
            if (spin.getValue()) {
78
                double gcdFix = (Math.pow(mc.options.sensitivity().get() * 0.6 + 0.2, 3.0)) * 1.2;
79
                float newYaw = mc.player.getYRot() + rotateSpeed.getValue();
80
                mc.player.setYRot((float) (newYaw - (newYaw - mc.player.getYRot()) % gcdFix));
81
            }
82
83
            if (jump.getValue() && mc.player.onGround())
84
                mc.player.jumpFromGround();
85
86
            if (swing.getValue() && ThreadLocalRandom.current().nextInt(99) == 0)
87
                mc.player.swing(mc.player.getUsedItemHand());
88
89
            if (command.getValue() && ThreadLocalRandom.current().nextInt(99) == 0)
90
                mc.player.connection.sendCommand("qwerty");
91
92
        } else {
93
            if (inactiveTime.every(5000)) {
94
                if (step > 3)
95
                    step = 0;
96
97
                switch (step) {
98
                    case 0: {
99
                        mc.player.connection.sendChat("#goto ~ ~" + radius.getValue());
100
                        break;
101
                    }
102
                    case 1: {
103
                        mc.player.connection.sendChat("#goto ~" + radius.getValue() + " ~");
104
                        break;
105
                    }
106
                    case 2: {
107
                        mc.player.connection.sendChat("#goto ~ ~-" + radius.getValue());
108
                        break;
109
                    }
110
                    case 3: {
111
                        mc.player.connection.sendChat("#goto ~-" + radius.getValue() + " ~");
112
                        break;
113
                    }
114
                }
115
                step++;
116
            }
117
        }
118
    }
119
120
    @Override
121
    public void onDisable() {
122
        if (alwayssneak.getValue())
123
            mc.options.keyShift.setDown(false);
124
125
        if (mode.getValue() == Mode.Baritone)
126
            mc.player.connection.sendChat("#stop");
127
    }
128
129
    private boolean isAfk() {
130
        return !onlyWhenAfk.getValue() || inactiveTime.passedS(10);
131
    }
132
133
    private boolean isActive() {
134
        return mc.options.keyUp.isDown() || mc.options.keyLeft.isDown() || mc.options.keyRight.isDown() || mc.options.keyDown.isDown();
135
    }
136
}
137
OfflineClientMISCsrc/main/java/com/jellypudding/offlineclient/modules/misc/AntiAfk.javaJava · 406 lines · 14.5 KB

Keeps you from being kicked for idling.

SettingsIntervalUse AIAI rangeWalk rangeWait timeWait spreadShow wait timeJumpSwingSneakSneak timeStrafeTurnSpeedPitchSend messagesMessage delay
AntiAfk.javaJava · Minecraft 26.2 · 406 lines · 14.5 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.misc;
2
3
import com.jellypudding.offlineclient.event.Subscribe;
4
import com.jellypudding.offlineclient.event.events.TickEvent;
5
import com.jellypudding.offlineclient.module.Category;
6
import com.jellypudding.offlineclient.module.Module;
7
import com.jellypudding.offlineclient.modules.movement.Jesus;
8
import com.jellypudding.offlineclient.path.PathFinder;
9
import com.jellypudding.offlineclient.path.PathGoal;
10
import com.jellypudding.offlineclient.path.PathWalker;
11
import com.jellypudding.offlineclient.setting.BoolSetting;
12
import com.jellypudding.offlineclient.setting.EnumSetting;
13
import com.jellypudding.offlineclient.setting.NumberSetting;
14
import com.jellypudding.offlineclient.util.ChatUtil;
15
import com.jellypudding.offlineclient.util.InputUtil;
16
import com.jellypudding.offlineclient.util.Modules;
17
import com.jellypudding.offlineclient.util.RotationManager;
18
import com.jellypudding.offlineclient.util.RotationPriority;
19
import com.jellypudding.offlineclient.util.TextLines;
20
import net.minecraft.core.BlockPos;
21
import net.minecraft.util.Mth;
22
import net.minecraft.world.InteractionHand;
23
import net.minecraft.world.phys.Vec3;
24
25
import java.util.concurrent.ThreadLocalRandom;
26
27
public final class AntiAfk extends Module {
28
29
    // Ticks between each change of strafe direction.
30
    private static final int STRAFE_TICKS = 20;
31
32
    // How close a plain walk gets before it counts as there.
33
    private static final double WALK_ARRIVED = 0.5;
34
35
    private static final int TICKS_PER_SECOND = 20;
36
37
    public enum Turn { NONE, NUDGE, SPIN, SPIN_VIEW }
38
39
    private final NumberSetting interval = new NumberSetting("Interval",
40
        "Average seconds between hops and swings and crouches. Each one fires at a random moment.",
41
        5, 1, 60, 1, "s").min(1);
42
    private final BoolSetting useAi = new BoolSetting("Use AI",
43
        "Finds a path to each random spot instead of walking straight at it.", false);
44
    private final NumberSetting aiRange = new NumberSetting("AI range",
45
        "How far from where you started the random goals may be.", 16, 1, 64, 1, " blocks")
46
        .min(1).max(128).under(useAi);
47
    private final NumberSetting walkRange = new NumberSetting("Walk range",
48
        "How far from where you started the plain walks go. One is a shuffle on the spot.",
49
        1, 1, 64, 1, " blocks").min(1).max(128).unless(useAi);
50
    private final NumberSetting waitTime = new NumberSetting("Wait time",
51
        "Seconds of standing still between one walk and the next.", 2.5, 0, 60, 0.5, "s").min(0);
52
    private final NumberSetting waitSpread = new NumberSetting("Wait spread",
53
        "Random seconds taken off or added to each wait.", 0.5, 0, 60, 0.5, "s").min(0);
54
    private final BoolSetting showWait = new BoolSetting("Show wait time",
55
        "Shows the seconds left until the next walk after the name.", true);
56
    private final BoolSetting jump = new BoolSetting("Jump",
57
        "Hops on the spot.", true);
58
    private final BoolSetting swing = new BoolSetting("Swing",
59
        "Swings your arm.", false);
60
    private final BoolSetting sneak = new BoolSetting("Sneak",
61
        "Crouches for a moment and stands up again.", false);
62
    private final NumberSetting sneakTime = new NumberSetting("Sneak time",
63
        "How many ticks each crouch lasts.", 5, 1, 20, 1, " ticks").min(1)
64
        .under(sneak);
65
    private final BoolSetting strafe = new BoolSetting("Strafe",
66
        "Steps left and right on the spot.", false);
67
    private final EnumSetting<Turn> turn = new EnumSetting<>("Turn",
68
        "How your head moves.", Turn.SPIN)
69
        .describe(Turn.NONE, "Your head stays where it is.")
70
        .describe(Turn.NUDGE, "Turns your view a little every now and then.")
71
        .describe(Turn.SPIN, "Spins you round for everyone else whilst your own view stays still.")
72
        .describe(Turn.SPIN_VIEW, "Spins your own view round and round. The plain walk stops whilst this is on.");
73
    private final NumberSetting speed = new NumberSetting("Speed",
74
        "Degrees turned each tick.", 7, 1, 45, 1, " degrees").min(1).max(180)
75
        .under(turn, Turn.SPIN, Turn.SPIN_VIEW);
76
    private final NumberSetting pitch = new NumberSetting("Pitch",
77
        "How far up or down the spin looks for everyone else.", 0, -90, 90, 1, " degrees")
78
        .under(turn, Turn.SPIN);
79
    private final BoolSetting sendMessages = new BoolSetting("Send messages",
80
        "Sends chat lines on a timer.", false);
81
    private final NumberSetting messageDelay = new NumberSetting("Message delay",
82
        "Seconds between messages.", 15, 1, 30, 1, "s").min(1).max(600)
83
        .under(sendMessages);
84
    private final TextLines lines = new TextLines("Messages",
85
        "How many lines to rotate through.", "I am still here", "Just standing about")
86
        .under(sendMessages);
87
88
    private int sneakTimer;
89
    private boolean crouching;
90
    private int strafeTimer;
91
    private boolean strafeLeft;
92
    private boolean strafing;
93
    private float spinYaw;
94
    private int messageTimer;
95
96
    private final PathFinder finder = new PathFinder();
97
    // An idle wander should not burn hunger.
98
    private final PathWalker walker = new PathWalker().sprint(false);
99
    private BlockPos home;
100
    private int waitTicks;
101
    // Where the plain walk is heading or null whilst it rests.
102
    private Vec3 walkTarget;
103
    private boolean walking;
104
    private boolean surfacing;
105
    // Creative flight as it was on enable. A wander must not drop a flying player.
106
    private boolean creativeFlight;
107
108
    public AntiAfk() {
109
        super("AntiAFK", "Keeps you from being kicked for idling.", Category.MISC);
110
        addSettings(interval, useAi, aiRange, walkRange, waitTime, waitSpread, showWait, jump, swing,
111
            sneak, sneakTime, strafe, turn, speed, pitch, sendMessages, messageDelay);
112
        addSettings(lines.settings());
113
        searchTags("afk", "idle", "away", "wander");
114
    }
115
116
    @Override
117
    public String getSuffix() {
118
        if (!showWait.isOn() || wandering() || waitTicks <= 0) {
119
            return null;
120
        }
121
        return String.format("%.1fs", waitTicks / (double) TICKS_PER_SECOND);
122
    }
123
124
    @Override
125
    protected void onEnable() {
126
        sneakTimer = 0;
127
        strafeTimer = 0;
128
        strafeLeft = false;
129
        messageTimer = messageDelay.getInt() * TICKS_PER_SECOND;
130
        waitTicks = nextWait();
131
        home = null;
132
        walkTarget = null;
133
        lines.restart();
134
        if (inGame()) {
135
            spinYaw = mc.player.getYRot();
136
            home = mc.player.blockPosition();
137
            creativeFlight = mc.player.getAbilities().flying;
138
        }
139
        if (sendMessages.isOn() && lines.isEmpty()) {
140
            ChatUtil.error("No message lines are filled in so messages are switched off.");
141
            sendMessages.setValue(false);
142
        }
143
    }
144
145
    @Override
146
    protected void onDisable() {
147
        stopStrafe();
148
        standUp();
149
        stopWander();
150
    }
151
152
    @Subscribe
153
    private void onTick(TickEvent event) {
154
        if (!inGame()) {
155
            return;
156
        }
157
        if (mc.player.isDeadOrDying()) {
158
            setEnabled(false);
159
            return;
160
        }
161
        if (creativeFlight && mc.player.getAbilities().mayfly) {
162
            mc.player.getAbilities().flying = true;
163
        }
164
        if (jump.isOn() && mc.player.onGround() && chance()) {
165
            mc.player.jumpFromGround();
166
        }
167
        if (swing.isOn() && chance()) {
168
            mc.player.swing(InteractionHand.MAIN_HAND);
169
        }
170
        tickWander();
171
        tickSneak();
172
        tickStrafe();
173
        tickTurn();
174
        tickMessages();
175
    }
176
177
    // Either walk waits between goals. The wait is the same for both.
178
    private void tickWander() {
179
        if (home == null) {
180
            home = mc.player.blockPosition();
181
        }
182
        if (useAi.isOn()) {
183
            tickPathWander();
184
        } else {
185
            tickPlainWalk();
186
        }
187
    }
188
189
    // Walks to a random spot round the one the module was switched on at.
190
    // Falling and diving are off. A wander cannot end somewhere nasty.
191
    private void tickPathWander() {
192
        stopPlainWalk();
193
        if (surface()) {
194
            return;
195
        }
196
        PathFinder.Result result = finder.poll();
197
        if (result != null) {
198
            walker.follow(result.nodes());
199
        }
200
        if (finder.busy()) {
201
            return;
202
        }
203
        if (walker.arrived() || walker.lost()) {
204
            walker.releaseKeys();
205
            walking = false;
206
            if (waitTicks-- > 0) {
207
                return;
208
            }
209
            waitTicks = nextWait();
210
            walking = true;
211
            pickGoal();
212
            return;
213
        }
214
        // The Turn setting owns the view. The walker steers with the keys.
215
        walker.turn(PathWalker.Turn.NONE);
216
        walker.tick(finder.liveRules());
217
    }
218
219
    private void pickGoal() {
220
        int reach = aiRange.getInt();
221
        ThreadLocalRandom random = ThreadLocalRandom.current();
222
        BlockPos spot = home.offset(random.nextInt(-reach, reach + 1), 0,
223
            random.nextInt(-reach, reach + 1));
224
        finder.maxFall(0).swim(false)
225
            .search(PathFinder.standingAt(mc.player), new PathGoal.Around(spot, 2));
226
    }
227
228
    // Under water the wander holds jump until the head is out. Jesus keeps you up anyway.
229
    private boolean surface() {
230
        if (mc.player.isUnderWater() && !Modules.enabled(Jesus.class)) {
231
            walker.releaseKeys();
232
            InputUtil.hold(mc.options.keyJump);
233
            surfacing = true;
234
            return true;
235
        }
236
        if (surfacing) {
237
            InputUtil.release(mc.options.keyJump);
238
            surfacing = false;
239
        }
240
        return false;
241
    }
242
243
    // Turns to a random spot and holds forward until it is reached.
244
    private void tickPlainWalk() {
245
        finder.cancel();
246
        walker.stop();
247
        if (turn.is(Turn.SPIN_VIEW)) {
248
            stopPlainWalk();
249
            return;
250
        }
251
        if (walkTarget == null) {
252
            if (waitTicks-- > 0) {
253
                return;
254
            }
255
            waitTicks = nextWait();
256
            int reach = walkRange.getInt();
257
            ThreadLocalRandom random = ThreadLocalRandom.current();
258
            walkTarget = new Vec3(home.getX() + 0.5 + random.nextInt(-reach, reach + 1),
259
                mc.player.getY(), home.getZ() + 0.5 + random.nextInt(-reach, reach + 1));
260
        }
261
        double dx = walkTarget.x - mc.player.getX();
262
        double dz = walkTarget.z - mc.player.getZ();
263
        if (dx * dx + dz * dz <= WALK_ARRIVED * WALK_ARRIVED) {
264
            stopPlainWalk();
265
            return;
266
        }
267
        walking = true;
268
        mc.player.setYRot(RotationManager.yawTo(walkTarget));
269
        InputUtil.hold(mc.options.keyUp);
270
        if (mc.player.isInWater()) {
271
            InputUtil.hold(mc.options.keyJump);
272
        } else {
273
            InputUtil.release(mc.options.keyJump);
274
        }
275
    }
276
277
    private void stopPlainWalk() {
278
        if (walking) {
279
            InputUtil.release(mc.options.keyUp);
280
            InputUtil.release(mc.options.keyJump);
281
        }
282
        walking = false;
283
        walkTarget = null;
284
    }
285
286
    private void stopWander() {
287
        finder.cancel();
288
        walker.stop();
289
        stopPlainWalk();
290
        if (surfacing) {
291
            InputUtil.release(mc.options.keyJump);
292
            surfacing = false;
293
        }
294
    }
295
296
    // Ticks to rest before the next walk. The spread keeps the rhythm uneven.
297
    private int nextWait() {
298
        double spread = waitSpread.getValue();
299
        double seconds = waitTime.getValue()
300
            + (spread > 0 ? ThreadLocalRandom.current().nextDouble(-spread, spread) : 0);
301
        return (int) Math.round(Math.max(0, seconds) * TICKS_PER_SECOND);
302
    }
303
304
    // True whilst a walk of either kind is driving the movement keys.
305
    private boolean wandering() {
306
        return walking || surfacing;
307
    }
308
309
    // Holds the crouch for the set ticks then waits a random moment before the next.
310
    private void tickSneak() {
311
        if (!sneak.isOn() || wandering()) {
312
            standUp();
313
            return;
314
        }
315
        if (sneakTimer < sneakTime.getInt()) {
316
            sneakTimer++;
317
            InputUtil.hold(mc.options.keyShift);
318
            crouching = true;
319
            return;
320
        }
321
        standUp();
322
        if (chance()) {
323
            sneakTimer = 0;
324
        }
325
    }
326
327
    private void standUp() {
328
        if (crouching) {
329
            InputUtil.release(mc.options.keyShift);
330
            crouching = false;
331
        }
332
    }
333
334
    private void tickStrafe() {
335
        if (!strafe.isOn() || wandering()) {
336
            stopStrafe();
337
            return;
338
        }
339
        if (strafeTimer-- > 0) {
340
            return;
341
        }
342
        strafeTimer = STRAFE_TICKS;
343
        strafeLeft = !strafeLeft;
344
        strafing = true;
345
        if (strafeLeft) {
346
            InputUtil.release(mc.options.keyRight);
347
            InputUtil.hold(mc.options.keyLeft);
348
        } else {
349
            InputUtil.release(mc.options.keyLeft);
350
            InputUtil.hold(mc.options.keyRight);
351
        }
352
    }
353
354
    private void stopStrafe() {
355
        if (strafing) {
356
            InputUtil.release(mc.options.keyLeft);
357
            InputUtil.release(mc.options.keyRight);
358
            strafing = false;
359
        }
360
        strafeTimer = 0;
361
    }
362
363
    private void tickTurn() {
364
        switch (turn.getValue()) {
365
            case NONE -> {
366
            }
367
            case NUDGE -> {
368
                if (chance()) {
369
                    // The vanilla turn keeps the last frame in step. A raw set snaps.
370
                    float delta = ThreadLocalRandom.current().nextFloat(-15f, 15f);
371
                    mc.player.turn(delta / InputUtil.MOUSE_TURN, 0);
372
                }
373
            }
374
            case SPIN -> {
375
                spinYaw = Mth.wrapDegrees(spinYaw + speed.getFloat());
376
                RotationManager.requestExact(spinYaw, pitch.getFloat(), RotationPriority.IDLE);
377
            }
378
            case SPIN_VIEW -> mc.player.turn(speed.getFloat() / InputUtil.MOUSE_TURN, 0);
379
        }
380
    }
381
382
    private void tickMessages() {
383
        if (!sendMessages.isOn() || mc.getConnection() == null) {
384
            return;
385
        }
386
        if (messageTimer-- > 0) {
387
            return;
388
        }
389
        messageTimer = messageDelay.getInt() * TICKS_PER_SECOND;
390
        String text = lines.pick();
391
        if (text == null) {
392
            return;
393
        }
394
        if (text.startsWith("/")) {
395
            mc.getConnection().sendCommand(text.substring(1));
396
        } else {
397
            mc.getConnection().sendChat(text);
398
        }
399
    }
400
401
    // Fires once every interval on average.
402
    private boolean chance() {
403
        return ThreadLocalRandom.current().nextInt(interval.getInt() * TICKS_PER_SECOND) == 0;
404
    }
405
}
406
NicotineMovementsrc/client/java/nicotine/mod/mods/movement/AntiAFK.javaJava · 88 lines · 2.6 KB
SettingsMoveJumpLookSwing
AntiAFK.javaJava · Minecraft 26.3 · 88 lines · 2.6 KB · complete file, verbatimOriginal ↗
1
package nicotine.mod.mods.movement;
2
3
import net.minecraft.client.KeyMapping;
4
import net.minecraft.world.InteractionHand;
5
import net.minecraft.world.item.component.SwingAnimation;
6
import nicotine.events.ClientLevelTickEvent;
7
import nicotine.mod.Mod;
8
import nicotine.mod.ModCategory;
9
import nicotine.mod.ModManager;
10
import nicotine.mod.option.ToggleOption;
11
import nicotine.util.EventBus;
12
13
import java.util.Arrays;
14
import java.util.Random;
15
16
import static nicotine.util.Common.mc;
17
18
public class AntiAFK extends Mod {
19
    private int ticks = 0;
20
    private KeyMapping randomMovementKeybind = null;
21
22
    private final ToggleOption move = new ToggleOption("Move");
23
    private final ToggleOption jump = new ToggleOption("Jump");
24
    private final ToggleOption look = new ToggleOption("Look");
25
    private final ToggleOption swing = new ToggleOption("Swing");
26
27
    public AntiAFK() {
28
        super(ModCategory.Movement, "AntiAFK");
29
        this.addOptions(Arrays.asList(move, jump, look, swing));
30
    }
31
32
    @Override
33
    public void toggle() {
34
        this.enabled = !this.enabled;
35
36
        if (!this.enabled && randomMovementKeybind != null) {
37
            randomMovementKeybind.setDown(false);
38
            ticks = 0;
39
        }
40
    }
41
42
    @Override
43
    protected void init() {
44
        final KeyMapping[] movementKeybinds =  new KeyMapping[]{
45
                mc.options.keyUp,
46
                mc.options.keyDown,
47
                mc.options.keyLeft,
48
                mc.options.keyRight,
49
        };
50
51
        EventBus.register(ClientLevelTickEvent.class, event -> {
52
            if (!this.enabled)
53
                return true;
54
55
            if (ticks == 0) {
56
                Random random = new Random();
57
58
                if (randomMovementKeybind != null)
59
                    randomMovementKeybind.setDown(false);
60
61
                if (move.enabled && random.nextBoolean()) {
62
                    randomMovementKeybind = movementKeybinds[random.nextInt(movementKeybinds.length)];
63
                    randomMovementKeybind.setDown(true);
64
                }
65
66
                if (jump.enabled && random.nextBoolean()) {
67
                    mc.player.jumpFromGround();
68
                }
69
70
                if (swing.enabled && random.nextBoolean()) {
71
                    mc.player.swing(InteractionHand.MAIN_HAND, SwingAnimation.DEFAULT, true);
72
                }
73
74
                if (look.enabled && random.nextBoolean()) {
75
                   mc.player.setYRot(random.nextFloat(360));
76
                }
77
78
79
                ticks = 60 + random.nextInt(30);
80
            }
81
82
            ticks--;
83
84
            return true;
85
        });
86
    }
87
}
88
LiquidBounce (Kotlin)PLAYERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/ModuleAntiAFK.ktKotlin · 198 lines · 6.8 KB

Prevents you from being kicked for being AFK.

SettingsInteractionDelayIgnoreOpenInventoryAngleJumpMove
ModuleAntiAFK.ktKotlin · Minecraft 26.2 · 198 lines · 6.8 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.Mode
22
import net.ccbluex.liquidbounce.config.types.group.ModeValueGroup
23
import net.ccbluex.liquidbounce.config.types.group.ToggleableValueGroup
24
import net.ccbluex.liquidbounce.config.types.list.Tagged
25
import net.ccbluex.liquidbounce.event.events.MovementInputEvent
26
import net.ccbluex.liquidbounce.event.handler
27
import net.ccbluex.liquidbounce.event.once
28
import net.ccbluex.liquidbounce.event.tickHandler
29
import net.ccbluex.liquidbounce.event.waitTicks
30
import net.ccbluex.liquidbounce.features.module.ClientModule
31
import net.ccbluex.liquidbounce.features.module.ModuleCategories
32
import net.ccbluex.liquidbounce.features.module.modules.player.ModuleAntiAFK.CustomMode.Rotate.angle
33
import net.ccbluex.liquidbounce.features.module.modules.player.ModuleAntiAFK.CustomMode.Rotate.ignoreOpenInventory
34
import net.ccbluex.liquidbounce.features.module.modules.player.ModuleAntiAFK.CustomMode.Rotate.rotations
35
import net.ccbluex.liquidbounce.utils.aiming.RotationManager
36
import net.ccbluex.liquidbounce.utils.aiming.RotationsValueGroup
37
import net.ccbluex.liquidbounce.utils.aiming.data.Rotation
38
import net.ccbluex.liquidbounce.utils.kotlin.Priority
39
import net.ccbluex.liquidbounce.utils.kotlin.random
40
import net.ccbluex.liquidbounce.utils.movement.DirectionalInput
41
import net.minecraft.world.InteractionHand
42
import kotlin.random.Random
43
44
/**
45
 * AntiAFK module
46
 *
47
 * Prevents you from being kicked for AFK.
48
 */
49
50
object ModuleAntiAFK : ClientModule("AntiAFK", ModuleCategories.PLAYER) {
51
    private val modes = choices(
52
        "Mode", RandomInteraction, arrayOf(
53
            OldMode, RandomInteraction, CustomMode
54
        )
55
    )
56
57
    private object OldMode : Mode("Old") {
58
        override val parent: ModeValueGroup<Mode>
59
            get() = modes
60
61
        @Suppress("unused")
62
        val repeatable = tickHandler {
63
            waitTicks(10)
64
            player.yRot += 180f
65
        }
66
67
        @Suppress("unused")
68
        val movementInputEvent = handler<MovementInputEvent> {
69
            it.directionalInput = it.directionalInput.copy(
70
                forwards = true
71
            )
72
        }
73
74
    }
75
76
    private object RandomInteraction : Mode("RandomInteraction") {
77
        override val parent: ModeValueGroup<Mode>
78
            get() = modes
79
80
        var randomDirection = DirectionalInput.NONE
81
82
        private val interactions by multiEnumChoice("Interaction",
83
            Interaction.YAW,
84
            Interaction.PITCH,
85
            Interaction.SWING_HAND,
86
        )
87
88
        private val delay by intRange("Delay", 4..7, 0..20, suffix = "ticks")
89
90
        @Suppress("unused")
91
        val repeatable = tickHandler {
92
            interactions.randomOrNull()?.let {
93
                it.perform()
94
                waitTicks(delay.random())
95
            }
96
        }
97
98
        @Suppress("unused")
99
        val movementInputEvent = handler<MovementInputEvent> {
100
            it.directionalInput = randomDirection
101
        }
102
103
        @Suppress("unused", "MagicNumber")
104
        private enum class Interaction(
105
            override val tag: String,
106
            val perform: suspend () -> Unit,
107
        ): Tagged {
108
            JUMP("Jump", {
109
                once<MovementInputEvent> { event ->
110
                    event.jump = true
111
                }
112
            }),
113
            SWING_HAND("SwingHand", {
114
                if (!player.swinging) {
115
                    player.swing(InteractionHand.MAIN_HAND)
116
                }
117
            }),
118
            CHANGE_SLOT("ChangeSlot", {
119
                player.inventory.selectedSlot = Random.nextInt(0, 9)
120
            }),
121
            YAW("Yaw", {
122
                player.yRot += (-180f..180f).random()
123
            }),
124
            PITCH("Pitch", {
125
                player.xRot = ((-5f..5f).random() + player.xRot).coerceIn(-90f, 90f)
126
            }),
127
            RANDOM_DIRECTION("RandomDirection", {
128
                randomDirection = DirectionalInput(
129
                    Random.nextBoolean(),
130
                    Random.nextBoolean(),
131
                    Random.nextBoolean(),
132
                    Random.nextBoolean()
133
                )
134
                waitTicks(delay.random())
135
                randomDirection = DirectionalInput.NONE
136
            })
137
        }
138
    }
139
140
    private object CustomMode : Mode("Custom") {
141
        override val parent: ModeValueGroup<Mode>
142
            get() = modes
143
144
145
        private object Rotate : ToggleableValueGroup(ModuleAntiAFK, "Rotate", true) {
146
            val ignoreOpenInventory by boolean("IgnoreOpenInventory", true)
147
            val rotations = tree(RotationsValueGroup(this))
148
            val delay by int("Delay", 5, 0..20, "ticks")
149
            val angle by float("Angle", 1f, -180f..180f)
150
        }
151
152
        private object Swing : ToggleableValueGroup(ModuleAntiAFK, "Swing", true) {
153
            val delay by int("Delay", 5, 0..20, "ticks")
154
        }
155
156
        init {
157
            tree(Rotate)
158
            tree(Swing)
159
        }
160
161
        val jump by boolean("Jump", true)
162
        val move by boolean("Move", true)
163
164
        @Suppress("unused")
165
        val swingRepeatable = tickHandler {
166
            if (Swing.enabled && !player.swinging) {
167
                waitTicks(Swing.delay)
168
                player.swing(InteractionHand.MAIN_HAND)
169
            }
170
        }
171
172
        @Suppress("unused")
173
        val repeatable = tickHandler {
174
            if (move) {
175
                mc.options.keyUp.isDown = true
176
            }
177
178
            if (jump && player.onGround()) {
179
                once<MovementInputEvent> { event ->
180
                    event.jump = true
181
                }
182
            }
183
184
            if (Rotate.enabled) {
185
                waitTicks(Rotate.delay)
186
                val currentRotation = RotationManager.serverRotation
187
                val pitchRandomization = Random.nextDouble(-5.0, 5.0).toFloat()
188
                RotationManager.setRotationTarget(
189
                    Rotation(
190
                        currentRotation.yaw + angle, (currentRotation.pitch + pitchRandomization).coerceIn(-90f, 90f)
191
                    ), ignoreOpenInventory, rotations, Priority.IMPORTANT_FOR_USAGE_1, ModuleAntiAFK
192
                )
193
            }
194
195
        }
196
    }
197
}
198