support multiple inventories in InventoryUtils
This commit is contained in:
@@ -67,7 +67,7 @@ public class TileConstructor extends TileMachine implements ICompareSetting
|
|||||||
compare = nbt.getInteger(NBT_COMPARE);
|
compare = nbt.getInteger(NBT_COMPARE);
|
||||||
}
|
}
|
||||||
|
|
||||||
InventoryUtils.restoreInventory(inventory, nbt);
|
InventoryUtils.restoreInventory(inventory, 0, nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -77,7 +77,7 @@ public class TileConstructor extends TileMachine implements ICompareSetting
|
|||||||
|
|
||||||
nbt.setInteger(NBT_COMPARE, compare);
|
nbt.setInteger(NBT_COMPARE, compare);
|
||||||
|
|
||||||
InventoryUtils.saveInventory(inventory, nbt);
|
InventoryUtils.saveInventory(inventory, 0, nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -174,7 +174,7 @@ public class TileDetector extends TileMachine implements ICompareSetting
|
|||||||
amount = nbt.getInteger(NBT_AMOUNT);
|
amount = nbt.getInteger(NBT_AMOUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
InventoryUtils.restoreInventory(inventory, nbt);
|
InventoryUtils.restoreInventory(inventory, 0, nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -186,7 +186,7 @@ public class TileDetector extends TileMachine implements ICompareSetting
|
|||||||
nbt.setInteger(NBT_MODE, mode);
|
nbt.setInteger(NBT_MODE, mode);
|
||||||
nbt.setInteger(NBT_AMOUNT, amount);
|
nbt.setInteger(NBT_AMOUNT, amount);
|
||||||
|
|
||||||
InventoryUtils.saveInventory(inventory, nbt);
|
InventoryUtils.saveInventory(inventory, 0, nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -59,7 +59,7 @@ public class TileDrive extends TileMachine implements IInventory, IStorageProvid
|
|||||||
{
|
{
|
||||||
super.readFromNBT(nbt);
|
super.readFromNBT(nbt);
|
||||||
|
|
||||||
InventoryUtils.restoreInventory(this, nbt);
|
InventoryUtils.restoreInventory(this, 0, nbt);
|
||||||
|
|
||||||
if (nbt.hasKey(NBT_PRIORITY))
|
if (nbt.hasKey(NBT_PRIORITY))
|
||||||
{
|
{
|
||||||
@@ -72,7 +72,7 @@ public class TileDrive extends TileMachine implements IInventory, IStorageProvid
|
|||||||
{
|
{
|
||||||
super.writeToNBT(nbt);
|
super.writeToNBT(nbt);
|
||||||
|
|
||||||
InventoryUtils.saveInventory(this, nbt);
|
InventoryUtils.saveInventory(this, 0, nbt);
|
||||||
|
|
||||||
nbt.setInteger(NBT_PRIORITY, priority);
|
nbt.setInteger(NBT_PRIORITY, priority);
|
||||||
}
|
}
|
||||||
|
@@ -111,7 +111,7 @@ public class TileExporter extends TileMachine implements ICompareSetting
|
|||||||
compare = nbt.getInteger(NBT_COMPARE);
|
compare = nbt.getInteger(NBT_COMPARE);
|
||||||
}
|
}
|
||||||
|
|
||||||
InventoryUtils.restoreInventory(inventory, nbt);
|
InventoryUtils.restoreInventory(inventory, 0, nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -121,7 +121,7 @@ public class TileExporter extends TileMachine implements ICompareSetting
|
|||||||
|
|
||||||
nbt.setInteger(NBT_COMPARE, compare);
|
nbt.setInteger(NBT_COMPARE, compare);
|
||||||
|
|
||||||
InventoryUtils.saveInventory(inventory, nbt);
|
InventoryUtils.saveInventory(inventory, 0, nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -169,7 +169,7 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
|||||||
{
|
{
|
||||||
super.readFromNBT(nbt);
|
super.readFromNBT(nbt);
|
||||||
|
|
||||||
InventoryUtils.restoreInventory(inventory, nbt);
|
InventoryUtils.restoreInventory(inventory, 0, nbt);
|
||||||
|
|
||||||
if (nbt.hasKey(NBT_PRIORITY))
|
if (nbt.hasKey(NBT_PRIORITY))
|
||||||
{
|
{
|
||||||
@@ -192,7 +192,7 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
|
|||||||
{
|
{
|
||||||
super.writeToNBT(nbt);
|
super.writeToNBT(nbt);
|
||||||
|
|
||||||
InventoryUtils.saveInventory(inventory, nbt);
|
InventoryUtils.saveInventory(inventory, 0, nbt);
|
||||||
|
|
||||||
nbt.setInteger(NBT_PRIORITY, priority);
|
nbt.setInteger(NBT_PRIORITY, priority);
|
||||||
nbt.setInteger(NBT_COMPARE, compare);
|
nbt.setInteger(NBT_COMPARE, compare);
|
||||||
|
@@ -60,7 +60,7 @@ public class TileGrid extends TileMachine
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
private InventoryCrafting patternCraftingInventory = new InventoryCrafting(patternCraftingContainer, 3, 3);
|
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 InventorySimple patternInventory = new InventorySimple("pattern", 2, this);
|
||||||
|
|
||||||
private int sortingDirection = 0;
|
private int sortingDirection = 0;
|
||||||
@@ -181,10 +181,10 @@ public class TileGrid extends TileMachine
|
|||||||
{
|
{
|
||||||
super.readFromNBT(nbt);
|
super.readFromNBT(nbt);
|
||||||
|
|
||||||
InventoryUtils.restoreInventory(craftingInventory, nbt);
|
InventoryUtils.restoreInventory(craftingInventory, 0, nbt);
|
||||||
InventoryUtils.restoreInventory(patternCraftingInventory, nbt);
|
|
||||||
InventoryUtils.restoreInventory(patternCraftingResultInventory, nbt);
|
InventoryUtils.restoreInventory(patternCraftingInventory, 1, nbt);
|
||||||
InventoryUtils.restoreInventory(patternInventory, nbt);
|
InventoryUtils.restoreInventory(patternInventory, 2, nbt);
|
||||||
|
|
||||||
if (nbt.hasKey(NBT_SORTING_DIRECTION))
|
if (nbt.hasKey(NBT_SORTING_DIRECTION))
|
||||||
{
|
{
|
||||||
@@ -202,10 +202,10 @@ public class TileGrid extends TileMachine
|
|||||||
{
|
{
|
||||||
super.writeToNBT(nbt);
|
super.writeToNBT(nbt);
|
||||||
|
|
||||||
InventoryUtils.saveInventory(craftingInventory, nbt);
|
InventoryUtils.saveInventory(craftingInventory, 0, nbt);
|
||||||
InventoryUtils.saveInventory(patternCraftingInventory, nbt);
|
|
||||||
InventoryUtils.saveInventory(patternCraftingResultInventory, nbt);
|
InventoryUtils.saveInventory(patternCraftingInventory, 1, nbt);
|
||||||
InventoryUtils.saveInventory(patternInventory, nbt);
|
InventoryUtils.saveInventory(patternInventory, 2, nbt);
|
||||||
|
|
||||||
nbt.setInteger(NBT_SORTING_DIRECTION, sortingDirection);
|
nbt.setInteger(NBT_SORTING_DIRECTION, sortingDirection);
|
||||||
nbt.setInteger(NBT_SORTING_TYPE, sortingType);
|
nbt.setInteger(NBT_SORTING_TYPE, sortingType);
|
||||||
|
@@ -175,7 +175,7 @@ public class TileImporter extends TileMachine implements ICompareSetting, IModeS
|
|||||||
mode = nbt.getInteger(NBT_MODE);
|
mode = nbt.getInteger(NBT_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
InventoryUtils.restoreInventory(inventory, nbt);
|
InventoryUtils.restoreInventory(inventory, 0, nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -186,7 +186,7 @@ public class TileImporter extends TileMachine implements ICompareSetting, IModeS
|
|||||||
nbt.setInteger(NBT_COMPARE, compare);
|
nbt.setInteger(NBT_COMPARE, compare);
|
||||||
nbt.setInteger(NBT_MODE, mode);
|
nbt.setInteger(NBT_MODE, mode);
|
||||||
|
|
||||||
InventoryUtils.saveInventory(inventory, nbt);
|
InventoryUtils.saveInventory(inventory, 0, nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -95,7 +95,7 @@ public class TileSolderer extends TileMachine implements IInventory, ISidedInven
|
|||||||
{
|
{
|
||||||
super.readFromNBT(nbt);
|
super.readFromNBT(nbt);
|
||||||
|
|
||||||
InventoryUtils.restoreInventory(this, nbt);
|
InventoryUtils.restoreInventory(this, 0, nbt);
|
||||||
|
|
||||||
recipe = SoldererRegistry.getRecipe(inventory);
|
recipe = SoldererRegistry.getRecipe(inventory);
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ public class TileSolderer extends TileMachine implements IInventory, ISidedInven
|
|||||||
{
|
{
|
||||||
super.writeToNBT(nbt);
|
super.writeToNBT(nbt);
|
||||||
|
|
||||||
InventoryUtils.saveInventory(this, nbt);
|
InventoryUtils.saveInventory(this, 0, nbt);
|
||||||
|
|
||||||
nbt.setBoolean(NBT_WORKING, working);
|
nbt.setBoolean(NBT_WORKING, working);
|
||||||
nbt.setInteger(NBT_PROGRESS, progress);
|
nbt.setInteger(NBT_PROGRESS, progress);
|
||||||
|
@@ -62,7 +62,7 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
|||||||
{
|
{
|
||||||
super.readFromNBT(nbt);
|
super.readFromNBT(nbt);
|
||||||
|
|
||||||
InventoryUtils.restoreInventory(inventory, nbt);
|
InventoryUtils.restoreInventory(inventory, 0, nbt);
|
||||||
|
|
||||||
if (nbt.hasKey(NBT_STORAGE))
|
if (nbt.hasKey(NBT_STORAGE))
|
||||||
{
|
{
|
||||||
@@ -90,7 +90,7 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora
|
|||||||
{
|
{
|
||||||
super.writeToNBT(nbt);
|
super.writeToNBT(nbt);
|
||||||
|
|
||||||
InventoryUtils.saveInventory(inventory, nbt);
|
InventoryUtils.saveInventory(inventory, 0, nbt);
|
||||||
|
|
||||||
nbt.setTag(NBT_STORAGE, tag);
|
nbt.setTag(NBT_STORAGE, tag);
|
||||||
nbt.setInteger(NBT_PRIORITY, priority);
|
nbt.setInteger(NBT_PRIORITY, priority);
|
||||||
|
@@ -118,7 +118,7 @@ public class TileWirelessTransmitter extends TileMachine implements IInventory
|
|||||||
{
|
{
|
||||||
super.readFromNBT(nbt);
|
super.readFromNBT(nbt);
|
||||||
|
|
||||||
InventoryUtils.restoreInventory(this, nbt);
|
InventoryUtils.restoreInventory(this, 0, nbt);
|
||||||
|
|
||||||
if (nbt.hasKey(NBT_WORKING))
|
if (nbt.hasKey(NBT_WORKING))
|
||||||
{
|
{
|
||||||
@@ -136,7 +136,7 @@ public class TileWirelessTransmitter extends TileMachine implements IInventory
|
|||||||
{
|
{
|
||||||
super.writeToNBT(nbt);
|
super.writeToNBT(nbt);
|
||||||
|
|
||||||
InventoryUtils.saveInventory(this, nbt);
|
InventoryUtils.saveInventory(this, 0, nbt);
|
||||||
|
|
||||||
nbt.setBoolean(NBT_WORKING, working);
|
nbt.setBoolean(NBT_WORKING, working);
|
||||||
nbt.setInteger(NBT_PROGRESS, progress);
|
nbt.setInteger(NBT_PROGRESS, progress);
|
||||||
|
@@ -10,15 +10,14 @@ import net.minecraftforge.common.util.Constants;
|
|||||||
|
|
||||||
public class InventoryUtils
|
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 String NBT_SLOT = "Slot";
|
||||||
|
|
||||||
public static final int COMPARE_DAMAGE = 1;
|
public static final int COMPARE_DAMAGE = 1;
|
||||||
public static final int COMPARE_NBT = 2;
|
public static final int COMPARE_NBT = 2;
|
||||||
public static final int COMPARE_QUANTITY = 4;
|
public static final int COMPARE_QUANTITY = 4;
|
||||||
|
|
||||||
// @TODO: Save multiple inventories
|
public static void saveInventory(IInventory inventory, int id, NBTTagCompound nbt)
|
||||||
public static void saveInventory(IInventory inventory, NBTTagCompound nbt)
|
|
||||||
{
|
{
|
||||||
NBTTagList tagList = new NBTTagList();
|
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, int id, NBTTagCompound nbt)
|
||||||
public static void restoreInventory(IInventory inventory, 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++)
|
for (int i = 0; i < tagList.tagCount(); i++)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user