DefineTarget module

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

1 implementationMISC

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.

CombatantMISCsrc/main/java/combatant/client/features/module/modules/misc/DefineTarget.javaJava · 332 lines · 12.4 KB
SettingsdefineTargetBedwarsRelationsdefineTargetBedwarsColorModedefineTargetModedefineTargetBlockCategoriesdefineTargetBedwarsBlockCategories
DefineTarget.javaJava · Minecraft 26.2 · 332 lines · 12.4 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Combatant Client distribution.
3
 * Copyright (c) 2026 pivosos2007.
4
 *
5
 * Licensed under the GNU General Public License v3.0.
6
 */
7
8
package combatant.client.features.module.modules.misc;
9
10
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
11
import net.minecraft.client.Minecraft;
12
import net.minecraft.core.registries.BuiltInRegistries;
13
import net.minecraft.world.InteractionResult;
14
import net.minecraft.world.entity.Entity;
15
import net.minecraft.world.entity.player.Player;
16
import net.minecraft.world.phys.EntityHitResult;
17
import net.minecraft.world.phys.HitResult;
18
import combatant.client.config.values.BooleanMapValue;
19
import combatant.client.config.values.BooleanValue;
20
import combatant.client.config.values.EnumValue;
21
import combatant.client.config.values.ModeValue;
22
import combatant.client.features.gui.clickgui.settings.TextListSetting;
23
import combatant.client.features.module.Module;
24
import combatant.client.features.module.ModuleCategory;
25
import combatant.client.features.module.ModuleInfo;
26
import combatant.client.features.module.Notifier;
27
import combatant.client.features.relations.CategoryRules;
28
import combatant.client.features.relations.CategoryType;
29
import combatant.client.features.relations.EntityFilters;
30
import combatant.client.features.relations.PlayerRelations;
31
import combatant.client.util.text.ChatNameUtil;
32
33
/**
34
 * Quick target classification under the crosshair:
35
 * - Players: friend/enemy/staff
36
 * - Non-players: toggle ignored entities (EntityFilters)
37
 */
38
//todo Description
39
@ModuleInfo(id = "definetarget", displayName = "DefineTarget", aliases = {"clickfriend"}, category = ModuleCategory.MISC)
40
public class DefineTarget extends Module {
41
42
    private static final String SETTING_MODE = "mode";
43
    private static final String SETTING_BLOCK_DAMAGE_TO = "block_damage_to";
44
    private static final String SETTING_BEDWARS_RELATIONS = "bedwars_relations";
45
    private static final String SETTING_BEDWARS_COLOR_MODE = "bedwars_color_mode";
46
    private static final String SETTING_BLOCK_DAMAGE_TO_BEDWARS = "block_damage_to_bedwars";
47
    private static final String SETTING_IGNORED_ENTITIES = "ignored_entities";
48
    private static final String ACTION_TOGGLE_TARGET = "toggle_target";
49
    private final Minecraft mc = Minecraft.getInstance();
50
    private final BooleanValue bedwarsRelations = bool("defineTargetBedwarsRelations", SETTING_BEDWARS_RELATIONS, false);
51
    private final EnumValue<BedwarsColorMode> bedwarsColorMode =
52
            visibleWhen(enumSetting("defineTargetBedwarsColorMode", SETTING_BEDWARS_COLOR_MODE, BedwarsColorMode.RELATION_COLORS, BedwarsColorMode.values()),
53
                    bedwarsRelations::get);
54
    private final ModeValue modeValue = modeSetting(
55
            "defineTargetMode",
56
            SETTING_MODE,
57
            "friend",
58
            "friend",
59
            "enemy",
60
            "staff"
61
    );
62
    private final BooleanMapValue blockCategories = group(
63
            "defineTargetBlockCategories",
64
            SETTING_BLOCK_DAMAGE_TO,
65
            new java.util.LinkedHashMap<>() {{
66
                put("friends", true);
67
                put("staff", true);
68
                put("enemies", false);
69
                put("entities", true);
70
            }}
71
    );
72
    private final BooleanMapValue bedwarsBlockCategories = visibleWhen(group(
73
            "defineTargetBedwarsBlockCategories",
74
            SETTING_BLOCK_DAMAGE_TO_BEDWARS,
75
            new java.util.LinkedHashMap<>() {{
76
                put("bedwars_self", true);
77
                put("bedwars_enemy", false);
78
            }}
79
    ), bedwarsRelations::get);
80
81
    private long lastBlockToast;
82
83
    {
84
        addAction(ACTION_TOGGLE_TARGET, "MOUSE_MIDDLE");
85
        addRelationSettings();
86
87
        AttackEntityCallback.EVENT.register((player, world, hand, target, hitResult) -> {
88
            if (!isEnabled()) return InteractionResult.PASS;
89
            if (target instanceof Player targetPlayer) {
90
                String name = targetPlayer.getGameProfile().name();
91
                CategoryType type = CategoryRules.determine(name);
92
93
                boolean block = switch (type) {
94
                    case FRIEND -> blockCategories.get("friends");
95
                    case STAFF -> blockCategories.get("staff");
96
                    case ENEMY -> blockCategories.get("enemies");
97
                    case BEDWARS_SELF -> bedwarsRelations.get() && bedwarsBlockCategories.get("bedwars_self");
98
                    case BEDWARS_ENEMY -> bedwarsRelations.get() && bedwarsBlockCategories.get("bedwars_enemy");
99
                    default -> false;
100
                };
101
102
                if (block) {
103
                    notifyBlock(target);
104
                    return InteractionResult.FAIL;
105
                }
106
            }
107
            boolean blockEntities = blockCategories.get("entities");
108
            if (blockEntities) {
109
                var id = BuiltInRegistries.ENTITY_TYPE.getKey(target.getType());
110
                if (id != null && EntityFilters.get().isIgnoredEntity(id.toString())) {
111
                    notifyBlock(target);
112
                    return InteractionResult.FAIL;
113
                }
114
            }
115
116
            return InteractionResult.PASS;
117
        });
118
    }
119
120
    private void addRelationSettings() {
121
        EntityFilters filters = EntityFilters.get();
122
123
        settings.add(new TextListSetting(SETTING_IGNORED_ENTITIES, filters.getIgnoredEntitiesValue(), TextListSetting.PickerMode.ENTITIES) {
124
            @Override
125
            public void applyEditorText(String rawText) {
126
                super.applyEditorText(rawText);
127
                filters.save();
128
            }
129
130
            @Override
131
            public Object save() {
132
                return null;
133
            }
134
135
            @Override
136
            public void load(Object data) {
137
            }
138
        });
139
    }
140
141
    @Override
142
    public void onTick() {
143
        if (!isEnabled() || mc.player == null || mc.level == null) return;
144
145
        if (isActionPressedOnce(ACTION_TOGGLE_TARGET)) {
146
            handleToggle();
147
        }
148
    }
149
150
    private void handleToggle() {
151
        HitResult hit = mc.hitResult;
152
        if (!(hit instanceof EntityHitResult ehr)) return;
153
        Entity ent = ehr.getEntity();
154
        if (ent == null) return;
155
156
        RelationTargetMode mode = RelationTargetMode.fromId(modeValue.get());
157
158
        if (ent instanceof Player p && mode != null) {
159
            String name = p.getGameProfile().name();
160
            if (name == null || name.isBlank()) return;
161
            boolean added = togglePlayerRelation(mode, name);
162
            notifyToggle(mode.fallbackLabel(), name, added);
163
            return;
164
        }
165
166
        // Non-player: always toggle ignore list in EntityFilters
167
        var id = BuiltInRegistries.ENTITY_TYPE.getKey(ent.getType());
168
        if (id == null) return;
169
        String key = id.toString().toLowerCase();
170
        EntityFilters filters = EntityFilters.get();
171
        if (filters.isIgnoredEntity(key)) {
172
            filters.removeIgnoredEntity(key);
173
            notifyToggle("Entity", key, false);
174
        } else {
175
            filters.addIgnoredEntity(key);
176
            notifyToggle("Entity", key, true);
177
        }
178
        filters.save();
179
    }
180
181
182
    public RelationTargetMode currentRelationTargetMode() {
183
        RelationTargetMode mode = RelationTargetMode.fromId(modeValue.get());
184
        return mode != null ? mode : RelationTargetMode.FRIEND;
185
    }
186
187
    public boolean hasBedwarsRelationsConfigured() {
188
        return bedwarsRelations.get();
189
    }
190
191
    public static boolean isPlayerInRelationMode(RelationTargetMode mode, String rawName) {
192
        if (mode == null) return false;
193
        String name = normalizePlayerName(rawName);
194
        if (name.isBlank()) return false;
195
        PlayerRelations rel = PlayerRelations.get();
196
        return switch (mode) {
197
            case FRIEND -> rel.isFriend(name);
198
            case ENEMY -> rel.isEnemyPersisted(name);
199
            case STAFF -> rel.isStaff(name);
200
        };
201
    }
202
203
    public static boolean assignPlayerRelation(RelationTargetMode mode, String rawName) {
204
        if (mode == null) return false;
205
        String name = normalizePlayerName(rawName);
206
        if (!ChatNameUtil.isNickLike(name)) return false;
207
        PlayerRelations rel = PlayerRelations.get();
208
        boolean changed = removeAllPersistentRelations(rel, name);
209
        changed |= addPersistentRelation(rel, mode, name);
210
        if (changed) rel.save();
211
        return changed;
212
    }
213
214
    public static boolean togglePlayerRelation(RelationTargetMode mode, String rawName) {
215
        if (mode == null) return false;
216
        String name = normalizePlayerName(rawName);
217
        if (!ChatNameUtil.isNickLike(name)) return false;
218
        PlayerRelations rel = PlayerRelations.get();
219
        boolean wasInMode = isPlayerInRelationMode(mode, name);
220
        boolean changed;
221
        if (wasInMode) {
222
            changed = removePersistentRelation(rel, mode, name);
223
            if (changed) rel.save();
224
            return false;
225
        }
226
        changed = removeAllPersistentRelations(rel, name);
227
        changed |= addPersistentRelation(rel, mode, name);
228
        if (changed) rel.save();
229
        return true;
230
    }
231
232
    private static String normalizePlayerName(String rawName) {
233
        String normalized = ChatNameUtil.normalizeNickCandidate(rawName);
234
        return normalized == null ? "" : normalized;
235
    }
236
237
    private static boolean addPersistentRelation(PlayerRelations rel, RelationTargetMode mode, String name) {
238
        if (rel == null || mode == null || name == null || name.isBlank()) return false;
239
        return switch (mode) {
240
            case FRIEND -> rel.addFriend(name);
241
            case ENEMY -> rel.addEnemy(name);
242
            case STAFF -> rel.addStaff(name);
243
        };
244
    }
245
246
    private static boolean removePersistentRelation(PlayerRelations rel, RelationTargetMode mode, String name) {
247
        if (rel == null || mode == null || name == null || name.isBlank()) return false;
248
        return switch (mode) {
249
            case FRIEND -> rel.removeFriend(name);
250
            case ENEMY -> rel.removeEnemy(name);
251
            case STAFF -> rel.removeStaff(name);
252
        };
253
    }
254
255
    private static boolean removeAllPersistentRelations(PlayerRelations rel, String name) {
256
        if (rel == null || name == null || name.isBlank()) return false;
257
        boolean changed = false;
258
        changed |= rel.removeFriend(name);
259
        changed |= rel.removeEnemy(name);
260
        changed |= rel.removeStaff(name);
261
        changed |= rel.removeBedwarsSelf(name);
262
        changed |= rel.removeBedwarsEnemy(name);
263
        return changed;
264
    }
265
266
    private void notifyToggle(String type, String target, boolean added) {
267
        Notifier.state(type + ": " + target, added);
268
    }
269
270
    private void notifyBlock(Entity target) {
271
        long now = System.currentTimeMillis();
272
        if (now - lastBlockToast < 600) return;
273
        lastBlockToast = now;
274
        String name = target.getName() != null ? target.getName().getString() : target.getType().toString();
275
        Notifier.info("Blocked damage to " + name);
276
    }
277
278
    public boolean isBedwarsRelationsActive() {
279
        return isEnabled() && bedwarsRelations.get();
280
    }
281
282
    public boolean useBedwarsTeamColors() {
283
        return isBedwarsRelationsActive() && bedwarsColorMode.get() == BedwarsColorMode.TEAM_COLORS;
284
    }
285
286
    public enum RelationTargetMode {
287
        FRIEND("friend", "Friend"),
288
        ENEMY("enemy", "Enemy"),
289
        STAFF("staff", "Staff");
290
291
        private final String id;
292
        private final String fallbackLabel;
293
294
        RelationTargetMode(String id, String fallbackLabel) {
295
            this.id = id;
296
            this.fallbackLabel = fallbackLabel;
297
        }
298
299
        public String id() {
300
            return id;
301
        }
302
303
        public String fallbackLabel() {
304
            return fallbackLabel;
305
        }
306
307
        public int color(PlayerRelations relations) {
308
            PlayerRelations rel = relations != null ? relations : PlayerRelations.get();
309
            return switch (this) {
310
                case FRIEND -> rel.colorFriend();
311
                case ENEMY -> rel.colorEnemy();
312
                case STAFF -> rel.colorStaff();
313
            };
314
        }
315
316
        public static RelationTargetMode fromId(String rawId) {
317
            if (rawId == null || rawId.isBlank()) return FRIEND;
318
            String id = rawId.toLowerCase(java.util.Locale.ROOT);
319
            if (id.equals("entities")) return FRIEND;
320
            for (RelationTargetMode mode : values()) {
321
                if (mode.id.equals(id)) return mode;
322
            }
323
            return FRIEND;
324
        }
325
    }
326
327
    public enum BedwarsColorMode {
328
        RELATION_COLORS,
329
        TEAM_COLORS
330
    }
331
}
332