Fixed save/loading liquid in a network
Got it for sure this time though it looks like i need to fix the autoDrain method some more. As well prevent the fill method from trying to refill the source of the liquid.
This commit is contained in:
parent
5a2034015a
commit
6b72ce462b
4 changed files with 85 additions and 40 deletions
|
@ -4,13 +4,14 @@ import hydraulic.api.IFluidNetworkPart;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.block.IConductor;
|
||||
import net.minecraftforge.liquids.ILiquidTank;
|
||||
import universalelectricity.prefab.block.BlockAdvanced;
|
||||
import fluidmech.common.FluidMech;
|
||||
import fluidmech.common.TabFluidMech;
|
||||
|
@ -64,7 +65,6 @@ public class BlockPipe extends BlockAdvanced
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World world, int x, int y, int z, int blockID)
|
||||
{
|
||||
|
@ -75,7 +75,7 @@ public class BlockPipe extends BlockAdvanced
|
|||
((IFluidNetworkPart) tileEntity).updateAdjacentConnections();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World var1)
|
||||
{
|
||||
|
@ -97,4 +97,26 @@ public class BlockPipe extends BlockAdvanced
|
|||
par3List.add(new ItemStack(par1, 1, i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, int par5, int par6)
|
||||
{
|
||||
super.breakBlock(world, x, y, z, par5, par6);
|
||||
TileEntity entity = world.getBlockTileEntity(x, y, z);
|
||||
if (entity instanceof TileEntityPipe)
|
||||
{
|
||||
ILiquidTank tank = ((TileEntityPipe) entity).getTank();
|
||||
if (tank != null && tank.getLiquid() != null && tank.getLiquid().amount > 0)
|
||||
{
|
||||
if (tank.getLiquid().itemID == Block.waterStill.blockID)
|
||||
{
|
||||
world.setBlockAndMetadataWithNotify(x, y, z, Block.waterStill.blockID, 7, 3);
|
||||
}
|
||||
if (tank.getLiquid().itemID == Block.lavaStill.blockID)
|
||||
{
|
||||
world.setBlockAndMetadataWithNotify(x, y, z, Block.lavaStill.blockID, 4, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
|
|||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.writeToNBT(nbt);
|
||||
LiquidStack stack = this.getNetwork().drainVolumeFromSystem(this.getNetwork().getVolumePerPart(), true);
|
||||
LiquidStack stack = this.fakeTank.getLiquid();
|
||||
if (stack != null)
|
||||
{
|
||||
nbt.setTag("stored", stack.writeToNBT(new NBTTagCompound()));
|
||||
|
@ -268,12 +268,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
|
|||
{
|
||||
|
||||
if (this.worldObj != null && !this.worldObj.isRemote)
|
||||
{
|
||||
if (this.fakeTank.getLiquid() != null && this.fakeTank.getLiquid().amount > 0)
|
||||
{
|
||||
int fill = this.getNetwork().addFluidToNetwork(this, this.fakeTank.getLiquid(), 0, true);
|
||||
this.fakeTank.drain(fill, true);
|
||||
}
|
||||
{
|
||||
|
||||
boolean[] previousConnections = this.renderConnection.clone();
|
||||
this.connectedBlocks = new TileEntity[6];
|
||||
|
@ -380,4 +375,17 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
|
|||
return LiquidContainerRegistry.BUCKET_VOLUME * 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILiquidTank getTank()
|
||||
{
|
||||
return this.fakeTank;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTankContent(LiquidStack stack)
|
||||
{
|
||||
this.fakeTank.setLiquid(stack);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,8 +4,10 @@ import universalelectricity.core.block.IConnectionProvider;
|
|||
import hydraulic.core.liquidNetwork.HydraulicNetwork;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.liquids.ILiquidTank;
|
||||
import net.minecraftforge.liquids.ITankContainer;
|
||||
import net.minecraftforge.liquids.LiquidStack;
|
||||
import net.minecraftforge.liquids.LiquidTank;
|
||||
|
||||
/**
|
||||
* A machine that acts as one with the liquid network using the networks pressure for some function
|
||||
|
@ -46,5 +48,9 @@ public interface IFluidNetworkPart extends IPipeConnection, IColorCoded, IConnec
|
|||
* size of the pipes liquid storage ability
|
||||
*/
|
||||
public int getTankSize();
|
||||
|
||||
public ILiquidTank getTank();
|
||||
|
||||
public void setTankContent(LiquidStack stack);
|
||||
|
||||
}
|
||||
|
|
|
@ -326,6 +326,7 @@ public class HydraulicNetwork
|
|||
{
|
||||
used = this.combinedStorage.fill(stack, doFill);
|
||||
System.out.println("Network Target filled for " + used);
|
||||
this.moveAndSumVolume(false);
|
||||
filledMain = true;
|
||||
}
|
||||
/* IF THE COMBINED STORAGE OF THE PIPES HAS LIQUID MOVE IT FIRST */
|
||||
|
@ -344,6 +345,7 @@ public class HydraulicNetwork
|
|||
used = Math.min(used, Math.max(used - this.combinedStorage.getLiquid().amount, 0));
|
||||
drainStack = this.combinedStorage.drain(pUsed - used, doFill);
|
||||
}
|
||||
this.moveAndSumVolume(false);
|
||||
System.out.println("Pulling " + stack.amount + " from combined");
|
||||
}
|
||||
}
|
||||
|
@ -439,7 +441,7 @@ public class HydraulicNetwork
|
|||
else
|
||||
{
|
||||
conductor.setNetwork(this);
|
||||
capacity += conductor.getTankSize();
|
||||
capacity += LiquidContainerRegistry.BUCKET_VOLUME;
|
||||
}
|
||||
}
|
||||
this.combinedStorage.setCapacity(capacity);
|
||||
|
@ -484,6 +486,8 @@ public class HydraulicNetwork
|
|||
}
|
||||
else
|
||||
{
|
||||
this.moveAndSumVolume(false);
|
||||
network.moveAndSumVolume(false);
|
||||
LiquidStack stack = new LiquidStack(0, 0, 0);
|
||||
if (this.combinedStorage.getLiquid() != null && network.combinedStorage.getLiquid() != null && this.combinedStorage.getLiquid().isLiquidEqual(network.combinedStorage.getLiquid()))
|
||||
{
|
||||
|
@ -504,7 +508,7 @@ public class HydraulicNetwork
|
|||
newNetwork.getFluidNetworkParts().addAll(network.getFluidNetworkParts());
|
||||
|
||||
newNetwork.cleanUpConductors();
|
||||
newNetwork.combinedStorage.setLiquid(stack);
|
||||
newNetwork.moveAndSumVolume(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -520,7 +524,7 @@ public class HydraulicNetwork
|
|||
if (splitPoint instanceof TileEntity)
|
||||
{
|
||||
this.getFluidNetworkParts().remove(splitPoint);
|
||||
|
||||
this.moveAndSumVolume(false);
|
||||
/**
|
||||
* Loop through the connected blocks and attempt to see if there are connections between
|
||||
* the two points elsewhere.
|
||||
|
@ -574,12 +578,7 @@ public class HydraulicNetwork
|
|||
}
|
||||
|
||||
newNetwork.cleanUpConductors();
|
||||
|
||||
LiquidStack stack = this.combinedStorage.getLiquid();
|
||||
if (stack != null)
|
||||
{
|
||||
newNetwork.combinedStorage.setLiquid(new LiquidStack(stack.itemID, parts * this.getVolumePerPart(), stack.itemMeta));
|
||||
}
|
||||
newNetwork.moveAndSumVolume(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -589,35 +588,45 @@ public class HydraulicNetwork
|
|||
}
|
||||
|
||||
/**
|
||||
* gets the amount of liquid stored in each part in the system
|
||||
* Moves the volume stored in the network to the parts or sums up the volume from the parts and
|
||||
* loads it to the network. Assumes that all liquidStacks stored are equal
|
||||
*
|
||||
* @param load - loads the volume from the parts before leveling out the volumes
|
||||
*/
|
||||
public int getVolumePerPart()
|
||||
public void moveAndSumVolume(boolean load)
|
||||
{
|
||||
int volumePerPart = 0;
|
||||
int cap = 0;
|
||||
LiquidStack stack = this.combinedStorage.getLiquid();
|
||||
if (stack != null)
|
||||
int volume = 0;
|
||||
int itemID = 0;
|
||||
int itemMeta = 0;
|
||||
if (load)
|
||||
{
|
||||
for (IFluidNetworkPart par : this.fluidParts)
|
||||
for (IFluidNetworkPart part : this.fluidParts)
|
||||
{
|
||||
cap += par.getTankSize();
|
||||
}
|
||||
volumePerPart = this.combinedStorage.getLiquid().amount / cap;
|
||||
}
|
||||
return volumePerPart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drain a set volume from the system
|
||||
*/
|
||||
public LiquidStack drainVolumeFromSystem(int volume, boolean doDrain)
|
||||
{
|
||||
LiquidStack stack = null;
|
||||
if (part.getTank() != null && part.getTank().getLiquid() != null)
|
||||
{
|
||||
if (itemID == 0)
|
||||
{
|
||||
itemID = part.getTank().getLiquid().itemID;
|
||||
itemMeta = part.getTank().getLiquid().itemMeta;
|
||||
}
|
||||
volume += part.getTank().getLiquid().amount;
|
||||
}
|
||||
}
|
||||
this.combinedStorage.setLiquid(new LiquidStack(itemID, volume, itemMeta));
|
||||
}
|
||||
if (this.combinedStorage.getLiquid() != null)
|
||||
{
|
||||
stack = this.combinedStorage.drain(this.getVolumePerPart(), doDrain);
|
||||
volume = this.combinedStorage.getLiquid().amount / this.fluidParts.size();
|
||||
itemID = this.combinedStorage.getLiquid().itemID;
|
||||
itemMeta = this.combinedStorage.getLiquid().itemMeta;
|
||||
|
||||
for (IFluidNetworkPart part : this.fluidParts)
|
||||
{
|
||||
part.setTankContent(null);
|
||||
part.setTankContent(new LiquidStack(itemID, volume, itemMeta));
|
||||
}
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue