FightBot module

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

1 implementationCOMBAT

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.

OfflineClientCOMBATsrc/main/java/com/jellypudding/offlineclient/modules/combat/FightBot.javaJava · 106 lines · 4.1 KB

Runs after a target and fights it for you.

SettingsRangeDistanceSearch rangeUse pathfinderPause in containers
FightBot.javaJava · Minecraft 26.2 · 106 lines · 4.1 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.Chase;
12
import com.jellypudding.offlineclient.util.EntityFilter;
13
import com.jellypudding.offlineclient.util.EntityUtil;
14
import com.jellypudding.offlineclient.util.InventoryUtil;
15
import com.jellypudding.offlineclient.util.SwingMode;
16
import com.jellypudding.offlineclient.util.TargetFilter;
17
import com.jellypudding.offlineclient.util.TargetPriority;
18
import net.minecraft.world.InteractionHand;
19
import net.minecraft.world.entity.Entity;
20
21
import java.util.List;
22
23
// Runs at whatever it is set on and hits it until one of you is dead.
24
public final class FightBot extends Module {
25
26
    private final NumberSetting range = new NumberSetting("Range",
27
        "How close a target has to be before the hits start.", 4.25, 1, 6, 0.05).min(1).max(6);
28
    private final NumberSetting distance = new NumberSetting("Distance",
29
        "How close the bot walks. Keep it under the range.", 3, 1, 6, 0.05).min(0.5).max(6);
30
    private final NumberSetting searchRange = new NumberSetting("Search range",
31
        "How far away a target is picked up.", 32, 8, 64, 1, " blocks").min(1);
32
    private final EnumSetting<TargetPriority> priority =
33
        TargetPriority.setting("Attacks", TargetPriority.NEAREST);
34
    private final BoolSetting usePath = new BoolSetting("Use pathfinder",
35
        "Finds a way round what is in between instead of running straight at the target.", false);
36
    private final EnumSetting<SwingMode> swing = SwingMode.setting(SwingMode.BOTH);
37
    private final BoolSetting pauseInContainers = new BoolSetting("Pause in containers",
38
        "Holds off whilst a chest or another container is open.", true);
39
    private final EntityFilter filter = EntityFilter.living("Fight", "fought", true,
40
        EntityFilter.Pick.NONE, List.of());
41
    private final TargetFilter targets = new TargetFilter();
42
    private final AttackTimer timer = new AttackTimer();
43
44
    private final Chase chase = new Chase();
45
    private Entity target;
46
47
    public FightBot() {
48
        super("FightBot", "Runs after a target and fights it for you.", Category.COMBAT);
49
        addSettings(range, distance, searchRange, priority, usePath, swing, pauseInContainers);
50
        addSettings(filter.settings());
51
        addSettings(targets.settings());
52
        addSettings(timer.settings());
53
        searchTags("fight bot", "auto fight", "pvp bot");
54
    }
55
56
    @Override
57
    public boolean savesEnabledState() {
58
        return false;
59
    }
60
61
    @Override
62
    public String getSuffix() {
63
        return target == null ? null : target.getName().getString();
64
    }
65
66
    @Override
67
    protected void onEnable() {
68
        timer.clear();
69
        target = null;
70
    }
71
72
    @Override
73
    protected void onDisable() {
74
        chase.stop();
75
        target = null;
76
    }
77
78
    @Subscribe
79
    private void onTick(TickEvent event) {
80
        if (!inGame() || mc.player.isSpectator() || mc.player.isDeadOrDying()) {
81
            chase.stop();
82
            return;
83
        }
84
        if (pauseInContainers.isOn() && InventoryUtil.isStorage(mc.gui.screen())) {
85
            chase.stop();
86
            return;
87
        }
88
        target = EntityUtil.best(searchRange.getValue(), priority.getValue(), this::attackable);
89
        if (target == null) {
90
            chase.stop();
91
            return;
92
        }
93
        chase.tick(target, distance.getValue(), usePath.isOn());
94
        if (!timer.ready() || EntityUtil.reachDistance(mc.player, target) > range.getValue()) {
95
            return;
96
        }
97
        mc.gameMode.attack(mc.player, target);
98
        swing.getValue().swing(InteractionHand.MAIN_HAND);
99
        timer.spent();
100
    }
101
102
    private boolean attackable(Entity entity) {
103
        return targets.attackable(entity, filter);
104
    }
105
}
106