Fixed tank duping issue

I think it simple came down to i need to clean up the network before
doing anything to the network. As well i think the fluid container
network was not clearing the save stack data when it was empty.
This commit is contained in:
DarkGuardsman 2013-09-13 08:51:57 -04:00
parent c6031ce624
commit 9a10f8be31
4 changed files with 11 additions and 6 deletions

View file

@ -154,10 +154,12 @@ public class FluidCraftingHandler
} }
else if (stackTwo != null && stackOne != null && !stackOne.isFluidEqual(stackTwo)) else if (stackTwo != null && stackOne != null && !stackOne.isFluidEqual(stackTwo))
{ {
System.out.println("preforming fluid merge event");
Object result = fluidMergeResults.get(new Pair<Fluid, Fluid>(stackOne.getFluid(), stackTwo.getFluid())); Object result = fluidMergeResults.get(new Pair<Fluid, Fluid>(stackOne.getFluid(), stackTwo.getFluid()));
/* Try to merge fluids by mod defined rules first */ /* Try to merge fluids by mod defined rules first */
if (result != null) if (result != null)
{ {
System.out.println("result = " + result.toString());
if (result instanceof Fluid) if (result instanceof Fluid)
{ {
resultStack = new FluidStack(((Fluid) result).getID(), stackOne.amount + stackTwo.amount); resultStack = new FluidStack(((Fluid) result).getID(), stackOne.amount + stackTwo.amount);
@ -186,6 +188,7 @@ public class FluidCraftingHandler
} }
if (resultStack == null) if (resultStack == null)
{ {
System.out.println("Merging fluids into a waste fluid stack");
Fluid waste = FluidRegistry.getFluid("waste"); Fluid waste = FluidRegistry.getFluid("waste");
if (waste == null) if (waste == null)
{ {

View file

@ -39,6 +39,7 @@ public class NetworkFluidContainers extends NetworkFluidTiles
if (this.combinedStorage() == null || this.combinedStorage().getFluid() == null) if (this.combinedStorage() == null || this.combinedStorage().getFluid() == null)
{ {
super.writeDataToTiles();
return; return;
} }
FluidStack fillStack = this.combinedStorage().getFluid().copy(); FluidStack fillStack = this.combinedStorage().getFluid().copy();
@ -85,6 +86,7 @@ public class NetworkFluidContainers extends NetworkFluidTiles
/* Fill all tanks on this level */ /* Fill all tanks on this level */
for (INetworkFluidPart part : parts) for (INetworkFluidPart part : parts)
{ {
((INetworkFluidPart) part).drainTankContent(0, Integer.MAX_VALUE, true);
fillStack.amount -= part.fillTankContent(0, FluidHelper.getStack(fillStack, fillvolume), true); fillStack.amount -= part.fillTankContent(0, FluidHelper.getStack(fillStack, fillvolume), true);
} }
} }

View file

@ -111,6 +111,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
@Override @Override
public void writeDataToTiles() public void writeDataToTiles()
{ {
this.cleanUpMembers();
if (this.combinedStorage().getFluid() != null && this.networkMember.size() > 0) if (this.combinedStorage().getFluid() != null && this.networkMember.size() > 0)
{ {
FluidStack stack = this.combinedStorage().getFluid() == null ? null : this.combinedStorage().getFluid().copy(); FluidStack stack = this.combinedStorage().getFluid() == null ? null : this.combinedStorage().getFluid().copy();
@ -125,7 +126,6 @@ public class NetworkFluidTiles extends NetworkTileEntities
{ {
//EMPTY TANK //EMPTY TANK
((INetworkFluidPart) par).drainTankContent(0, Integer.MAX_VALUE, true); ((INetworkFluidPart) par).drainTankContent(0, Integer.MAX_VALUE, true);
//FILL TANK //FILL TANK
if (stack != null) if (stack != null)
{ {
@ -135,7 +135,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
} }
} }
} }
this.cleanUpMembers();
} }
@Override @Override
@ -232,10 +232,9 @@ public class NetworkFluidTiles extends NetworkTileEntities
newNetwork.getNetworkMemebers().addAll(this.getNetworkMemebers()); newNetwork.getNetworkMemebers().addAll(this.getNetworkMemebers());
newNetwork.getNetworkMemebers().addAll(network.getNetworkMemebers()); newNetwork.getNetworkMemebers().addAll(network.getNetworkMemebers());
newNetwork.refresh(); newNetwork.cleanUpMembers();
newNetwork.combinedStorage().setFluid(FluidCraftingHandler.mergeFluidStacks(one, two)); newNetwork.combinedStorage().setFluid(FluidCraftingHandler.mergeFluidStacks(one, two));
newNetwork.writeDataToTiles(); newNetwork.writeDataToTiles();
} }
@Override @Override

View file

@ -16,6 +16,7 @@ import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.fluids.IFluidHandler;
import net.minecraftforge.fluids.IFluidTank; import net.minecraftforge.fluids.IFluidTank;
@ -96,7 +97,7 @@ public class TileEntityTank extends TileEntityFluidStorage implements IFluidHand
if (id == 0) if (id == 0)
{ {
this.getTank().setFluid(FluidStack.loadFluidStackFromNBT(PacketHandler.instance().readNBTTagCompound(dataStream))); this.getTank().setFluid(FluidStack.loadFluidStackFromNBT(PacketHandler.instance().readNBTTagCompound(dataStream)));
System.out.println("Received Fluid Packet Fluid = " + this.getTank().getFluid().getFluid().getName() + "@" + this.getTank().getFluid().amount); //System.out.println("Received Fluid Packet Fluid = " + this.getTank().getFluid().getFluid().getName() + "@" + this.getTank().getFluid().amount);
} }
else else
{ {
@ -355,7 +356,7 @@ public class TileEntityTank extends TileEntityFluidStorage implements IFluidHand
} }
@Override @Override
public IFluidTank getTank(int index) public FluidTank getTank(int index)
{ {
return this.getTank(); return this.getTank();
} }