diff options
| author | viciscat <51047087+viciscat@users.noreply.github.com> | 2024-05-08 15:04:27 +0200 |
|---|---|---|
| committer | viciscat <51047087+viciscat@users.noreply.github.com> | 2024-12-12 18:19:04 +0100 |
| commit | 3133b406b743d07fdd42ecf428a22125d1437770 (patch) | |
| tree | ddb9793f4e363dd76f6b7f8e33005cd3f471f886 /src | |
| parent | dcba939382628279ebce2cb0dc4b4a0ce8ee2f2f (diff) | |
| download | Skyblocker-3133b406b743d07fdd42ecf428a22125d1437770.tar.gz Skyblocker-3133b406b743d07fdd42ecf428a22125d1437770.tar.bz2 Skyblocker-3133b406b743d07fdd42ecf428a22125d1437770.zip | |
more progress
Diffstat (limited to 'src')
7 files changed, 76 insertions, 182 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/PlayerListMgr.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/PlayerListMgr.java index 6cf8c684..b8f0cc42 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/PlayerListMgr.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/PlayerListMgr.java @@ -99,7 +99,7 @@ public class PlayerListMgr { continue; } // add player to contents - contents.add(displayName); + contents.add(displayName); // Players don't have the silly space } else { if (string.isBlank()) continue; if (infoColumnPredicate.test(string)) continue; @@ -111,12 +111,25 @@ public class PlayerListMgr { if (!nameAndInfo.right().getString().isBlank()) contents.add(nameAndInfo.right()); continue; } - contents.add(displayName); + contents.add(removeSpace(displayName)); // remove the silly space } } ScreenBuilder.positionsNeedsUpdating = true; } + private static Text removeSpace(Text text) { + AtomicBoolean removed = new AtomicBoolean(false); + MutableText out = Text.empty(); + text.visit((style, asString) -> { + if (!removed.get()) { + out.append(Text.literal(asString.substring(1)).fillStyle(style)); + removed.set(true); + } else out.append(Text.literal(asString).fillStyle(style)); + return Optional.empty(); + }, Style.EMPTY); + return out; + } + private static TabHudWidget getTabHudWidget(String hypixelWidgetName, List<Text> lines) { if (widgetInstances.containsKey(hypixelWidgetName)) { TabHudWidget tabHudWidget = widgetInstances.get(hypixelWidgetName); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/GardenServerWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/GardenServerWidget.java index af0b5769..e69de29b 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/GardenServerWidget.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/GardenServerWidget.java @@ -1,66 +0,0 @@ -package de.hysky.skyblocker.skyblock.tabhud.widget; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import de.hysky.skyblocker.skyblock.tabhud.util.Ico; -import de.hysky.skyblocker.skyblock.tabhud.util.PlayerListMgr; -import de.hysky.skyblocker.skyblock.tabhud.widget.component.IcoTextComponent; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; - -// this widget shows info about the garden server - -public class GardenServerWidget extends HudWidget { - private static final MutableText TITLE = Text.literal("Server Info").formatted(Formatting.DARK_AQUA, - Formatting.BOLD); - //From the armor trim tooltip - private static final int COPPER_COLOR = 11823181; - - // match the next visitor in the garden - // group 1: visitor name - private static final Pattern VISITOR_PATTERN = Pattern.compile("Visitors: (?<vis>.*)"); - - public GardenServerWidget() { - super(TITLE, Formatting.DARK_AQUA.getColorValue()); - } - - @Override - public void updateContent() { - this.addSimpleIcoText(Ico.MAP, "Area:", Formatting.DARK_AQUA, 41); - this.addSimpleIcoText(Ico.NTAG, "Server ID:", Formatting.GRAY, 42); - this.addSimpleIcoText(Ico.EMERALD, "Gems:", Formatting.GREEN, 43); - - Text copperText = HudWidget.simpleEntryText(44, "Copper:", Formatting.WHITE); - ((MutableText) copperText.getSiblings().getFirst()).withColor(COPPER_COLOR); - - this.addComponent(new IcoTextComponent(Ico.COPPER, copperText)); - - boolean hasPesthunterBonus = PlayerListMgr.strAt(46) != null; - - if (hasPesthunterBonus) { - this.addComponent(new IcoTextComponent(Ico.NETHERITE_UPGRADE_ST, PlayerListMgr.textAt(46))); - } - - int offset = hasPesthunterBonus ? 1 : 0; - - Matcher m = PlayerListMgr.regexAt(53 + offset, VISITOR_PATTERN); - if (m == null ) { - this.addComponent(new IcoTextComponent()); - return; - } - - String vis = m.group("vis").replaceAll("[()]*", ""); - Formatting col; - if (vis.equals("Not Unlocked!") || vis.equals("Queue Full!")) { - col = Formatting.RED; - } else { - col = Formatting.GREEN; - } - Text visitor = HudWidget.simpleEntryText(vis, "Next Visitor: ", col); - IcoTextComponent v = new IcoTextComponent(Ico.PLAYER, visitor); - this.addComponent(v); - } - -} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/MinionWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/MinionWidget.java index 00c17d30..1e2d6eb9 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/MinionWidget.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/MinionWidget.java @@ -1,6 +1,7 @@ package de.hysky.skyblocker.skyblock.tabhud.widget; import java.util.HashMap; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -16,7 +17,7 @@ import net.minecraft.util.Formatting; // this widget shows info about minions placed on the home island -public class MinionWidget extends HudWidget { +public class MinionWidget extends TabHudWidget { private static final MutableText TITLE = Text.literal("Minions").formatted(Formatting.DARK_AQUA, Formatting.BOLD); @@ -89,47 +90,31 @@ public class MinionWidget extends HudWidget { // group 1: name // group 2: level // group 3: status - public static final Pattern MINION_PATTERN = Pattern.compile("(?<name>.*) (?<level>[XVI]*) \\[(?<status>.*)\\]"); + public static final Pattern MINION_PATTERN = Pattern.compile("^(?<amount>\\d+)x (?<name>.*) (?<level>[XVI]*) \\[(?<status>.*)]"); public MinionWidget() { - super(TITLE, Formatting.DARK_AQUA.getColorValue()); + super("Minions" ,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 void updateContent(List<Text> lines) { + for (int i = 1; i < lines.size(); i++) { + String string = lines.get(i).getString(); + if (string.toLowerCase().contains("... and")) this.addComponent(new PlainTextComponent(lines.get(i))); + else addMinionComponent(string); } } - public boolean addMinionComponent(int i) { - Matcher m = PlayerListMgr.regexAt(i, MINION_PATTERN); - if (m != null) { + public void addMinionComponent(String line) { + Matcher m = MINION_PATTERN.matcher(line); + if (m.matches()) { String min = m.group("name"); + String amount = m.group("amount"); String lvl = m.group("level"); String stat = m.group("status"); - MutableText mt = Text.literal(min + " " + lvl).append(Text.literal(": ")); + MutableText mt = Text.literal(amount +"x " + min + " " + lvl).append(Text.literal(": ")); Formatting format = Formatting.RED; if (stat.equals("ACTIVE")) { @@ -142,9 +127,6 @@ public class MinionWidget extends HudWidget { IcoTextComponent itc = new IcoTextComponent(MIN_ICOS.get(min), mt); this.addComponent(itc); - return true; - } else { - return false; } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/ParkServerWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/ParkServerWidget.java deleted file mode 100644 index ecbf9db1..00000000 --- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/ParkServerWidget.java +++ /dev/null @@ -1,30 +0,0 @@ -package de.hysky.skyblocker.skyblock.tabhud.widget; - - -import de.hysky.skyblocker.skyblock.tabhud.util.Ico; - -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; - -// this widget shows info about the park server - -public class ParkServerWidget extends HudWidget { - - private static final MutableText TITLE = Text.literal("Server Info").formatted(Formatting.DARK_AQUA, - Formatting.BOLD); - - public ParkServerWidget() { - super(TITLE, Formatting.DARK_AQUA.getColorValue()); - } - - @Override - public void updateContent() { - this.addSimpleIcoText(Ico.MAP, "Area:", Formatting.DARK_AQUA, 41); - this.addSimpleIcoText(Ico.NTAG, "Server ID:", Formatting.GRAY, 42); - this.addSimpleIcoText(Ico.EMERALD, "Gems:", Formatting.GREEN, 43); - this.addSimpleIcoText(Ico.WATER, "Rain:", Formatting.BLUE, 44); - - } - -} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/ServerWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/ServerWidget.java index 04dee3a2..c0c4eb81 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/ServerWidget.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/ServerWidget.java @@ -3,28 +3,44 @@ package de.hysky.skyblocker.skyblock.tabhud.widget; import de.hysky.skyblocker.skyblock.tabhud.util.Ico; +import de.hysky.skyblocker.skyblock.tabhud.widget.component.IcoTextComponent; +import de.hysky.skyblocker.skyblock.tabhud.widget.component.PlainTextComponent; import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; +import java.util.List; + // this widget shows info about "generic" servers. // a server is "generic", when only name, server ID and gems are shown // in the third column of the tab HUD -public class ServerWidget extends HudWidget { +public class ServerWidget extends TabHudWidget { private static final MutableText TITLE = Text.literal("Server Info").formatted(Formatting.DARK_AQUA, Formatting.BOLD); public ServerWidget() { - super(TITLE, Formatting.DARK_AQUA.getColorValue()); + super("Area", TITLE, Formatting.DARK_AQUA.getColorValue()); } @Override - public void updateContent() { - this.addSimpleIcoText(Ico.MAP, "Area:", Formatting.DARK_AQUA, 41); - this.addSimpleIcoText(Ico.NTAG, "Server ID:", Formatting.GRAY, 42); - this.addSimpleIcoText(Ico.EMERALD, "Gems:", Formatting.GREEN, 43); + public void updateContent(List<Text> lines) { + this.addComponent(new IcoTextComponent(Ico.MAP, Text.literal("Area:").append(lines.getFirst().copy().formatted(Formatting.DARK_AQUA)))); + for (int i = 1; i < lines.size(); i++) { + Text text = lines.get(i); + String string = text.getString(); + switch (string.toLowerCase()) { + case String s when s.contains("server") -> this.addSimpleIcoText(Ico.NTAG, "Server ID:", Formatting.GRAY, string); + case String s when s.contains("gems") -> this.addComponent(new IcoTextComponent(Ico.EMERALD, text)); + case String s when s.contains("crystals") -> this.addComponent(new IcoTextComponent(Ico.EMERALD, text)); + case String s when s.contains("copper") -> this.addComponent(new IcoTextComponent(Ico.COPPER, text)); + case String s when s.contains("garden") -> this.addComponent(new IcoTextComponent(Ico.EXPERIENCE_BOTTLE, text)); + case String s when s.contains("fairy") -> this.addComponent(new IcoTextComponent(Ico.DIAMOND, text)); + case String s when s.contains("rain") -> this.addComponent(new IcoTextComponent(Ico.WATER, text)); + default -> this.addComponent(new PlainTextComponent(text)); + } + } } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/SkillsWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/SkillsWidget.java index 2a331403..4e5229fb 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/SkillsWidget.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/SkillsWidget.java @@ -1,15 +1,12 @@ package de.hysky.skyblocker.skyblock.tabhud.widget; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import de.hysky.skyblocker.skyblock.tabhud.util.Ico; import de.hysky.skyblocker.skyblock.tabhud.util.PlayerListMgr; -import de.hysky.skyblocker.skyblock.tabhud.widget.component.Component; -import de.hysky.skyblocker.skyblock.tabhud.widget.component.IcoFatTextComponent; -import de.hysky.skyblocker.skyblock.tabhud.widget.component.IcoTextComponent; -import de.hysky.skyblocker.skyblock.tabhud.widget.component.ProgressComponent; -import de.hysky.skyblocker.skyblock.tabhud.widget.component.TableComponent; +import de.hysky.skyblocker.skyblock.tabhud.widget.component.*; import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; @@ -17,7 +14,7 @@ import net.minecraft.util.Formatting; // this widget shows info about a skill and some stats, // as seen in the rightmost column of the default HUD -public class SkillsWidget extends HudWidget { +public class SkillsWidget extends TabHudWidget { private static final MutableText TITLE = Text.literal("Skill Info").formatted(Formatting.YELLOW, Formatting.BOLD); @@ -25,54 +22,35 @@ public class SkillsWidget extends HudWidget { // match the skill entry // group 1: skill name and level // group 2: progress to next level (without "%") - private static final Pattern SKILL_PATTERN = Pattern.compile("\\S*: ([A-Za-z]* [0-9]*): ([0-9.MAX]*)%?"); + private static final Pattern SKILL_PATTERN = Pattern.compile("([A-Za-z]* [0-9]*): ([0-9.MAX]*)%?"); public SkillsWidget() { - super(TITLE, Formatting.YELLOW.getColorValue()); + super("Skills", TITLE, Formatting.YELLOW.getColorValue()); } @Override - public void updateContent() { - Matcher m = PlayerListMgr.regexAt(66, SKILL_PATTERN); - Component progress; - if (m == null) { - progress = new ProgressComponent(); - } else { - - String skill = m.group(1); - String pcntStr = m.group(2); - - if (!pcntStr.equals("MAX")) { - float pcnt = Float.parseFloat(pcntStr); - progress = new ProgressComponent(Ico.LANTERN, Text.of(skill), - Text.of(pcntStr + "%"), pcnt, Formatting.GOLD.getColorValue()); + public void updateContent(List<Text> lines) { + for (Text line : lines) { + Component progress; + Matcher m = SKILL_PATTERN.matcher(line.getString()); + if (m.matches()) { + String skill = m.group(1); + String pcntStr = m.group(2); + + if (!pcntStr.equals("MAX")) { + float pcnt = Float.parseFloat(pcntStr); + progress = new ProgressComponent(Ico.LANTERN, Text.of(skill), + Text.of(pcntStr + "%"), pcnt, Formatting.GOLD.getColorValue()); + } else { + progress = new IcoFatTextComponent(Ico.LANTERN, Text.of(skill), + Text.literal(pcntStr).formatted(Formatting.RED)); + } } else { - progress = new IcoFatTextComponent(Ico.LANTERN, Text.of(skill), - Text.literal(pcntStr).formatted(Formatting.RED)); + progress = new PlainTextComponent(line); } + this.addComponent(progress); } - - this.addComponent(progress); - - Text speed = HudWidget.simpleEntryText(67, "SPD", Formatting.WHITE); - IcoTextComponent spd = new IcoTextComponent(Ico.SUGAR, speed); - Text strength = HudWidget.simpleEntryText(68, "STR", Formatting.RED); - IcoTextComponent str = new IcoTextComponent(Ico.IRON_SWORD, strength); - Text critDmg = HudWidget.simpleEntryText(69, "CCH", Formatting.BLUE); - IcoTextComponent cdg = new IcoTextComponent(Ico.IRON_SWORD, critDmg); - Text critCh = HudWidget.simpleEntryText(70, "CDG", Formatting.BLUE); - IcoTextComponent cch = new IcoTextComponent(Ico.IRON_SWORD, critCh); - Text aSpeed = HudWidget.simpleEntryText(71, "ASP", Formatting.YELLOW); - IcoTextComponent asp = new IcoTextComponent(Ico.IRON_HOE, aSpeed); - - TableComponent tc = new TableComponent(2, 3, Formatting.YELLOW.getColorValue()); - tc.addToCell(0, 0, spd); - tc.addToCell(0, 1, str); - tc.addToCell(0, 2, asp); - tc.addToCell(1, 0, cdg); - tc.addToCell(1, 1, cch); - this.addComponent(tc); } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/TabHudWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/TabHudWidget.java index 58b5d34a..ccb1f240 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/TabHudWidget.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/TabHudWidget.java @@ -34,7 +34,8 @@ public abstract class TabHudWidget extends HudWidget { /** * Update the content from the hypixel widget's lines * - * @param lines the lines, they are formatted, no blank lines will be present + * @param lines the lines, they are formatted, no blank lines will be present. + * If the vanilla tab widget has text right after the : they will be put on the first line. */ protected abstract void updateContent(List<Text> lines); |
