ElytraBoost module

ElytraBoost: Minecraft 26.3 cheat module, full source for every implementation (1 client: OfflineClient).

1 implementationMOVEMENT

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.

OfflineClientMOVEMENTsrc/main/java/com/jellypudding/offlineclient/modules/movement/ElytraBoost.javaJava · 261 lines · 9.6 KB

Press the bind whilst gliding to fire a firework rocket.

SettingsAnti consumeFlight durationPlay soundAutoIntervalTake offSwap backTake from inventory
ElytraBoost.javaJava · Minecraft 26.2 · 261 lines · 9.6 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.TickEvent;
5
import com.jellypudding.offlineclient.module.Category;
6
import com.jellypudding.offlineclient.module.Module;
7
import com.jellypudding.offlineclient.setting.BoolSetting;
8
import com.jellypudding.offlineclient.setting.NumberSetting;
9
import com.jellypudding.offlineclient.util.ChatUtil;
10
import com.jellypudding.offlineclient.util.InventoryUtil;
11
import com.jellypudding.offlineclient.util.Modules;
12
import net.minecraft.core.component.DataComponents;
13
import net.minecraft.sounds.SoundEvents;
14
import net.minecraft.sounds.SoundSource;
15
import net.minecraft.world.InteractionHand;
16
import net.minecraft.world.entity.Entity;
17
import net.minecraft.world.entity.EquipmentSlot;
18
import net.minecraft.world.entity.projectile.FireworkRocketEntity;
19
import net.minecraft.world.item.ItemStack;
20
import net.minecraft.world.item.Items;
21
import net.minecraft.world.item.component.Fireworks;
22
23
import java.util.HashSet;
24
import java.util.List;
25
import java.util.Set;
26
27
// A client side rocket boosts you the same way a real one does and the server
28
// only ever sees the movement. A real rocket is used when that is switched off.
29
public final class ElytraBoost extends Module {
30
31
    private static final double TICKS_PER_SECOND = 20;
32
33
    private static final int MIN_GAP_TICKS = 10;
34
35
    private static final float LAUNCH_VOLUME = 3;
36
37
    private final BoolSetting antiConsume = new BoolSetting("Anti consume",
38
        "Boosts with a client side rocket so none of yours is spent. Works with no rockets at all.", true);
39
    private final NumberSetting flightDuration = new NumberSetting("Flight duration",
40
        "The flight duration of the client side rocket. Zero is the shortest boost.",
41
        0, 0, 255, 1, "").min(0).max(255).under(antiConsume);
42
    private final BoolSetting playSound = new BoolSetting("Play sound",
43
        "Plays the launch sound for a client side rocket.", true).under(antiConsume);
44
    private final BoolSetting auto = new BoolSetting("Auto",
45
        "Keeps firing on its own whilst you glide.", false);
46
    private final NumberSetting interval = new NumberSetting("Interval",
47
        "Seconds between rockets whilst Auto is on.", 3, 0.5, 15, 0.5, "s")
48
        .min(MIN_GAP_TICKS / TICKS_PER_SECOND).under(auto);
49
    private final BoolSetting takeOff = new BoolSetting("Take off",
50
        "Opens the elytra when you press the bind midair.", true);
51
    private final BoolSetting swapBack = new BoolSetting("Swap back",
52
        "Returns to the slot you had after every rocket.", true);
53
    private final BoolSetting fromInventory = new BoolSetting("Take from inventory",
54
        "Borrows rockets from the rest of the inventory when the hotbar has none.", true)
55
        .unless(antiConsume);
56
57
    private int lastFireTick = Integer.MIN_VALUE / 2;
58
    private boolean warned;
59
    private final InventoryUtil.HotbarLoan loan = new InventoryUtil.HotbarLoan();
60
    private final InventoryUtil.SlotSwap slots = new InventoryUtil.SlotSwap();
61
    // The client side rockets alive right now. FireworkRocketEntityMixin asks after them.
62
    private final Set<FireworkRocketEntity> fakes = new HashSet<>();
63
64
    public ElytraBoost() {
65
        super("ElytraBoost", "Press the bind whilst gliding to fire a firework rocket.", Category.MOVEMENT);
66
        addSettings(antiConsume, flightDuration, playSound, auto, interval, takeOff, swapBack,
67
            fromInventory);
68
        searchTags("elytra", "firework", "rocket", "boost");
69
    }
70
71
    @Override
72
    public String getSuffix() {
73
        if (!inGame()) {
74
            return null;
75
        }
76
        if (antiConsume.isOn()) {
77
            return "free";
78
        }
79
        int rockets = countRockets();
80
        return rockets == 0 ? "no rockets" : rockets + " rockets";
81
    }
82
83
    @Override
84
    protected void onEnable() {
85
        warned = false;
86
    }
87
88
    @Override
89
    protected void onDisable() {
90
        loan.giveBack();
91
        fakes.forEach(Entity::discard);
92
        fakes.clear();
93
    }
94
95
    // True for a client side rocket this module launched.
96
    public boolean isFake(FireworkRocketEntity rocket) {
97
        return isEnabled() && fakes.contains(rocket);
98
    }
99
100
    // MultiPlayerGameModeMixin asks before a right click uses an item.
101
    // A real rocket about to be spent whilst gliding is replaced by a client side one.
102
    public boolean interceptsUse(ItemStack held) {
103
        if (!antiConsume.isOn() || !held.is(Items.FIREWORK_ROCKET) || !inGame()
104
            || !mc.player.isFallFlying()) {
105
            return false;
106
        }
107
        launchFake();
108
        return true;
109
    }
110
111
    @Override
112
    public void onKeybind() {
113
        if (!isEnabled() || !inGame() || mc.player.isSpectator()) {
114
            toggle();
115
            return;
116
        }
117
        if (mc.player.isFallFlying()) {
118
            fire();
119
            return;
120
        }
121
        // ElytraFly opens the elytra itself.
122
        if (takeOff.isOn() && !Modules.enabled(ElytraFly.class) && canGlide()) {
123
            ElytraFly.sendStartGlide();
124
            return;
125
        }
126
        toggle();
127
    }
128
129
    @Subscribe
130
    private void onTick(TickEvent event) {
131
        fakes.removeIf(Entity::isRemoved);
132
        if (inGame() && !mc.player.isFallFlying()) {
133
            // Borrowed rockets go home once the glide is over.
134
            loan.giveBack();
135
        }
136
        if (!auto.isOn() || !usable() || !mc.player.isFallFlying()) {
137
            return;
138
        }
139
        if (cruising()) {
140
            return;
141
        }
142
        int gap = (int) Math.round(interval.getValue() * TICKS_PER_SECOND);
143
        if (now() - lastFireTick < Math.max(gap, MIN_GAP_TICKS)) {
144
            return;
145
        }
146
        fire();
147
    }
148
149
    // The player is rebuilt on a respawn or a dimension change.
150
    // Its tick counter starts over.
151
    private int now() {
152
        int tick = mc.player.tickCount;
153
        if (tick < lastFireTick) {
154
            lastFireTick = Integer.MIN_VALUE / 2;
155
        }
156
        return tick;
157
    }
158
159
    private boolean usable() {
160
        return inGame() && !mc.player.isSpectator() && !mc.player.isUsingItem()
161
            && !mc.player.isInWater();
162
    }
163
164
    private boolean canGlide() {
165
        return !mc.player.onGround() && !mc.player.isPassenger()
166
            && mc.player.getItemBySlot(EquipmentSlot.CHEST).is(Items.ELYTRA);
167
    }
168
169
    // Also used by ElytraFly whilst it cruises on rockets.
170
    public void fire() {
171
        if (now() - lastFireTick < MIN_GAP_TICKS) {
172
            return;
173
        }
174
        if (antiConsume.isOn()) {
175
            launchFake();
176
            lastFireTick = mc.player.tickCount;
177
            return;
178
        }
179
        if (mc.player.getOffhandItem().is(Items.FIREWORK_ROCKET)) {
180
            use(InteractionHand.OFF_HAND);
181
            return;
182
        }
183
        int slot = InventoryUtil.hotbarSlot(stack -> stack.is(Items.FIREWORK_ROCKET));
184
        if (slot == -1 && fromInventory.isOn()) {
185
            slot = borrowRockets();
186
        }
187
        if (slot == -1) {
188
            if (!warned) {
189
                warned = true;
190
                ChatUtil.error("You have no firework rockets" + (fromInventory.isOn() ? "." : " in your hotbar."));
191
            }
192
            return;
193
        }
194
        warned = false;
195
        slots.select(slot);
196
        use(InteractionHand.MAIN_HAND);
197
        if (swapBack.isOn()) {
198
            slots.restoreIfMine();
199
        } else {
200
            slots.forget();
201
        }
202
    }
203
204
    // A rocket that exists on this client alone. It rides the player the way a
205
    // real one does and the vanilla entity tick supplies the push.
206
    private void launchFake() {
207
        if (!mc.player.isFallFlying() || mc.gui.screen() != null) {
208
            return;
209
        }
210
        ItemStack stack = Items.FIREWORK_ROCKET.getDefaultInstance();
211
        stack.set(DataComponents.FIREWORKS, new Fireworks(flightDuration.getInt(), List.of()));
212
        FireworkRocketEntity rocket = new FireworkRocketEntity(mc.level, stack, mc.player);
213
        fakes.add(rocket);
214
        if (playSound.isOn()) {
215
            mc.level.playSound(mc.player, rocket, SoundEvents.FIREWORK_ROCKET_LAUNCH,
216
                SoundSource.AMBIENT, LAUNCH_VOLUME, 1);
217
        }
218
        mc.level.addEntity(rocket);
219
    }
220
221
    // Moves a stack of rockets into the hotbar. The slot it landed in or minus one.
222
    private int borrowRockets() {
223
        for (int i = InventoryUtil.HOTBAR_SIZE; i < InventoryUtil.WHOLE_INVENTORY; i++) {
224
            if (!mc.player.getInventory().getItem(i).is(Items.FIREWORK_ROCKET)) {
225
                continue;
226
            }
227
            int before = InventoryUtil.selectedSlot();
228
            if (!loan.select(i)) {
229
                return -1;
230
            }
231
            int slot = InventoryUtil.selectedSlot();
232
            // The loan selected the slot for us. The caller decides what to hold.
233
            mc.player.getInventory().setSelectedSlot(before);
234
            return slot;
235
        }
236
        return -1;
237
    }
238
239
    private void use(InteractionHand hand) {
240
        if (mc.gameMode.useItem(mc.player, hand).consumesAction()) {
241
            mc.player.swing(hand);
242
            lastFireTick = mc.player.tickCount;
243
        }
244
    }
245
246
    private int countRockets() {
247
        int total = InventoryUtil.count(Items.FIREWORK_ROCKET, InventoryUtil.HOTBAR_SIZE);
248
        ItemStack offhand = mc.player.getOffhandItem();
249
        if (offhand.is(Items.FIREWORK_ROCKET)) {
250
            total += offhand.getCount();
251
        }
252
        return total;
253
    }
254
255
    // ElytraFly holds its own speed whilst cruising. A rocket only breaks the cycle.
256
    private boolean cruising() {
257
        ElytraFly elytraFly = Modules.active(ElytraFly.class);
258
        return elytraFly != null && elytraFly.inCruiseMode();
259
    }
260
}
261