More work, currently broken

This commit is contained in:
Aidan Brady 2014-08-01 15:49:03 -04:00
parent fc7dd3e65a
commit 548c5b0835
5 changed files with 42 additions and 87 deletions

View file

@ -8,6 +8,7 @@ import java.util.Set;
import mekanism.api.Coord4D;
import mekanism.common.tank.DynamicTankCache;
import mekanism.common.tank.SynchronizedTankData;
import mekanism.common.tile.TileEntityDynamicTank;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -57,19 +58,7 @@ public class MultiblockManager
public DynamicTankCache pullInventory(World world, int id)
{
DynamicTankCache toReturn = inventories.get(id);
for(Coord4D obj : inventories.get(id).locations)
{
TileEntityDynamicTank tileEntity = (TileEntityDynamicTank)obj.getTileEntity(world);
if(tileEntity != null)
{
tileEntity.cachedData = new DynamicTankCache();
tileEntity.inventory = new ItemStack[2];
tileEntity.inventoryID = -1;
}
}
inventories.remove(id);
dataHandler.markDirty();
@ -82,19 +71,21 @@ public class MultiblockManager
* @param cache - cache of the dynamic tank
* @param tileEntity - dynamic tank TileEntity
*/
public void updateCache(int inventoryID, DynamicTankCache cache, TileEntityDynamicTank tileEntity)
public void updateCache(TileEntityDynamicTank tileEntity)
{
if(!inventories.containsKey(inventoryID))
if(!inventories.containsKey(tileEntity.structure.inventoryID))
{
DynamicTankCache cache = new DynamicTankCache();
cache.sync(tileEntity.structure);
cache.locations.add(Coord4D.get(tileEntity));
inventories.put(inventoryID, cache);
inventories.put(tileEntity.structure.inventoryID, cache);
return;
}
inventories.put(inventoryID, cache);
inventories.get(inventoryID).locations.add(Coord4D.get(tileEntity));
inventories.get(tileEntity.structure.inventoryID).sync(tileEntity.structure);
inventories.get(tileEntity.structure.inventoryID).locations.add(Coord4D.get(tileEntity));
dataHandler.markDirty();
}
@ -138,7 +129,7 @@ public class MultiblockManager
{
TileEntity tileEntity = obj.getTileEntity(world);
if(!(tileEntity instanceof TileEntityDynamicTank) || ((TileEntityDynamicTank)tileEntity).inventoryID != inventoryID)
if(!(tileEntity instanceof TileEntityDynamicTank) || getStructureId(((TileEntityDynamicTank)tileEntity)) != inventoryID)
{
if(!tilesToKill.containsKey(inventoryID))
{
@ -167,24 +158,32 @@ public class MultiblockManager
for(int inventoryID : idsToKill)
{
for(Coord4D obj : manager.inventories.get(inventoryID).locations)
{
TileEntityDynamicTank dynamicTank = (TileEntityDynamicTank)obj.getTileEntity(world);
if(dynamicTank != null)
{
dynamicTank.cachedData = new DynamicTankCache();
dynamicTank.inventory = new ItemStack[2];
dynamicTank.inventoryID = -1;
}
}
manager.inventories.remove(inventoryID);
manager.dataHandler.markDirty();
}
}
}
public static int getStructureId(TileEntityDynamicTank tile)
{
return tile.structure != null ? tile.structure.inventoryID : -1;
}
public int getInventoryId(TileEntityDynamicTank tile)
{
Coord4D coord = Coord4D.get(tile);
for(Map.Entry<Integer, DynamicTankCache> entry : inventories.entrySet())
{
if(entry.getValue().locations.contains(coord))
{
return entry.getKey();
}
}
return -1;
}
public static void load(World world)
{
for(MultiblockManager manager : managers)

View file

@ -12,6 +12,8 @@ import net.minecraftforge.fluids.FluidStack;
public class DynamicTankCache
{
public HashSet<Coord4D> locations = new HashSet<Coord4D>();
public ItemStack[] inventory = new ItemStack[2];
public FluidStack fluid;
public ContainerEditMode editMode = ContainerEditMode.BOTH;
@ -78,6 +80,4 @@ public class DynamicTankCache
nbtTags.setTag("cachedFluid", fluid.writeToNBT(new NBTTagCompound()));
}
}
public HashSet<Coord4D> locations = new HashSet<Coord4D>();
}

View file

@ -4,7 +4,6 @@ import java.util.HashSet;
import java.util.Set;
import mekanism.api.Coord4D;
import mekanism.common.tile.TileEntityDynamicTank;
import mekanism.common.util.FluidContainerUtils.ContainerEditMode;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
@ -21,6 +20,8 @@ public class SynchronizedTankData
public int volHeight;
public int volume;
public int inventoryID;
public FluidStack fluidStored;

View file

@ -8,10 +8,10 @@ import java.util.Set;
import mekanism.api.Coord4D;
import mekanism.common.Mekanism;
import mekanism.common.MekanismBlocks;
import mekanism.common.multiblock.MultiblockManager;
import mekanism.common.tank.SynchronizedTankData.ValveData;
import mekanism.common.tile.TileEntityDynamicTank;
import mekanism.common.tile.TileEntityDynamicValve;
import mekanism.common.util.MekanismUtils;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
@ -388,9 +388,9 @@ public class TankUpdateProtocol
{
TileEntityDynamicTank tileEntity = (TileEntityDynamicTank)obj.getTileEntity(pointer.getWorldObj());
if(tileEntity.inventoryID != -1)
if(Mekanism.tankManager.getInventoryId(tileEntity) != -1)
{
idsFound.add(tileEntity.inventoryID);
idsFound.add(tileEntity.structure.inventoryID);
}
}
@ -418,15 +418,14 @@ public class TankUpdateProtocol
{
structureFound.fluidStored.amount = Math.min(structureFound.fluidStored.amount, structureFound.volume*FLUID_PER_TANK);
}
structureFound.inventoryID = idToUse;
for(Coord4D obj : structureFound.locations)
{
TileEntityDynamicTank tileEntity = (TileEntityDynamicTank)obj.getTileEntity(pointer.getWorldObj());
tileEntity.inventoryID = idToUse;
tileEntity.structure = structureFound;
tileEntity.cachedData.sync(structureFound);
}
}
else {

View file

@ -10,16 +10,13 @@ import mekanism.api.Coord4D;
import mekanism.common.IFluidContainerManager;
import mekanism.common.Mekanism;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.tank.DynamicTankCache;
import mekanism.common.tank.SynchronizedTankData;
import mekanism.common.tank.SynchronizedTankData.ValveData;
import mekanism.common.tank.TankUpdateProtocol;
import mekanism.common.util.FluidContainerUtils;
import mekanism.common.util.FluidContainerUtils.ContainerEditMode;
import mekanism.common.util.MekanismUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
@ -30,14 +27,8 @@ import cpw.mods.fml.relauncher.SideOnly;
public class TileEntityDynamicTank extends TileEntityContainerBlock implements IFluidContainerManager
{
/** Unique inventory ID for the dynamic tank, serves as a way to retrieve cached inventories. */
public int inventoryID = -1;
/** The tank data for this structure. */
public SynchronizedTankData structure;
/** The cache used by this specific tank segment */
public DynamicTankCache cachedData = new DynamicTankCache();
/** Whether or not to send this tank's structure in the next update packet. */
public boolean sendStructure;
@ -149,11 +140,6 @@ public class TileEntityDynamicTank extends TileEntityContainerBlock implements I
isRendering = false;
}
if(inventoryID != -1 && structure == null)
{
Mekanism.tankManager.updateCache(inventoryID, cachedData, this);
}
if(structure == null && ticker == 5)
{
update();
@ -187,10 +173,9 @@ public class TileEntityDynamicTank extends TileEntityContainerBlock implements I
{
structure.didTick = false;
if(inventoryID != -1)
if(structure.inventoryID != -1)
{
cachedData.sync(structure);
Mekanism.tankManager.updateCache(inventoryID, cachedData, this);
Mekanism.tankManager.updateCache(this);
}
manageInventory();
@ -532,35 +517,6 @@ public class TileEntityDynamicTank extends TileEntityContainerBlock implements I
}
}
@Override
public void readFromNBT(NBTTagCompound nbtTags)
{
super.readFromNBT(nbtTags);
if(structure == null)
{
inventoryID = nbtTags.getInteger("inventoryID");
if(inventoryID != -1)
{
cachedData.load(nbtTags);
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbtTags)
{
super.writeToNBT(nbtTags);
nbtTags.setInteger("inventoryID", inventoryID);
if(inventoryID != -1)
{
cachedData.save(nbtTags);
}
}
@Override
@SideOnly(Side.CLIENT)
public AxisAlignedBB getRenderBoundingBox()