ElytraSwap module

ElytraSwap: Minecraft 26.3 cheat module, full source for every implementation (2 clients: MelaHack (ThunderHack fork), LiquidBounce (Kotlin)).

2 implementationsPLAYER

Full module source: 2 implementations

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

MelaHack (ThunderHack fork)PLAYERsrc/main/java/thunder/hack/features/modules/player/ElytraSwap.javaJava · 186 lines · 8.2 KB

Automatically equips an elytra.

SettingsDelayModeSwitchButtonFireWorkButtonStartFireWorkFireWorkMode
ElytraSwap.javaJava · Minecraft 26.2 · 186 lines · 8.2 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.player;
2
3
import meteordevelopment.orbit.EventHandler;
4
import net.minecraft.network.protocol.game.ServerboundContainerClosePacket;
5
import net.minecraft.network.protocol.game.ServerboundPlayerCommandPacket;
6
import net.minecraft.network.protocol.game.ServerboundSwingPacket;
7
import net.minecraft.network.protocol.game.ServerboundUseItemPacket;
8
import net.minecraft.world.InteractionHand;
9
import net.minecraft.world.inventory.ContainerInput;
10
import net.minecraft.world.item.Item;
11
import net.minecraft.world.item.Items;
12
import thunder.hack.core.Managers;
13
import thunder.hack.events.impl.PacketEvent;
14
import thunder.hack.features.modules.Module;
15
import thunder.hack.setting.Setting;
16
import thunder.hack.setting.impl.Bind;
17
import thunder.hack.utility.Timer;
18
import thunder.hack.utility.player.InventoryUtility;
19
import thunder.hack.utility.player.SearchInvResult;
20
21
import static thunder.hack.features.modules.client.ClientSettings.isRu;
22
23
public class ElytraSwap extends Module {
24
    public ElytraSwap() {
25
        super("ElytraSwap", Category.PLAYER);
26
    }
27
28
    private final Setting<Boolean> delay = new Setting<>("Delay", false);
29
    private final Setting<Mode> mode = new Setting<>("Mode", Mode.Enable);
30
    private final Setting<Bind> switchButton = new Setting<>("SwitchButton", new Bind(-1, false, false), v -> mode.getValue() == Mode.Bind);
31
    private final Setting<Bind> fireWorkButton = new Setting<>("FireWorkButton", new Bind(-1, false, false), v -> mode.getValue() == Mode.Bind);
32
    private final Setting<Boolean> startFireWork = new Setting<>("StartFireWork", true, v -> mode.getValue() == Mode.Bind);
33
    private final Setting<FireWorkMode> fireWorkMode = new Setting<>("FireWorkMode", FireWorkMode.Normal, v -> mode.getValue() == Mode.Bind);
34
35
    private final Timer switchTimer = new Timer();
36
    private final Timer fireworkTimer = new Timer();
37
38
    public static boolean swapping = false;
39
40
    private enum Mode {
41
        Enable, Bind
42
    }
43
44
    private enum FireWorkMode {
45
        Silent, Normal
46
    }
47
48
    @Override
49
    public void onEnable() {
50
        if (mode.getValue() == Mode.Enable)
51
            swapChest(true);
52
    }
53
54
    @Override
55
    public void onUpdate() {
56
        if (mode.getValue() == Mode.Bind && mc.gui.screen() == null) {
57
            if (switchButton.getValue().getKey() != -1 && isKeyPressed(switchButton.getValue().getKey()) && switchTimer.every(500))
58
                swapChest(false);
59
60
            if (fireWorkButton.getValue().getKey() != -1 && isKeyPressed(fireWorkButton.getValue().getKey()) && fireworkTimer.every(500) && mc.player.isFallFlying())
61
                useFireWork();
62
        }
63
    }
64
65
    @EventHandler
66
    public void onPacketSend(PacketEvent.SendPost e) {
67
        if (e.getPacket() instanceof ServerboundPlayerCommandPacket command
68
                && command.getAction() == ServerboundPlayerCommandPacket.Action.START_FALL_FLYING
69
                && mode.getValue() == Mode.Bind
70
                && startFireWork.getValue()) {
71
            useFireWork();
72
        }
73
    }
74
75
    public void useFireWork() {
76
        SearchInvResult hotbarFireWorkResult = InventoryUtility.findItemInHotBar(Items.FIREWORK_ROCKET);
77
        SearchInvResult fireWorkResult = InventoryUtility.findItemInInventory(Items.FIREWORK_ROCKET);
78
79
        InventoryUtility.saveSlot();
80
        if (hotbarFireWorkResult.found()) {
81
            hotbarFireWorkResult.switchTo();
82
        } else if (fireWorkResult.found()) {
83
            mc.gameMode.handleContainerInput(mc.player.containerMenu.containerId, fireWorkResult.slot(), mc.player.getInventory().getSelectedSlot(), ContainerInput.SWAP, mc.player);
84
            sendPacket(new ServerboundContainerClosePacket(mc.player.containerMenu.containerId));
85
        } else {
86
            sendMessage(isRu() ? "У тебя нет фейерверков!" : "You've got no fireworks!");
87
            return;
88
        }
89
90
        sendSequencedPacket(id -> new ServerboundUseItemPacket(InteractionHand.MAIN_HAND, id, mc.player.getYRot(), mc.player.getXRot()));
91
        sendPacket(new ServerboundSwingPacket(InteractionHand.MAIN_HAND));
92
93
        if (fireWorkMode.getValue() == FireWorkMode.Silent) {
94
            InventoryUtility.returnSlot();
95
            if (!hotbarFireWorkResult.found()) {
96
                mc.gameMode.handleContainerInput(mc.player.containerMenu.containerId, fireWorkResult.slot(), mc.player.getInventory().getSelectedSlot(), ContainerInput.SWAP, mc.player);
97
                sendPacket(new ServerboundContainerClosePacket(mc.player.containerMenu.containerId));
98
            }
99
        }
100
    }
101
102
    public static int getChestPlateSlot() {
103
        Item[] items = {Items.NETHERITE_CHESTPLATE, Items.DIAMOND_CHESTPLATE, Items.CHAINMAIL_CHESTPLATE, Items.IRON_CHESTPLATE, Items.GOLDEN_CHESTPLATE, Items.LEATHER_CHESTPLATE};
104
        for (Item item : items) {
105
            SearchInvResult slot = InventoryUtility.findItemInInventory(item);
106
            if (slot.found()) {
107
                return slot.slot();
108
            }
109
        }
110
        return -1;
111
    }
112
113
    private void swapChest(boolean disable) {
114
        SearchInvResult result = InventoryUtility.findItemInInventory(Items.ELYTRA);
115
116
117
        if (mc.player.getInventory().getItem(38).getItem() == Items.ELYTRA) {
118
            int slot = getChestPlateSlot();
119
            if (slot != -1) {
120
                if (delay.getValue())
121
                    Managers.ASYNC.run(() -> {
122
                        swapping = true;
123
                        clickSlot(slot);
124
                        try {
125
                            Thread.sleep(200);
126
                        } catch (Exception ignored) {
127
                        }
128
                        clickSlot(6);
129
                        try {
130
                            Thread.sleep(200);
131
                        } catch (Exception ignored) {
132
                        }
133
                        clickSlot(slot);
134
                        sendPacket(new ServerboundContainerClosePacket(mc.player.containerMenu.containerId));
135
                        swapping = false;
136
                    });
137
                else {
138
                    clickSlot(slot);
139
                    clickSlot(6);
140
                    clickSlot(slot);
141
                    sendPacket(new ServerboundContainerClosePacket(mc.player.containerMenu.containerId));
142
                }
143
            } else {
144
                if (disable) disable(isRu() ? "У тебя нет нагрудника!" : "You don't have a chestplate!");
145
                else sendMessage(isRu() ? "У тебя нет нагрудника!" : "You don't have a chestplate!");
146
                return;
147
            }
148
        } else if (result.found()) {
149
            if (delay.getValue())
150
                new Thread(() -> {
151
                    swapping = true;
152
                    clickSlot(result.slot());
153
                    try {
154
                        Thread.sleep(200);
155
                    } catch (Exception ignored) {
156
                    }
157
                    clickSlot(6);
158
                    try {
159
                        Thread.sleep(200);
160
                    } catch (Exception ignored) {
161
                    }
162
                    clickSlot(result.slot());
163
                    sendPacket(new ServerboundContainerClosePacket(mc.player.containerMenu.containerId));
164
                    if (startFireWork.getValue() && mc.player.fallDistance > 0)
165
                        sendPacket(new ServerboundPlayerCommandPacket(mc.player, ServerboundPlayerCommandPacket.Action.START_FALL_FLYING));
166
                    swapping = false;
167
                }).start();
168
            else {
169
                clickSlot(result.slot());
170
                clickSlot(6);
171
                clickSlot(result.slot());
172
                sendPacket(new ServerboundContainerClosePacket(mc.player.containerMenu.containerId));
173
                if (startFireWork.getValue() && mc.player.fallDistance > 0)
174
                    sendPacket(new ServerboundPlayerCommandPacket(mc.player, ServerboundPlayerCommandPacket.Action.START_FALL_FLYING));
175
            }
176
        } else {
177
            if (disable) disable(isRu() ? "У тебя нет элитры!" : "You don't have an elytra!");
178
            else sendMessage(isRu() ? "У тебя нет элитры!" : "You don't have an elytra!");
179
            return;
180
        }
181
182
        if (disable)
183
            disable(isRu() ? "Свапнул! Отключаю.." : "Swapped! Disabling..");
184
    }
185
}
186
LiquidBounce (Kotlin)PLAYERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/misc/ModuleElytraSwap.ktKotlin · 92 lines · 3.4 KB

Allows to quickly replace the chestplate with an elytra and vice versa.

ModuleElytraSwap.ktKotlin · Minecraft 26.2 · 92 lines · 3.4 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.misc
20
21
import net.ccbluex.liquidbounce.event.events.ScheduleInventoryActionEvent
22
import net.ccbluex.liquidbounce.event.handler
23
import net.ccbluex.liquidbounce.features.module.ClientModule
24
import net.ccbluex.liquidbounce.features.module.ModuleCategories
25
import net.ccbluex.liquidbounce.utils.inventory.ArmorItemSlot
26
import net.ccbluex.liquidbounce.utils.inventory.HotbarItemSlot
27
import net.ccbluex.liquidbounce.utils.inventory.InventoryAction
28
import net.ccbluex.liquidbounce.utils.inventory.ItemSlot
29
import net.ccbluex.liquidbounce.utils.inventory.PlayerInventoryConstraints
30
import net.ccbluex.liquidbounce.utils.inventory.Slots
31
import net.ccbluex.liquidbounce.utils.item.isChestArmor
32
import net.ccbluex.liquidbounce.utils.item.isGlider
33
import net.ccbluex.liquidbounce.utils.kotlin.EventPriorityConvention
34
35
/**
36
 * ModuleElytraSwap
37
 *
38
 * Allows you to quickly replace your chestplate with an elytra and vice versa.
39
 *
40
 * @author sqlerrorthing
41
 * @since 2/13/2025
42
 **/
43
object ModuleElytraSwap : ClientModule(
44
    "ElytraSwap",
45
    ModuleCategories.PLAYER,
46
    aliases = listOf("ChestSwap"),
47
    disableOnQuit = true
48
) {
49
50
    private val constraints = tree(PlayerInventoryConstraints())
51
52
    private val slotsToSearch = Slots.Hotbar + Slots.Inventory + HotbarItemSlot.OFFHAND
53
54
    @Suppress("unused")
55
    private val scheduleInventoryActionHandler = handler<ScheduleInventoryActionEvent>(
56
        EventPriorityConvention.CRITICAL_MODIFICATION
57
    ) { event ->
58
        val elytraItem = slotsToSearch.findSlot { it.isGlider && !it.nextDamageWillBreak() }
59
        val chestplateItem = slotsToSearch.findSlot { it.isChestArmor }
60
61
        val chestplateStack = ArmorItemSlot.CHEST.itemStack
62
        when {
63
            // put on elytra
64
            chestplateStack.isEmpty && elytraItem != null -> event.doSwap(elytraItem)
65
66
            // replacing of elytra with a chestplate
67
            chestplateStack.isGlider && chestplateItem != null -> event.doSwap(chestplateItem)
68
69
            // replacing the chestplate with elytra
70
            chestplateStack.isChestArmor && elytraItem != null -> event.doSwap(elytraItem)
71
        }
72
73
        enabled = false
74
    }
75
76
    private fun ScheduleInventoryActionEvent.doSwap(slot: ItemSlot) {
77
        var exchange: InventoryAction? = null
78
        if (!ArmorItemSlot.CHEST.itemStack.isEmpty) {
79
            exchange = InventoryAction.Click.performPickup(slot = slot)
80
        }
81
82
        val actions = listOfNotNull(
83
            InventoryAction.Click.performPickup(slot = slot),
84
            InventoryAction.Click.performPickup(slot = ArmorItemSlot.CHEST),
85
            exchange
86
        )
87
88
        schedule(constraints, actions)
89
    }
90
91
}
92