Protect module

Protect: 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/Protect.javaJava · 139 lines · 5.7 KB

Follows a friend about and fights off whatever comes near.

SettingsFriendNameRangeAlert rangeUse pathfinderPause in containers
Protect.javaJava · Minecraft 26.2 · 139 lines · 5.7 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.setting.TextSetting;
11
import com.jellypudding.offlineclient.util.AttackTimer;
12
import com.jellypudding.offlineclient.util.Chase;
13
import com.jellypudding.offlineclient.util.ChatUtil;
14
import com.jellypudding.offlineclient.util.EntityFilter;
15
import com.jellypudding.offlineclient.util.EntityUtil;
16
import com.jellypudding.offlineclient.util.InventoryUtil;
17
import com.jellypudding.offlineclient.util.SwingMode;
18
import com.jellypudding.offlineclient.util.TargetFilter;
19
import net.minecraft.world.InteractionHand;
20
import net.minecraft.world.entity.Entity;
21
import net.minecraft.world.entity.LivingEntity;
22
import net.minecraft.world.entity.player.Player;
23
24
import java.util.List;
25
26
// A bodyguard. Sticks to one friend and hits whatever comes close.
27
public final class Protect extends Module {
28
29
    public enum Friend { NEAREST, NAME }
30
31
    // How far off the friend may get before the bot leaves a fight to catch up.
32
    private static final double STRAY = 24;
33
    private static final double KEEP_FROM_FRIEND = 2;
34
    private static final double KEEP_FROM_ENEMY = 3;
35
36
    private final EnumSetting<Friend> friendChoice = new EnumSetting<>("Friend",
37
        "Who is guarded.", Friend.NEAREST)
38
        .describe(Friend.NEAREST, "The nearest player when this is switched on.")
39
        .describe(Friend.NAME, "The player whose name you type in.");
40
    private final TextSetting friendName = new TextSetting("Name",
41
        "The name of the player to guard. Click to type it.", "")
42
        .under(friendChoice, Friend.NAME);
43
    private final NumberSetting range = new NumberSetting("Range",
44
        "How close an enemy has to be before the hits start.", 4.25, 1, 6, 0.05).min(1).max(6);
45
    private final NumberSetting alertRange = new NumberSetting("Alert range",
46
        "How close to you an enemy has to come to be fought at all.", 6, 2, 16, 0.5, " blocks")
47
        .min(1);
48
    private final BoolSetting usePath = new BoolSetting("Use pathfinder",
49
        "Finds a way round what is in between instead of running straight.", false);
50
    private final EnumSetting<SwingMode> swing = SwingMode.setting(SwingMode.BOTH);
51
    private final BoolSetting pauseInContainers = new BoolSetting("Pause in containers",
52
        "Holds off whilst a chest or another container is open.", true);
53
    private final EntityFilter filter = EntityFilter.living("Fight", "fought", false,
54
        EntityFilter.Pick.ALL, List.of());
55
    private final TargetFilter targets = new TargetFilter();
56
    private final AttackTimer timer = new AttackTimer();
57
58
    private final Chase chase = new Chase();
59
    private LivingEntity friend;
60
    private Entity enemy;
61
62
    public Protect() {
63
        super("Protect", "Follows a friend about and fights off whatever comes near.", Category.COMBAT);
64
        addSettings(friendChoice, friendName, range, alertRange, usePath, swing, pauseInContainers);
65
        addSettings(filter.settings());
66
        addSettings(targets.settings());
67
        addSettings(timer.settings());
68
        searchTags("bodyguard", "protect", "guard");
69
    }
70
71
    @Override
72
    public boolean savesEnabledState() {
73
        return false;
74
    }
75
76
    @Override
77
    public String getSuffix() {
78
        return friend == null ? null : "guarding " + friend.getName().getString();
79
    }
80
81
    @Override
82
    protected void onEnable() {
83
        timer.clear();
84
        enemy = null;
85
        friend = inGame() ? pickFriend() : null;
86
        if (friend == null) {
87
            ChatUtil.error("Nobody to guard was found.");
88
            setEnabled(false);
89
        }
90
    }
91
92
    @Override
93
    protected void onDisable() {
94
        chase.stop();
95
        friend = null;
96
        enemy = null;
97
    }
98
99
    private LivingEntity pickFriend() {
100
        String wanted = friendName.getValue().trim();
101
        Entity found = EntityUtil.nearest(STRAY * 4, entity -> entity instanceof Player player
102
            && player != mc.player && player.isAlive()
103
            && (friendChoice.is(Friend.NEAREST) || player.getName().getString().equalsIgnoreCase(wanted)));
104
        return found instanceof LivingEntity living ? living : null;
105
    }
106
107
    @Subscribe
108
    private void onTick(TickEvent event) {
109
        if (!inGame() || mc.player.isSpectator() || mc.player.isDeadOrDying()) {
110
            chase.stop();
111
            return;
112
        }
113
        if (friend == null || friend.isRemoved() || !friend.isAlive() || friend.level() != mc.level) {
114
            ChatUtil.message("The friend is gone. Protect switched off.");
115
            setEnabled(false);
116
            return;
117
        }
118
        if (pauseInContainers.isOn() && InventoryUtil.isStorage(mc.gui.screen())) {
119
            chase.stop();
120
            return;
121
        }
122
        enemy = EntityUtil.nearest(alertRange.getValue(), this::attackable);
123
        boolean fighting = enemy != null && mc.player.distanceTo(friend) < STRAY;
124
        Entity target = fighting ? enemy : friend;
125
        chase.tick(target, fighting ? KEEP_FROM_ENEMY : KEEP_FROM_FRIEND, usePath.isOn());
126
        if (!fighting || !timer.ready()
127
            || EntityUtil.reachDistance(mc.player, enemy) > range.getValue()) {
128
            return;
129
        }
130
        mc.gameMode.attack(mc.player, enemy);
131
        swing.getValue().swing(InteractionHand.MAIN_HAND);
132
        timer.spent();
133
    }
134
135
    private boolean attackable(Entity entity) {
136
        return entity != friend && targets.attackable(entity, filter);
137
    }
138
}
139