Added waste create code as merge conflict
In the case that two liquids merge safely with no result it will create waste liquid. To prevent this a mod should register a merge result allowing for more complex or better liquid merging.
This commit is contained in:
parent
b618f85ce7
commit
b607193f16
1 changed files with 73 additions and 8 deletions
|
@ -5,9 +5,11 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
@ -119,7 +121,8 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
|||
* @param sumParts - loads the volume from the parts before leveling out the volumes */
|
||||
public void balanceColletiveTank(boolean sumParts)
|
||||
{
|
||||
Fluid fluid = null;
|
||||
int fluid = -1;
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
int volume = 0;
|
||||
|
||||
if (sumParts)
|
||||
|
@ -131,17 +134,18 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
|||
INetworkFluidPart part = ((INetworkFluidPart) par);
|
||||
if (part.getTank() != null && part.getTank().getFluid() != null)
|
||||
{
|
||||
if (fluid == null)
|
||||
if (fluid == -1)
|
||||
{
|
||||
fluid = part.getTank().getFluid().getFluid();
|
||||
fluid = part.getTank().getFluid().fluidID;
|
||||
tag = part.getTank().getFluid().tag;
|
||||
}
|
||||
volume += part.getTank().getFluid().amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fluid != null)
|
||||
if (fluid != -1)
|
||||
{
|
||||
this.combinedStorage().setFluid(new FluidStack(fluid, volume));
|
||||
this.combinedStorage().setFluid(new FluidStack(fluid, volume, tag));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -153,7 +157,8 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
|||
if (this.combinedStorage().getFluid() != null && this.networkMember.size() > 0)
|
||||
{
|
||||
volume = this.combinedStorage().getFluid().amount / this.networkMember.size();
|
||||
fluid = this.combinedStorage().getFluid().getFluid();
|
||||
fluid = this.combinedStorage().getFluid().fluidID;
|
||||
tag = this.combinedStorage().getFluid().tag;
|
||||
|
||||
for (INetworkPart par : this.networkMember)
|
||||
{
|
||||
|
@ -161,7 +166,7 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
|||
{
|
||||
INetworkFluidPart part = ((INetworkFluidPart) par);
|
||||
part.setTankContent(null);
|
||||
part.setTankContent(new FluidStack(fluid, volume));
|
||||
part.setTankContent(new FluidStack(fluid, volume, tag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -213,14 +218,72 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
|||
{
|
||||
stack = stackOne.copy();
|
||||
}
|
||||
else
|
||||
else if (stackTwo != null && stackOne != null && !stackOne.isFluidEqual(stackTwo))
|
||||
{
|
||||
Fluid waste = FluidRegistry.getFluid("waste");
|
||||
/* If the two liquids are not waste merge and set tag too liquids */
|
||||
if (stackTwo.fluidID != waste.getID() && stackOne.fluidID != waste.getID())
|
||||
{
|
||||
stack = new FluidStack(waste, stackTwo.amount + stackOne.amount);
|
||||
stack.tag = new NBTTagCompound();
|
||||
stack.tag.setCompoundTag("Liquid1", stackTwo.writeToNBT(new NBTTagCompound()));
|
||||
stack.tag.setCompoundTag("Liquid2", stackOne.writeToNBT(new NBTTagCompound()));
|
||||
stack.tag.setInteger("liquids", 2);
|
||||
}
|
||||
else if (stackTwo.fluidID == waste.getID() && stackOne.fluidID == waste.getID())
|
||||
{
|
||||
List<FluidStack> stacks = new ArrayList<FluidStack>();
|
||||
stacks.addAll(this.getStacksFromWaste(stackOne.copy()));
|
||||
stacks.addAll(this.getStacksFromWaste(stackTwo.copy()));
|
||||
stack = new FluidStack(waste, stackOne.amount + stackTwo.amount);
|
||||
stack.tag = new NBTTagCompound();
|
||||
stack.tag.setInteger("liquids", stacks.size());
|
||||
for (int i = 0; i < stacks.size(); i++)
|
||||
{
|
||||
stack.tag.setCompoundTag("Liquids" + 1 + i, stacks.get(i).writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FluidStack wasteStack = null, codeStack = null;
|
||||
if (stackOne.fluidID != waste.getID() && stackTwo.fluidID == waste.getID())
|
||||
{
|
||||
wasteStack = stackTwo.copy();
|
||||
codeStack = stackOne.copy();
|
||||
}
|
||||
else if (stackOne.fluidID == waste.getID() && stackTwo.fluidID != waste.getID())
|
||||
{
|
||||
wasteStack = stackOne.copy();
|
||||
codeStack = stackTwo.copy();
|
||||
}
|
||||
if (wasteStack != null)
|
||||
{
|
||||
wasteStack.tag.setCompoundTag("Liquid" + wasteStack.tag.getInteger("liquids") + 1, codeStack.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
}
|
||||
//TODO do mixing of liquids and create a new waste liquid stack that is encoded with the volume of the two liquids before it
|
||||
//TODO check merge result first to allow for some liquids to merge in X way
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
public List<FluidStack> getStacksFromWaste(FluidStack wasteStack)
|
||||
{
|
||||
List<FluidStack> stacks = new ArrayList<FluidStack>();
|
||||
if (wasteStack.fluidID == FluidRegistry.getFluidID("waste"))
|
||||
{
|
||||
for (int i = 1; i <= wasteStack.tag.getInteger("liquids"); i++)
|
||||
{
|
||||
FluidStack readStack = FluidStack.loadFluidStackFromNBT(wasteStack.tag.getCompoundTag("Liquid" + i));
|
||||
if (readStack != null)
|
||||
{
|
||||
stacks.add(readStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
return stacks;
|
||||
}
|
||||
|
||||
/** Checks if the liquid can be merged without damage */
|
||||
public String canMergeFluids(FluidStack stackOne, FluidStack stackTwo)
|
||||
{
|
||||
|
@ -228,6 +291,8 @@ public class NetworkFluidTiles extends NetworkTileEntities
|
|||
{
|
||||
if (this.mergeResult.containsKey(new Pair<Fluid, Fluid>(stackOne.getFluid(), stackTwo.getFluid())))
|
||||
{
|
||||
//TODO add volume calculation too see if merge can happen resulting in one liquid just vanishing
|
||||
//Case 100mb of fuel 10000mb of lava will result in fuel being comsumed with no explosion
|
||||
return this.mergeResult.get(new Pair<Fluid, Fluid>(stackOne.getFluid(), stackTwo.getFluid()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue