Visible inventory logistical management (hopefully) complete

This commit is contained in:
Aidan Brady 2013-08-04 21:27:56 -04:00
parent 0bb73d5183
commit ab02a09159
4 changed files with 72 additions and 23 deletions

View file

@ -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)

View file

@ -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;
}

View file

@ -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);

View file

@ -94,18 +94,21 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
}
//Visible inventory
NBTTagList tagList1 = nbtTags.getTagList("VisibleItems");
structure.visibleInventory = new ItemStack[3];
for(int tagCount = 0; tagCount < tagList1.tagCount(); tagCount++)
if(nbtTags.hasKey("VisibleItems"))
{
NBTTagCompound tagCompound = (NBTTagCompound)tagList1.tagAt(tagCount);
byte slotID = tagCompound.getByte("Slot");
if(slotID >= 0 && slotID < structure.visibleInventory.length)
{
setInventorySlotContents(slotID, ItemStack.loadItemStackFromNBT(tagCompound));
}
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));
}
}
}
}
@ -130,20 +133,24 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
nbtTags.setTag("Items", tagList);
//Visible inventory
NBTTagList tagList1 = new NBTTagList();
for(int slotCount = 0; slotCount < structure.visibleInventory.length; slotCount++)
if(!structure.wroteVisibleInventory)
{
if(getStackInSlot(slotCount) != null)
{
NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setByte("Slot", (byte)slotCount);
getStackInSlot(slotCount).writeToNBT(tagCompound);
tagList1.appendTag(tagCompound);
}
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;
}
nbtTags.setTag("VisibleItems", tagList1);
}
public void update()