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:
parent
a053839398
commit
519fcb62c3
3 changed files with 85 additions and 103 deletions
|
@ -6,6 +6,7 @@ import java.util.List;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
import net.minecraftforge.fluids.IFluidHandler;
|
||||||
import dark.api.ColorCode;
|
import dark.api.ColorCode;
|
||||||
import dark.api.INetworkPart;
|
import dark.api.INetworkPart;
|
||||||
import dark.api.fluid.INetworkFluidPart;
|
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
|
/** 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
|
* ://www.e4training.com/hydraulic_calculators/B1.htm} as well as stay compatible with the forge
|
||||||
* Liquids
|
* Liquids
|
||||||
*
|
*
|
||||||
* @author Rseifert */
|
* @author Rseifert */
|
||||||
public class NetworkFluidContainers extends NetworkFluidTiles
|
public class NetworkFluidContainers extends NetworkFluidTiles
|
||||||
{
|
{
|
||||||
|
@ -31,49 +32,25 @@ public class NetworkFluidContainers extends NetworkFluidTiles
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void balanceColletiveTank(boolean sumParts)
|
public void writeDataToTiles()
|
||||||
{
|
{
|
||||||
int volume = 0;
|
int fluid = this.combinedStorage().getFluid().fluidID;
|
||||||
int fluid = -1;
|
int volume = Math.abs(this.combinedStorage().getFluid().amount);
|
||||||
NBTTagCompound tag = new NBTTagCompound();
|
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)
|
if (this.combinedStorage().getFluid() != null && this.getNetworkMemebers().size() > 0)
|
||||||
{
|
{
|
||||||
this.cleanUpMembers();
|
|
||||||
|
|
||||||
int lowestY = 255;
|
|
||||||
int highestY = 0;
|
|
||||||
for (INetworkPart part : this.getNetworkMemebers())
|
for (INetworkPart part : this.getNetworkMemebers())
|
||||||
{
|
{
|
||||||
|
if (part instanceof IFluidHandler)
|
||||||
|
{
|
||||||
|
((INetworkFluidPart) part).setTankContent(null);
|
||||||
|
}
|
||||||
if (part instanceof TileEntity && ((TileEntity) part).yCoord < lowestY)
|
if (part instanceof TileEntity && ((TileEntity) part).yCoord < lowestY)
|
||||||
{
|
{
|
||||||
lowestY = ((TileEntity) part).yCoord;
|
lowestY = ((TileEntity) part).yCoord;
|
||||||
|
@ -83,13 +60,14 @@ public class NetworkFluidContainers extends NetworkFluidTiles
|
||||||
highestY = ((TileEntity) part).yCoord;
|
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
|
//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++)
|
for (int y = lowestY; y <= highestY; y++)
|
||||||
{
|
{
|
||||||
|
/** List of parts for this Y level */
|
||||||
List<INetworkFluidPart> parts = new ArrayList<INetworkFluidPart>();
|
List<INetworkFluidPart> parts = new ArrayList<INetworkFluidPart>();
|
||||||
|
|
||||||
|
/* Grab all parts that share this Y level*/
|
||||||
for (INetworkPart part : this.getNetworkMemebers())
|
for (INetworkPart part : this.getNetworkMemebers())
|
||||||
{
|
{
|
||||||
if (part instanceof INetworkFluidPart && ((TileEntity) part).yCoord == y)
|
if (part instanceof INetworkFluidPart && ((TileEntity) part).yCoord == y)
|
||||||
|
@ -97,15 +75,20 @@ public class NetworkFluidContainers extends NetworkFluidTiles
|
||||||
parts.add((INetworkFluidPart) part);
|
parts.add((INetworkFluidPart) part);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int fillvolume = Math.abs(volume / parts.size());
|
if (!parts.isEmpty())
|
||||||
|
|
||||||
for (INetworkFluidPart part : parts)
|
|
||||||
{
|
{
|
||||||
part.setTankContent(null);
|
/* Div out the volume for this level. TODO change this to use a percent system for even filling */
|
||||||
int fill = Math.min(fillvolume, part.getTank().getCapacity());
|
int fillvolume = Math.abs(volume / parts.size());
|
||||||
part.setTankContent(new FluidStack(fluid, fill, tag));
|
|
||||||
volume -= fill;
|
/* 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)
|
if (volume <= 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
||||||
if (this.sharedTank == null)
|
if (this.sharedTank == null)
|
||||||
{
|
{
|
||||||
this.sharedTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
|
this.sharedTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
|
||||||
this.balanceColletiveTank(true);
|
this.readDataFromTiles();
|
||||||
}
|
}
|
||||||
return this.sharedTank;
|
return this.sharedTank;
|
||||||
}
|
}
|
||||||
|
@ -79,14 +79,14 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
||||||
}
|
}
|
||||||
if (!loadedLiquids)
|
if (!loadedLiquids)
|
||||||
{
|
{
|
||||||
this.balanceColletiveTank(true);
|
this.readDataFromTiles();
|
||||||
}
|
}
|
||||||
if (this.combinedStorage().getFluid() == null || this.combinedStorage().getFluid().amount < this.combinedStorage().getCapacity())
|
if (this.combinedStorage().getFluid() == null || this.combinedStorage().getFluid().amount < this.combinedStorage().getCapacity())
|
||||||
{
|
{
|
||||||
int filled = this.combinedStorage().fill(stack, doFill);
|
int filled = this.combinedStorage().fill(stack, doFill);
|
||||||
if (doFill)
|
if (doFill)
|
||||||
{
|
{
|
||||||
this.balanceColletiveTank(false);
|
this.writeDataToTiles();
|
||||||
}
|
}
|
||||||
return filled;
|
return filled;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
||||||
{
|
{
|
||||||
if (!loadedLiquids)
|
if (!loadedLiquids)
|
||||||
{
|
{
|
||||||
this.balanceColletiveTank(true);
|
this.readDataFromTiles();
|
||||||
}
|
}
|
||||||
FluidStack stack = this.combinedStorage().getFluid();
|
FluidStack stack = this.combinedStorage().getFluid();
|
||||||
if (stack != null)
|
if (stack != null)
|
||||||
|
@ -111,7 +111,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
||||||
stack = this.combinedStorage().drain(maxDrain, doDrain);
|
stack = this.combinedStorage().drain(maxDrain, doDrain);
|
||||||
if (doDrain)
|
if (doDrain)
|
||||||
{
|
{
|
||||||
this.balanceColletiveTank(false);
|
this.writeDataToTiles();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return stack;
|
return stack;
|
||||||
|
@ -126,50 +126,15 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Moves the volume stored in the network to the parts or sums up the volume from the parts and
|
@Override
|
||||||
* loads it to the network. Assumes that all liquidStacks stored are equal
|
public void writeDataToTiles()
|
||||||
*
|
|
||||||
* @param sumParts - loads the volume from the parts before leveling out the volumes */
|
|
||||||
public void balanceColletiveTank(boolean sumParts)
|
|
||||||
{
|
{
|
||||||
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)
|
if (this.combinedStorage().getFluid() != null && this.networkMember.size() > 0)
|
||||||
{
|
{
|
||||||
volume = this.combinedStorage().getFluid().amount / this.networkMember.size();
|
//TODO change this to percent based system so tiles get volume that they can store
|
||||||
fluid = this.combinedStorage().getFluid().fluidID;
|
int volume = this.combinedStorage().getFluid().amount / this.networkMember.size();
|
||||||
tag = this.combinedStorage().getFluid().tag;
|
int fluid = this.combinedStorage().getFluid().fluidID;
|
||||||
|
NBTTagCompound tag = this.combinedStorage().getFluid().tag;
|
||||||
|
|
||||||
for (INetworkPart par : this.networkMember)
|
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
|
@Override
|
||||||
public boolean removeTile(TileEntity ent)
|
public boolean removeTile(TileEntity ent)
|
||||||
{
|
{
|
||||||
|
@ -340,7 +339,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
||||||
public void init()
|
public void init()
|
||||||
{
|
{
|
||||||
super.init();
|
super.init();
|
||||||
this.balanceColletiveTank(true);
|
this.readDataFromTiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -350,8 +349,8 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
||||||
{
|
{
|
||||||
NetworkFluidTiles network = (NetworkFluidTiles) mergingNetwork;
|
NetworkFluidTiles network = (NetworkFluidTiles) mergingNetwork;
|
||||||
|
|
||||||
this.balanceColletiveTank(true);
|
this.readDataFromTiles();
|
||||||
network.balanceColletiveTank(true);
|
network.readDataFromTiles();
|
||||||
Object result = this.canMergeFluids(this.combinedStorage().getFluid(), network.combinedStorage().getFluid());
|
Object result = this.canMergeFluids(this.combinedStorage().getFluid(), network.combinedStorage().getFluid());
|
||||||
if (mergePoint instanceof TileEntity)
|
if (mergePoint instanceof TileEntity)
|
||||||
{
|
{
|
||||||
|
@ -438,7 +437,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
||||||
|
|
||||||
newNetwork.cleanUpMembers();
|
newNetwork.cleanUpMembers();
|
||||||
newNetwork.combinedStorage().setFluid(mergeFluids(one, two));
|
newNetwork.combinedStorage().setFluid(mergeFluids(one, two));
|
||||||
newNetwork.balanceColletiveTank(false);
|
newNetwork.writeDataToTiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -446,7 +445,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
||||||
{
|
{
|
||||||
if (!loadedLiquids)
|
if (!loadedLiquids)
|
||||||
{
|
{
|
||||||
this.balanceColletiveTank(true);
|
this.readDataFromTiles();
|
||||||
}
|
}
|
||||||
Iterator<INetworkPart> it = this.networkMember.iterator();
|
Iterator<INetworkPart> it = this.networkMember.iterator();
|
||||||
int capacity = 0;
|
int capacity = 0;
|
||||||
|
|
|
@ -20,7 +20,7 @@ import dark.core.tile.network.NetworkTileEntities;
|
||||||
/** Side note: the network should act like this when done {@link http
|
/** 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
|
* ://www.e4training.com/hydraulic_calculators/B1.htm} as well as stay compatible with the forge
|
||||||
* Liquids
|
* Liquids
|
||||||
*
|
*
|
||||||
* @author Rseifert */
|
* @author Rseifert */
|
||||||
public class NetworkPipes extends NetworkFluidTiles
|
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
|
/** Adds FLuid to this network from one of the connected Pipes
|
||||||
*
|
*
|
||||||
* @param source - Were this liquid came from
|
* @param source - Were this liquid came from
|
||||||
* @param stack - LiquidStack to be sent
|
* @param stack - LiquidStack to be sent
|
||||||
* @param doFill - actually fill the tank or just check numbers
|
* @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
|
/** Adds FLuid to this network from one of the connected Pipes
|
||||||
*
|
*
|
||||||
* @param source - Were this liquid came from
|
* @param source - Were this liquid came from
|
||||||
* @param stack - LiquidStack to be sent
|
* @param stack - LiquidStack to be sent
|
||||||
* @param doFill - actually fill the tank or just check numbers
|
* @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)
|
if (prevCombined != null && this.combinedStorage().getFluid() != null && prevCombined.amount != this.combinedStorage().getFluid().amount)
|
||||||
{
|
{
|
||||||
this.balanceColletiveTank(false);
|
this.writeDataToTiles();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.processingRequest = false;
|
this.processingRequest = false;
|
||||||
|
|
Loading…
Reference in a new issue