Added autoDrain && Fixed network saving
Pipes on each connection update should try to drain liquid from there connected sources. I'll improve this later to limit the network from getting surged all at once. Also fixed, i think, the network saving its stored liquid to all connected parts that can stored liquid. There still might be a bit of a lose but i'll fix that later
This commit is contained in:
parent
7488a448f0
commit
5a2034015a
4 changed files with 47 additions and 18 deletions
|
@ -73,7 +73,7 @@ public class TileEntityReleaseValve extends TileEntityAdvanced implements IPipeC
|
|||
if (inputPipe != null)
|
||||
{
|
||||
ILiquidTank pipeVolume = inputPipe.getTanks(ForgeDirection.UNKNOWN)[0];
|
||||
int ammountFilled = inputPipe.getNetwork().addFluidToNetwork(stack, 100, true);
|
||||
int ammountFilled = inputPipe.getNetwork().addFluidToNetwork(this,stack, 100, true);
|
||||
drainedTank.drain(ForgeDirection.UNKNOWN, ammountFilled, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -208,6 +208,10 @@ public class TileEntityTank extends TileEntityAdvanced implements IPacketReceive
|
|||
@Override
|
||||
public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
|
||||
{
|
||||
if(from == ForgeDirection.UP || from == ForgeDirection.DOWN)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return this.drain(0, maxDrain, doDrain);
|
||||
}
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
|
|||
liquid.readFromNBT(nbt.getCompoundTag("stored"));
|
||||
if (Item.itemsList[liquid.itemID] != null && liquid.amount > 0)
|
||||
{
|
||||
this.getNetwork().addFluidToNetwork(liquid, 0, true);
|
||||
this.fakeTank.setLiquid(liquid);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,7 +180,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
|
|||
{
|
||||
return 0;
|
||||
}
|
||||
return this.fill(0, resource, doFill);
|
||||
return this.getNetwork().addFluidToNetwork(worldObj.getBlockTileEntity(xCoord + from.offsetX, yCoord + from.offsetY, zCoord + from.offsetZ), resource, 0, doFill);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -190,7 +190,7 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
|
|||
{
|
||||
return 0;
|
||||
}
|
||||
return this.getNetwork().addFluidToNetwork(resource, 0, doFill);
|
||||
return this.getNetwork().addFluidToNetwork(this, resource, 0, doFill);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -269,6 +269,12 @@ 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];
|
||||
|
||||
|
@ -278,9 +284,20 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
|
|||
this.validateConnectionSide(this.worldObj.getBlockTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ), dir);
|
||||
|
||||
this.renderConnection[i] = this.connectedBlocks[i] != null;
|
||||
|
||||
if (this.renderConnection[i] && this.connectedBlocks[i] instanceof ITankContainer && !(this.connectedBlocks[i] instanceof IFluidNetworkPart))
|
||||
{
|
||||
this.getNetwork().addEntity((ITankContainer) this.connectedBlocks[i]);
|
||||
ITankContainer tankContainer = (ITankContainer) this.connectedBlocks[i];
|
||||
this.getNetwork().addEntity(tankContainer);
|
||||
|
||||
/* LITTLE TRICK TO AUTO DRAIN TANKS ON EACH CONNECTION UPDATE */
|
||||
|
||||
LiquidStack stack = tankContainer.drain(dir, LiquidContainerRegistry.BUCKET_VOLUME, false);
|
||||
if (stack != null && stack.amount > 0)
|
||||
{
|
||||
int fill = this.getNetwork().addFluidToNetwork((TileEntity) tankContainer, stack, 0, true);
|
||||
tankContainer.drain(dir, fill, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -238,7 +238,7 @@ public class HydraulicNetwork
|
|||
*
|
||||
* @return The amount of Liquid used.
|
||||
*/
|
||||
public int addFluidToNetwork(LiquidStack stack, double pressure, boolean doFill)
|
||||
public int addFluidToNetwork(TileEntity source, LiquidStack stack, double pressure, boolean doFill)
|
||||
{
|
||||
int used = 0;
|
||||
|
||||
|
@ -268,7 +268,7 @@ public class HydraulicNetwork
|
|||
/* FIND THE FILL TARGET FROM THE LIST OF FLUID RECIEVERS */
|
||||
for (ITankContainer tankContainer : fluidTanks)
|
||||
{
|
||||
if (tankContainer instanceof TileEntity)
|
||||
if (tankContainer instanceof TileEntity && tankContainer != source)
|
||||
{
|
||||
TileEntity[] connectedTiles = connectionHelper.getSurroundingTileEntities((TileEntity) tankContainer);
|
||||
|
||||
|
@ -311,37 +311,40 @@ public class HydraulicNetwork
|
|||
break;
|
||||
}
|
||||
}// End of tank finder
|
||||
|
||||
boolean filledMain = false;
|
||||
if (primaryFill != null)
|
||||
{
|
||||
System.out.println("Primary Target");
|
||||
used = primaryFill.fill(fillDir, stack, doFill);
|
||||
}
|
||||
else if (secondayFill != null)
|
||||
{
|
||||
System.out.println("Seconday Target");
|
||||
used = secondayFill.fill(fillDir, stack, doFill);
|
||||
}
|
||||
else if (this.combinedStorage.getLiquid() == null || this.combinedStorage.getLiquid().amount < this.combinedStorage.getCapacity())
|
||||
{
|
||||
used = this.combinedStorage.fill(stack, doFill);
|
||||
System.out.println("Network Target");
|
||||
System.out.println("Network Target filled for " + used);
|
||||
filledMain = true;
|
||||
}
|
||||
/* IF THE COMBINED STORAGE OF THE PIPES HAS LIQUID MOVE IT FIRST */
|
||||
if (this.combinedStorage.getLiquid() != null && this.combinedStorage.getLiquid().amount > 0)
|
||||
if (!filledMain && used > 0 && this.combinedStorage.getLiquid() != null && this.combinedStorage.getLiquid().amount > 0)
|
||||
{
|
||||
System.out.println("Pulling from combined");
|
||||
|
||||
LiquidStack drainStack = new LiquidStack(0, 0, 0);
|
||||
if (this.combinedStorage.getLiquid().amount >= used)
|
||||
{
|
||||
drainStack = this.combinedStorage.drain(used, doFill);
|
||||
used = 0;
|
||||
this.combinedStorage.drain(stack.amount, doFill);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
int pUsed = stack.amount;
|
||||
used = Math.min(used, Math.max(stack.amount - this.combinedStorage.getLiquid().amount, 0));
|
||||
this.combinedStorage.drain(pUsed - used, doFill);
|
||||
int pUsed = used;
|
||||
used = Math.min(used, Math.max(used - this.combinedStorage.getLiquid().amount, 0));
|
||||
drainStack = this.combinedStorage.drain(pUsed - used, doFill);
|
||||
}
|
||||
|
||||
System.out.println("Pulling " + stack.amount + " from combined");
|
||||
}
|
||||
}
|
||||
this.processingRequest = false;
|
||||
|
@ -591,10 +594,15 @@ public class HydraulicNetwork
|
|||
public int getVolumePerPart()
|
||||
{
|
||||
int volumePerPart = 0;
|
||||
int cap = 0;
|
||||
LiquidStack stack = this.combinedStorage.getLiquid();
|
||||
if (stack != null)
|
||||
{
|
||||
volumePerPart = this.combinedStorage.getLiquid().amount / this.fluidParts.size();
|
||||
for (IFluidNetworkPart par : this.fluidParts)
|
||||
{
|
||||
cap += par.getTankSize();
|
||||
}
|
||||
volumePerPart = this.combinedStorage.getLiquid().amount / cap;
|
||||
}
|
||||
return volumePerPart;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue