Updated fluid container network code
converted it to the new system plus worked out an idea to use a collection sorter.
This commit is contained in:
parent
db24fbb52e
commit
d0b3b6cc6a
1 changed files with 54 additions and 14 deletions
|
@ -1,22 +1,25 @@
|
|||
package dark.core.network.fluid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import universalelectricity.core.vector.Vector2;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import dark.api.fluid.INetworkFluidPart;
|
||||
import dark.api.parts.INetworkPart;
|
||||
import dark.core.interfaces.ColorCode;
|
||||
import dark.core.prefab.helpers.FluidHelper;
|
||||
import dark.core.prefab.tilenetwork.NetworkTileEntities;
|
||||
|
||||
/** 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
|
||||
* Liquids
|
||||
*
|
||||
* @author Rseifert */
|
||||
/** Designed to be used by fluid containers with only one internal tank */
|
||||
public class NetworkFluidContainers extends NetworkFluidTiles
|
||||
{
|
||||
|
||||
|
@ -38,9 +41,8 @@ public class NetworkFluidContainers extends NetworkFluidTiles
|
|||
{
|
||||
return;
|
||||
}
|
||||
int fluid = this.combinedStorage().getFluid().fluidID;
|
||||
int volume = Math.abs(this.combinedStorage().getFluid().amount);
|
||||
NBTTagCompound tag = this.combinedStorage().getFluid().tag;
|
||||
FluidStack tankStack = this.combinedStorage().getFluid();
|
||||
int volume = tankStack.amount;
|
||||
|
||||
int lowestY = 255;
|
||||
int highestY = 0;
|
||||
|
@ -53,7 +55,7 @@ public class NetworkFluidContainers extends NetworkFluidTiles
|
|||
{
|
||||
if (part instanceof IFluidHandler)
|
||||
{
|
||||
((INetworkFluidPart) part).setTankContent(null);
|
||||
((INetworkFluidPart) part).drainTankContent(0, Integer.MAX_VALUE, true);
|
||||
}
|
||||
if (part instanceof TileEntity && ((TileEntity) part).yCoord < lowestY)
|
||||
{
|
||||
|
@ -82,14 +84,13 @@ public class NetworkFluidContainers extends NetworkFluidTiles
|
|||
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)
|
||||
{
|
||||
int fill = Math.min(fillvolume, part.getTank().getCapacity());
|
||||
part.setTankContent(new FluidStack(fluid, fill, tag));
|
||||
volume -= fill;
|
||||
int fill = Math.min(fillVolume, part.getTank(0).getCapacity());
|
||||
volume -= part.fillTankContent(0, FluidHelper.getStack(tankStack, fillVolume), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,4 +153,43 @@ public class NetworkFluidContainers extends NetworkFluidTiles
|
|||
return stack;
|
||||
}
|
||||
|
||||
public void sortBlockList(final Set<INetworkPart> set)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<INetworkPart> list = new ArrayList<INetworkPart>();
|
||||
Iterator<INetworkPart> it = list.iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
if (!(it.next() instanceof TileEntity))
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
Collections.sort(list, new Comparator<INetworkPart>()
|
||||
{
|
||||
@Override
|
||||
public int compare(INetworkPart partA, INetworkPart partB)
|
||||
{
|
||||
Vector3 vecA = new Vector3((TileEntity) partA);
|
||||
Vector3 vecB = new Vector3((TileEntity) partB);
|
||||
//Though unlikely always return zero for equal vectors
|
||||
if (vecA.equals(vecB) || vecA.intY() == vecB.intY())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Integer.compare(vecA.intY(), vecB.intY());
|
||||
}
|
||||
});
|
||||
set.clear();
|
||||
set.addAll(list);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("FluidMech>>>BlockDrain>>FillArea>>Error>>CollectionSorter");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue