Merge branch 'master' of https://github.com/calclavia/Resonant-Induction
This commit is contained in:
commit
f14f1ec50e
4 changed files with 107 additions and 2 deletions
|
@ -59,6 +59,11 @@ public class SetUtil
|
|||
return toReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies a set.
|
||||
* @param set - set to copy
|
||||
* @return copied set
|
||||
*/
|
||||
public static <V> Set<V> copy(Set<V> set)
|
||||
{
|
||||
Set<V> toReturn = new HashSet<V>();
|
||||
|
@ -145,6 +150,11 @@ public class SetUtil
|
|||
return toReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the top object in a set.
|
||||
* @param set - set to get the object from
|
||||
* @return top object in the set
|
||||
*/
|
||||
public static <V> V getTop(Set<V> set)
|
||||
{
|
||||
for(V obj : set)
|
||||
|
|
|
@ -219,11 +219,17 @@ public class BatteryUpdateProtocol
|
|||
{
|
||||
ArrayList<Set<ItemStack>> inventories = SetUtil.split(oldStructure.inventory, iteratedNodes.size());
|
||||
List<TileEntityBattery> iterList = SetUtil.asList(iteratedNodes);
|
||||
boolean didVisibleInventory = false;
|
||||
|
||||
for(int i = 0; i < iterList.size(); i++)
|
||||
{
|
||||
TileEntityBattery tile = iterList.get(i);
|
||||
tile.structure = SynchronizedBatteryData.getBase(tile, inventories.get(i));
|
||||
|
||||
if(!didVisibleInventory)
|
||||
{
|
||||
tile.structure.visibleInventory = oldStructure.visibleInventory;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -258,6 +264,12 @@ public class BatteryUpdateProtocol
|
|||
TileEntityBattery tileEntity = (TileEntityBattery)obj.getTileEntity(pointer.worldObj);
|
||||
|
||||
structureFound.inventory = SetUtil.merge(structureFound.inventory, tileEntity.structure.inventory);
|
||||
|
||||
if(tileEntity.structure.hasVisibleInventory())
|
||||
{
|
||||
structureFound.visibleInventory = tileEntity.structure.visibleInventory;
|
||||
}
|
||||
|
||||
tileEntity.structure = structureFound;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,11 @@ public class SynchronizedBatteryData
|
|||
|
||||
public Set<ItemStack> inventory = new HashSet<ItemStack>();
|
||||
|
||||
/**
|
||||
* Slot 0: Cell input slot
|
||||
* Slot 1: Battery charge slot
|
||||
* Slot 2: Battery discharge slot
|
||||
*/
|
||||
public ItemStack[] visibleInventory = new ItemStack[3];
|
||||
|
||||
public int length;
|
||||
|
@ -26,6 +31,8 @@ public class SynchronizedBatteryData
|
|||
|
||||
public boolean didTick;
|
||||
|
||||
public boolean wroteVisibleInventory;
|
||||
|
||||
public int getVolume()
|
||||
{
|
||||
return length*width*height;
|
||||
|
@ -67,6 +74,19 @@ public class SynchronizedBatteryData
|
|||
}
|
||||
}
|
||||
|
||||
public boolean hasVisibleInventory()
|
||||
{
|
||||
for(ItemStack itemStack : visibleInventory)
|
||||
{
|
||||
if(itemStack != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static SynchronizedBatteryData getBase(TileEntityBattery tileEntity, Set<ItemStack> inventory)
|
||||
{
|
||||
SynchronizedBatteryData structure = getBase(tileEntity);
|
||||
|
|
|
@ -82,6 +82,7 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
|||
{
|
||||
super.readFromNBT(nbtTags);
|
||||
|
||||
//Main inventory
|
||||
NBTTagList tagList = nbtTags.getTagList("Items");
|
||||
structure.inventory = new HashSet<ItemStack>();
|
||||
|
||||
|
@ -91,6 +92,24 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
|||
|
||||
structure.inventory.add(ItemStack.loadItemStackFromNBT(tagCompound));
|
||||
}
|
||||
|
||||
//Visible inventory
|
||||
if(nbtTags.hasKey("VisibleItems"))
|
||||
{
|
||||
NBTTagList tagList1 = nbtTags.getTagList("VisibleItems");
|
||||
structure.visibleInventory = new ItemStack[3];
|
||||
|
||||
for(int tagCount = 0; tagCount < tagList1.tagCount(); tagCount++)
|
||||
{
|
||||
NBTTagCompound tagCompound = (NBTTagCompound)tagList1.tagAt(tagCount);
|
||||
byte slotID = tagCompound.getByte("Slot");
|
||||
|
||||
if(slotID >= 0 && slotID < structure.visibleInventory.length)
|
||||
{
|
||||
setInventorySlotContents(slotID, ItemStack.loadItemStackFromNBT(tagCompound));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -98,6 +117,7 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
|||
{
|
||||
super.writeToNBT(nbtTags);
|
||||
|
||||
//Inventory
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
|
||||
for(ItemStack itemStack : structure.inventory)
|
||||
|
@ -111,6 +131,26 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
|||
}
|
||||
|
||||
nbtTags.setTag("Items", tagList);
|
||||
|
||||
//Visible inventory
|
||||
if(!structure.wroteVisibleInventory)
|
||||
{
|
||||
NBTTagList tagList1 = new NBTTagList();
|
||||
|
||||
for(int slotCount = 0; slotCount < structure.visibleInventory.length; slotCount++)
|
||||
{
|
||||
if(getStackInSlot(slotCount) != null)
|
||||
{
|
||||
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||
tagCompound.setByte("Slot", (byte)slotCount);
|
||||
getStackInSlot(slotCount).writeToNBT(tagCompound);
|
||||
tagList1.appendTag(tagCompound);
|
||||
}
|
||||
}
|
||||
|
||||
nbtTags.setTag("VisibleItems", tagList1);
|
||||
structure.wroteVisibleInventory = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void update()
|
||||
|
@ -246,10 +286,33 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j)
|
||||
public ItemStack decrStackSize(int slotID, int amount)
|
||||
{
|
||||
if(getStackInSlot(slotID) != null)
|
||||
{
|
||||
ItemStack tempStack;
|
||||
|
||||
if(getStackInSlot(slotID).stackSize <= amount)
|
||||
{
|
||||
tempStack = getStackInSlot(slotID);
|
||||
setInventorySlotContents(slotID, null);
|
||||
return tempStack;
|
||||
}
|
||||
else {
|
||||
tempStack = getStackInSlot(slotID).splitStack(amount);
|
||||
|
||||
if(getStackInSlot(slotID).stackSize == 0)
|
||||
{
|
||||
setInventorySlotContents(slotID, null);
|
||||
}
|
||||
|
||||
return tempStack;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int i)
|
||||
|
|
Loading…
Reference in a new issue