Another attempt at the MCPC+ bug
This commit is contained in:
parent
3c3c17d18b
commit
4caf4e1237
3 changed files with 24 additions and 5 deletions
|
@ -457,7 +457,8 @@ public class WrappedStack implements Comparable<WrappedStack>, JsonDeserializer<
|
||||||
|
|
||||||
if (wrappedStack.wrappedStack instanceof ItemStack)
|
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)
|
else if (wrappedStack.wrappedStack instanceof OreStack)
|
||||||
{
|
{
|
||||||
|
@ -505,7 +506,8 @@ public class WrappedStack implements Comparable<WrappedStack>, JsonDeserializer<
|
||||||
{
|
{
|
||||||
if (className.equalsIgnoreCase(ItemStack.class.getSimpleName()))
|
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)
|
if (stackSize > 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,7 +21,7 @@ import java.text.DecimalFormat;
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public class ItemTooltipEventHandler
|
public class ItemTooltipEventHandler
|
||||||
{
|
{
|
||||||
private static boolean debug = false;
|
private static boolean debug = true;
|
||||||
private static DecimalFormat emcDecimalFormat = new DecimalFormat("#.###");
|
private static DecimalFormat emcDecimalFormat = new DecimalFormat("#.###");
|
||||||
|
|
||||||
@ForgeSubscribe
|
@ForgeSubscribe
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.pahimar.ee3.helper;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.*;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
|
@ -17,6 +18,7 @@ public class GsonItemStackSerialization implements JsonDeserializer<ItemStack>,
|
||||||
int stackSize = -1;
|
int stackSize = -1;
|
||||||
int itemID = -1;
|
int itemID = -1;
|
||||||
Integer itemDamage = null;
|
Integer itemDamage = null;
|
||||||
|
NBTTagCompound stackTagCompound = null;
|
||||||
|
|
||||||
if (jsonItemStack.get("stackSize") != null)
|
if (jsonItemStack.get("stackSize") != null)
|
||||||
{
|
{
|
||||||
|
@ -33,16 +35,30 @@ public class GsonItemStackSerialization implements JsonDeserializer<ItemStack>,
|
||||||
itemDamage = jsonItemStack.get("itemDamage").getAsInt();
|
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)
|
if (stackSize != -1 && itemID != -1)
|
||||||
{
|
{
|
||||||
|
ItemStack itemStack;
|
||||||
|
|
||||||
if (itemDamage != null)
|
if (itemDamage != null)
|
||||||
{
|
{
|
||||||
return new ItemStack(itemID, stackSize, itemDamage);
|
itemStack = new ItemStack(itemID, stackSize, itemDamage);
|
||||||
}
|
}
|
||||||
else
|
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<ItemStack>,
|
||||||
jsonItemStack.addProperty("stackSize", itemStack.stackSize);
|
jsonItemStack.addProperty("stackSize", itemStack.stackSize);
|
||||||
jsonItemStack.addProperty("itemID", itemStack.itemID);
|
jsonItemStack.addProperty("itemID", itemStack.itemID);
|
||||||
jsonItemStack.addProperty("itemDamage", itemStack.getItemDamage());
|
jsonItemStack.addProperty("itemDamage", itemStack.getItemDamage());
|
||||||
|
jsonItemStack.add("stackTagCompound", new Gson().toJsonTree(itemStack.getTagCompound()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return jsonItemStack;
|
return jsonItemStack;
|
||||||
|
|
Loading…
Reference in a new issue