swapped Balance Tank method for read/write tiles method

Honestly shouldn't act to different from how its was seeing as nothing
really changed. Only thing that happened was that the load and write
part of BalanceCollectiveTank was split into two different methods. Will
need some testing though to check if everything works.

Also for NetworkFluidContainers its balance method was changed a bit to
maybe fix errors with fluid remaining in the tank that shouldn't have
fluid in them. Render will still need to be changed to fix this a little
better.
This commit is contained in:
DarkGuardsman 2013-07-29 03:55:26 -04:00
parent a053839398
commit 519fcb62c3
3 changed files with 85 additions and 103 deletions

View file

@ -6,6 +6,7 @@ import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
import dark.api.ColorCode;
import dark.api.INetworkPart;
import dark.api.fluid.INetworkFluidPart;
@ -14,7 +15,7 @@ import dark.core.tile.network.NetworkTileEntities;
/** Side note: the network should act like this when done {@link http
* ://www.e4training.com/hydraulic_calculators/B1.htm} as well as stay compatible with the forge
* Liquids
*
*
* @author Rseifert */
public class NetworkFluidContainers extends NetworkFluidTiles
{
@ -31,49 +32,25 @@ public class NetworkFluidContainers extends NetworkFluidTiles
}
@Override
public void balanceColletiveTank(boolean sumParts)
public void writeDataToTiles()
{
int volume = 0;
int fluid = -1;
NBTTagCompound tag = new NBTTagCompound();
int fluid = this.combinedStorage().getFluid().fluidID;
int volume = Math.abs(this.combinedStorage().getFluid().amount);
NBTTagCompound tag = this.combinedStorage().getFluid().tag;
int lowestY = 255;
int highestY = 0;
this.cleanUpMembers();
if (sumParts)
{
for (INetworkPart par : this.networkMember)
{
if (par instanceof INetworkFluidPart)
{
INetworkFluidPart part = ((INetworkFluidPart) par);
if (part.getTank() != null && part.getTank().getFluid() != null)
{
FluidStack fluidStack = part.getTank().getFluid();
fluid = fluidStack.fluidID;
volume += fluidStack.amount;
if (fluidStack.tag != null && !fluidStack.tag.hasNoTags() && tag.hasNoTags())
{
tag = fluidStack.tag;
}
}
}
}
if (fluid != -1)
{
this.combinedStorage().setFluid(new FluidStack(fluid, volume));
}
else
{
this.combinedStorage().setFluid(null);
}
this.loadedLiquids = true;
}
if (this.combinedStorage().getFluid() != null && this.getNetworkMemebers().size() > 0)
{
this.cleanUpMembers();
int lowestY = 255;
int highestY = 0;
for (INetworkPart part : this.getNetworkMemebers())
{
if (part instanceof IFluidHandler)
{
((INetworkFluidPart) part).setTankContent(null);
}
if (part instanceof TileEntity && ((TileEntity) part).yCoord < lowestY)
{
lowestY = ((TileEntity) part).yCoord;
@ -83,13 +60,14 @@ public class NetworkFluidContainers extends NetworkFluidTiles
highestY = ((TileEntity) part).yCoord;
}
}
fluid = this.combinedStorage().getFluid().fluidID;
volume = Math.abs(this.combinedStorage().getFluid().amount);
tag = this.combinedStorage().getFluid().tag;
//TODO change this to use hydraulics to not only place fluid at the lowest but as well not move it to another side if there is no path there threw fluid
for (int y = lowestY; y <= highestY; y++)
{
/** List of parts for this Y level */
List<INetworkFluidPart> parts = new ArrayList<INetworkFluidPart>();
/* Grab all parts that share this Y level*/
for (INetworkPart part : this.getNetworkMemebers())
{
if (part instanceof INetworkFluidPart && ((TileEntity) part).yCoord == y)
@ -97,15 +75,20 @@ public class NetworkFluidContainers extends NetworkFluidTiles
parts.add((INetworkFluidPart) part);
}
}
int fillvolume = Math.abs(volume / parts.size());
for (INetworkFluidPart part : parts)
if (!parts.isEmpty())
{
part.setTankContent(null);
int fill = Math.min(fillvolume, part.getTank().getCapacity());
part.setTankContent(new FluidStack(fluid, fill, tag));
volume -= fill;
/* Div out the volume for this level. TODO change this to use a percent system for even filling */
int fillvolume = Math.abs(volume / parts.size());
/* Fill all tanks on this level */
for (INetworkFluidPart part : parts)
{
int fill = Math.min(fillvolume, part.getTank().getCapacity());
part.setTankContent(new FluidStack(fluid, fill, tag));
volume -= fill;
}
}
if (volume <= 0)
{
break;

View file

@ -65,7 +65,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
if (this.sharedTank == null)
{
this.sharedTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
this.balanceColletiveTank(true);
this.readDataFromTiles();
}
return this.sharedTank;
}
@ -79,14 +79,14 @@ public class NetworkFluidTiles extends NetworkTileEntities
}
if (!loadedLiquids)
{
this.balanceColletiveTank(true);
this.readDataFromTiles();
}
if (this.combinedStorage().getFluid() == null || this.combinedStorage().getFluid().amount < this.combinedStorage().getCapacity())
{
int filled = this.combinedStorage().fill(stack, doFill);
if (doFill)
{
this.balanceColletiveTank(false);
this.writeDataToTiles();
}
return filled;
}
@ -98,7 +98,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
{
if (!loadedLiquids)
{
this.balanceColletiveTank(true);
this.readDataFromTiles();
}
FluidStack stack = this.combinedStorage().getFluid();
if (stack != null)
@ -111,7 +111,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
stack = this.combinedStorage().drain(maxDrain, doDrain);
if (doDrain)
{
this.balanceColletiveTank(false);
this.writeDataToTiles();
}
}
return stack;
@ -126,50 +126,15 @@ public class NetworkFluidTiles extends NetworkTileEntities
return null;
}
/** 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 sumParts - loads the volume from the parts before leveling out the volumes */
public void balanceColletiveTank(boolean sumParts)
@Override
public void writeDataToTiles()
{
int fluid = -1;
NBTTagCompound tag = new NBTTagCompound();
int volume = 0;
if (sumParts)
{
for (INetworkPart par : this.networkMember)
{
if (par instanceof INetworkFluidPart)
{
INetworkFluidPart part = ((INetworkFluidPart) par);
if (part.getTank() != null && part.getTank().getFluid() != null)
{
if (fluid == -1)
{
fluid = part.getTank().getFluid().fluidID;
tag = part.getTank().getFluid().tag;
}
volume += part.getTank().getFluid().amount;
}
}
}
if (fluid != -1)
{
this.combinedStorage().setFluid(new FluidStack(fluid, volume, tag));
}
else
{
this.combinedStorage().setFluid(null);
}
this.loadedLiquids = true;
}
if (this.combinedStorage().getFluid() != null && this.networkMember.size() > 0)
{
volume = this.combinedStorage().getFluid().amount / this.networkMember.size();
fluid = this.combinedStorage().getFluid().fluidID;
tag = this.combinedStorage().getFluid().tag;
//TODO change this to percent based system so tiles get volume that they can store
int volume = this.combinedStorage().getFluid().amount / this.networkMember.size();
int fluid = this.combinedStorage().getFluid().fluidID;
NBTTagCompound tag = this.combinedStorage().getFluid().tag;
for (INetworkPart par : this.networkMember)
{
@ -183,6 +148,40 @@ public class NetworkFluidTiles extends NetworkTileEntities
}
}
@Override
public void readDataFromTiles()
{
int fluid = -1;
NBTTagCompound tag = new NBTTagCompound();
int volume = 0;
//TODO change this to map out all the liquids too do a merge conflict or reject fluids
for (INetworkPart par : this.networkMember)
{
if (par instanceof INetworkFluidPart)
{
INetworkFluidPart part = ((INetworkFluidPart) par);
if (part.getTank() != null && part.getTank().getFluid() != null)
{
if (fluid == -1)
{
fluid = part.getTank().getFluid().fluidID;
tag = part.getTank().getFluid().tag;
}
volume += part.getTank().getFluid().amount;
}
}
}
if (fluid != -1)
{
this.combinedStorage().setFluid(new FluidStack(fluid, volume, tag));
}
else
{
this.combinedStorage().setFluid(null);
}
this.loadedLiquids = true;
}
@Override
public boolean removeTile(TileEntity ent)
{
@ -340,7 +339,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
public void init()
{
super.init();
this.balanceColletiveTank(true);
this.readDataFromTiles();
}
@Override
@ -350,8 +349,8 @@ public class NetworkFluidTiles extends NetworkTileEntities
{
NetworkFluidTiles network = (NetworkFluidTiles) mergingNetwork;
this.balanceColletiveTank(true);
network.balanceColletiveTank(true);
this.readDataFromTiles();
network.readDataFromTiles();
Object result = this.canMergeFluids(this.combinedStorage().getFluid(), network.combinedStorage().getFluid());
if (mergePoint instanceof TileEntity)
{
@ -438,7 +437,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
newNetwork.cleanUpMembers();
newNetwork.combinedStorage().setFluid(mergeFluids(one, two));
newNetwork.balanceColletiveTank(false);
newNetwork.writeDataToTiles();
}
@Override
@ -446,7 +445,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
{
if (!loadedLiquids)
{
this.balanceColletiveTank(true);
this.readDataFromTiles();
}
Iterator<INetworkPart> it = this.networkMember.iterator();
int capacity = 0;

View file

@ -20,7 +20,7 @@ import dark.core.tile.network.NetworkTileEntities;
/** Side note: the network should act like this when done {@link http
* ://www.e4training.com/hydraulic_calculators/B1.htm} as well as stay compatible with the forge
* Liquids
*
*
* @author Rseifert */
public class NetworkPipes extends NetworkFluidTiles
{
@ -164,7 +164,7 @@ public class NetworkPipes extends NetworkFluidTiles
}
/** Adds FLuid to this network from one of the connected Pipes
*
*
* @param source - Were this liquid came from
* @param stack - LiquidStack to be sent
* @param doFill - actually fill the tank or just check numbers
@ -175,7 +175,7 @@ public class NetworkPipes extends NetworkFluidTiles
}
/** Adds FLuid to this network from one of the connected Pipes
*
*
* @param source - Were this liquid came from
* @param stack - LiquidStack to be sent
* @param doFill - actually fill the tank or just check numbers
@ -304,7 +304,7 @@ public class NetworkPipes extends NetworkFluidTiles
}
if (prevCombined != null && this.combinedStorage().getFluid() != null && prevCombined.amount != this.combinedStorage().getFluid().amount)
{
this.balanceColletiveTank(false);
this.writeDataToTiles();
}
}
this.processingRequest = false;