Skip to content

Commit

Permalink
Use profile id
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinthegreat1 committed Oct 26, 2023
1 parent 6c8b6df commit 1a737c4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -51,24 +54,22 @@ 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();
int index = getStorageIndexFromTitle(title);
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();
}
}
Expand Down Expand Up @@ -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"));
}

Expand Down
14 changes: 13 additions & 1 deletion src/main/java/de/hysky/skyblocker/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down Expand Up @@ -89,6 +91,11 @@ public static String getProfile() {
return profile;
}

@NotNull
public static String getProfileId() {
return profileId;
}

/**
* @return the server parsed from /locraw.
*/
Expand Down Expand Up @@ -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
*/
Expand All @@ -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;
}

Expand Down
Binary file not shown.

0 comments on commit 1a737c4

Please sign in to comment.