Improved fluid tile read/write methods

This commit is contained in:
DarkGuardsman 2013-09-12 21:20:00 -04:00
parent 5cc4b5f851
commit 4017098901

View file

@ -129,21 +129,25 @@ public class NetworkFluidTiles extends NetworkTileEntities
@Override @Override
public void writeDataToTiles() public void writeDataToTiles()
{ {
super.writeDataToTiles();
if (this.combinedStorage().getFluid() != null && this.networkMember.size() > 0) if (this.combinedStorage().getFluid() != null && this.networkMember.size() > 0)
{ {
//TODO change this to percent based system so tiles get volume that they can store FluidStack stack = this.combinedStorage().getFluid().copy();
int vol = this.combinedStorage().getFluid().amount / this.networkMember.size(); int membersFilled = 0;
int fluid = this.combinedStorage().getFluid().fluidID;
NBTTagCompound tag = this.combinedStorage().getFluid().tag;
for (INetworkPart par : this.networkMember) for (INetworkPart par : this.networkMember)
{ {
int fillVol = this.combinedStorage().getFluid().amount / this.networkMember.size(); //UPDATE FILL VOLUME
int fillVol = stack.amount / (this.networkMember.size() - membersFilled);
if (par instanceof INetworkFluidPart) if (par instanceof INetworkFluidPart)
{ {
INetworkFluidPart part = ((INetworkFluidPart) par); //EMPTY TANK
part.drainTankContent(0, fillVol, true); ((INetworkFluidPart) par).drainTankContent(0, fillVol, true);
vol -= part.fillTankContent(0, new FluidStack(fluid, fillVol, tag), true);
//FILL TANK
stack.amount -= ((INetworkFluidPart) par).fillTankContent(0, FluidHelper.getStack(stack, fillVol), true);
membersFilled++;
} }
} }
} }
@ -152,29 +156,30 @@ public class NetworkFluidTiles extends NetworkTileEntities
@Override @Override
public void readDataFromTiles() public void readDataFromTiles()
{ {
int fluid = -1; super.readDataFromTiles();
NBTTagCompound tag = new NBTTagCompound();
int volume = 0; FluidStack stack = null;
//TODO change this to map out all the liquids too do a merge conflict or reject fluids
for (INetworkPart par : this.networkMember) for (INetworkPart par : this.networkMember)
{ {
if (par instanceof INetworkFluidPart) if (par instanceof INetworkFluidPart)
{ {
INetworkFluidPart part = ((INetworkFluidPart) par); if (((INetworkFluidPart) par).getTank(0) != null && ((INetworkFluidPart) par).getTank(0).getFluid() != null)
if (part.getTank(0) != null && part.getTank(0).getFluid() != null)
{ {
if (fluid == -1) if (stack == null)
{ {
fluid = part.getTank(0).getFluid().fluidID; stack = ((INetworkFluidPart) par).getTank(0).getFluid();
tag = part.getTank(0).getFluid().tag; }
else
{
stack.amount += ((INetworkFluidPart) par).getTank(0).getFluid().amount;
} }
volume += part.getTank(0).getFluid().amount;
} }
} }
} }
if (fluid != -1) if (stack != null && stack.amount > 0)
{ {
this.combinedStorage().setFluid(new FluidStack(fluid, volume, tag)); this.combinedStorage().setFluid(stack);
} }
else else
{ {