Move away from serializing ItemStack directly. Instead, use a false ItemStack to store only the values we care about (solves Gson related issues with ItemStack in the mod)
This commit is contained in:
parent
e3e6d533e2
commit
070528db9b
2 changed files with 27 additions and 4 deletions
11
src/main/java/com/pahimar/ee3/api/JsonItemStack.java
Normal file
11
src/main/java/com/pahimar/ee3/api/JsonItemStack.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package com.pahimar.ee3.api;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class JsonItemStack
|
||||
{
|
||||
public int stackSize;
|
||||
public int itemID;
|
||||
public NBTTagCompound stackTagCompound;
|
||||
public int itemDamage;
|
||||
}
|
|
@ -456,7 +456,15 @@ public class WrappedStack implements Comparable<WrappedStack>, JsonDeserializer<
|
|||
|
||||
if (wrappedStack.wrappedStack instanceof ItemStack)
|
||||
{
|
||||
jsonWrappedStack.add("wrappedStack", gsonWrappedStack.toJsonTree(wrappedStack.wrappedStack, ItemStack.class));
|
||||
JsonItemStack jsonItemStack = new JsonItemStack();
|
||||
jsonItemStack.itemID = ((ItemStack) wrappedStack.wrappedStack).itemID;
|
||||
jsonItemStack.itemDamage = ((ItemStack) wrappedStack.wrappedStack).getItemDamage();
|
||||
jsonItemStack.stackSize = ((ItemStack) wrappedStack.wrappedStack).stackSize;
|
||||
if (((ItemStack) wrappedStack.wrappedStack).stackTagCompound != null)
|
||||
{
|
||||
jsonItemStack.stackTagCompound = ((ItemStack) wrappedStack.wrappedStack).stackTagCompound;
|
||||
}
|
||||
jsonWrappedStack.add("wrappedStack", gsonWrappedStack.toJsonTree(jsonItemStack, JsonItemStack.class));
|
||||
}
|
||||
else if (wrappedStack.wrappedStack instanceof OreStack)
|
||||
{
|
||||
|
@ -504,11 +512,15 @@ public class WrappedStack implements Comparable<WrappedStack>, JsonDeserializer<
|
|||
{
|
||||
if (className.equalsIgnoreCase(ItemStack.class.getSimpleName()))
|
||||
{
|
||||
ItemStack itemStack = gsonSerializer.fromJson(jsonWrappedStack.get("wrappedStack"), ItemStack.class);
|
||||
|
||||
JsonItemStack jsonItemStack = gsonSerializer.fromJson(jsonWrappedStack.get("wrappedStack"), JsonItemStack.class);
|
||||
ItemStack itemStack = null;
|
||||
if (stackSize > 0)
|
||||
{
|
||||
itemStack.stackSize = stackSize;
|
||||
itemStack = new ItemStack(jsonItemStack.itemID, stackSize, jsonItemStack.itemDamage);
|
||||
if (jsonItemStack.stackTagCompound != null)
|
||||
{
|
||||
itemStack.stackTagCompound = jsonItemStack.stackTagCompound;
|
||||
}
|
||||
}
|
||||
stackObject = itemStack;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue