AutoNametag module

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

1 implementationWORLD

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.

OfflineClientWORLDsrc/main/java/com/jellypudding/offlineclient/modules/world/AutoNametag.javaJava · 128 lines · 4.9 KB

Names every chosen mob near you with the tag you carry.

SettingsEntitiesRangeRenameRotate
AutoNametag.javaJava · Minecraft 26.2 · 128 lines · 4.9 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.world;
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.RegistryListSetting;
11
import com.jellypudding.offlineclient.util.BlockUtil;
12
import com.jellypudding.offlineclient.util.ChatUtil;
13
import com.jellypudding.offlineclient.util.EntityUtil;
14
import com.jellypudding.offlineclient.util.InventoryUtil;
15
import com.jellypudding.offlineclient.util.InventoryUtil.SlotSwap;
16
import com.jellypudding.offlineclient.util.TargetPriority;
17
import net.minecraft.core.registries.BuiltInRegistries;
18
import net.minecraft.world.InteractionHand;
19
import net.minecraft.world.entity.Entity;
20
import net.minecraft.world.entity.EntityType;
21
import net.minecraft.world.entity.EntityTypes;
22
import net.minecraft.world.entity.LivingEntity;
23
import net.minecraft.world.entity.player.Player;
24
import net.minecraft.world.item.ItemStack;
25
import net.minecraft.world.item.Items;
26
import net.minecraft.world.phys.EntityHitResult;
27
28
import java.util.HashMap;
29
import java.util.List;
30
import java.util.Map;
31
32
// Puts the name tag in your hotbar on every chosen mob in reach.
33
public final class AutoNametag extends Module {
34
35
    // Ticks before the same mob is tried again.
36
    private static final int COOLDOWN = 20;
37
38
    private final RegistryListSetting<EntityType<?>> entities = new RegistryListSetting<>("Entities",
39
        "The mobs to name.", BuiltInRegistries.ENTITY_TYPE,
40
        List.of(EntityTypes.VILLAGER, EntityTypes.HORSE, EntityTypes.WOLF, EntityTypes.CAT));
41
    private final NumberSetting range = new NumberSetting("Range",
42
        "How close a mob has to be.", 5, 1, 6, 0.1).max(6);
43
    private final EnumSetting<TargetPriority> priority = TargetPriority.setting("Names", TargetPriority.NEAREST);
44
    private final BoolSetting rename = new BoolSetting("Rename",
45
        "Also names mobs that already carry a different name.", true);
46
    private final BoolSetting rotate = new BoolSetting("Rotate",
47
        "Turn towards the mob on the server side.", true);
48
49
    private final Map<Integer, Integer> tried = new HashMap<>();
50
    private int lastTick;
51
    private final SlotSwap slots = new SlotSwap();
52
    private int named;
53
54
    public AutoNametag() {
55
        super("AutoNametag", "Names every chosen mob near you with the tag you carry.", Category.WORLD);
56
        addSettings(entities, range, priority, rename, rotate);
57
        searchTags("name tag", "rename mobs");
58
    }
59
60
    @Override
61
    public String getSuffix() {
62
        return named == 0 ? null : named + " named";
63
    }
64
65
    @Override
66
    protected void onEnable() {
67
        tried.clear();
68
        named = 0;
69
    }
70
71
    @Override
72
    protected void onDisable() {
73
        slots.restoreIfMine();
74
    }
75
76
    @Subscribe
77
    private void onTick(TickEvent event) {
78
        if (!inGame() || mc.player.isSpectator() || mc.gui.screen() != null) {
79
            return;
80
        }
81
        int slot = InventoryUtil.hotbarSlot(stack -> stack.is(Items.NAME_TAG));
82
        if (slot == -1) {
83
            ChatUtil.error("No name tag in the hotbar.");
84
            setEnabled(false);
85
            return;
86
        }
87
        int now = mc.player.tickCount;
88
        if (now < lastTick) {
89
            tried.clear();
90
        }
91
        lastTick = now;
92
        tried.values().removeIf(expiry -> expiry <= now);
93
        ItemStack tag = mc.player.getInventory().getItem(slot);
94
95
        Entity target = EntityUtil.best(range.getValue(), priority.getValue(),
96
            entity -> wanted(entity, tag));
97
        if (target == null) {
98
            slots.restoreIfMine();
99
            return;
100
        }
101
        slots.select(slot);
102
        if (rotate.isOn()) {
103
            BlockUtil.faceVector(target.getBoundingBox().getCenter());
104
        }
105
        EntityHitResult hit = new EntityHitResult(target, target.getBoundingBox().getCenter());
106
        if (mc.gameMode.interact(mc.player, target, hit, InteractionHand.MAIN_HAND).consumesAction()) {
107
            mc.player.swing(InteractionHand.MAIN_HAND);
108
            named++;
109
        }
110
        tried.put(target.getId(), now + COOLDOWN);
111
        slots.restoreIfMine();
112
    }
113
114
    private boolean wanted(Entity entity, ItemStack tag) {
115
        if (entity instanceof Player || !(entity instanceof LivingEntity living) || !living.isAlive()) {
116
            return false;
117
        }
118
        if (!entities.contains(entity.getType()) || tried.containsKey(entity.getId())) {
119
            return false;
120
        }
121
        if (!entity.hasCustomName()) {
122
            return true;
123
        }
124
        // A mob already wearing this exact name gains nothing from another tag.
125
        return rename.isOn() && !entity.getCustomName().getString().equals(tag.getHoverName().getString());
126
    }
127
}
128