support multiple inventories in InventoryUtils

This commit is contained in:
Raoul Van den Berge
2016-02-03 19:51:51 +01:00
parent f2bf12b833
commit c2f31485f0
11 changed files with 35 additions and 35 deletions

View File

@@ -67,7 +67,7 @@ public class TileConstructor extends TileMachine implements ICompareSetting
compare = nbt.getInteger(NBT_COMPARE);
}
InventoryUtils.restoreInventory(inventory, nbt);
InventoryUtils.restoreInventory(inventory, 0, nbt);
}
@Override
@@ -77,7 +77,7 @@ public class TileConstructor extends TileMachine implements ICompareSetting
nbt.setInteger(NBT_COMPARE, compare);
InventoryUtils.saveInventory(inventory, nbt);
InventoryUtils.saveInventory(inventory, 0, nbt);
}
@Override

View File

@@ -174,7 +174,7 @@ public class TileDetector extends TileMachine implements ICompareSetting
amount = nbt.getInteger(NBT_AMOUNT);
}
InventoryUtils.restoreInventory(inventory, nbt);
InventoryUtils.restoreInventory(inventory, 0, nbt);
}
@Override
@@ -186,7 +186,7 @@ public class TileDetector extends TileMachine implements ICompareSetting
nbt.setInteger(NBT_MODE, mode);
nbt.setInteger(NBT_AMOUNT, amount);
InventoryUtils.saveInventory(inventory, nbt);
InventoryUtils.saveInventory(inventory, 0, nbt);
}
@Override

View File

@@ -59,7 +59,7 @@ public class TileDrive extends TileMachine implements IInventory, IStorageProvid
{
super.readFromNBT(nbt);
InventoryUtils.restoreInventory(this, nbt);
InventoryUtils.restoreInventory(this, 0, nbt);
if (nbt.hasKey(NBT_PRIORITY))
{
@@ -72,7 +72,7 @@ public class TileDrive extends TileMachine implements IInventory, IStorageProvid
{
super.writeToNBT(nbt);
InventoryUtils.saveInventory(this, nbt);
InventoryUtils.saveInventory(this, 0, nbt);
nbt.setInteger(NBT_PRIORITY, priority);
}

View File

@@ -111,7 +111,7 @@ public class TileExporter extends TileMachine implements ICompareSetting
compare = nbt.getInteger(NBT_COMPARE);
}
InventoryUtils.restoreInventory(inventory, nbt);
InventoryUtils.restoreInventory(inventory, 0, nbt);
}
@Override
@@ -121,7 +121,7 @@ public class TileExporter extends TileMachine implements ICompareSetting
nbt.setInteger(NBT_COMPARE, compare);
InventoryUtils.saveInventory(inventory, nbt);
InventoryUtils.saveInventory(inventory, 0, nbt);
}
@Override

View File

@@ -169,7 +169,7 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
{
super.readFromNBT(nbt);
InventoryUtils.restoreInventory(inventory, nbt);
InventoryUtils.restoreInventory(inventory, 0, nbt);
if (nbt.hasKey(NBT_PRIORITY))
{
@@ -192,7 +192,7 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
{
super.writeToNBT(nbt);
InventoryUtils.saveInventory(inventory, nbt);
InventoryUtils.saveInventory(inventory, 0, nbt);
nbt.setInteger(NBT_PRIORITY, priority);
nbt.setInteger(NBT_COMPARE, compare);

View File

@@ -60,7 +60,7 @@ public class TileGrid extends TileMachine
}
};
private InventoryCrafting patternCraftingInventory = new InventoryCrafting(patternCraftingContainer, 3, 3);
private InventorySimple patternCraftingResultInventory = new InventorySimple("pattern_crafting_result", 1, this);
private InventorySimple patternCraftingResultInventory = new InventorySimple("pattern_crafting_result", 1);
private InventorySimple patternInventory = new InventorySimple("pattern", 2, this);
private int sortingDirection = 0;
@@ -181,10 +181,10 @@ public class TileGrid extends TileMachine
{
super.readFromNBT(nbt);
InventoryUtils.restoreInventory(craftingInventory, nbt);
InventoryUtils.restoreInventory(patternCraftingInventory, nbt);
InventoryUtils.restoreInventory(patternCraftingResultInventory, nbt);
InventoryUtils.restoreInventory(patternInventory, nbt);
InventoryUtils.restoreInventory(craftingInventory, 0, nbt);
InventoryUtils.restoreInventory(patternCraftingInventory, 1, nbt);
InventoryUtils.restoreInventory(patternInventory, 2, nbt);
if (nbt.hasKey(NBT_SORTING_DIRECTION))
{
@@ -202,10 +202,10 @@ public class TileGrid extends TileMachine
{
super.writeToNBT(nbt);
InventoryUtils.saveInventory(craftingInventory, nbt);
InventoryUtils.saveInventory(patternCraftingInventory, nbt);
InventoryUtils.saveInventory(patternCraftingResultInventory, nbt);
InventoryUtils.saveInventory(patternInventory, nbt);
InventoryUtils.saveInventory(craftingInventory, 0, nbt);
InventoryUtils.saveInventory(patternCraftingInventory, 1, nbt);
InventoryUtils.saveInventory(patternInventory, 2, nbt);
nbt.setInteger(NBT_SORTING_DIRECTION, sortingDirection);
nbt.setInteger(NBT_SORTING_TYPE, sortingType);

View File

@@ -175,7 +175,7 @@ public class TileImporter extends TileMachine implements ICompareSetting, IModeS
mode = nbt.getInteger(NBT_MODE);
}
InventoryUtils.restoreInventory(inventory, nbt);
InventoryUtils.restoreInventory(inventory, 0, nbt);
}
@Override
@@ -186,7 +186,7 @@ public class TileImporter extends TileMachine implements ICompareSetting, IModeS
nbt.setInteger(NBT_COMPARE, compare);
nbt.setInteger(NBT_MODE, mode);
InventoryUtils.saveInventory(inventory, nbt);
InventoryUtils.saveInventory(inventory, 0, nbt);
}
@Override

View File

@@ -95,7 +95,7 @@ public class TileSolderer extends TileMachine implements IInventory, ISidedInven
{
super.readFromNBT(nbt);
InventoryUtils.restoreInventory(this, nbt);
InventoryUtils.restoreInventory(this, 0, nbt);
recipe = SoldererRegistry.getRecipe(inventory);
@@ -115,7 +115,7 @@ public class TileSolderer extends TileMachine implements IInventory, ISidedInven
{
super.writeToNBT(nbt);
InventoryUtils.saveInventory(this, nbt);
InventoryUtils.saveInventory(this, 0, nbt);
nbt.setBoolean(NBT_WORKING, working);
nbt.setInteger(NBT_PROGRESS, progress);

View File

@@ -62,7 +62,7 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
{
super.readFromNBT(nbt);
InventoryUtils.restoreInventory(inventory, nbt);
InventoryUtils.restoreInventory(inventory, 0, nbt);
if (nbt.hasKey(NBT_STORAGE))
{
@@ -90,7 +90,7 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
{
super.writeToNBT(nbt);
InventoryUtils.saveInventory(inventory, nbt);
InventoryUtils.saveInventory(inventory, 0, nbt);
nbt.setTag(NBT_STORAGE, tag);
nbt.setInteger(NBT_PRIORITY, priority);

View File

@@ -118,7 +118,7 @@ public class TileWirelessTransmitter extends TileMachine implements IInventory
{
super.readFromNBT(nbt);
InventoryUtils.restoreInventory(this, nbt);
InventoryUtils.restoreInventory(this, 0, nbt);
if (nbt.hasKey(NBT_WORKING))
{
@@ -136,7 +136,7 @@ public class TileWirelessTransmitter extends TileMachine implements IInventory
{
super.writeToNBT(nbt);
InventoryUtils.saveInventory(this, nbt);
InventoryUtils.saveInventory(this, 0, nbt);
nbt.setBoolean(NBT_WORKING, working);
nbt.setInteger(NBT_PROGRESS, progress);

View File

@@ -10,15 +10,14 @@ import net.minecraftforge.common.util.Constants;
public class InventoryUtils
{
public static final String NBT_INVENTORY = "Inventory";
public static final String NBT_INVENTORY = "Inventory_%d";
public static final String NBT_SLOT = "Slot";
public static final int COMPARE_DAMAGE = 1;
public static final int COMPARE_NBT = 2;
public static final int COMPARE_QUANTITY = 4;
// @TODO: Save multiple inventories
public static void saveInventory(IInventory inventory, NBTTagCompound nbt)
public static void saveInventory(IInventory inventory, int id, NBTTagCompound nbt)
{
NBTTagList tagList = new NBTTagList();
@@ -36,15 +35,16 @@ public class InventoryUtils
}
}
nbt.setTag(NBT_INVENTORY, tagList);
nbt.setTag(String.format(NBT_INVENTORY, id), tagList);
}
// @TODO: Restore multiple inventories
public static void restoreInventory(IInventory inventory, NBTTagCompound nbt)
public static void restoreInventory(IInventory inventory, int id, NBTTagCompound nbt)
{
if (nbt.hasKey(NBT_INVENTORY))
String name = String.format(NBT_INVENTORY, id);
if (nbt.hasKey(name))
{
NBTTagList tagList = nbt.getTagList(NBT_INVENTORY, Constants.NBT.TAG_COMPOUND);
NBTTagList tagList = nbt.getTagList(name, Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < tagList.tagCount(); i++)
{