From 1a737c461c0d861028612c0a2615d3f5c0487d74 Mon Sep 17 00:00:00 2001 From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> Date: Wed, 25 Oct 2023 21:01:06 -0400 Subject: [PATCH] Use profile id --- .../skyblock/item/BackpackPreview.java | 26 +++++++++--------- .../java/de/hysky/skyblocker/utils/Utils.java | 14 +++++++++- .../textures/gui/inventory_background.png | Bin 577 -> 0 bytes 3 files changed, 26 insertions(+), 14 deletions(-) delete mode 100644 src/main/resources/assets/skyblocker/textures/gui/inventory_background.png diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/BackpackPreview.java b/src/main/java/de/hysky/skyblocker/skyblock/item/BackpackPreview.java index 18acbaf786..d510d65a79 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/BackpackPreview.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/BackpackPreview.java @@ -14,7 +14,10 @@ import net.minecraft.inventory.Inventory; import net.minecraft.inventory.SimpleInventory; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.*; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtInt; +import net.minecraft.nbt.NbtIo; +import net.minecraft.nbt.NbtList; import net.minecraft.util.Identifier; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -35,7 +38,7 @@ public class BackpackPreview { private static final Storage[] storages = new Storage[STORAGE_SIZE]; - private static String loaded = ""; // uuid + sb profile currently loaded + private static String loaded = ""; // profile id currently loaded private static Path save_dir = null; public static void init() { @@ -51,15 +54,13 @@ public static void tick() { if (Utils.isOnSkyblock()) { // save all dirty storages saveStorages(); - // update save dir based on uuid and sb profile - String uuid = MinecraftClient.getInstance().getSession().getUuidOrNull().toString().replaceAll("-", ""); - String profile = Utils.getProfile(); //TODO switch to profile id - if (!profile.isEmpty()) { - String loading = uuid + "/" + profile; - save_dir = FabricLoader.getInstance().getConfigDir().resolve("skyblocker/backpack-preview/" + loading); + // update save dir based on sb profile id + String profileId = Utils.getProfileId(); + if (!profileId.isEmpty()) { + save_dir = FabricLoader.getInstance().getConfigDir().resolve("skyblocker/backpack-preview/" + profileId); //noinspection ResultOfMethodCallIgnored save_dir.toFile().mkdirs(); - if (loaded.equals(loading)) { + if (loaded.equals(profileId)) { // mark currently opened storage as dirty if (MinecraftClient.getInstance().currentScreen != null) { String title = MinecraftClient.getInstance().currentScreen.getTitle().getString(); @@ -67,8 +68,8 @@ public static void tick() { if (index != -1) storages[index].markDirty(); } } else { - // load storage again because uuid/profile changed - loaded = loading; + // load storage again because profile id changed + loaded = profileId; loadStorages(); } } @@ -197,8 +198,7 @@ private void markClean() { @NotNull private static Storage fromNbt(NbtCompound root) { - SimpleInventory inventory = new SimpleInventory(root.getInt("size")); - inventory.readNbtList(root.getList("list", NbtCompound.COMPOUND_TYPE)); + SimpleInventory inventory = new SimpleInventory(root.getList("list", NbtCompound.COMPOUND_TYPE).stream().map(NbtCompound.class::cast).map(ItemStack::fromNbt).toArray(ItemStack[]::new)); return new Storage(inventory, root.getString("name")); } diff --git a/src/main/java/de/hysky/skyblocker/utils/Utils.java b/src/main/java/de/hysky/skyblocker/utils/Utils.java index bbfd11018d..f09d16edc2 100644 --- a/src/main/java/de/hysky/skyblocker/utils/Utils.java +++ b/src/main/java/de/hysky/skyblocker/utils/Utils.java @@ -44,6 +44,8 @@ public class Utils { @NotNull private static String profile = ""; @NotNull + private static String profileId = ""; + @NotNull private static String server = ""; @NotNull private static String gameType = ""; @@ -89,6 +91,11 @@ public static String getProfile() { return profile; } + @NotNull + public static String getProfileId() { + return profileId; + } + /** * @return the server parsed from /locraw. */ @@ -323,7 +330,7 @@ private static void updateLocRaw() { } /** - * Parses the /locraw reply from the server + * Parses the /locraw reply from the server and updates the player's profile id * * @return not display the message in chat is the command is sent by the mod */ @@ -349,6 +356,11 @@ public static boolean onChatMessage(Text text, boolean overlay) { return shouldFilter; } } + + if (isOnSkyblock && message.startsWith("Profile ID: ")) { + profileId = message.replace("Profile ID: ", ""); + } + return true; } diff --git a/src/main/resources/assets/skyblocker/textures/gui/inventory_background.png b/src/main/resources/assets/skyblocker/textures/gui/inventory_background.png deleted file mode 100644 index fb58890739b226f9473e13be4bdfc9da55232d7a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 577 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|GzJDH4o?@ykcv5P?_SJpHV|RG zkUnMQAt{}vBXW`|XBd+&_G@KHhi>5vxl;N3k87viH05|nJD*N|ZwJ{^7nv(Ww|B-& zJNj!m-_j`@svEl1bn3K>eS=$MU+a0@5j|jY{&+82-NT}tE-pvDR`qTWzOm%zpM#Iu zV`j~-XWFC1%FsFY+P*ix>prvYTGw4D^Ylce)$-iiXDw^;w=yW*``@73me>IiKE8S7 z{>NerLct6ZW-v7z5n)hS#-LybG(eNV!-vr!i3___&R3g;b+3~o+RlnkRBr$O^7P6B zd~pld{8;bxM?*C>th%%9|C`4mf=j1t^0}N+q&V|7--0>kpF6WN^?zU}kpC|HqP6?V jp-1e%5F5UrfqgHd{>_%x4=biD0r}F?)z4*}Q$iB}b?1;+