diff options
author | DoKM <mcazzyman@gmail.com> | 2021-07-21 10:38:49 +0200 |
---|---|---|
committer | DoKM <mcazzyman@gmail.com> | 2021-07-21 10:38:49 +0200 |
commit | 95d7022abc7f7769d9670d6da65b01355fff9d11 (patch) | |
tree | 8045451f630cf2e16385f64356ab915a617a2074 | |
parent | df5c87a53429e94bba42132d2dcf5537783a457b (diff) | |
download | NotEnoughUpdates-95d7022abc7f7769d9670d6da65b01355fff9d11.tar.gz NotEnoughUpdates-95d7022abc7f7769d9670d6da65b01355fff9d11.tar.bz2 NotEnoughUpdates-95d7022abc7f7769d9670d6da65b01355fff9d11.zip |
Add Storage & Personal Vault to PV
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/profileviewer/GuiProfileViewer.java | 35 | ||||
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java | 110 |
2 files changed, 129 insertions, 16 deletions
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<numInventories; i++) {
int thisRows = Math.min(maxRowsPerPage, rows-maxRowsPerPage*i);
+ if(invName.equals("backpack_contents")) {
+ thisRows = backPackSizes.get(i).getAsInt()/9;
+ }
if(thisRows <= 0) break;
ItemStack[][] items = new ItemStack[thisRows][rowSize];
+ int invSize =0;
+
+ invSize = Math.min(jsonInvSize, maxInvSize + maxInvSize * i);
+
+
- int invSize = Math.min(jsonInvSize, maxInvSize+maxInvSize*i);
for(int j=maxInvSize*i; j<invSize; j++) {
int xIndex = (j%maxInvSize)%rowSize;
int yIndex = (j%maxInvSize)/rowSize;
@@ -1865,7 +1888,7 @@ public class GuiProfileViewer extends GuiScreen { }
for(int i=0; i<armorItems.length; i++) {
- ItemStack stack = armorItems[i];
+ ItemStack stack = armorItems[i];
if(stack != null) {
Utils.drawItemStack(stack, guiLeft+173, guiTop+67-18*i);
if(stack != fillerStack) {
@@ -1885,7 +1908,7 @@ public class GuiProfileViewer extends GuiScreen { ItemStack[][] inventory = inventories[currentInventoryIndex];
if(inventory == null) {
- Utils.drawStringCentered(EnumChatFormatting.RED+"Inventory API not enabled!", Minecraft.getMinecraft().fontRendererObj,
+ Utils.drawStringCentered(EnumChatFormatting.RED+"Inventory API not enabled!"+selectedInventory, Minecraft.getMinecraft().fontRendererObj,
guiLeft+317, guiTop+101, true, 0);
return;
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java index 3e2c7e43..66354dbc 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewer.java @@ -9,7 +9,6 @@ import io.github.moulberry.notenoughupdates.NEUManager; import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.util.Constants;
import io.github.moulberry.notenoughupdates.util.Utils;
-import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
@@ -17,12 +16,10 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
-import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import javax.annotation.Nullable;
import java.io.ByteArrayInputStream;
-import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -780,6 +777,12 @@ public class ProfileViewer { String fishing_bag_bytes = Utils.getElementAsString(Utils.getElement(profileInfo, "fishing_bag.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=");
String quiver_bytes = Utils.getElementAsString(Utils.getElement(profileInfo, "quiver.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=");
String ender_chest_contents_bytes = Utils.getElementAsString(Utils.getElement(profileInfo, "ender_chest_contents.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=");
+ //Todo clean this up
+ //Fake string is so for I loop works the same
+ String backpack_contents_json_fake = "fake should fix later";
+ JsonObject backpack_contents_json = (JsonObject) Utils.getElement(profileInfo, "backpack_contents");
+ JsonObject backpack_icons = (JsonObject) Utils.getElement(profileInfo, "backpack_icons");
+ String personal_vault_contents_bytes = Utils.getElementAsString(Utils.getElement(profileInfo, "personal_vault_contents.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=");
String wardrobe_contents_bytes = Utils.getElementAsString(Utils.getElement(profileInfo, "wardrobe_contents.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=");
String potion_bag_bytes = Utils.getElementAsString(Utils.getElement(profileInfo, "potion_bag.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=");
String inv_contents_bytes = Utils.getElementAsString(Utils.getElement(profileInfo, "inv_contents.data"), "Hz8IAAAAAAAAAD9iYD9kYD9kAAMAPwI/Gw0AAAA=");
@@ -788,20 +791,29 @@ public class ProfileViewer { JsonObject inventoryInfo = new JsonObject();
- String[] inv_names = new String[]{"inv_armor", "fishing_bag", "quiver", "ender_chest_contents", "wardrobe_contents",
+ String[] inv_names = new String[]{"inv_armor", "fishing_bag", "quiver", "ender_chest_contents", "backpack_contents", "personal_vault_contents", "wardrobe_contents",
"potion_bag", "inv_contents", "talisman_bag", "candy_inventory_contents"};
- String[] inv_bytes = new String[]{inv_armor_bytes, fishing_bag_bytes, quiver_bytes, ender_chest_contents_bytes, wardrobe_contents_bytes,
+ String[] inv_bytes = new String[]{inv_armor_bytes, fishing_bag_bytes, quiver_bytes, ender_chest_contents_bytes, backpack_contents_json_fake, personal_vault_contents_bytes, wardrobe_contents_bytes,
potion_bag_bytes, inv_contents_bytes, talisman_bag_bytes, candy_inventory_contents_bytes};
for(int i=0; i<inv_bytes.length; i++) {
try {
String bytes = inv_bytes[i];
JsonArray contents = new JsonArray();
- NBTTagCompound inv_contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(Base64.getDecoder().decode(bytes)));
- NBTTagList items = inv_contents_nbt.getTagList("i", 10);
- for(int j=0; j<items.tagCount(); j++) {
- JsonObject item = manager.getJsonFromNBTEntry(items.getCompoundTagAt(j));
- contents.add(item);
+
+ if(inv_names[i].equals("backpack_contents")){
+ JsonObject temp = getBackpackData(backpack_contents_json, backpack_icons);
+ contents = (JsonArray) temp.get("contents");
+ inventoryInfo.add("backpack_sizes", temp.get("backpack_sizes"));
+
+ } else {
+
+ NBTTagCompound inv_contents_nbt = CompressedStreamTools.readCompressed(new ByteArrayInputStream(Base64.getDecoder().decode(bytes)));
+ NBTTagList items = inv_contents_nbt.getTagList("i", 10);
+ for (int j = 0; j < items.tagCount(); j++) {
+ JsonObject item = manager.getJsonFromNBTEntry(items.getCompoundTagAt(j));
+ contents.add(item);
+ }
}
inventoryInfo.add(inv_names[i], contents);
} catch(IOException e) {
@@ -814,6 +826,84 @@ public class ProfileViewer { return inventoryInfo;
}
+ public JsonObject getBackpackData(JsonObject backpack_contents_json, JsonObject backpack_icons) {
+
+
+ for (StackTraceElement ste : Thread.currentThread().getStackTrace()) {
+ System.out.println(ste);
+ }
+
+ JsonArray contents = new JsonArray();
+
+
+ String[] backpackArray = new String[0];
+
+
+ //Create backpack array which sizes up
+ for(Map.Entry<String, JsonElement> 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;
|