inventory-tweaks module

inventory-tweaks: Minecraft 26.3 cheat module, full source for every implementation (1 client: Meteor Client).

1 implementationMisc

Clients with this module

Full module source: 1 implementation

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

Meteor ClientMiscsrc/main/java/meteordevelopment/meteorclient/systems/modules/misc/InventoryTweaks.javaJava · 508 lines · 18.2 KB

Various inventory related utilities.

Settingsmouse-drag-item-movexcarryuncap-bundle-scrollingframe-input-handlingsorting-enabledsorting-keysorting-delaydisable-in-creativeanti-drop-itemsitem-framesoverride-bindauto-drop-itemsexclude-equippedexclude-hotbaronly-full-stackssteal-screensinventory-buttonssteal-dropdrop-backwardsdump-filterdump-itemssteal-filtersteal-itemsauto-stealauto-dumpdelayinitial-delayrandom
InventoryTweaks.javaJava · Minecraft 26.2 · 508 lines · 18.2 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.misc;
7
8
import meteordevelopment.meteorclient.MeteorClient;
9
import meteordevelopment.meteorclient.events.entity.DropItemsEvent;
10
import meteordevelopment.meteorclient.events.entity.player.InteractBlockEvent;
11
import meteordevelopment.meteorclient.events.entity.player.InteractEntityEvent;
12
import meteordevelopment.meteorclient.events.game.OpenScreenEvent;
13
import meteordevelopment.meteorclient.events.meteor.KeyInputEvent;
14
import meteordevelopment.meteorclient.events.meteor.MouseClickEvent;
15
import meteordevelopment.meteorclient.events.packets.InventoryEvent;
16
import meteordevelopment.meteorclient.events.packets.PacketEvent;
17
import meteordevelopment.meteorclient.events.world.TickEvent;
18
import meteordevelopment.meteorclient.mixin.AbstractContainerScreenAccessor;
19
import meteordevelopment.meteorclient.settings.*;
20
import meteordevelopment.meteorclient.systems.modules.Categories;
21
import meteordevelopment.meteorclient.systems.modules.Module;
22
import meteordevelopment.meteorclient.utils.Utils;
23
import meteordevelopment.meteorclient.utils.misc.Keybind;
24
import meteordevelopment.meteorclient.utils.misc.input.KeyAction;
25
import meteordevelopment.meteorclient.utils.network.MeteorExecutor;
26
import meteordevelopment.meteorclient.utils.player.*;
27
import meteordevelopment.orbit.EventHandler;
28
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
29
import net.minecraft.network.protocol.game.ServerboundContainerClosePacket;
30
import net.minecraft.world.InteractionHand;
31
import net.minecraft.world.entity.decoration.ItemFrame;
32
import net.minecraft.world.inventory.AbstractContainerMenu;
33
import net.minecraft.world.inventory.MenuType;
34
import net.minecraft.world.inventory.Slot;
35
import net.minecraft.world.item.Item;
36
import net.minecraft.world.item.ItemStack;
37
import net.minecraft.world.level.block.Block;
38
import net.minecraft.world.level.block.DecoratedPotBlock;
39
import com.mojang.blaze3d.platform.InputConstants;
40
41
import java.util.List;
42
import java.util.concurrent.ThreadLocalRandom;
43
44
public class InventoryTweaks extends Module {
45
    private final SettingGroup sgGeneral = settings.getDefaultGroup();
46
    private final SettingGroup sgSorting = settings.createGroup("Sorting");
47
    private final SettingGroup sgAntiDrop = settings.createGroup("Anti Drop");
48
    private final SettingGroup sgAutoDrop = settings.createGroup("Auto Drop");
49
    private final SettingGroup sgStealDump = settings.createGroup("Steal and Dump");
50
    private final SettingGroup sgAutoSteal = settings.createGroup("Auto Steal");
51
52
    // General
53
54
    private final Setting<Boolean> mouseDragItemMove = sgGeneral.add(new BoolSetting.Builder()
55
        .name("mouse-drag-item-move")
56
        .description("Moving mouse over items while holding shift will transfer it to the other container.")
57
        .defaultValue(true)
58
        .build()
59
    );
60
61
    private final Setting<Boolean> xCarry = sgGeneral.add(new BoolSetting.Builder()
62
        .name("xcarry")
63
        .description("Allows you to store four extra item stacks in your crafting grid.")
64
        .defaultValue(true)
65
        .onChanged(v -> {
66
            if (v || !Utils.canUpdate()) return;
67
            mc.player.connection.send(new ServerboundContainerClosePacket(mc.player.inventoryMenu.containerId));
68
            invOpened = false;
69
        })
70
        .build()
71
    );
72
73
    private final Setting<Boolean> uncapBundleScrolling = sgGeneral.add(new BoolSetting.Builder()
74
        .name("uncap-bundle-scrolling")
75
        .description("Whether to uncap the bundle scrolling feature to let you select any item.")
76
        .defaultValue(true)
77
        .build()
78
    );
79
80
    private final Setting<Boolean> frameInput = sgGeneral.add(new BoolSetting.Builder()
81
        .name("frame-input-handling")
82
        .description("Changes input handling to work every frame instead of every tick. A very minor effect but may\n" +
83
            "make inputs feel smoother, especially in laggy environments. Will flag anticheats that check packet order (Grim).")
84
        .defaultValue(false)
85
        .build()
86
    );
87
88
    // Sorting
89
90
    private final Setting<Boolean> sortingEnabled = sgSorting.add(new BoolSetting.Builder()
91
        .name("sorting-enabled")
92
        .description("Automatically sorts stacks in inventory.")
93
        .defaultValue(true)
94
        .build()
95
    );
96
97
    private final Setting<Keybind> sortingKey = sgSorting.add(new KeybindSetting.Builder()
98
        .name("sorting-key")
99
        .description("Key to trigger the sort.")
100
        .visible(sortingEnabled::get)
101
        .defaultValue(Keybind.fromButton(InputConstants.MOUSE_BUTTON_MIDDLE))
102
        .build()
103
    );
104
105
    private final Setting<Integer> sortingDelay = sgSorting.add(new IntSetting.Builder()
106
        .name("sorting-delay")
107
        .description("Delay in ticks between moving items when sorting.")
108
        .visible(sortingEnabled::get)
109
        .defaultValue(1)
110
        .min(0)
111
        .build()
112
    );
113
114
    private final Setting<Boolean> disableInCreative = sgSorting.add(new BoolSetting.Builder()
115
        .name("disable-in-creative")
116
        .description("Disables the inventory sorter when in creative mode.")
117
        .defaultValue(true)
118
        .visible(sortingEnabled::get)
119
        .build()
120
    );
121
122
    // Anti drop
123
124
    private final Setting<List<Item>> antiDropItems = sgAntiDrop.add(new ItemListSetting.Builder()
125
        .name("anti-drop-items")
126
        .description("Items to prevent dropping. Doesn't work in creative inventory screen.")
127
        .build()
128
    );
129
130
    private final Setting<Boolean> antiItemFrame = sgAntiDrop.add(new BoolSetting.Builder()
131
        .name("item-frames")
132
        .description("Prevent anti-drop items from being placed in item frames or pots")
133
        .defaultValue(true)
134
        .build()
135
    );
136
137
    private final Setting<Keybind> antiDropOverrideBind = sgAntiDrop.add(new KeybindSetting.Builder()
138
        .name("override-bind")
139
        .description("Hold this bind to temporarily bypass anti-drop")
140
        .build()
141
    );
142
143
    // Auto Drop
144
145
    private final Setting<List<Item>> autoDropItems = sgAutoDrop.add(new ItemListSetting.Builder()
146
        .name("auto-drop-items")
147
        .description("Items to drop.")
148
        .build()
149
    );
150
151
    private final Setting<Boolean> autoDropExcludeEquipped = sgAutoDrop.add(new BoolSetting.Builder()
152
        .name("exclude-equipped")
153
        .description("Whether or not to drop items equipped in armor slots.")
154
        .defaultValue(true)
155
        .build()
156
    );
157
158
    private final Setting<Boolean> autoDropExcludeHotbar = sgAutoDrop.add(new BoolSetting.Builder()
159
        .name("exclude-hotbar")
160
        .description("Whether or not to drop items from your hotbar.")
161
        .defaultValue(false)
162
        .build()
163
    );
164
165
    private final Setting<Boolean> autoDropOnlyFullStacks = sgAutoDrop.add(new BoolSetting.Builder()
166
        .name("only-full-stacks")
167
        .description("Only drops the items if the stack is full.")
168
        .defaultValue(false)
169
        .build()
170
    );
171
172
    // Steal & Dump
173
174
    public final Setting<List<MenuType<?>>> stealScreens = sgStealDump.add(new ScreenHandlerListSetting.Builder()
175
        .name("steal-screens")
176
        .description("Select the screens to display buttons and auto steal.")
177
        .defaultValue(List.of(MenuType.GENERIC_9x3, MenuType.GENERIC_9x6))
178
        .build()
179
    );
180
181
    private final Setting<Boolean> buttons = sgStealDump.add(new BoolSetting.Builder()
182
        .name("inventory-buttons")
183
        .description("Shows steal and dump buttons in container guis.")
184
        .defaultValue(true)
185
        .build()
186
    );
187
188
    private final Setting<Boolean> stealDrop = sgStealDump.add(new BoolSetting.Builder()
189
        .name("steal-drop")
190
        .description("Drop items to the ground instead of stealing them.")
191
        .defaultValue(false)
192
        .build()
193
    );
194
195
    private final Setting<Boolean> dropBackwards = sgStealDump.add(new BoolSetting.Builder()
196
        .name("drop-backwards")
197
        .description("Drop items behind you.")
198
        .defaultValue(false)
199
        .visible(stealDrop::get)
200
        .build()
201
    );
202
203
    private final Setting<ListMode> dumpFilter = sgStealDump.add(new EnumSetting.Builder<ListMode>()
204
        .name("dump-filter")
205
        .description("Dump mode.")
206
        .defaultValue(ListMode.None)
207
        .build()
208
    );
209
210
    private final Setting<List<Item>> dumpItems = sgStealDump.add(new ItemListSetting.Builder()
211
        .name("dump-items")
212
        .description("Items to dump.")
213
        .build()
214
    );
215
216
    private final Setting<ListMode> stealFilter = sgStealDump.add(new EnumSetting.Builder<ListMode>()
217
        .name("steal-filter")
218
        .description("Steal mode.")
219
        .defaultValue(ListMode.None)
220
        .build()
221
    );
222
223
    private final Setting<List<Item>> stealItems = sgStealDump.add(new ItemListSetting.Builder()
224
        .name("steal-items")
225
        .description("Items to steal.")
226
        .build()
227
    );
228
229
    // Auto Steal
230
231
    private final Setting<Boolean> autoSteal = sgAutoSteal.add(new BoolSetting.Builder()
232
        .name("auto-steal")
233
        .description("Automatically removes all possible items when you open a container.")
234
        .defaultValue(false)
235
        .onChanged(_ -> checkAutoStealSettings())
236
        .build()
237
    );
238
239
    private final Setting<Boolean> autoDump = sgAutoSteal.add(new BoolSetting.Builder()
240
        .name("auto-dump")
241
        .description("Automatically dumps all possible items when you open a container.")
242
        .defaultValue(false)
243
        .onChanged(_ -> checkAutoStealSettings())
244
        .build()
245
    );
246
247
    private final Setting<Integer> autoStealDelay = sgAutoSteal.add(new IntSetting.Builder()
248
        .name("delay")
249
        .description("The minimum delay between stealing the next stack in milliseconds.")
250
        .defaultValue(20)
251
        .sliderMax(1000)
252
        .build()
253
    );
254
255
    private final Setting<Integer> autoStealInitDelay = sgAutoSteal.add(new IntSetting.Builder()
256
        .name("initial-delay")
257
        .description("The initial delay before stealing in milliseconds. 0 to use normal delay instead.")
258
        .defaultValue(50)
259
        .sliderMax(1000)
260
        .build()
261
    );
262
263
    private final Setting<Integer> autoStealRandomDelay = sgAutoSteal.add(new IntSetting.Builder()
264
        .name("random")
265
        .description("Randomly adds a delay of up to the specified time in milliseconds.")
266
        .min(0)
267
        .sliderMax(1000)
268
        .defaultValue(50)
269
        .build()
270
    );
271
272
    private InventorySorter sorter;
273
    private boolean invOpened;
274
275
    public InventoryTweaks() {
276
        super(Categories.Misc, "inventory-tweaks", "Various inventory related utilities.");
277
    }
278
279
    @Override
280
    public void onActivate() {
281
        invOpened = false;
282
    }
283
284
    @Override
285
    public void onDeactivate() {
286
        sorter = null;
287
288
        if (invOpened) {
289
            mc.player.connection.send(new ServerboundContainerClosePacket(mc.player.inventoryMenu.containerId));
290
        }
291
    }
292
293
    // Sorting and armour swapping
294
295
    @EventHandler
296
    private void onKey(KeyInputEvent event) {
297
        if (event.action != KeyAction.Press) return;
298
299
        if (sortingKey.get().matches(event.input)) {
300
            if (sort()) event.cancel();
301
        }
302
    }
303
304
    @EventHandler
305
    private void onMouseClick(MouseClickEvent event) {
306
        if (event.action != KeyAction.Press) return;
307
308
        if (sortingKey.get().matches(event.input)) {
309
            if (sort()) event.cancel();
310
        }
311
    }
312
313
    private boolean sort() {
314
        if (!sortingEnabled.get() || !(mc.gui.screen() instanceof AbstractContainerScreen<?> screen) || sorter != null || (mc.player.isCreative() && disableInCreative.get()))
315
            return false;
316
317
        if (!mc.player.containerMenu.getCarried().isEmpty()) {
318
            FindItemResult empty = InvUtils.findEmpty();
319
            if (!empty.found()) InvUtils.click().slot(-999);
320
            else InvUtils.click().slot(empty.slot());
321
        }
322
323
        Slot focusedSlot = ((AbstractContainerScreenAccessor) screen).meteor$getHoveredSlot();
324
        if (focusedSlot == null) return false;
325
326
        sorter = new InventorySorter(screen, focusedSlot);
327
        return true;
328
    }
329
330
    @EventHandler
331
    private void onOpenScreen(OpenScreenEvent event) {
332
        sorter = null;
333
    }
334
335
    @EventHandler
336
    private void onTickPre(TickEvent.Pre event) {
337
        if (sorter != null && sorter.tick(sortingDelay.get())) sorter = null;
338
    }
339
340
    // Auto Drop
341
342
    @EventHandler
343
    private void onTickPost(TickEvent.Post event) {
344
        // Auto Drop
345
        if (!Utils.canUpdate() || mc.gui.screen() instanceof AbstractContainerScreen<?> || autoDropItems.get().isEmpty())
346
            return;
347
348
        for (int i = autoDropExcludeHotbar.get() ? 9 : 0; i < mc.player.getInventory().getContainerSize(); i++) {
349
            ItemStack itemStack = mc.player.getInventory().getItem(i);
350
351
            if (autoDropItems.get().contains(itemStack.getItem())) {
352
                if ((!autoDropOnlyFullStacks.get() || itemStack.getCount() == itemStack.getMaxStackSize()) &&
353
                    !(autoDropExcludeEquipped.get() && SlotUtils.isArmor(i))) InvUtils.drop().slot(i);
354
            }
355
        }
356
    }
357
358
    // Anti Drop
359
360
    @EventHandler
361
    private void onDropItems(DropItemsEvent event) {
362
        if (antiDropOverrideBind.get().isPressed()) return;
363
        if (antiDropItems.get().contains(event.itemStack.getItem())) event.cancel();
364
    }
365
366
    @EventHandler
367
    private void onInteractEntity(InteractEntityEvent event) {
368
        if (!antiItemFrame.get() || antiDropOverrideBind.get().isPressed()) return;
369
        if (!(event.entity instanceof ItemFrame)) return;
370
371
        Item item = mc.player.getItemInHand(event.hand).getItem();
372
        if (antiDropItems.get().contains(item)) event.cancel();
373
    }
374
375
    @EventHandler
376
    private void onInteractBlock(InteractBlockEvent event) {
377
        if (!antiItemFrame.get() || antiDropOverrideBind.get().isPressed()) return;
378
        if (event.hand != InteractionHand.MAIN_HAND) return;
379
        Block block = mc.level.getBlockState(event.result.getBlockPos()).getBlock();
380
        if (!(block instanceof DecoratedPotBlock)) return;
381
382
        Item item = mc.player.getItemInHand(event.hand).getItem();
383
        if (antiDropItems.get().contains(item)) event.cancel();
384
    }
385
386
    // XCarry
387
388
    @EventHandler
389
    private void onSendPacket(PacketEvent.Send event) {
390
        if (!xCarry.get() || !(event.packet instanceof ServerboundContainerClosePacket packet)) return;
391
392
        if (packet.getContainerId() == mc.player.inventoryMenu.containerId) {
393
            invOpened = true;
394
            event.cancel();
395
        }
396
    }
397
398
    // Auto Steal
399
400
    private void checkAutoStealSettings() {
401
        if (autoSteal.get() && autoDump.get()) {
402
            error("You can't enable Auto Steal and Auto Dump at the same time!");
403
            autoDump.set(false);
404
        }
405
    }
406
407
    private int getSleepTime() {
408
        return autoStealDelay.get() + (autoStealRandomDelay.get() > 0 ? ThreadLocalRandom.current().nextInt(0, autoStealRandomDelay.get()) : 0);
409
    }
410
411
    private void moveSlots(AbstractContainerMenu handler, int start, int end, boolean steal) {
412
        boolean initial = autoStealInitDelay.get() != 0;
413
        for (int i = start; i < end; i++) {
414
            if (!handler.getSlot(i).hasItem()) continue;
415
416
            // Exit if user closes screen or exit world
417
            if (mc.gui.screen() == null || !Utils.canUpdate()) break;
418
419
            Item item = handler.getSlot(i).getItem().getItem();
420
            if (steal) {
421
                if (stealFilter.get() == ListMode.Whitelist && !stealItems.get().contains(item))
422
                    continue;
423
                if (stealFilter.get() == ListMode.Blacklist && stealItems.get().contains(item))
424
                    continue;
425
            } else {
426
                if (dumpFilter.get() == ListMode.Whitelist && !dumpItems.get().contains(item))
427
                    continue;
428
                if (dumpFilter.get() == ListMode.Blacklist && dumpItems.get().contains(item))
429
                    continue;
430
            }
431
432
            int sleep;
433
            if (initial) {
434
                sleep = autoStealInitDelay.get();
435
                initial = false;
436
            } else sleep = getSleepTime();
437
            if (sleep > 0) {
438
                try {
439
                    Thread.sleep(sleep);
440
                } catch (InterruptedException e) {
441
                    MeteorClient.LOG.error("Error when sleeping the slot mover", e);
442
                }
443
            }
444
445
            // Exit if user closes screen or exit world
446
            if (mc.gui.screen() == null || !Utils.canUpdate()) break;
447
448
            if (steal && stealDrop.get()) {
449
                if (dropBackwards.get()) {
450
                    int iCopy = i;
451
                    Rotations.rotate(mc.player.getYRot() - 180, mc.player.getXRot(), () -> InvUtils.drop().slotId(iCopy));
452
                }
453
            } else InvUtils.shiftClick().slotId(i);
454
        }
455
    }
456
457
    public void steal(AbstractContainerMenu handler) {
458
        MeteorExecutor.execute(() -> moveSlots(handler, 0, SlotUtils.indexToId(SlotUtils.MAIN_START), true));
459
    }
460
461
    public void dump(AbstractContainerMenu handler) {
462
        int playerInvOffset = SlotUtils.indexToId(SlotUtils.MAIN_START);
463
        MeteorExecutor.execute(() -> moveSlots(handler, playerInvOffset, playerInvOffset + 4 * 9, false));
464
    }
465
466
    public boolean showButtons() {
467
        return isActive() && buttons.get();
468
    }
469
470
    public boolean mouseDragItemMove() {
471
        return isActive() && mouseDragItemMove.get();
472
    }
473
474
    public boolean uncapBundleScrolling() {
475
        return isActive() && uncapBundleScrolling.get();
476
    }
477
478
    public boolean frameInput() {
479
        return isActive() && frameInput.get();
480
    }
481
482
    public boolean canSteal(AbstractContainerMenu handler) {
483
        try {
484
            return (stealScreens.get().contains(handler.getType()));
485
        } catch (UnsupportedOperationException _) {
486
            return false;
487
        }
488
    }
489
490
    @EventHandler
491
    private void onInventory(InventoryEvent event) {
492
        AbstractContainerMenu handler = mc.player.containerMenu;
493
        if (canSteal(handler) && event.packet.containerId() == handler.containerId) {
494
            if (autoSteal.get()) {
495
                steal(handler);
496
            } else if (autoDump.get()) {
497
                dump(handler);
498
            }
499
        }
500
    }
501
502
    public enum ListMode {
503
        Whitelist,
504
        Blacklist,
505
        None
506
    }
507
}
508