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 fb58890739..0000000000 Binary files a/src/main/resources/assets/skyblocker/textures/gui/inventory_background.png and /dev/null differ