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;
|
||||||
|
@ -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;
|
||||||
|
|
||||||
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 lowestY = 255;
|
||||||
int highestY = 0;
|
int highestY = 0;
|
||||||
|
|
||||||
|
this.cleanUpMembers();
|
||||||
|
|
||||||
|
if (this.combinedStorage().getFluid() != null && this.getNetworkMemebers().size() > 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!parts.isEmpty())
|
||||||
|
{
|
||||||
|
/* 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());
|
int fillvolume = Math.abs(volume / parts.size());
|
||||||
|
|
||||||
|
/* Fill all tanks on this level */
|
||||||
for (INetworkFluidPart part : parts)
|
for (INetworkFluidPart part : parts)
|
||||||
{
|
{
|
||||||
part.setTankContent(null);
|
|
||||||
int fill = Math.min(fillvolume, part.getTank().getCapacity());
|
int fill = Math.min(fillvolume, part.getTank().getCapacity());
|
||||||
part.setTankContent(new FluidStack(fluid, fill, tag));
|
part.setTankContent(new FluidStack(fluid, fill, tag));
|
||||||
volume -= fill;
|
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,18 +126,35 @@ 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 */
|
if (this.combinedStorage().getFluid() != null && this.networkMember.size() > 0)
|
||||||
public void balanceColletiveTank(boolean sumParts)
|
{
|
||||||
|
//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)
|
||||||
|
{
|
||||||
|
if (par instanceof INetworkFluidPart)
|
||||||
|
{
|
||||||
|
INetworkFluidPart part = ((INetworkFluidPart) par);
|
||||||
|
part.setTankContent(null);
|
||||||
|
part.setTankContent(new FluidStack(fluid, volume, tag));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readDataFromTiles()
|
||||||
{
|
{
|
||||||
int fluid = -1;
|
int fluid = -1;
|
||||||
NBTTagCompound tag = new NBTTagCompound();
|
NBTTagCompound tag = new NBTTagCompound();
|
||||||
int volume = 0;
|
int volume = 0;
|
||||||
|
//TODO change this to map out all the liquids too do a merge conflict or reject fluids
|
||||||
if (sumParts)
|
|
||||||
{
|
|
||||||
for (INetworkPart par : this.networkMember)
|
for (INetworkPart par : this.networkMember)
|
||||||
{
|
{
|
||||||
if (par instanceof INetworkFluidPart)
|
if (par instanceof INetworkFluidPart)
|
||||||
|
@ -165,24 +182,6 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
||||||
this.loadedLiquids = true;
|
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;
|
|
||||||
|
|
||||||
for (INetworkPart par : this.networkMember)
|
|
||||||
{
|
|
||||||
if (par instanceof INetworkFluidPart)
|
|
||||||
{
|
|
||||||
INetworkFluidPart part = ((INetworkFluidPart) par);
|
|
||||||
part.setTankContent(null);
|
|
||||||
part.setTankContent(new FluidStack(fluid, volume, tag));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@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;
|
||||||
|
|
|
@ -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