aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/MinionWidget.java
blob: 35b9a0c6cb3ef4fe7641e5a864eb3a6d788d2ed9 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package de.hysky.skyblocker.skyblock.tabhud.widget;

import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import de.hysky.skyblocker.skyblock.tabhud.util.PlayerListMgr;
import de.hysky.skyblocker.skyblock.tabhud.widget.component.IcoTextComponent;
import de.hysky.skyblocker.skyblock.tabhud.widget.component.PlainTextComponent;

import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

// this widget shows info about minions placed on the home island

public class MinionWidget extends Widget {
    private static final MutableText TITLE = Text.literal("Minions").formatted(Formatting.DARK_AQUA,
            Formatting.BOLD);

    private static final HashMap<String, ItemStack> MIN_ICOS = new HashMap<>();

    // hmm...
    static {
        MIN_ICOS.put("Blaze", new ItemStack(Items.BLAZE_ROD));
        MIN_ICOS.put("Cave Spider", new ItemStack(Items.SPIDER_EYE));
        MIN_ICOS.put("Creeper", new ItemStack(Items.GUNPOWDER));
        MIN_ICOS.put("Enderman", new ItemStack(Items.ENDER_PEARL));
        MIN_ICOS.put("Ghast", new ItemStack(Items.GHAST_TEAR));
        MIN_ICOS.put("Magma Cube", new ItemStack(Items.MAGMA_CREAM));
        MIN_ICOS.put("Skeleton", new ItemStack(Items.BONE));
        MIN_ICOS.put("Slime", new ItemStack(Items.SLIME_BALL));
        MIN_ICOS.put("Spider", new ItemStack(Items.STRING));
        MIN_ICOS.put("Zombie", new ItemStack(Items.ROTTEN_FLESH));
        MIN_ICOS.put("Cactus", new ItemStack(Items.CACTUS));
        MIN_ICOS.put("Carrot", new ItemStack(Items.CARROT));
        MIN_ICOS.put("Chicken", new ItemStack(Items.CHICKEN));
        MIN_ICOS.put("Cocoa Beans", new ItemStack(Items.COCOA_BEANS));
        MIN_ICOS.put("Cow", new ItemStack(Items.BEEF));
        MIN_ICOS.put("Melon", new ItemStack(Items.MELON_SLICE));
        MIN_ICOS.put("Mushroom", new ItemStack(Items.RED_MUSHROOM));
        MIN_ICOS.put("Nether Wart", new ItemStack(Items.NETHER_WART));
        MIN_ICOS.put("Pig", new ItemStack(Items.PORKCHOP));
        MIN_ICOS.put("Potato", new ItemStack(Items.POTATO));
        MIN_ICOS.put("Pumpkin", new ItemStack(Items.PUMPKIN));
        MIN_ICOS.put("Rabbit", new ItemStack(Items.RABBIT));
        MIN_ICOS.put("Sheep", new ItemStack(Items.WHITE_WOOL));
        MIN_ICOS.put("Sugar Cane", new ItemStack(Items.SUGAR_CANE));
        MIN_ICOS.put("Wheat", new ItemStack(Items.WHEAT));
        MIN_ICOS.put("Clay", new ItemStack(Items.CLAY));
        MIN_ICOS.put("Fishing", new ItemStack(Items.FISHING_ROD));
        MIN_ICOS.put("Coal", new ItemStack(Items.COAL));
        MIN_ICOS.put("Cobblestone", new ItemStack(Items.COBBLESTONE));
        MIN_ICOS.put("Diamond", new ItemStack(Items.DIAMOND));
        MIN_ICOS.put("Emerald", new ItemStack(Items.EMERALD));
        MIN_ICOS.put("End Stone", new ItemStack(Items.END_STONE));
        MIN_ICOS.put("Glowstone", new ItemStack(Items.GLOWSTONE_DUST));
        MIN_ICOS.put("Gold", new ItemStack(Items.GOLD_INGOT));
        MIN_ICOS.put("Gravel", new ItemStack(Items.GRAVEL));
        MIN_ICOS.put("Hard Stone", new ItemStack(Items.STONE));
        MIN_ICOS.put("Ice", new ItemStack(Items.ICE));
        MIN_ICOS.put("Iron", new ItemStack(Items.IRON_INGOT));
        MIN_ICOS.put("Lapis", new ItemStack(Items.LAPIS_LAZULI));
        MIN_ICOS.put("Mithril", new ItemStack(Items.PRISMARINE_CRYSTALS));
        MIN_ICOS.put("Mycelium", new ItemStack(Items.MYCELIUM));
        MIN_ICOS.put("Obsidian", new ItemStack(Items.OBSIDIAN));
        MIN_ICOS.put("Quartz", new ItemStack(Items.QUARTZ));
        MIN_ICOS.put("Red Sand", new ItemStack(Items.RED_SAND));
        MIN_ICOS.put("Redstone", new ItemStack(Items.REDSTONE));
        MIN_ICOS.put("Sand", new ItemStack(Items.SAND));
        MIN_ICOS.put("Snow", new ItemStack(Items.SNOWBALL));
        MIN_ICOS.put("Inferno", new ItemStack(Items.BLAZE_SPAWN_EGG));
        MIN_ICOS.put("Revenant", new ItemStack(Items.ZOMBIE_SPAWN_EGG));
        MIN_ICOS.put("Tarantula", new ItemStack(Items.SPIDER_SPAWN_EGG));
        MIN_ICOS.put("Vampire", new ItemStack(Items.REDSTONE));
        MIN_ICOS.put("Voidling", new ItemStack(Items.ENDERMAN_SPAWN_EGG));
        MIN_ICOS.put("Acacia", new ItemStack(Items.ACACIA_LOG));
        MIN_ICOS.put("Birch", new ItemStack(Items.BIRCH_LOG));
        MIN_ICOS.put("Dark Oak", new ItemStack(Items.DARK_OAK_LOG));
        MIN_ICOS.put("Flower", new ItemStack(Items.POPPY));
        MIN_ICOS.put("Jungle", new ItemStack(Items.JUNGLE_LOG));
        MIN_ICOS.put("Oak", new ItemStack(Items.OAK_LOG));
        MIN_ICOS.put("Spruce", new ItemStack(Items.SPRUCE_LOG));
    }

    // matches a minion entry
    // group 1: name
    // group 2: level
    // group 3: status
    public static final Pattern MINION_PATTERN = Pattern.compile("(?<name>.*) (?<level>[XVI]*) \\[(?<status>.*)\\]");

    public MinionWidget() {
        super(TITLE, Formatting.DARK_AQUA.getColorValue());
    }

    @Override
    public void updateContent() {

        // this looks a bit weird because if we used regex mismatch as a stop condition,
        //   it'd spam the chat.
        // not sure if not having that debug output is worth the cleaner solution here...

        for (int i = 48; i < 59; i++) {
            if (!this.addMinionComponent(i)) {
                break;
            }
        }

        // if more minions are placed than the tab menu can display,
        // a "And X more..." text is shown
        // look for that and add it to the widget
        String more = PlayerListMgr.strAt(59);
        if (more == null) {
            return;
        } else if (more.startsWith("And ")) {
            this.addComponent(new PlainTextComponent(Text.of(more)));
        } else {
            this.addMinionComponent(59);
        }
    }

    public boolean addMinionComponent(int i) {
        Matcher m = PlayerListMgr.regexAt(i, MINION_PATTERN);
        if (m != null) {

            String min = m.group("name");
            String lvl = m.group("level");
            String stat = m.group("status");

            MutableText mt = Text.literal(min + " " + lvl).append(Text.literal(": "));

            Formatting format = Formatting.RED;
            if (stat.equals("ACTIVE")) {
                format = Formatting.GREEN;
            } else if (stat.equals("SLOW")) {
                format = Formatting.YELLOW;
            }
            // makes "BLOCKED" also red. in reality, it's some kind of crimson
            mt.append(Text.literal(stat).formatted(format));

            IcoTextComponent itc = new IcoTextComponent(MIN_ICOS.get(min), mt);
            this.addComponent(itc);
            return true;
        } else {
            return false;
        }
    }

}