BowSpam module

BowSpam: Minecraft 26.3 cheat module, full source for every implementation (2 clients: MelaHack (ThunderHack fork), OfflineClient).

2 implementationsCOMBAT

Full module source: 2 implementations

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

MelaHack (ThunderHack fork)COMBATsrc/main/java/thunder/hack/features/modules/combat/BowSpam.javaJava · 32 lines · 1.4 KB

Automatically releases the bow.

SettingsDelay
BowSpam.javaJava · Minecraft 26.2 · 32 lines · 1.4 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.combat;
2
3
import meteordevelopment.orbit.EventHandler;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
6
import net.minecraft.network.protocol.game.ServerboundUseItemPacket;
7
import net.minecraft.world.InteractionHand;
8
import net.minecraft.world.item.Items;
9
import thunder.hack.events.impl.EventSync;
10
import thunder.hack.features.modules.Module;
11
import thunder.hack.setting.Setting;
12
import thunder.hack.utility.player.PlayerUtility;
13
14
public class BowSpam extends Module {
15
    private final Setting<Integer> ticks = new Setting<>("Delay", 3, 0, 20);
16
17
    public BowSpam() {
18
        super("BowSpam", Category.COMBAT);
19
    }
20
21
    @EventHandler
22
    public void onSync(EventSync event) {
23
        if ((mc.player.getOffhandItem().getItem() == Items.BOW || mc.player.getMainHandItem().getItem() == Items.BOW) && mc.player.isUsingItem()) {
24
            if (mc.player.getTicksUsingItem() >= this.ticks.getValue()) {
25
                sendPacket(new ServerboundPlayerActionPacket(ServerboundPlayerActionPacket.Action.RELEASE_USE_ITEM, BlockPos.ZERO, mc.player.getDirection()));
26
                sendSequencedPacket(id -> new ServerboundUseItemPacket(mc.player.getOffhandItem().getItem() == Items.BOW ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND, id, mc.player.getYRot(), mc.player.getXRot()));
27
                mc.player.releaseUsingItem();
28
            }
29
        }
30
    }
31
}
32
OfflineClientCOMBATsrc/main/java/com/jellypudding/offlineclient/modules/combat/BowSpam.javaJava · 207 lines · 7.9 KB

Fires your bow or crossbow as fast as it will go.

SettingsChargeWhilst holding useOnly with targetTarget rangeView angleCrossbowsCrossbow delaySearch inventory
BowSpam.javaJava · Minecraft 26.2 · 207 lines · 7.9 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.combat;
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.EntityUtil;
10
import com.jellypudding.offlineclient.util.InputUtil;
11
import com.jellypudding.offlineclient.util.InventoryUtil;
12
import com.jellypudding.offlineclient.util.InventoryUtil.SlotSwap;
13
import net.minecraft.world.InteractionHand;
14
import net.minecraft.world.entity.player.Player;
15
import net.minecraft.world.inventory.ContainerInput;
16
import net.minecraft.world.item.BowItem;
17
import net.minecraft.world.item.CrossbowItem;
18
import net.minecraft.world.item.ItemStack;
19
import net.minecraft.world.item.Items;
20
21
public final class BowSpam extends Module {
22
23
    // Stands in for an item in hand that is not being drawn at all.
24
    private static final int NOT_DRAWN = Integer.MAX_VALUE;
25
26
    // A bow discards anything under power 0.1 which is everything below three ticks.
27
    private static final int MIN_CHARGE = 3;
28
29
    private final NumberSetting charge = new NumberSetting("Charge",
30
        "Ticks to draw the bow before letting go.", 5, 3, 20, 1, " ticks");
31
    private final BoolSetting holdingUse = new BoolSetting("Whilst holding use",
32
        "Only fire whilst you hold the use key down.", false);
33
    private final BoolSetting onlyWithTarget = new BoolSetting("Only with target",
34
        "Hold fire until an enemy is in view.", false);
35
    private final NumberSetting targetRange = new NumberSetting("Target range",
36
        "How far away enemies are considered.", 40, 5, 100, 1, " blocks")
37
        .under(onlyWithTarget);
38
    private final NumberSetting viewAngle = new NumberSetting("View angle",
39
        "How far off the crosshair a target still counts.", 30, 5, 90, 1, " degrees")
40
        .under(onlyWithTarget);
41
    private final BoolSetting crossbows = new BoolSetting("Crossbows",
42
        "Fire every loaded crossbow in your hotbar as well. Each one is picked up and fired and put back.", true);
43
    private final NumberSetting crossbowDelay = new NumberSetting("Crossbow delay",
44
        "Ticks to wait between crossbow shots.", 10, 0, 20, 1, " ticks")
45
        .under(crossbows);
46
    private final BoolSetting searchInventory = new BoolSetting("Search inventory",
47
        "Also fetch loaded crossbows from the rest of your inventory into a hotbar slot that is empty or holds a crossbow or arrows.", true)
48
        .under(crossbows);
49
50
    private final SlotSwap slots = new SlotSwap();
51
    private int crossbowTimer;
52
53
    public BowSpam() {
54
        super("BowSpam", "Fires your bow or crossbow as fast as it will go.", Category.COMBAT);
55
        addSettings(charge, holdingUse, onlyWithTarget, targetRange, viewAngle,
56
            crossbows, crossbowDelay, searchInventory);
57
        searchTags("auto bow", "crossbow", "rapid fire");
58
    }
59
60
    @Override
61
    protected void onEnable() {
62
        crossbowTimer = 0;
63
        slots.forget();
64
    }
65
66
    @Override
67
    protected void onDisable() {
68
        slots.restore();
69
        // Leaving a draw hanging would keep the server thinking the bow is up.
70
        if (inGame() && mc.player.isUsingItem() && drawTicks() != NOT_DRAWN) {
71
            mc.gameMode.releaseUsingItem(mc.player);
72
        }
73
    }
74
75
    @Subscribe
76
    private void onTick(TickEvent event) {
77
        if (!inGame() || mc.player.isSpectator()) {
78
            return;
79
        }
80
        if (mc.player.containerMenu != mc.player.inventoryMenu) {
81
            return;
82
        }
83
        if (crossbowTimer > 0) {
84
            crossbowTimer--;
85
        }
86
87
        if (mc.player.isUsingItem()) {
88
            if (mc.player.getTicksUsingItem() >= drawTicks()) {
89
                mc.gameMode.releaseUsingItem(mc.player);
90
            }
91
            return;
92
        }
93
        if (holdingUse.isOn() && !InputUtil.physicallyHeld(mc.options.keyUse)) {
94
            return;
95
        }
96
        if (onlyWithTarget.isOn() && !targetInView()) {
97
            return;
98
        }
99
100
        if (crossbows.isOn()) {
101
            if (crossbowTimer == 0 && fireLoadedCrossbow()) {
102
                crossbowTimer = crossbowDelay.getInt();
103
                return;
104
            }
105
            InteractionHand spent = handWithCrossbow(false);
106
            // An empty crossbow has to be drawn before there is anything to fire.
107
            if (spent != null && hasAmmo(spent)) {
108
                mc.gameMode.useItem(mc.player, spent);
109
                return;
110
            }
111
        }
112
113
        InteractionHand hand = handWithBow();
114
        if (hand == null || !hasAmmo(hand)) {
115
            return;
116
        }
117
        mc.gameMode.useItem(mc.player, hand);
118
    }
119
120
    // Ticks the item in hand has to be held before letting go.
121
    private int drawTicks() {
122
        ItemStack using = mc.player.getUseItem();
123
        if (using.getItem() instanceof BowItem) {
124
            return Math.max(charge.getInt(), MIN_CHARGE);
125
        }
126
        if (using.getItem() instanceof CrossbowItem) {
127
            return CrossbowItem.getChargeDuration(using, mc.player);
128
        }
129
        return NOT_DRAWN;
130
    }
131
132
    private boolean hasAmmo(InteractionHand hand) {
133
        return mc.player.getAbilities().instabuild
134
            || !mc.player.getProjectile(mc.player.getItemInHand(hand)).isEmpty();
135
    }
136
137
    // Fires the first loaded crossbow in either hand or the hotbar or the inventory.
138
    // True when a shot went out.
139
    private boolean fireLoadedCrossbow() {
140
        InteractionHand loaded = handWithCrossbow(true);
141
        if (loaded != null) {
142
            mc.gameMode.useItem(mc.player, loaded);
143
            return true;
144
        }
145
        int slot = InventoryUtil.hotbarSlot(BowSpam::isLoaded);
146
        if (slot == -1 && searchInventory.isOn()) {
147
            slot = fetchLoadedCrossbow();
148
        }
149
        if (slot == -1) {
150
            return false;
151
        }
152
        slots.select(slot);
153
        mc.gameMode.useItem(mc.player, InteractionHand.MAIN_HAND);
154
        slots.restore();
155
        return true;
156
    }
157
158
    // Swaps a loaded crossbow from the inventory into a hotbar slot that can spare
159
    // the room. The hotbar slot it landed in or minus one.
160
    private int fetchLoadedCrossbow() {
161
        int from = InventoryUtil.findSlot(BowSpam::isLoaded, InventoryUtil.WHOLE_INVENTORY);
162
        if (from < InventoryUtil.HOTBAR_SIZE || !InventoryUtil.canClick()
163
            || !InventoryUtil.carried().isEmpty()) {
164
            return -1;
165
        }
166
        int to = InventoryUtil.hotbarSlot(stack -> stack.isEmpty()
167
            || stack.getItem() instanceof CrossbowItem || stack.is(Items.ARROW));
168
        if (to == -1) {
169
            return -1;
170
        }
171
        mc.gameMode.handleContainerInput(0, InventoryUtil.networkSlot(from), to,
172
            ContainerInput.SWAP, mc.player);
173
        return to;
174
    }
175
176
    private static boolean isLoaded(ItemStack stack) {
177
        return stack.getItem() instanceof CrossbowItem && CrossbowItem.isCharged(stack);
178
    }
179
180
    private InteractionHand handWithBow() {
181
        for (InteractionHand hand : InteractionHand.values()) {
182
            if (mc.player.getItemInHand(hand).getItem() instanceof BowItem) {
183
                return hand;
184
            }
185
        }
186
        return null;
187
    }
188
189
    private InteractionHand handWithCrossbow(boolean loaded) {
190
        for (InteractionHand hand : InteractionHand.values()) {
191
            ItemStack stack = mc.player.getItemInHand(hand);
192
            if (stack.getItem() instanceof CrossbowItem && CrossbowItem.isCharged(stack) == loaded) {
193
                return hand;
194
            }
195
        }
196
        return null;
197
    }
198
199
    private boolean targetInView() {
200
        Player target = EntityUtil.nearestEnemy(targetRange.getValue());
201
        if (target == null || !mc.player.hasLineOfSight(target)) {
202
            return false;
203
        }
204
        return EntityUtil.lookAngleTo(target) <= viewAngle.getValue();
205
    }
206
}
207