From 95d7022abc7f7769d9670d6da65b01355fff9d11 Mon Sep 17 00:00:00 2001 From: DoKM Date: Wed, 21 Jul 2021 10:38:49 +0200 Subject: Add Storage & Personal Vault to PV --- .../profileviewer/GuiProfileViewer.java | 35 +++++-- .../profileviewer/ProfileViewer.java | 110 +++++++++++++++++++-- 2 files changed, 129 insertions(+), 16 deletions(-) (limited to 'src/main') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java index 1822f630..8f1b47d1 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java @@ -518,16 +518,23 @@ public class GuiProfileViewer extends GuiScreen { selectedInventory = "ender_chest_contents"; break; case Keyboard.KEY_3: case Keyboard.KEY_NUMPAD3: - selectedInventory = "talisman_bag"; break; + selectedInventory = "backpack_contents"; break; case Keyboard.KEY_4: case Keyboard.KEY_NUMPAD4: - selectedInventory = "wardrobe_contents"; break; + selectedInventory = "personal_vault_contents"; break; case Keyboard.KEY_5: case Keyboard.KEY_NUMPAD5: - selectedInventory = "fishing_bag"; break; + selectedInventory = "talisman_bag"; break; case Keyboard.KEY_6: case Keyboard.KEY_NUMPAD6: + selectedInventory = "wardrobe_contents"; break; + case Keyboard.KEY_7: + case Keyboard.KEY_NUMPAD7: + selectedInventory = "fishing_bag"; break; + case Keyboard.KEY_8: + case Keyboard.KEY_NUMPAD8: selectedInventory = "potion_bag"; break; + } Utils.playPressSound(); } @@ -1583,6 +1590,8 @@ public class GuiProfileViewer extends GuiScreen { static { invNameToDisplayMap.put("inv_contents", Utils.createItemStack(Item.getItemFromBlock(Blocks.chest), EnumChatFormatting.GRAY+"Inventory")); invNameToDisplayMap.put("ender_chest_contents", Utils.createItemStack(Item.getItemFromBlock(Blocks.ender_chest), EnumChatFormatting.GRAY+"Ender Chest")); + invNameToDisplayMap.put("backpack_contents", Utils.createItemStack(Item.getItemFromBlock(Blocks.dropper), EnumChatFormatting.GRAY+"Backpacks")); + invNameToDisplayMap.put("personal_vault_contents", Utils.createItemStack(Item.getItemFromBlock(Blocks.dispenser), EnumChatFormatting.GRAY+"Personal vault")); invNameToDisplayMap.put("talisman_bag", Utils.createItemStack(Items.golden_apple, EnumChatFormatting.GRAY+"Accessory Bag")); invNameToDisplayMap.put("wardrobe_contents", Utils.createItemStack(Items.leather_chestplate, EnumChatFormatting.GRAY+"Wardrobe")); invNameToDisplayMap.put("fishing_bag", Utils.createItemStack(Items.fish, EnumChatFormatting.GRAY+"Fishing Bag")); @@ -1654,6 +1663,8 @@ public class GuiProfileViewer extends GuiScreen { switch(invName) { case "wardrobe_contents": return 4; + case "backpack_contents": + return 5; } return 6; } @@ -1663,6 +1674,7 @@ public class GuiProfileViewer extends GuiScreen { case "talisman_bag": case "fishing_bag": case "potion_bag": + case "personal_vault_contents": return true; } return false; @@ -1739,6 +1751,10 @@ public class GuiProfileViewer extends GuiScreen { int maxInvSize = rowSize*maxRowsPerPage; int numInventories = (jsonInvSize-1)/maxInvSize+1; + JsonArray backPackSizes = (JsonArray) inventoryInfo.get("backpack_sizes"); + if(invName.equals("backpack_contents")) { + numInventories = backPackSizes.size(); + } ItemStack[][][] inventories = new ItemStack[numInventories][][]; @@ -1746,11 +1762,18 @@ public class GuiProfileViewer extends GuiScreen { for(int i=0; i backpackIcon : backpack_icons.entrySet()) { + if(backpackIcon.getValue() instanceof JsonObject){ + JsonObject backpackData = (JsonObject)backpack_contents_json.get(backpackIcon.getKey()); + String bytes = Utils.getElementAsString(backpackData.get("data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA="); + backpackArray = growArray(bytes, Integer.parseInt(backpackIcon.getKey()), backpackArray); + } + } + + + //reduce backpack array to filter out not existent backpacks + { + int backpackCount = 0; + String[] tempBackpackArray = new String[0]; + for (String s : backpackArray) { + if (s != null) { + backpackCount++; + String[] veryTempBackpackArray = new String[tempBackpackArray.length + 1]; + System.arraycopy(tempBackpackArray, 0, veryTempBackpackArray, 0, tempBackpackArray.length); + + veryTempBackpackArray[veryTempBackpackArray.length - 1] = s; + tempBackpackArray = veryTempBackpackArray; + } + } + backpackArray = tempBackpackArray; + } + + JsonArray backpackSizes = new JsonArray(); + + for (String backpack : backpackArray) { + try { + NBTTagCompound inv_contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(Base64.getDecoder().decode(backpack))); + NBTTagList items = inv_contents_nbt.getTagList("i", 10); + + backpackSizes.add(new JsonPrimitive(items.tagCount())); + for (int j = 0; j < items.tagCount(); j++) { + JsonObject item = manager.getJsonFromNBTEntry(items.getCompoundTagAt(j)); + contents.add(item); + } + } catch (IOException ignored) { + } + } + + + JsonObject bundledReturn = new JsonObject(); + bundledReturn.add("contents", contents); + bundledReturn.add("backpack_sizes", backpackSizes); + + return bundledReturn; + } + + public String[] growArray(String bytes, int index, String[] oldArray){ + int newSize = Math.max(index+1, oldArray.length); + + String[] newArray = new String[newSize]; + for (int i = 0; i < oldArray.length; i++) { + newArray[i] = oldArray[i]; + } + newArray[index] = bytes; + + return newArray; + } + + + public JsonObject getPetsInfo(String profileId) { JsonObject profileInfo = getProfileInformation(profileId); if(profileInfo == null) return null; -- cgit