chest-swap module

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

1 implementationPlayer

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 ClientPlayersrc/main/java/meteordevelopment/meteorclient/systems/modules/player/ChestSwap.javaJava · 151 lines · 5.2 KB

Automatically swaps between a chestplate and an elytra.

Settingschestplatestay-onclose-inventory
ChestSwap.javaJava · Minecraft 26.2 · 151 lines · 5.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.player;
7
8
import meteordevelopment.meteorclient.settings.BoolSetting;
9
import meteordevelopment.meteorclient.settings.EnumSetting;
10
import meteordevelopment.meteorclient.settings.Setting;
11
import meteordevelopment.meteorclient.settings.SettingGroup;
12
import meteordevelopment.meteorclient.systems.config.Config;
13
import meteordevelopment.meteorclient.systems.modules.Categories;
14
import meteordevelopment.meteorclient.systems.modules.Module;
15
import meteordevelopment.meteorclient.utils.player.InvUtils;
16
import net.minecraft.core.component.DataComponents;
17
import net.minecraft.network.protocol.game.ServerboundContainerClosePacket;
18
import net.minecraft.world.entity.EquipmentSlot;
19
import net.minecraft.world.item.Item;
20
import net.minecraft.world.item.ItemStack;
21
import net.minecraft.world.item.Items;
22
23
public class ChestSwap extends Module {
24
    private final SettingGroup sgGeneral = settings.getDefaultGroup();
25
26
    private final Setting<Chestplate> chestplate = sgGeneral.add(new EnumSetting.Builder<Chestplate>()
27
        .name("chestplate")
28
        .description("Which type of chestplate to swap to.")
29
        .defaultValue(Chestplate.PreferNetherite)
30
        .build()
31
    );
32
33
    private final Setting<Boolean> stayOn = sgGeneral.add(new BoolSetting.Builder()
34
        .name("stay-on")
35
        .description("Stays on and activates when you turn it off.")
36
        .defaultValue(false)
37
        .build()
38
    );
39
40
    private final Setting<Boolean> closeInventory = sgGeneral.add(new BoolSetting.Builder()
41
        .name("close-inventory")
42
        .description("Sends inventory close after swap.")
43
        .defaultValue(true)
44
        .build()
45
    );
46
47
    public ChestSwap() {
48
        super(Categories.Player, "chest-swap", "Automatically swaps between a chestplate and an elytra.");
49
    }
50
51
    @Override
52
    public void onActivate() {
53
        swap();
54
        if (!stayOn.get()) toggle();
55
    }
56
57
    @Override
58
    public void onDeactivate() {
59
        if (stayOn.get()) swap();
60
    }
61
62
    public void swap() {
63
        ItemStack currentItem = mc.player.getItemBySlot(EquipmentSlot.CHEST);
64
65
        if (currentItem.has(DataComponents.GLIDER)) {
66
            equipChestplate();
67
        } else if (currentItem.has(DataComponents.EQUIPPABLE) && currentItem.get(DataComponents.EQUIPPABLE).slot().getIndex() == EquipmentSlot.CHEST.getIndex()) {
68
            equipElytra();
69
        } else {
70
            if (!equipChestplate()) equipElytra();
71
        }
72
    }
73
74
    private boolean equipChestplate() {
75
        int bestSlot = -1;
76
        boolean breakLoop = false;
77
78
        for (int i = 0; i < mc.player.getInventory().getNonEquipmentItems().size(); i++) {
79
            Item item = mc.player.getInventory().getNonEquipmentItems().get(i).getItem();
80
81
            switch (chestplate.get()) {
82
                case Diamond:
83
                    if (item == Items.DIAMOND_CHESTPLATE) {
84
                        bestSlot = i;
85
                        breakLoop = true;
86
                    }
87
                    break;
88
                case Netherite:
89
                    if (item == Items.NETHERITE_CHESTPLATE) {
90
                        bestSlot = i;
91
                        breakLoop = true;
92
                    }
93
                    break;
94
                case PreferDiamond:
95
                    if (item == Items.DIAMOND_CHESTPLATE) {
96
                        bestSlot = i;
97
                        breakLoop = true;
98
                    } else if (item == Items.NETHERITE_CHESTPLATE) {
99
                        bestSlot = i;
100
                    }
101
                    break;
102
                case PreferNetherite:
103
                    if (item == Items.DIAMOND_CHESTPLATE) {
104
                        bestSlot = i;
105
                    } else if (item == Items.NETHERITE_CHESTPLATE) {
106
                        bestSlot = i;
107
                        breakLoop = true;
108
                    }
109
                    break;
110
            }
111
112
            if (breakLoop) break;
113
        }
114
115
        if (bestSlot != -1) equip(bestSlot);
116
        return bestSlot != -1;
117
    }
118
119
    private void equipElytra() {
120
        for (int i = 0; i < mc.player.getInventory().getNonEquipmentItems().size(); i++) {
121
            ItemStack item = mc.player.getInventory().getNonEquipmentItems().get(i);
122
123
            if (item.has(DataComponents.GLIDER)) {
124
                equip(i);
125
                break;
126
            }
127
        }
128
    }
129
130
    private void equip(int slot) {
131
        InvUtils.move().from(slot).toArmor(2);
132
        if (closeInventory.get()) {
133
            // Notchian clients send a Close Window packet with Window ID 0 to close their inventory even though there is never an Open Screen packet for the inventory.
134
            mc.getConnection().send(new ServerboundContainerClosePacket(0));
135
        }
136
    }
137
138
    @Override
139
    public void sendToggledMsg() {
140
        if (stayOn.get()) super.sendToggledMsg();
141
        else if (Config.get().chatFeedback.get() && chatFeedback) info("Triggered (highlight)%s(default).", title);
142
    }
143
144
    public enum Chestplate {
145
        Diamond,
146
        Netherite,
147
        PreferDiamond,
148
        PreferNetherite
149
    }
150
}
151