aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/StorageManager.java
diff options
context:
space:
mode:
authorAscynx <78341107+Ascynx@users.noreply.github.com>2022-09-12 10:41:12 +0200
committerGitHub <noreply@github.com>2022-09-12 10:41:12 +0200
commit765b569dd667d6a7e86b26d5ef1e7c5a5bade8f7 (patch)
treebf19bef5042d95243e94ba988e2162e141562262 /src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/StorageManager.java
parentef557a6f4dff5ed9ce13f26f41b55c60008e8eae (diff)
downloadnotenoughupdates-765b569dd667d6a7e86b26d5ef1e7c5a5bade8f7.tar.gz
notenoughupdates-765b569dd667d6a7e86b26d5ef1e7c5a5bade8f7.tar.bz2
notenoughupdates-765b569dd667d6a7e86b26d5ef1e7c5a5bade8f7.zip
Bug fixes (aka #249 but less of a mess) (#251)
* made equipment overlay own class lmk if there's any bugs * fix infer (i think) * fuck infer * First refactoringering * Fix more stuff * itemlisting * NEU 3.0 release notes * The changes of #249 (https://github.com/NotEnoughUpdates/NotEnoughUpdates/pull/249) * fixed nea bug https://imgur.com/a/Sg3iw74 * whitespace * fixed equipment overlay not working ? and caching * nopoing idk what im doing * FHJNX GHD trwsmokürtsew tze jiozterdgjjiüzetr jipztr * reverted "janky pet expended bugfix" * Revert "FHJNX GHD" This reverts commit 24eceba3db5e500be296f5a96412bd8b95647a22. * Revert "nopoing" This reverts commit bee07cb98f8b9672c2e1bc192c6c3e5ae8b02b95. * Revert "fixed equipment overlay" This reverts commit b15376f934a738900e2dd98efdb0d4a7ec131dfa. * idk i think this works maybe * ??? ????????? * Update to the catacombs base floor exp. Based on the hypixel wiki's calculator (see: https://canary.discord.com/channels/516977525906341928/1016050994557222912) * no more black lines * equipment cache * Fix lag with optifine and removal of unused field. Removed onMouseClick as it was triggered more than once per tick when optifine is installed. Removed tooltipsToDisplay field (as it was replaced by a local variable). * this should be true by default to keep old behaviour * itemList now doesn't close when clicking the searchbar itemList will now only close when searchMode is triggered. * Infer moment hoping this doesn't trigger it. * I forgot to push that change when I created the pr. * Fixed json resetting if an item has no nbt Co-authored-by: efefury <69400149+efefury@users.noreply.github.com> Co-authored-by: nea <romangraef@gmail.com> Co-authored-by: Lulonaut <lulonaut@tutanota.de> Co-authored-by: nopo <noahogno@gmail.com> Co-authored-by: Roman / Linnea Gräf <roman.graef@gmail.com> Co-authored-by: Lorenz <lo.scherf@gmail.com>
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/StorageManager.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/StorageManager.java63
1 files changed, 61 insertions, 2 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/StorageManager.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/StorageManager.java
index cc463308..93e9f516 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/StorageManager.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/StorageManager.java
@@ -45,6 +45,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.nbt.NBTBase;
+import net.minecraft.nbt.NBTException;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.nbt.NBTTagByteArray;
import net.minecraft.nbt.NBTTagCompound;
@@ -83,11 +84,12 @@ public class StorageManager {
private static final StorageManager INSTANCE = new StorageManager();
private static final Gson GSON = new GsonBuilder()
.registerTypeAdapter(ItemStack.class, new ItemStackSerializer())
- .registerTypeAdapter(ItemStack.class, new ItemStackDeserilizer()).create();
+ .registerTypeAdapter(ItemStack.class, new ItemStackDeserializer()).create();
public static class ItemStackSerializer implements JsonSerializer<ItemStack> {
@Override
public JsonElement serialize(ItemStack src, Type typeOfSrc, JsonSerializationContext context) {
+ fixPetInfo(src);
NBTTagCompound tag = src.serializeNBT();
return nbtToJson(tag);
}
@@ -95,7 +97,7 @@ public class StorageManager {
private static final Pattern JSON_FIX_REGEX = Pattern.compile("\"([^,:]+)\":");
- public static class ItemStackDeserilizer implements JsonDeserializer<ItemStack> {
+ public static class ItemStackDeserializer implements JsonDeserializer<ItemStack> {
@Override
public ItemStack deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
@@ -135,6 +137,63 @@ public class StorageManager {
return (JsonObject) loadJson(NBTTagCompound);
}
+ private static class PetInfo {
+ String type;
+ Boolean active;
+ Double exp;
+ String tier;
+ Boolean hideInfo;
+ Integer candyUsed;
+ String uuid;
+ Boolean hideRightClick;
+ String heldItem;
+ String skin;
+
+ private <T> void appendIfNotNull(StringBuilder builder, String key, T value) {
+ if (value != null) {
+ if (builder.indexOf("{") != builder.length()-1) {
+ builder.append(",");
+ }
+ builder.append(key).append(":");
+ if (value instanceof String) {
+ builder.append("\"").append(value).append("\"");
+ } else {
+ builder.append(value);
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder object = new StringBuilder();
+ object.append("{");
+ appendIfNotNull(object, "type", type);
+ appendIfNotNull(object, "active", active);
+ appendIfNotNull(object, "exp", exp);
+ appendIfNotNull(object, "tier", tier);
+ appendIfNotNull(object, "hideInfo", hideInfo);
+ appendIfNotNull(object, "candyUsed", candyUsed);
+ appendIfNotNull(object, "uuid", uuid);
+ appendIfNotNull(object, "hideRightClick", hideRightClick);
+ appendIfNotNull(object, "heldItem", heldItem);
+ appendIfNotNull(object, "skin", skin);
+ object.append("}");
+ return object.toString();
+ }
+ }
+
+ private static void fixPetInfo(ItemStack src) {
+ if (src.getTagCompound() == null || !src.getTagCompound().hasKey("ExtraAttributes") || !src.getTagCompound().getCompoundTag("ExtraAttributes").hasKey("petInfo")) return;
+ PetInfo oldPetInfo = GSON.fromJson(src.getTagCompound().getCompoundTag("ExtraAttributes").getString("petInfo"), PetInfo.class);
+ src.getTagCompound().getCompoundTag("ExtraAttributes").removeTag("petInfo");
+ try {
+ src.getTagCompound().getCompoundTag("ExtraAttributes").setTag(
+ "petInfo",
+ JsonToNBT.getTagFromJson(oldPetInfo.toString())
+ );
+ } catch (NBTException | NullPointerException ignored) {}
+ }
+
private static JsonElement loadJson(NBTBase tag) {
if (tag instanceof NBTTagCompound) {
NBTTagCompound compoundTag = (NBTTagCompound) tag;