aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/rift/GoodToKnowWidget.java
blob: 3a5da1427b874d3be9d8928b83ac6b211164d098 (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
package de.hysky.skyblocker.skyblock.tabhud.widget.rift;

import de.hysky.skyblocker.skyblock.tabhud.widget.Widget;
import de.hysky.skyblocker.skyblock.tabhud.widget.component.IcoTextComponent;
import de.hysky.skyblocker.skyblock.tabhud.util.Ico;
import de.hysky.skyblocker.skyblock.tabhud.util.PlayerListMgr;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

public class GoodToKnowWidget extends Widget {

	private static final MutableText TITLE = Text.literal("Good To Know").formatted(Formatting.BLUE, Formatting.BOLD);

	public GoodToKnowWidget() {
		super(TITLE, Formatting.BLUE.getColorValue());
    }

    @Override
    public void updateContent() {
		// After you progress further the tab adds more info so we need to be careful of
		// that
		// In beginning it only shows montezuma, then timecharms and enigma souls are
		// added

        int headerPos = 0;
        // this seems suboptimal, but I'm not sure if there's a way to do it better.
        // search for the GTK header and offset the rest accordingly.
        for (int i = 45; i <= 49; i++) {
            String str = PlayerListMgr.strAt(i);
            if (str != null && str.startsWith("Good to")) {
                headerPos = i;
                break;
            }
        }

		Text posA = PlayerListMgr.textAt(headerPos + 2); // Can be times visited rift
		Text posB = PlayerListMgr.textAt(headerPos + 4); // Can be lifetime motes or visited rift
		Text posC = PlayerListMgr.textAt(headerPos + 6); // Can be lifetime motes

		int visitedRiftPos = 0;
		int lifetimeMotesPos = 0;

		// Check each position to see what is or isn't there so we don't try adding
		// invalid components
		if (posA != null && posA.getString().contains("times"))
			visitedRiftPos = headerPos + 2;
		if (posB != null && posB.getString().contains("Motes"))
			lifetimeMotesPos = headerPos + 4;
		if (posB != null && posB.getString().contains("times"))
			visitedRiftPos = headerPos + 4;
		if (posC != null && posC.getString().contains("Motes"))
			lifetimeMotesPos = headerPos + 6;

		Text timesVisitedRift = (visitedRiftPos == headerPos + 4) ? posB : (visitedRiftPos == headerPos + 2) ? posA : Text.literal("No Data").formatted(Formatting.GRAY);
		Text lifetimeMotesEarned = (lifetimeMotesPos == headerPos + 6) ? posC : (lifetimeMotesPos == headerPos + 4) ? posB : Text.literal("No Data").formatted(Formatting.GRAY);

		if (visitedRiftPos != 0) {
			this.addComponent(new IcoTextComponent(Ico.EXPERIENCE_BOTTLE,
					Text.literal("Visited Rift: ").append(timesVisitedRift)));
		}

		if (lifetimeMotesPos != 0) {
			this.addComponent(
					new IcoTextComponent(Ico.PINK_DYE, Text.literal("Lifetime Earned: ").append(lifetimeMotesEarned)));
		}

	}
}