aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/DwarvenHud.java
blob: 78362ac1c5e269380cef29cca88638c906c383eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package me.xmrvizzy.skyblocker.skyblock.dwarven;

import me.xmrvizzy.skyblocker.config.SkyblockerConfig;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.text.LiteralText;
import net.minecraft.util.Formatting;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DwarvenHud {


    public static MinecraftClient client = MinecraftClient.getInstance();

    public static final List<String> COMMISSIONS = List.of(
            "((?:Titanium|Mithril|Hard Stone) Miner): (.*)",
            "((?:Ice Walker|Goblin|Goblin Raid|Automaton|Sludge|Team Treasuite Member|Yog|Boss Corleone|Thyst) Slayer): (.*)",
            "((?:Lava Springs|Cliffside Veins|Rampart's Quarry|Upper Mines|Royal Mines) Mithril): (.*)",
            "((?:Lava Springs|Cliffside Veins|Rampart's Quarry|Upper Mines|Royal Mines) Titanium): (.*)",
            "(Goblin Raid): (.*)",
            "((?:Powder Ghast|Star Sentry) Puncher): (.*)",
            "((?<!Lucky )Raffle): (.*)",
            "(Lucky Raffle): (.*)",
            "(2x Mithril Powder Collector): (.*)",
            "((?:Ruby|Amber|Sapphire|Jade|Amethyst|Topaz) Gemstone Collector): (.*)",
            "((?:Amber|Sapphire|Jade|Amethyst|Topaz) Crystal Hunter): (.*)",
            "(Chest Looter): (.*)"
            );
    public static void init(){
        HudRenderCallback.EVENT.register((matrixStack, tickDelta) -> {
            if (SkyblockerConfig.get().locations.dwarvenMines.dwarvenHud.enabled) {
                int hudX = SkyblockerConfig.get().locations.dwarvenMines.dwarvenHud.x;
                int hudY = SkyblockerConfig.get().locations.dwarvenMines.dwarvenHud.y;
                List<Commission> commissions = new ArrayList<>();
                client.getNetworkHandler().getPlayerList().forEach(playerListEntry -> {
                    if (playerListEntry.getDisplayName() != null) {
                        for (String pattern : COMMISSIONS) {
                            Matcher matcher = Pattern.compile(pattern).matcher(playerListEntry.getDisplayName().getString());
                            if (matcher.find()) {
                                commissions.add(new Commission(matcher.group(1), matcher.group(2)));
                            }

                        }
                    }
                });
                if (commissions.size() > 0){
                    if (SkyblockerConfig.get().locations.dwarvenMines.dwarvenHud.enableBackground)
                        DrawableHelper.fill(matrixStack, hudX, hudY, hudX + 200, hudY + (20 * commissions.size()), 0x64000000);
                    int y = 0;
                    for (Commission commission : commissions) {
                        client.textRenderer.drawWithShadow(matrixStack, new LiteralText(commission.commission).styled(style -> style.withColor(Formatting.AQUA)).append(new LiteralText(": " + commission.progression).styled(style -> style.withColor(Formatting.GREEN))), hudX + 5, hudY + y + 5, 0xFFFFFFFF);
                        y += 20;
                    }
                }
            }
        });
    }

    public static class Commission{
        String commission;
        String progression;

        public Commission(String commission, String progression){
            this.commission = commission;
            this.progression = progression;
        }
    }
}