From dad74c6c9d169ed6fb550ac2998e3799fdf0076c Mon Sep 17 00:00:00 2001 From: viciscat <51047087+viciscat@users.noreply.github.com> Date: Fri, 5 Jul 2024 23:45:05 +0200 Subject: rift and more async idk --- .../skyblock/item/SkyblockInventoryScreen.java | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker/skyblock') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockInventoryScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockInventoryScreen.java index 665b090c..42a52a85 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockInventoryScreen.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockInventoryScreen.java @@ -20,6 +20,7 @@ import net.minecraft.nbt.StringNbtReader; import net.minecraft.nbt.visitor.StringNbtWriter; import net.minecraft.screen.slot.Slot; import net.minecraft.util.Identifier; +import org.apache.commons.lang3.ArrayUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,7 +44,8 @@ public class SkyblockInventoryScreen extends InventoryScreen { private static final Logger LOGGER = LoggerFactory.getLogger("Equipment"); private static final Supplier EMPTY_EQUIPMENT = () -> new ItemStack[]{ItemStack.EMPTY, ItemStack.EMPTY, ItemStack.EMPTY, ItemStack.EMPTY}; public static final ItemStack[] equipment = EMPTY_EQUIPMENT.get(); - private static final Codec CODEC = ItemUtils.EMPTY_ALLOWING_ITEMSTACK_CODEC.listOf(4, 4) + public static final ItemStack[] equipment_rift = EMPTY_EQUIPMENT.get(); + private static final Codec CODEC = ItemUtils.EMPTY_ALLOWING_ITEMSTACK_CODEC.listOf(4, 8) // min size at 4 for backwards compat .xmap(itemStacks -> itemStacks.toArray(ItemStack[]::new), List::of).fieldOf("items").codec(); private static final Identifier SLOT_TEXTURE = Identifier.ofVanilla("container/slot"); @@ -61,7 +63,8 @@ public class SkyblockInventoryScreen extends InventoryScreen { Path resolve = FOLDER.resolve(profileId + ".nbt"); try (BufferedWriter writer = Files.newBufferedWriter(resolve)) { - writer.write(new StringNbtWriter().apply(CODEC.encodeStart(NbtOps.INSTANCE, equipment).getOrThrow())); + + writer.write(new StringNbtWriter().apply(CODEC.encodeStart(NbtOps.INSTANCE, ArrayUtils.addAll(equipment, equipment_rift)).getOrThrow())); } catch (Exception e) { LOGGER.error("[Skyblocker] Failed to save Equipment data", e); } @@ -78,27 +81,31 @@ public class SkyblockInventoryScreen extends InventoryScreen { } return EMPTY_EQUIPMENT.get(); // Schedule on main thread to avoid any async weirdness - }).thenAccept(itemStacks -> MinecraftClient.getInstance().execute(() -> System.arraycopy(itemStacks, 0, equipment, 0, Math.min(itemStacks.length, 4)))); + }).thenAccept(itemStacks -> MinecraftClient.getInstance().execute(() -> { + System.arraycopy(itemStacks, 0, equipment, 0, Math.min(itemStacks.length, 4)); + if (itemStacks.length <= 4) return; + System.arraycopy(itemStacks, 4, equipment_rift, 0, Math.clamp(itemStacks.length - 4, 0, 4)); + })); } public static void initEquipment() { SkyblockEvents.PROFILE_CHANGE.register(((prevProfileId, profileId) -> { - if (!prevProfileId.isEmpty()) save(prevProfileId); - load(profileId); + if (!prevProfileId.isEmpty()) CompletableFuture.runAsync(() -> save(prevProfileId)).thenRun(() -> load(profileId)); + else load(profileId); })); ClientLifecycleEvents.CLIENT_STOPPING.register(client1 -> { String profileId = Utils.getProfileId(); if (!profileId.isBlank()) { - save(profileId); + CompletableFuture.runAsync(() -> save(profileId)); } }); } public SkyblockInventoryScreen(PlayerEntity player) { super(player); - SimpleInventory inventory = new SimpleInventory(equipment); + SimpleInventory inventory = new SimpleInventory(Utils.isInTheRift() ? equipment_rift: equipment); Slot slot = handler.slots.get(45); ((SlotAccessor) slot).setX(slot.x + 21); -- cgit