From 4caf4e12377bd87a3a15c9a3968ae16c98581108 Mon Sep 17 00:00:00 2001 From: pahimar Date: Tue, 31 Dec 2013 03:23:06 -0500 Subject: [PATCH] Another attempt at the MCPC+ bug --- .../com/pahimar/ee3/api/WrappedStack.java | 6 ++++-- .../handler/ItemTooltipEventHandler.java | 2 +- .../helper/GsonItemStackSerialization.java | 21 +++++++++++++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/pahimar/ee3/api/WrappedStack.java b/src/main/java/com/pahimar/ee3/api/WrappedStack.java index 12fd6417..16767253 100644 --- a/src/main/java/com/pahimar/ee3/api/WrappedStack.java +++ b/src/main/java/com/pahimar/ee3/api/WrappedStack.java @@ -457,7 +457,8 @@ public class WrappedStack implements Comparable, JsonDeserializer< if (wrappedStack.wrappedStack instanceof ItemStack) { - jsonWrappedStack.add("wrappedStack", new GsonItemStackSerialization().serialize((ItemStack) wrappedStack.wrappedStack, type, context)); + Gson gsonItemStackSerializer = (new GsonBuilder()).registerTypeAdapter(ItemStack.class, new GsonItemStackSerialization()).create(); + jsonWrappedStack.add("wrappedStack", gsonItemStackSerializer.toJsonTree(wrappedStack.wrappedStack, ItemStack.class)); } else if (wrappedStack.wrappedStack instanceof OreStack) { @@ -505,7 +506,8 @@ public class WrappedStack implements Comparable, JsonDeserializer< { if (className.equalsIgnoreCase(ItemStack.class.getSimpleName())) { - ItemStack itemStack = new GsonItemStackSerialization().deserialize(jsonWrappedStack.get("wrappedStack"), type, context); + Gson gsonItemStackSerializer = (new GsonBuilder()).registerTypeAdapter(ItemStack.class, new GsonItemStackSerialization()).create(); + ItemStack itemStack = gsonItemStackSerializer.fromJson(jsonWrappedStack.get("wrappedStack"), ItemStack.class); if (stackSize > 0) { diff --git a/src/main/java/com/pahimar/ee3/client/handler/ItemTooltipEventHandler.java b/src/main/java/com/pahimar/ee3/client/handler/ItemTooltipEventHandler.java index 33f8f63f..c90673ac 100644 --- a/src/main/java/com/pahimar/ee3/client/handler/ItemTooltipEventHandler.java +++ b/src/main/java/com/pahimar/ee3/client/handler/ItemTooltipEventHandler.java @@ -21,7 +21,7 @@ import java.text.DecimalFormat; @SideOnly(Side.CLIENT) public class ItemTooltipEventHandler { - private static boolean debug = false; + private static boolean debug = true; private static DecimalFormat emcDecimalFormat = new DecimalFormat("#.###"); @ForgeSubscribe diff --git a/src/main/java/com/pahimar/ee3/helper/GsonItemStackSerialization.java b/src/main/java/com/pahimar/ee3/helper/GsonItemStackSerialization.java index 22151036..c45b1b6a 100644 --- a/src/main/java/com/pahimar/ee3/helper/GsonItemStackSerialization.java +++ b/src/main/java/com/pahimar/ee3/helper/GsonItemStackSerialization.java @@ -2,6 +2,7 @@ package com.pahimar.ee3.helper; import com.google.gson.*; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import java.lang.reflect.Type; @@ -17,6 +18,7 @@ public class GsonItemStackSerialization implements JsonDeserializer, int stackSize = -1; int itemID = -1; Integer itemDamage = null; + NBTTagCompound stackTagCompound = null; if (jsonItemStack.get("stackSize") != null) { @@ -33,16 +35,30 @@ public class GsonItemStackSerialization implements JsonDeserializer, itemDamage = jsonItemStack.get("itemDamage").getAsInt(); } + if (jsonItemStack.get("stackTagCompound") != null && !jsonItemStack.get("stackTagCompound").isJsonPrimitive()) + { + stackTagCompound = new Gson().fromJson(jsonItemStack.get("stackTagCompound"), NBTTagCompound.class); + } + if (stackSize != -1 && itemID != -1) { + ItemStack itemStack; + if (itemDamage != null) { - return new ItemStack(itemID, stackSize, itemDamage); + itemStack = new ItemStack(itemID, stackSize, itemDamage); } else { - return new ItemStack(itemID, stackSize, 0); + itemStack = new ItemStack(itemID, stackSize, 0); } + + if (stackTagCompound != null) + { + itemStack.setTagCompound(stackTagCompound); + } + + return itemStack; } } @@ -59,6 +75,7 @@ public class GsonItemStackSerialization implements JsonDeserializer, jsonItemStack.addProperty("stackSize", itemStack.stackSize); jsonItemStack.addProperty("itemID", itemStack.itemID); jsonItemStack.addProperty("itemDamage", itemStack.getItemDamage()); + jsonItemStack.add("stackTagCompound", new Gson().toJsonTree(itemStack.getTagCompound())); } return jsonItemStack;