Visible inventory logistical management (hopefully) complete
This commit is contained in:
parent
0bb73d5183
commit
ab02a09159
4 changed files with 72 additions and 23 deletions
|
@ -59,6 +59,11 @@ public class SetUtil
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies a set.
|
||||||
|
* @param set - set to copy
|
||||||
|
* @return copied set
|
||||||
|
*/
|
||||||
public static <V> Set<V> copy(Set<V> set)
|
public static <V> Set<V> copy(Set<V> set)
|
||||||
{
|
{
|
||||||
Set<V> toReturn = new HashSet<V>();
|
Set<V> toReturn = new HashSet<V>();
|
||||||
|
@ -145,6 +150,11 @@ public class SetUtil
|
||||||
return toReturn;
|
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)
|
public static <V> V getTop(Set<V> set)
|
||||||
{
|
{
|
||||||
for(V obj : set)
|
for(V obj : set)
|
||||||
|
|
|
@ -219,11 +219,17 @@ public class BatteryUpdateProtocol
|
||||||
{
|
{
|
||||||
ArrayList<Set<ItemStack>> inventories = SetUtil.split(oldStructure.inventory, iteratedNodes.size());
|
ArrayList<Set<ItemStack>> inventories = SetUtil.split(oldStructure.inventory, iteratedNodes.size());
|
||||||
List<TileEntityBattery> iterList = SetUtil.asList(iteratedNodes);
|
List<TileEntityBattery> iterList = SetUtil.asList(iteratedNodes);
|
||||||
|
boolean didVisibleInventory = false;
|
||||||
|
|
||||||
for(int i = 0; i < iterList.size(); i++)
|
for(int i = 0; i < iterList.size(); i++)
|
||||||
{
|
{
|
||||||
TileEntityBattery tile = iterList.get(i);
|
TileEntityBattery tile = iterList.get(i);
|
||||||
tile.structure = SynchronizedBatteryData.getBase(tile, inventories.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);
|
TileEntityBattery tileEntity = (TileEntityBattery)obj.getTileEntity(pointer.worldObj);
|
||||||
|
|
||||||
structureFound.inventory = SetUtil.merge(structureFound.inventory, tileEntity.structure.inventory);
|
structureFound.inventory = SetUtil.merge(structureFound.inventory, tileEntity.structure.inventory);
|
||||||
|
|
||||||
|
if(tileEntity.structure.hasVisibleInventory())
|
||||||
|
{
|
||||||
|
structureFound.visibleInventory = tileEntity.structure.visibleInventory;
|
||||||
|
}
|
||||||
|
|
||||||
tileEntity.structure = structureFound;
|
tileEntity.structure = structureFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,11 @@ public class SynchronizedBatteryData
|
||||||
|
|
||||||
public Set<ItemStack> inventory = new HashSet<ItemStack>();
|
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 ItemStack[] visibleInventory = new ItemStack[3];
|
||||||
|
|
||||||
public int length;
|
public int length;
|
||||||
|
@ -26,6 +31,8 @@ public class SynchronizedBatteryData
|
||||||
|
|
||||||
public boolean didTick;
|
public boolean didTick;
|
||||||
|
|
||||||
|
public boolean wroteVisibleInventory;
|
||||||
|
|
||||||
public int getVolume()
|
public int getVolume()
|
||||||
{
|
{
|
||||||
return length*width*height;
|
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)
|
public static SynchronizedBatteryData getBase(TileEntityBattery tileEntity, Set<ItemStack> inventory)
|
||||||
{
|
{
|
||||||
SynchronizedBatteryData structure = getBase(tileEntity);
|
SynchronizedBatteryData structure = getBase(tileEntity);
|
||||||
|
|
|
@ -94,6 +94,8 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
||||||
}
|
}
|
||||||
|
|
||||||
//Visible inventory
|
//Visible inventory
|
||||||
|
if(nbtTags.hasKey("VisibleItems"))
|
||||||
|
{
|
||||||
NBTTagList tagList1 = nbtTags.getTagList("VisibleItems");
|
NBTTagList tagList1 = nbtTags.getTagList("VisibleItems");
|
||||||
structure.visibleInventory = new ItemStack[3];
|
structure.visibleInventory = new ItemStack[3];
|
||||||
|
|
||||||
|
@ -108,6 +110,7 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound nbtTags)
|
public void writeToNBT(NBTTagCompound nbtTags)
|
||||||
|
@ -130,6 +133,8 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
||||||
nbtTags.setTag("Items", tagList);
|
nbtTags.setTag("Items", tagList);
|
||||||
|
|
||||||
//Visible inventory
|
//Visible inventory
|
||||||
|
if(!structure.wroteVisibleInventory)
|
||||||
|
{
|
||||||
NBTTagList tagList1 = new NBTTagList();
|
NBTTagList tagList1 = new NBTTagList();
|
||||||
|
|
||||||
for(int slotCount = 0; slotCount < structure.visibleInventory.length; slotCount++)
|
for(int slotCount = 0; slotCount < structure.visibleInventory.length; slotCount++)
|
||||||
|
@ -144,6 +149,8 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
||||||
}
|
}
|
||||||
|
|
||||||
nbtTags.setTag("VisibleItems", tagList1);
|
nbtTags.setTag("VisibleItems", tagList1);
|
||||||
|
structure.wroteVisibleInventory = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update()
|
public void update()
|
||||||
|
|
Loading…
Reference in a new issue