aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util
diff options
context:
space:
mode:
authorYasin <a.piri@hotmail.de>2023-10-09 12:58:02 +0200
committerYasin <a.piri@hotmail.de>2023-10-09 12:58:02 +0200
commitbd3f0329d0e391bd84b5f9e3ff207d9dd9815853 (patch)
tree2fd1d1ef625f57acc2e4916c967d8d2393844798 /src/main/java/de/hysky/skyblocker/skyblock/tabhud/util
parent2315b90da8117f28f66348927afdb621ee4fc815 (diff)
downloadSkyblocker-bd3f0329d0e391bd84b5f9e3ff207d9dd9815853.tar.gz
Skyblocker-bd3f0329d0e391bd84b5f9e3ff207d9dd9815853.tar.bz2
Skyblocker-bd3f0329d0e391bd84b5f9e3ff207d9dd9815853.zip
new pr because fixing merge conflict would take too long
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock/tabhud/util')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/Ico.java60
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/PlayerListMgr.java171
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/PlayerLocator.java87
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/ScreenConst.java13
4 files changed, 331 insertions, 0 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/Ico.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/Ico.java
new file mode 100644
index 00000000..24883d77
--- /dev/null
+++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/Ico.java
@@ -0,0 +1,60 @@
+package de.hysky.skyblocker.skyblock.tabhud.util;
+
+import net.minecraft.item.ItemStack;
+import net.minecraft.item.Items;
+
+/**
+ * Stores convenient shorthands for common ItemStack definitions
+ */
+public class Ico {
+ public static final ItemStack MAP = new ItemStack(Items.FILLED_MAP);
+ public static final ItemStack NTAG = new ItemStack(Items.NAME_TAG);
+ public static final ItemStack EMERALD = new ItemStack(Items.EMERALD);
+ public static final ItemStack CLOCK = new ItemStack(Items.CLOCK);
+ public static final ItemStack DIASWORD = new ItemStack(Items.DIAMOND_SWORD);
+ public static final ItemStack DBUSH = new ItemStack(Items.DEAD_BUSH);
+ public static final ItemStack VILLAGER = new ItemStack(Items.VILLAGER_SPAWN_EGG);
+ public static final ItemStack MOREGOLD = new ItemStack(Items.GOLDEN_APPLE);
+ public static final ItemStack COMPASS = new ItemStack(Items.COMPASS);
+ public static final ItemStack SUGAR = new ItemStack(Items.SUGAR);
+ public static final ItemStack HOE = new ItemStack(Items.IRON_HOE);
+ public static final ItemStack GOLD = new ItemStack(Items.GOLD_INGOT);
+ public static final ItemStack BONE = new ItemStack(Items.BONE);
+ public static final ItemStack SIGN = new ItemStack(Items.OAK_SIGN);
+ public static final ItemStack FISH_ROD = new ItemStack(Items.FISHING_ROD);
+ public static final ItemStack SWORD = new ItemStack(Items.IRON_SWORD);
+ public static final ItemStack LANTERN = new ItemStack(Items.LANTERN);
+ public static final ItemStack COOKIE = new ItemStack(Items.COOKIE);
+ public static final ItemStack POTION = new ItemStack(Items.POTION);
+ public static final ItemStack BARRIER = new ItemStack(Items.BARRIER);
+ public static final ItemStack PLAYER = new ItemStack(Items.PLAYER_HEAD);
+ public static final ItemStack WATER = new ItemStack(Items.WATER_BUCKET);
+ public static final ItemStack LEATHER = new ItemStack(Items.LEATHER);
+ public static final ItemStack MITHRIL = new ItemStack(Items.PRISMARINE_CRYSTALS);
+ public static final ItemStack REDSTONE = new ItemStack(Items.REDSTONE);
+ public static final ItemStack FIRE = new ItemStack(Items.CAMPFIRE);
+ public static final ItemStack STRING = new ItemStack(Items.STRING);
+ public static final ItemStack WITHER = new ItemStack(Items.WITHER_SKELETON_SKULL);
+ public static final ItemStack FLESH = new ItemStack(Items.ROTTEN_FLESH);
+ public static final ItemStack DRAGON = new ItemStack(Items.DRAGON_HEAD);
+ public static final ItemStack DIAMOND = new ItemStack(Items.DIAMOND);
+ public static final ItemStack ICE = new ItemStack(Items.ICE);
+ public static final ItemStack CHEST = new ItemStack(Items.CHEST);
+ public static final ItemStack COMMAND = new ItemStack(Items.COMMAND_BLOCK);
+ public static final ItemStack SKULL = new ItemStack(Items.SKELETON_SKULL);
+ public static final ItemStack BOOK = new ItemStack(Items.WRITABLE_BOOK);
+ public static final ItemStack FURNACE = new ItemStack(Items.FURNACE);
+ public static final ItemStack CHESTPLATE = new ItemStack(Items.IRON_CHESTPLATE);
+ public static final ItemStack B_ROD = new ItemStack(Items.BLAZE_ROD);
+ public static final ItemStack BOW = new ItemStack(Items.BOW);
+ public static final ItemStack COPPER = new ItemStack(Items.COPPER_INGOT);
+ public static final ItemStack COMPOSTER = new ItemStack(Items.COMPOSTER);
+ public static final ItemStack SAPLING = new ItemStack(Items.OAK_SAPLING);
+ public static final ItemStack MILESTONE = new ItemStack(Items.LODESTONE);
+ public static final ItemStack PICKAXE = new ItemStack(Items.IRON_PICKAXE);
+ public static final ItemStack NETHER_STAR = new ItemStack(Items.NETHER_STAR);
+ public static final ItemStack HEART_OF_THE_SEA = new ItemStack(Items.HEART_OF_THE_SEA);
+ public static final ItemStack EXPERIENCE_BOTTLE = new ItemStack(Items.EXPERIENCE_BOTTLE);
+ public static final ItemStack PINK_DYE = new ItemStack(Items.PINK_DYE);
+ public static final ItemStack ENCHANTED_BOOK = new ItemStack(Items.ENCHANTED_BOOK);
+}
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
new file mode 100644
index 00000000..f577f2d3
--- /dev/null
+++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/PlayerListMgr.java
@@ -0,0 +1,171 @@
+package de.hysky.skyblocker.skyblock.tabhud.util;
+
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import de.hysky.skyblocker.mixin.accessor.PlayerListHudAccessor;
+import de.hysky.skyblocker.utils.Utils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.network.ClientPlayNetworkHandler;
+import net.minecraft.client.network.PlayerListEntry;
+import net.minecraft.text.MutableText;
+import net.minecraft.text.Text;
+
+/**
+ * This class may be used to get data from the player list. It doesn't get its
+ * data every frame, instead, a scheduler is used to update the data this class
+ * is holding periodically. The list is sorted like in the vanilla game.
+ */
+public class PlayerListMgr {
+
+ public static final Logger LOGGER = LoggerFactory.getLogger("Skyblocker Regex");
+
+ private static List<PlayerListEntry> playerList;
+ private static String footer;
+
+ public static void updateList() {
+
+ if (!Utils.isOnSkyblock()) {
+ return;
+ }
+
+ ClientPlayNetworkHandler cpnwh = MinecraftClient.getInstance().getNetworkHandler();
+
+ // check is needed, else game crash on server leave
+ if (cpnwh != null) {
+ playerList = cpnwh.getPlayerList().stream().sorted(PlayerListHudAccessor.getOrdering()).toList();
+ }
+ }
+
+ public static void updateFooter(Text f) {
+ if (f == null) {
+ footer = null;
+ } else {
+ footer = f.getString();
+ }
+ }
+
+ public static String getFooter() {
+ return footer;
+ }
+
+ /**
+ * Get the display name at some index of the player list and apply a pattern to
+ * it
+ *
+ * @return the matcher if p fully matches, else null
+ */
+ public static Matcher regexAt(int idx, Pattern p) {
+
+ String str = PlayerListMgr.strAt(idx);
+
+ if (str == null) {
+ return null;
+ }
+
+ Matcher m = p.matcher(str);
+ if (!m.matches()) {
+ LOGGER.error("no match: \"{}\" against \"{}\"", str, p);
+ return null;
+ } else {
+ return m;
+ }
+ }
+
+ /**
+ * Get the display name at some index of the player list as string
+ *
+ * @return the string or null, if the display name is null, empty or whitespace
+ * only
+ */
+ public static String strAt(int idx) {
+
+ if (playerList == null) {
+ return null;
+ }
+
+ if (playerList.size() <= idx) {
+ return null;
+ }
+
+ Text txt = playerList.get(idx).getDisplayName();
+ if (txt == null) {
+ return null;
+ }
+ String str = txt.getString().trim();
+ if (str.isEmpty()) {
+ return null;
+ }
+ return str;
+ }
+
+ /**
+ * Gets the display name at some index of the player list
+ *
+ * @return the text or null, if the display name is null
+ *
+ * @implNote currently designed specifically for crimson isles faction quests
+ * widget and the rift widgets, might not work correctly without
+ * modification for other stuff. you've been warned!
+ */
+ public static Text textAt(int idx) {
+
+ if (playerList == null) {
+ return null;
+ }
+
+ if (playerList.size() <= idx) {
+ return null;
+ }
+
+ Text txt = playerList.get(idx).getDisplayName();
+ if (txt == null) {
+ return null;
+ }
+
+ // Rebuild the text object to remove leading space thats in all faction quest
+ // stuff (also removes trailing space just in case)
+ MutableText newText = Text.empty();
+ int size = txt.getSiblings().size();
+
+ for (int i = 0; i < size; i++) {
+ Text current = txt.getSiblings().get(i);
+ String textToAppend = current.getString();
+
+ // Trim leading & trailing space - this can only be done at the start and end
+ // otherwise it'll produce malformed results
+ if (i == 0)
+ textToAppend = textToAppend.stripLeading();
+ if (i == size - 1)
+ textToAppend = textToAppend.stripTrailing();
+
+ newText.append(Text.literal(textToAppend).setStyle(current.getStyle()));
+ }
+
+ // Avoid returning an empty component - Rift advertisements needed this
+ if (newText.getString().isEmpty()) {
+ return null;
+ }
+
+ return newText;
+ }
+
+ /**
+ * Get the display name at some index of the player list as Text as seen in the
+ * game
+ *
+ * @return the PlayerListEntry at that index
+ */
+ public static PlayerListEntry getRaw(int idx) {
+ return playerList.get(idx);
+ }
+
+ public static int getSize() {
+ return playerList.size();
+ }
+
+}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/PlayerLocator.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/PlayerLocator.java
new file mode 100644
index 00000000..e5f5bfc8
--- /dev/null
+++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/PlayerLocator.java
@@ -0,0 +1,87 @@
+package de.hysky.skyblocker.skyblock.tabhud.util;
+
+import de.hysky.skyblocker.utils.Utils;
+
+/**
+ * Uses data from the player list to determine the area the player is in.
+ */
+public class PlayerLocator {
+
+ public enum Location {
+ DUNGEON("dungeon"),
+ GUEST_ISLAND("guest_island"),
+ HOME_ISLAND("home_island"),
+ CRIMSON_ISLE("crimson_isle"),
+ DUNGEON_HUB("dungeon_hub"),
+ FARMING_ISLAND("farming_island"),
+ PARK("park"),
+ DWARVEN_MINES("dwarven_mines"),
+ CRYSTAL_HOLLOWS("crystal_hollows"),
+ END("end"),
+ GOLD_MINE("gold_mine"),
+ DEEP_CAVERNS("deep_caverns"),
+ HUB("hub"),
+ SPIDER_DEN("spider_den"),
+ JERRY("jerry_workshop"),
+ GARDEN("garden"),
+ INSTANCED("kuudra"),
+ THE_RIFT("rift"),
+ DARK_AUCTION("dark_auction"),
+ UNKNOWN("unknown");
+
+ public final String internal;
+
+ Location(String i) {
+ // as used internally by the mod, e.g. in the json
+ this.internal = i;
+ }
+
+ }
+
+ public static Location getPlayerLocation() {
+
+ if (!Utils.isOnSkyblock()) {
+ return Location.UNKNOWN;
+ }
+
+ String areaDescriptor = PlayerListMgr.strAt(41);
+
+ if (areaDescriptor == null || areaDescriptor.length() < 6) {
+ return Location.UNKNOWN;
+ }
+
+ if (areaDescriptor.startsWith("Dungeon")) {
+ return Location.DUNGEON;
+ }
+
+ return switch (areaDescriptor.substring(6)) {
+ case "Private Island" -> {
+ String islandType = PlayerListMgr.strAt(44);
+ if (islandType == null) {
+ yield Location.UNKNOWN;
+ } else if (islandType.endsWith("Guest")) {
+ yield Location.GUEST_ISLAND;
+ } else {
+ yield Location.HOME_ISLAND;
+ }
+ }
+ case "Crimson Isle" -> Location.CRIMSON_ISLE;
+ case "Dungeon Hub" -> Location.DUNGEON_HUB;
+ case "The Farming Islands" -> Location.FARMING_ISLAND;
+ case "The Park" -> Location.PARK;
+ case "Dwarven Mines" -> Location.DWARVEN_MINES;
+ case "Crystal Hollows" -> Location.CRYSTAL_HOLLOWS;
+ case "The End" -> Location.END;
+ case "Gold Mine" -> Location.GOLD_MINE;
+ case "Deep Caverns" -> Location.DEEP_CAVERNS;
+ case "Hub" -> Location.HUB;
+ case "Spider's Den" -> Location.SPIDER_DEN;
+ case "Jerry's Workshop" -> Location.JERRY;
+ case "Garden" -> Location.GARDEN;
+ case "Instanced" -> Location.INSTANCED;
+ case "The Rift" -> Location.THE_RIFT;
+ case "Dark Auction" -> Location.DARK_AUCTION;
+ default -> Location.UNKNOWN;
+ };
+ }
+}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/ScreenConst.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/ScreenConst.java
new file mode 100644
index 00000000..6a4d96d3
--- /dev/null
+++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/util/ScreenConst.java
@@ -0,0 +1,13 @@
+package de.hysky.skyblocker.skyblock.tabhud.util;
+
+import me.xmrvizzy.skyblocker.config.SkyblockerConfigManager;
+
+public class ScreenConst {
+ public static final int WIDGET_PAD = 5;
+ public static final int WIDGET_PAD_HALF = 3;
+ private static final int SCREEN_PAD_BASE = 20;
+
+ public static int getScreenPad() {
+ return (int) ((1f/((float)SkyblockerConfigManager.get().general.tabHud.tabHudScale/100f) * SCREEN_PAD_BASE));
+ }
+}