JsonElement jsonItemStack = null;
// There must be a size entry!
if ( ! jsonInventory.has(SIZE)) return null;
JsonPrimitive jsonSize = jsonInventory.get(SIZE).getAsJsonPrimitive();
int size = 0;
// What size/type is it?
if (jsonSize.isString() && jsonSize.getAsString().equals(PLAYER))
{
// We use 36 here since it's the size of the player inventory (without armor)
size = 36;
// This is a PlayerInventory
ret = new CraftInventoryPlayer(new MCorePlayerInventory());
PlayerInventory pret = (PlayerInventory)ret;
// helmet
if (jsonInventory.has(HELMET))
{
jsonItemStack = jsonInventory.get(HELMET);
itemStack = MCore.gson.fromJson(jsonItemStack, ItemStack.class);
pret.setHelmet(itemStack);
}
// chestplate
if (jsonInventory.has(CHESTPLATE))
{
jsonItemStack = jsonInventory.get(CHESTPLATE);
itemStack = MCore.gson.fromJson(jsonItemStack, ItemStack.class);
pret.setChestplate(itemStack);
}
// leggings
if (jsonInventory.has(LEGGINGS))
{
jsonItemStack = jsonInventory.get(LEGGINGS);
itemStack = MCore.gson.fromJson(jsonItemStack, ItemStack.class);
pret.setLeggings(itemStack);
}
// boots
if (jsonInventory.has(BOOTS))
{
jsonItemStack = jsonInventory.get(BOOTS);
itemStack = MCore.gson.fromJson(jsonItemStack, ItemStack.class);
pret.setBoots(itemStack);
}
}
else
{
// A custom size were specified
size = jsonSize.getAsInt();
// This is a "Custom" Inventory (content only).
ret = new CraftInventoryCustom(null, size);
}