TriggerBot module

TriggerBot: Minecraft 26.3 cheat module, full source for every implementation (4 clients: MelaHack (ThunderHack fork), OfflineClient, Combatant, …).

4 implementationsCOMBAT

Full module source: 4 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/TriggerBot.javaJava · 96 lines · 4.1 KB

Automatically attacks the entity you're looking at.

SettingsRangeSmartCritOnlyCritAutoJumpIgnoreWallsPauseWhileEatingRandomDelayMinRandomDelayMax
TriggerBot.javaJava · Minecraft 26.2 · 96 lines · 4.1 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.world.InteractionHand;
6
import net.minecraft.world.effect.MobEffects;
7
import net.minecraft.world.entity.Entity;
8
import net.minecraft.world.level.block.Blocks;
9
import thunder.hack.core.Managers;
10
import thunder.hack.core.manager.client.ModuleManager;
11
import thunder.hack.events.impl.PlayerUpdateEvent;
12
import thunder.hack.features.modules.Module;
13
import thunder.hack.setting.Setting;
14
import thunder.hack.setting.impl.BooleanSettingGroup;
15
import java.util.Random;
16
17
public final class TriggerBot extends Module {
18
    public final Setting<Float> attackRange = new Setting<>("Range", 3f, 1f, 7.0f);
19
    public final Setting<BooleanSettingGroup> smartCrit = new Setting<>("SmartCrit", new BooleanSettingGroup(true));
20
    public final Setting<Boolean> onlySpace = new Setting<>("OnlyCrit", false).addToGroup(smartCrit);
21
    public final Setting<Boolean> autoJump = new Setting<>("AutoJump", false).addToGroup(smartCrit);
22
    public final Setting<Boolean> ignoreWalls = new Setting<>("IgnoreWalls", false);
23
    public final Setting<Boolean> pauseEating = new Setting<>("PauseWhileEating", false);
24
    public final Setting<Integer> minDelay = new Setting<>("RandomDelayMin", 2, 0, 20);
25
    public final Setting<Integer> maxDelay = new Setting<>("RandomDelayMax", 13, 0, 20);
26
27
    private int delay;
28
    private final Random random = new Random(); // For random delay
29
30
    public TriggerBot() {
31
        super("TriggerBot", Category.COMBAT);
32
    }
33
34
    @EventHandler
35
    public void onAttack(PlayerUpdateEvent e) {
36
        if (mc.player.isUsingItem() && pauseEating.getValue()) {
37
            return;
38
        }
39
        if (!mc.options.keyJump.isDown() && mc.player.onGround() && autoJump.getValue())
40
            mc.player.jumpFromGround();
41
42
        // Smart crits should not be delayed
43
        if (!autoCrit()) {
44
            if (delay > 0) {
45
                delay--;
46
                return;
47
            }
48
        }
49
50
        Entity ent = Managers.PLAYER.getRtxTarget(mc.player.getYRot(), mc.player.getXRot(), attackRange.getValue(), ignoreWalls.getValue());
51
        if (ent != null && !Managers.FRIEND.isFriend(ent.getName().getString())) {
52
            mc.gameMode.attack(mc.player, ent);
53
            mc.player.swing(InteractionHand.MAIN_HAND);
54
55
            // Set delay for the next hit (10 to 20 ms)
56
            delay = random.nextInt(minDelay.getValue(), maxDelay.getValue() + 1) ; // (20ms / 50ms per tick = ~0.4 ticks, 10ms / 50ms = ~0.2 ticks)
57
            // ulybaka1337: am i cooking???
58
            // default delay is calculated with
59
            // nextInt(11) + 2
60
            // so max value is 11+2=13 and min is 2
61
        }
62
    }
63
64
    private boolean autoCrit() {
65
        boolean reasonForSkipCrit =
66
                !smartCrit.getValue().isEnabled()
67
                        || mc.player.getAbilities().flying
68
                        || (mc.player.isFallFlying() || ModuleManager.elytraPlus.isEnabled())
69
                        || mc.player.hasEffect(MobEffects.BLINDNESS)
70
                        || mc.player.isSuppressingSlidingDownLadder()
71
                        || mc.level.getBlockState(BlockPos.containing(mc.player.position())).getBlock() == Blocks.COBWEB;
72
73
        if (mc.player.fallDistance > 1 && mc.player.fallDistance < 1.14)
74
            return false;
75
76
        if (ModuleManager.aura.getAttackCooldown() < (mc.player.onGround() ? 1f : 0.9f))
77
            return false;
78
79
        boolean mergeWithTargetStrafe = !ModuleManager.targetStrafe.isEnabled() || !ModuleManager.targetStrafe.jump.getValue();
80
        boolean mergeWithSpeed = !ModuleManager.speed.isEnabled() || mc.player.onGround();
81
82
        if (!mc.options.keyJump.isDown() && mergeWithTargetStrafe && mergeWithSpeed && !onlySpace.getValue() && !autoJump.getValue())
83
            return true;
84
85
        if (mc.player.isInLava())
86
            return true;
87
88
        if (!mc.options.keyJump.isDown() && ModuleManager.aura.isAboveWater())
89
            return true;
90
91
        if (!reasonForSkipCrit)
92
            return !mc.player.onGround() && mc.player.fallDistance > 0.0f;
93
        return true;
94
    }
95
}
96
OfflineClientCOMBATsrc/main/java/com/jellypudding/offlineclient/modules/combat/TriggerBot.javaJava · 100 lines · 4.3 KB

Swings at whatever your crosshair is on.

SettingsRangeFOVOnly on clickAttack whilst blocking
TriggerBot.javaJava · Minecraft 26.2 · 100 lines · 4.3 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.EnumSetting;
9
import com.jellypudding.offlineclient.setting.NumberSetting;
10
import com.jellypudding.offlineclient.util.AttackTimer;
11
import com.jellypudding.offlineclient.util.EntityFilter;
12
import com.jellypudding.offlineclient.util.EntityUtil;
13
import com.jellypudding.offlineclient.util.FaceMode;
14
import com.jellypudding.offlineclient.util.Modules;
15
import com.jellypudding.offlineclient.util.RotationPriority;
16
import com.jellypudding.offlineclient.util.SwingMode;
17
import com.jellypudding.offlineclient.util.TargetFilter;
18
import com.jellypudding.offlineclient.util.TargetPriority;
19
import net.minecraft.world.InteractionHand;
20
import net.minecraft.world.entity.Entity;
21
22
import java.util.List;
23
24
public final class TriggerBot extends Module {
25
26
    // Hitbox reach is shorter than the centre distance. The scan runs wider.
27
    private static final double SCAN_MARGIN = 4;
28
29
    private final NumberSetting range = new NumberSetting("Range",
30
        "Maximum reach in blocks.", 4.2, 1, 10, 0.05).max(10);
31
    private final NumberSetting fov = new NumberSetting("FOV",
32
        "Only hit what sits within this angle of your view. Small values act as a crosshair check.",
33
        30, 30, 360, 10, " degrees").max(360);
34
    private final EnumSetting<TargetPriority> priority =
35
        TargetPriority.setting("Attacks", TargetPriority.CLOSEST_ANGLE);
36
    private final EntityFilter filter = EntityFilter.living("Swing at", "hit", true,
37
        EntityFilter.Pick.ALL, List.of());
38
    private final BoolSetting onlyOnClick = new BoolSetting("Only on click",
39
        "Only swing whilst you hold the attack key down.", false);
40
    private final BoolSetting whilstBlocking = new BoolSetting("Attack whilst blocking",
41
        "Swings even whilst you hold a shield up.", false);
42
    private final EnumSetting<FaceMode> faceTarget = FaceMode.setting(FaceMode.SPAM);
43
    private final EnumSetting<SwingMode> swing = SwingMode.setting(SwingMode.BOTH);
44
    private final TargetFilter targets = new TargetFilter();
45
    private final AttackTimer timer = new AttackTimer();
46
47
    public TriggerBot() {
48
        super("TriggerBot", "Swings at whatever your crosshair is on.", Category.COMBAT);
49
        addSettings(range, fov, priority);
50
        addSettings(filter.settings());
51
        addSettings(targets.settings());
52
        addSettings(onlyOnClick, whilstBlocking, faceTarget, swing);
53
        addSettings(timer.settings());
54
        searchTags("click aura", "trigger");
55
    }
56
57
    @Override
58
    protected void onEnable() {
59
        timer.clear();
60
    }
61
62
    @Subscribe
63
    private void onTick(TickEvent event) {
64
        if (!inGame() || mc.gui.screen() != null || mc.player.isSpectator()) {
65
            return;
66
        }
67
        boolean blocking = whilstBlocking.isOn() && mc.player.isBlocking();
68
        if ((mc.player.isUsingItem() && !blocking) || mc.gameMode.isDestroying() || Modules.eating()) {
69
            return;
70
        }
71
        if (onlyOnClick.isOn() && !mc.options.keyAttack.isDown()) {
72
            return;
73
        }
74
        if (mc.player.getAttackStrengthScale(0.5f) < 1 || !timer.ready()) {
75
            return;
76
        }
77
        Entity target = EntityUtil.best(range.getValue() + SCAN_MARGIN, priority.getValue(),
78
            this::attackable);
79
        if (target == null) {
80
            return;
81
        }
82
        // The look packet goes out first. The server sees a fair hit.
83
        faceTarget.getValue().face(target.getBoundingBox().getCenter(), RotationPriority.ATTACK);
84
        mc.gameMode.attack(mc.player, target);
85
        swing.getValue().swing(InteractionHand.MAIN_HAND);
86
        timer.spent();
87
    }
88
89
    private boolean attackable(Entity entity) {
90
        if (!targets.attackable(entity, filter)) {
91
            return false;
92
        }
93
        // The crosshair reaches further than the server allows a hit.
94
        if (EntityUtil.reachDistance(mc.player, entity) > range.getValue()) {
95
            return false;
96
        }
97
        return fov.getValue() >= 360 || EntityUtil.lookAngleTo(entity) <= fov.getValue() / 2;
98
    }
99
}
100
CombatantCOMBATsrc/main/java/combatant/client/features/module/modules/combat/AutoAttack.javaJava · 588 lines · 20.5 KB
Settingsautoattack_modeautoattack_objectiveautoattack_cps_minautoattack_cps_maxautoattack_delay_on_brokenautoattack_weaponautoattack_on_item_useautoattack_delay_post_stop_useautoattack_togglesautoattack_humanize_togglesautoattack_humanize_miss_rateautoattack_humanize_swing_rateautoattack_humanize_pause_rateautoattack_humanize_pause_minautoattack_humanize_pause_maxautoattack_protocol_modeautoattack_protocol_heuristics
AutoAttack.javaJava · Minecraft 26.2 · 588 lines · 20.5 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Combatant Client distribution.
3
 * Combatant modifications copyright (c) 2026 pivosos2007.
4
 *
5
 * Portions of this file are based on LiquidBounce
6
 * (https://github.com/CCBlueX/LiquidBounce).
7
 * Copyright (c) 2015-2026 CCBlueX.
8
 *
9
 * LiquidBounce portions are licensed under GPLv3-or-later.
10
 * Combatant modifications are licensed under GPLv3.
11
 * See THIRD_PARTY_NOTICES.md for details.
12
 */
13
14
package combatant.client.features.module.modules.combat;
15
16
/*
17
 * Inspired by LiquidBounce (https://github.com/CCBlueX/LiquidBounce).
18
 */
19
20
import combatant.client.config.values.*;
21
import lombok.Getter;
22
import lombok.RequiredArgsConstructor;
23
import net.minecraft.client.Minecraft;
24
import net.minecraft.client.player.LocalPlayer;
25
import net.minecraft.core.registries.BuiltInRegistries;
26
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
27
import net.minecraft.tags.ItemTags;
28
import net.minecraft.world.InteractionHand;
29
import net.minecraft.world.entity.Entity;
30
import net.minecraft.world.entity.LivingEntity;
31
import net.minecraft.world.entity.player.Player;
32
import net.minecraft.world.item.ItemStack;
33
import net.minecraft.world.item.Items;
34
import net.minecraft.world.phys.BlockHitResult;
35
import net.minecraft.world.phys.EntityHitResult;
36
import net.minecraft.world.phys.HitResult;
37
import combatant.client.config.common.CommonSettingSchemas;
38
import combatant.client.config.common.impl.TargetFilters;
39
import combatant.client.events.EventHandler;
40
import combatant.client.events.impl.EventSync;
41
import combatant.client.events.impl.PacketEvent;
42
import combatant.client.features.module.Module;
43
import combatant.client.features.module.ModuleCategory;
44
import combatant.client.features.module.ModuleInfo;
45
import combatant.client.features.module.Modules;
46
import combatant.client.features.relations.CategoryRules;
47
import combatant.client.features.relations.CategoryType;
48
import combatant.client.features.relations.EntityFilters;
49
import combatant.client.util.click.AttackPressing;
50
import combatant.client.util.click.ClickHumanizer;
51
import combatant.client.util.click.ClickScheduler;
52
import combatant.client.util.combat.CombatStrikeController;
53
import combatant.client.util.item.FoodUtil;
54
import combatant.client.util.player.ResetAttackCooldown;
55
import combatant.client.util.combat.protocol.CombatProtocolHeuristics;
56
import combatant.client.util.combat.protocol.ProtocolUtil;
57
58
import java.util.LinkedHashMap;
59
60
61
//todo Description
62
@ModuleInfo(
63
        id = "triggerbot",
64
        displayName = "TriggerBot",
65
        category = ModuleCategory.COMBAT
66
)
67
public class AutoAttack extends Module {
68
69
    private static final int MAX_CPS = 100;
70
    private static final String TOGGLE_HUMANIZE_MISS = "miss";
71
    private static final String TOGGLE_HUMANIZE_SWING = "miss_swing";
72
    private static final String TOGGLE_HUMANIZE_PAUSE = "pause";
73
    private final Minecraft mc = Minecraft.getInstance();
74
    private final ModeValue mode =
75
            mode(
76
                    "autoattack_mode",
77
                    "mode",
78
                    "hold",
79
                    "hold",
80
                    "auto"
81
            );
82
    private final EnumValue<ObjectiveType> objective =
83
            enumCommon(
84
                    "autoattack_objective",
85
                    "objective",
86
                    CommonSettingSchemas.COMBAT_OBJECTIVE,
87
                    ObjectiveType.ANY,
88
                    ObjectiveType.values()
89
            );
90
    private final NumberValue<Integer> cpsMin =
91
            visibleWhen(numCommon(
92
                    "autoattack_cps_min",
93
                    "cps_min",
94
                    CommonSettingSchemas.COMBAT_CPS_MIN,
95
                    8,
96
                    1,
97
                    MAX_CPS
98
            ), () -> objective.get() != ObjectiveType.BLOCK && !isAutoMode());
99
    private final NumberValue<Integer> cpsMax =
100
            visibleWhen(numCommon(
101
                    "autoattack_cps_max",
102
                    "cps_max",
103
                    CommonSettingSchemas.COMBAT_CPS_MAX,
104
                    12,
105
                    1,
106
                    MAX_CPS
107
            ), () -> objective.get() != ObjectiveType.BLOCK && !isAutoMode());
108
    private final ClickScheduler clicker = new ClickScheduler(cpsMin.get(), cpsMax.get());
109
    private final BooleanValue delayOnBroken =
110
            visibleWhen(bool(
111
                    "autoattack_delay_on_broken",
112
                    "delay_on_broken",
113
                    true
114
            ), () -> objective.get() != ObjectiveType.BLOCK);
115
    private final EnumValue<WeaponType> weapon =
116
            visibleWhen(enumCommon(
117
                    "autoattack_weapon",
118
                    "weapon",
119
                    CommonSettingSchemas.COMBAT_WEAPON,
120
                    WeaponType.ANY,
121
                    WeaponType.values()
122
            ), () -> objective.get() != ObjectiveType.BLOCK);
123
    private final EnumValue<UseMode> onItemUse =
124
            visibleWhen(enumCommon(
125
                    "autoattack_on_item_use",
126
                    "on_item_use",
127
                    CommonSettingSchemas.COMBAT_ON_ITEM_USE,
128
                    UseMode.WAIT,
129
                    UseMode.values()
130
            ), () -> objective.get() != ObjectiveType.BLOCK);
131
    private final NumberValue<Integer> delayPostStopUse =
132
            visibleWhen(num(
133
                    "autoattack_delay_post_stop_use",
134
                    "delay_post_stop_use",
135
                    0,
136
                    0,
137
                    20
138
            ), () -> objective.get() != ObjectiveType.BLOCK && onItemUse.get() != UseMode.IGNORE);
139
    private final BooleanMapValue targetToggles =
140
            visibleWhen(common(
141
                    group(
142
                            "autoattack_toggles",
143
                            "targets",
144
                            targetFilterDefaults()
145
                    ),
146
                    CommonSettingSchemas.TARGET_FILTERS.commonI18nKey()
147
            ), () -> objective.get() == ObjectiveType.ENEMY);
148
    private final BooleanMapValue humanizeToggles =
149
            visibleWhen(group(
150
                    "autoattack_humanize_toggles",
151
                    "humanize_toggles",
152
                    humanizeDefaults()
153
            ), () -> objective.get() != ObjectiveType.BLOCK && !isAutoMode());
154
    private final NumberValue<Integer> humanizeMissRate =
155
            visibleWhen(num(
156
                    "autoattack_humanize_miss_rate",
157
                    "humanize_miss_rate",
158
                    8,
159
                    1,
160
                    100
161
            ), () -> objective.get() != ObjectiveType.BLOCK
162
                    && !isAutoMode()
163
                    && humanizeToggles.get(TOGGLE_HUMANIZE_MISS));
164
    private final NumberValue<Integer> humanizeSwingRate =
165
            visibleWhen(num(
166
                    "autoattack_humanize_swing_rate",
167
                    "humanize_swing_rate",
168
                    5,
169
                    1,
170
                    100
171
            ), () -> objective.get() != ObjectiveType.BLOCK
172
                    && !isAutoMode()
173
                    && humanizeToggles.get(TOGGLE_HUMANIZE_SWING));
174
    private final NumberValue<Integer> humanizePauseRate =
175
            visibleWhen(num(
176
                    "autoattack_humanize_pause_rate",
177
                    "humanize_pause_rate",
178
                    5,
179
                    1,
180
                    100
181
            ), () -> objective.get() != ObjectiveType.BLOCK
182
                    && !isAutoMode()
183
                    && humanizeToggles.get(TOGGLE_HUMANIZE_PAUSE));
184
    private final NumberValue<Integer> humanizePauseMin =
185
            visibleWhen(num(
186
                    "autoattack_humanize_pause_min",
187
                    "humanize_pause_min",
188
                    1,
189
                    1,
190
                    10
191
            ), () -> objective.get() != ObjectiveType.BLOCK
192
                    && !isAutoMode()
193
                    && humanizeToggles.get(TOGGLE_HUMANIZE_PAUSE));
194
    private final NumberValue<Integer> humanizePauseMax =
195
            visibleWhen(num(
196
                    "autoattack_humanize_pause_max",
197
                    "humanize_pause_max",
198
                    2,
199
                    1,
200
                    20
201
            ), () -> objective.get() != ObjectiveType.BLOCK
202
                    && !isAutoMode()
203
                    && humanizeToggles.get(TOGGLE_HUMANIZE_PAUSE));
204
    private final ClickHumanizer humanizer = new ClickHumanizer(
205
            humanizeToggles,
206
            humanizeMissRate,
207
            humanizeSwingRate,
208
            humanizePauseRate,
209
            humanizePauseMin,
210
            humanizePauseMax,
211
            TOGGLE_HUMANIZE_MISS,
212
            TOGGLE_HUMANIZE_SWING,
213
            TOGGLE_HUMANIZE_PAUSE
214
    );
215
    private final EnumValue<ProtocolMode> protocolMode =
216
            visibleWhen(enumCommon(
217
                    "autoattack_protocol_mode",
218
                    "protocol_mode",
219
                    CommonSettingSchemas.COMBAT_PROTOCOL,
220
                    ProtocolMode.AUTO,
221
                    ProtocolMode.values()
222
            ), () -> objective.get() != ObjectiveType.BLOCK);
223
    private final BooleanMapValue protocolHeuristicSources =
224
            visibleWhen(protocolHeuristics(
225
                    "autoattack_protocol_heuristics",
226
                    "protocol_heuristics",
227
                    CommonSettingSchemas.COMBAT_PROTOCOL_HEURISTICS
228
            ), () -> objective.get() != ObjectiveType.BLOCK && protocolMode.get() == ProtocolMode.AUTO);
229
    private long lastFinishBreak = 0L;
230
    private int postUseDelayTicks = 0;
231
    private boolean wasUsingItem = false;
232
    private int lastSyncHandledAge = -1;
233
234
    private static LinkedHashMap<String, Boolean> targetFilterDefaults() {
235
        LinkedHashMap<String, Boolean> defaults = new LinkedHashMap<>();
236
        defaults.put(TargetFilters.PLAYERS_ONLY, false);
237
        defaults.put(TargetFilters.IGNORE_FRIENDS, true);
238
        defaults.put(TargetFilters.IGNORE_STAFF, true);
239
        defaults.put(TargetFilters.IGNORE_ENEMIES, false);
240
        defaults.put(TargetFilters.IGNORE_ENTITIES, true);
241
        defaults.put(TargetFilters.VISIBLE_ONLY, false);
242
        return defaults;
243
    }
244
245
    private static LinkedHashMap<String, Boolean> humanizeDefaults() {
246
        LinkedHashMap<String, Boolean> defaults = new LinkedHashMap<>();
247
        defaults.put(TOGGLE_HUMANIZE_MISS, false);
248
        defaults.put(TOGGLE_HUMANIZE_SWING, false);
249
        defaults.put(TOGGLE_HUMANIZE_PAUSE, false);
250
        return defaults;
251
    }
252
253
    @Override
254
    public void onEnable() {
255
        clicker.reset();
256
        lastFinishBreak = 0L;
257
        postUseDelayTicks = 0;
258
        wasUsingItem = false;
259
        lastSyncHandledAge = -1;
260
        humanizer.reset();
261
    }
262
263
    @Override
264
    public void onDisable() {
265
        clicker.reset();
266
        postUseDelayTicks = 0;
267
        wasUsingItem = false;
268
        lastSyncHandledAge = -1;
269
        humanizer.reset();
270
    }
271
272
    @Override
273
    public void onTick() {
274
    }
275
276
    @EventHandler(priority = -1000)
277
    private void onSync(EventSync event) {
278
        if (!isEnabled()) return;
279
        if (mc.player == null || mc.options == null) return;
280
        if (mc.player.tickCount == lastSyncHandledAge) return;
281
        lastSyncHandledAge = mc.player.tickCount;
282
283
        clicker.setCps(cpsMin.get(), cpsMax.get());
284
        clicker.tick();
285
286
        boolean attackInput = mc.options.keyAttack.isDown();
287
        HitResult hit = resolveHitResult(mc.player);
288
        if (objective.get() == ObjectiveType.BLOCK) {
289
            // Let vanilla handle block breaking; no CPS/humanize in this mode.
290
            wasUsingItem = mc.player.isUsingItem();
291
            return;
292
        }
293
        boolean autoMode = isAutoMode();
294
295
        if (!attackInput && !autoMode) {
296
            wasUsingItem = mc.player.isUsingItem();
297
            return;
298
        }
299
300
        // In auto mode, only process entity clicks (avoid block/air spam).
301
        if (autoMode && !(hit instanceof EntityHitResult)) {
302
            wasUsingItem = mc.player.isUsingItem();
303
            return;
304
        }
305
306
        if (!isWeaponSelected(mc.player)) return;
307
308
        if (mc.gameMode != null && mc.gameMode.isDestroying()) {
309
            return;
310
        }
311
312
        if (delayOnBroken.get() && System.currentTimeMillis() - lastFinishBreak < 300L) {
313
            return;
314
        }
315
316
        boolean usingItem = mc.player.isUsingItem();
317
        boolean usingShield = usingItem
318
                && (mc.player.getUseItem().is(Items.SHIELD)
319
                || mc.player.getOffhandItem().is(Items.SHIELD));
320
        boolean usingFood = usingItem && FoodUtil.isFood(mc.player.getUseItem());
321
322
        RubberHand rh = Modules.get(RubberHand.class);
323
        boolean rhEnabled = rh != null && rh.isEnabled();
324
        boolean bypassItemUseLogic = false;
325
326
        if (usingItem && rhEnabled) {
327
            if (usingShield) {
328
                if (!rh.canAttackWhileShield()) {
329
                    wasUsingItem = true;
330
                    return;
331
                }
332
                bypassItemUseLogic = true;
333
            } else if (usingFood) {
334
                if (!rh.canAttackWhileEating()) {
335
                    wasUsingItem = true;
336
                    return;
337
                }
338
                bypassItemUseLogic = true;
339
            }
340
        }
341
342
        if (!usingItem && wasUsingItem && onItemUse.get() != UseMode.IGNORE) {
343
            int delay = delayPostStopUse.get();
344
            if (delay > 0) {
345
                postUseDelayTicks = delay;
346
            }
347
        }
348
349
        if (postUseDelayTicks > 0) {
350
            postUseDelayTicks--;
351
            wasUsingItem = usingItem;
352
            return;
353
        }
354
355
        if (usingItem && !bypassItemUseLogic) {
356
            switch (onItemUse.get()) {
357
                case WAIT -> {
358
                    wasUsingItem = true;
359
                    return;
360
                }
361
                case STOP -> {
362
                    mc.player.releaseUsingItem();
363
                    postUseDelayTicks = delayPostStopUse.get();
364
                    wasUsingItem = false;
365
                    return;
366
                }
367
                case IGNORE -> {
368
                    // continue
369
                }
370
            }
371
        }
372
373
        wasUsingItem = usingItem;
374
375
        if (!isOnObjective(hit)) return;
376
377
        int clickCount = 1;
378
        if (!autoMode) {
379
            clickCount = resolveClickCountForCurrentProtocol();
380
            if (clickCount <= 0) return;
381
        }
382
383
        if (!autoMode) {
384
            ClickHumanizer.Decision decision = humanizer.decide();
385
            switch (decision) {
386
                case PAUSE -> {
387
                    return;
388
                }
389
                case MISS_SWING -> {
390
                    mc.player.swing(InteractionHand.MAIN_HAND);
391
                    return;
392
                }
393
                case MISS -> {
394
                    return;
395
                }
396
                case CLICK -> {
397
                    // proceed
398
                }
399
            }
400
        }
401
402
        if (hit instanceof EntityHitResult entityHit) {
403
            if (!(entityHit.getEntity() instanceof LivingEntity living) || !canAttackNow(mc.player, living)) {
404
                return;
405
            }
406
        }
407
        performClick(mc.player, hit, clickCount);
408
    }
409
410
    @EventHandler
411
    public void onPacketSend(PacketEvent.Send event) {
412
        if (!isEnabled()) return;
413
        if (!delayOnBroken.get()) return;
414
        if (event.getPacket() instanceof ServerboundPlayerActionPacket pkt
415
                && pkt.getAction() == ServerboundPlayerActionPacket.Action.STOP_DESTROY_BLOCK) {
416
            lastFinishBreak = System.currentTimeMillis();
417
        }
418
    }
419
420
    private HitResult resolveHitResult(LocalPlayer player) {
421
        HitResult hit = mc.hitResult;
422
        Reach reach = Modules.get(Reach.class);
423
        if ((hit == null || hit.getType() != HitResult.Type.ENTITY)
424
                && reach != null && reach.isEnabled()) {
425
            EntityHitResult reachHit = reach.raycastEntities(player);
426
            if (reachHit != null) {
427
                hit = reachHit;
428
            }
429
        }
430
        return hit;
431
    }
432
433
    private boolean isOnObjective(HitResult hit) {
434
        return switch (objective.get()) {
435
            case ENEMY -> hit instanceof EntityHitResult eHit && isValidTarget(eHit.getEntity());
436
            case ENTITY -> hit instanceof EntityHitResult;
437
            case BLOCK -> hit instanceof BlockHitResult;
438
            case ANY -> true;
439
        };
440
    }
441
442
    private boolean isValidTarget(Entity entity) {
443
        if (!(entity instanceof LivingEntity living) || !living.isAlive()) return false;
444
        if (mc.player == null) return false;
445
446
        if (targetToggles.get(TargetFilters.PLAYERS_ONLY) && !(living instanceof Player)) {
447
            return false;
448
        }
449
450
        if (targetToggles.get(TargetFilters.VISIBLE_ONLY) && !mc.player.hasLineOfSight(living)) {
451
            return false;
452
        }
453
454
        if (targetToggles.get(TargetFilters.IGNORE_ENTITIES)) {
455
            var id = BuiltInRegistries.ENTITY_TYPE.getKey(living.getType());
456
            if (id != null && EntityFilters.get().isIgnoredEntity(id.toString())) {
457
                return false;
458
            }
459
        }
460
461
        if (living instanceof Player p) {
462
            CategoryType type = CategoryRules.determine(p.getGameProfile().name());
463
            if (type == CategoryType.BEDWARS_SELF) return false;
464
            if (targetToggles.get(TargetFilters.IGNORE_FRIENDS) && type == CategoryType.FRIEND) return false;
465
            if (targetToggles.get(TargetFilters.IGNORE_STAFF) && type == CategoryType.STAFF) return false;
466
            return !targetToggles.get(TargetFilters.IGNORE_ENEMIES)
467
                    || (type != CategoryType.ENEMY && type != CategoryType.BEDWARS_ENEMY);
468
        }
469
470
        return true;
471
    }
472
473
    private boolean isWeaponSelected(LocalPlayer player) {
474
        ItemStack stack = player.getMainHandItem();
475
        return switch (weapon.get()) {
476
            case SWORD -> stack.is(ItemTags.SWORDS);
477
            case AXE -> stack.is(ItemTags.AXES);
478
            case BOTH -> stack.is(ItemTags.SWORDS) || stack.is(ItemTags.AXES);
479
            case ANY -> true;
480
        };
481
    }
482
483
    private void performClick(LocalPlayer player, HitResult hit, int clickCount) {
484
        boolean legacyProtocol = isLegacyAttackProtocol();
485
        if (hit instanceof EntityHitResult eHit) {
486
            Entity target = eHit.getEntity();
487
            if (objective.get() == ObjectiveType.ENEMY && !isValidTarget(target)) {
488
                return;
489
            }
490
491
            Reach reach = Modules.get(Reach.class);
492
            if (reach != null && reach.isEnabled()) {
493
                mc.hitResult = eHit;
494
            }
495
496
            if (target instanceof LivingEntity living) {
497
                CombatStrikeController.INSTANCE.tryAttack(
498
                        mc,
499
                        living,
500
                        legacyProtocol,
501
                        clickCount,
502
                        CombatStrikeController.SprintResetMode.LEGIT,
503
                        false,
504
                        null
505
                );
506
            }
507
            return;
508
        }
509
510
        if (objective.get() == ObjectiveType.BLOCK) {
511
            for (int i = 0; i < clickCount; i++) {
512
                player.swing(InteractionHand.MAIN_HAND);
513
                if (legacyProtocol) {
514
                    ResetAttackCooldown.resetAttackCooldown(player);
515
                }
516
            }
517
        }
518
    }
519
520
    public boolean isAutoMode() {
521
        return "auto".equalsIgnoreCase(mode.get());
522
    }
523
524
    public boolean shouldBlockBreaking() {
525
        return objective.get() != ObjectiveType.BLOCK;
526
    }
527
528
    private int resolveClickCountForCurrentProtocol() {
529
        if (!isLegacyAttackProtocol()) {
530
            return 1;
531
        }
532
533
        int clickCount = clicker.getClicksAt(0);
534
        if (clickCount <= 0) {
535
            return 0;
536
        }
537
538
        return clickCount;
539
    }
540
541
    private boolean canAttackNow(LocalPlayer player, LivingEntity target) {
542
        if (player == null) return false;
543
        return AttackPressing.INSTANCE.isCooldownComplete(player, target, isLegacyAttackProtocol(), 0);
544
    }
545
546
    private boolean isLegacyAttackProtocol() {
547
        return switch (protocolMode.get()) {
548
            case AUTO -> ProtocolUtil.isLegacyAttackProtocol(protocolHeuristicSources.getAll());
549
            case FORCE_1_8 -> true;
550
            case FORCE_1_9 -> false;
551
        };
552
    }
553
554
    public boolean usesLegacyProtocol() {
555
        return isLegacyAttackProtocol();
556
    }
557
558
    public enum ObjectiveType {
559
        ENEMY,
560
        ENTITY,
561
        BLOCK,
562
        ANY
563
    }
564
565
    public enum WeaponType {
566
        SWORD,
567
        AXE,
568
        BOTH,
569
        ANY
570
    }
571
572
    public enum UseMode {
573
        WAIT,
574
        STOP,
575
        IGNORE
576
    }
577
578
    @Getter
579
    @RequiredArgsConstructor
580
    public enum ProtocolMode implements EnumValue.IdProvider {
581
        AUTO("auto"),
582
        FORCE_1_8("1.8"),
583
        FORCE_1_9("1.9");
584
585
        private final String id;
586
    }
587
}
588
KiwiClientCOMBATsrc/main/java/com/tangykiwi/kiwiclient/module/combat/TriggerBot.javaJava · 65 lines · 2.4 KB

Automatically attacks the entity you are looking at

SettingsDelayTime
TriggerBot.javaJava · Minecraft 26.2 · 65 lines · 2.4 KB · complete file, verbatimOriginal ↗
1
package com.tangykiwi.kiwiclient.module.combat;
2
3
import static com.tangykiwi.kiwiclient.KiwiClient.mc;
4
5
import org.lwjgl.glfw.GLFW;
6
7
import java.util.Random;
8
9
import com.google.common.eventbus.Subscribe;
10
import com.tangykiwi.kiwiclient.KiwiClient;
11
import com.tangykiwi.kiwiclient.event.TickEvent;
12
import com.tangykiwi.kiwiclient.module.Category;
13
import com.tangykiwi.kiwiclient.module.Module;
14
import com.tangykiwi.kiwiclient.module.setting.SliderSetting;
15
import com.tangykiwi.kiwiclient.module.setting.ToggleSetting;
16
17
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
18
import net.minecraft.world.InteractionHand;
19
import net.minecraft.world.entity.Entity;
20
import net.minecraft.world.entity.LivingEntity;
21
import net.minecraft.world.entity.player.Player;
22
23
public class TriggerBot extends Module {
24
    public TriggerBot() {
25
        super("TriggerBot", "Automatically attacks the entity you are looking at", GLFW.GLFW_KEY_X, Category.COMBAT,
26
            new ToggleSetting("Delay", "Enable random delay", false).withChildren(
27
                new SliderSetting("Time", "Average random delay in milliseconds", 0, 500, 100, -1)
28
            )
29
        );
30
    }
31
32
    private long lastAttack = 0;
33
    private long randomDelay = 0;
34
    private final Random random = new Random();
35
36
    @Subscribe
37
    public void onTick(TickEvent.Pre e) {
38
        ToggleSetting delay = getSetting(0).asToggle();
39
        if (delay.getValue()) {
40
            if (System.currentTimeMillis() - lastAttack < randomDelay) {
41
                return;
42
            }
43
        }
44
45
        Player player = mc.player;
46
47
        if(player == null || !player.isAlive() || player.isSpectator() || player.getAttackStrengthScale(1) < 1 || mc.gui.screen() instanceof AbstractContainerScreen) return;
48
49
        Entity target = mc.crosshairPickEntity;
50
        if (target == null || (target instanceof LivingEntity && ((LivingEntity) target).isDeadOrDying()) || !target.isAlive()) return;
51
52
        Criticals criticals = (Criticals) KiwiClient.moduleManager.getModule(Criticals.class);
53
        if (criticals.isEnabled()) {
54
            criticals.doCritical(target);
55
        }
56
        mc.gameMode.attack(player, target);
57
        
58
        if (delay.getValue()) {
59
            lastAttack = System.currentTimeMillis();
60
            randomDelay = (long) (delay.getChild(0).asSlider().getValueD() * (1 + random.nextGaussian() * 0.18));
61
        }
62
        player.swing(InteractionHand.MAIN_HAND);
63
    }
64
}
65