Combat module

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

1 implementationHUD

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.

NicotineHUDsrc/client/java/nicotine/mod/mods/hud/Combat.javaJava · 113 lines · 4.2 KB

Shows the nearest player around you in a nice HUD

SettingsIgnoreFriendsDistanceTotemCountOtherPlayers
Combat.javaJava · Minecraft 26.3 · 113 lines · 4.2 KB · complete file, verbatimOriginal ↗
1
package nicotine.mod.mods.hud;
2
3
import net.minecraft.ChatFormatting;
4
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
5
import net.minecraft.client.player.AbstractClientPlayer;
6
import nicotine.events.GuiRenderBeforeEvent;
7
import nicotine.mod.ModCategory;
8
import nicotine.mod.HUDMod;
9
import nicotine.mod.option.ToggleOption;
10
import nicotine.screens.clickgui.HUDScreen;
11
import nicotine.util.ColorUtil;
12
import nicotine.util.EventBus;
13
import nicotine.util.Player;
14
import nicotine.util.render.Render2D;
15
16
import java.util.ArrayList;
17
import java.util.Arrays;
18
import java.util.List;
19
20
import static nicotine.util.Common.*;
21
22
public class Combat extends HUDMod {
23
    private final ToggleOption ignoreFriends = new ToggleOption("IgnoreFriends");
24
    private final ToggleOption distance = new ToggleOption("Distance");
25
    private final ToggleOption totemCount = new ToggleOption("TotemCount");
26
    private final ToggleOption otherPlayers = new ToggleOption("OtherPlayers");
27
    
28
    private final int PLAYER_MODEL_SIZE = 30;
29
    private final int WINDOW_WIDTH = 200;
30
    private final int WINDOW_HEIGHT = 70;
31
    private final int PADDING = 10;
32
33
    public Combat() {
34
        super(ModCategory.HUD, "Combat", "Shows the nearest player around you in a nice HUD");
35
        this.addOptions(Arrays.asList(ignoreFriends, distance, totemCount, otherPlayers));
36
    }
37
38
    @Override
39
    protected void init() {
40
        EventBus.register(GuiRenderBeforeEvent.class, event -> {
41
            if (!this.enabled)
42
                return true;
43
44
            AbstractClientPlayer nearestPlayer = Player.findNearestPlayer(ignoreFriends.enabled);
45
46
            if (mc.gui.screen() instanceof HUDScreen)
47
                nearestPlayer = mc.player;
48
49
            if (nearestPlayer == null || mc.gui.screen() instanceof InventoryScreen)
50
                return true;
51
52
            final int CENTER_WIDTH = mc.getWindow().getGuiScaledWidth() / 2;
53
54
            int posX = CENTER_WIDTH - (WINDOW_WIDTH / 2);
55
            int posY = 10;
56
57
            event.drawContext.fill(posX, posY, posX + WINDOW_WIDTH, posY + WINDOW_HEIGHT, ColorUtil.BACKGROUND_COLOR);
58
            Render2D.drawBorder(event.drawContext, posX, posY, WINDOW_WIDTH, WINDOW_HEIGHT, ColorUtil.getPulsatingColor());
59
60
            int modelX1 = posX;
61
            int modelY1 = posY;
62
            int modelX2 = posX + (PADDING + 5) + PLAYER_MODEL_SIZE;
63
            int modelY2 = posY + PADDING + (PLAYER_MODEL_SIZE * 2);
64
65
            InventoryScreen.extractEntityInInventoryFollowsMouse(event.drawContext,
66
                    modelX1,
67
                    modelY1,
68
                    modelX2,
69
                    modelY2,
70
                    PLAYER_MODEL_SIZE,
71
                    0,
72
                    (modelX1 + modelX2) / 2.0F,
73
                    (modelY1 + modelY2) / 2.0F,
74
                    nearestPlayer
75
            );
76
77
            List<String> playerInfo = new ArrayList<>();
78
79
            String playerName = nearestPlayer.getName().getString();
80
81
            if (friendList.contains(nearestPlayer.getUUID())) {
82
                playerInfo.add("[F] " + playerName);
83
            } else {
84
                playerInfo.add(playerName);
85
            }
86
87
            playerInfo.add("");
88
89
            if (distance.enabled)
90
                playerInfo.add(String.format("%.1f %sblocks away", nearestPlayer.distanceTo(mc.player), ChatFormatting.WHITE));
91
92
            if (totemCount.enabled) {
93
                int poppedTotems = totemPopCounter.getOrDefault(nearestPlayer, 0);
94
                playerInfo.add(String.format("%d %spopped totems", poppedTotems, ChatFormatting.WHITE));
95
            }
96
97
            if (otherPlayers.enabled)
98
                playerInfo.add(String.format("%d %sother players nearby", mc.level.players().size() - (mc.gui.screen() instanceof HUDScreen ? 1 : 2), ChatFormatting.WHITE));
99
100
            for (int i = 0; i < playerInfo.size(); i++) {
101
                event.drawContext.text(mc.font,
102
                        playerInfo.get(i),
103
                        posX + (WINDOW_WIDTH / 2) - (mc.font.width(playerInfo.get(i)) / 2),
104
                        posY + PADDING + (mc.font.lineHeight * i),
105
                        ColorUtil.ACTIVE_FOREGROUND_COLOR,
106
                        true);
107
            }
108
109
            return true;
110
        });
111
    }
112
}
113