mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-22 04:52:25 +00:00
Fancy new eject algorithms, should fix issues with PRC
This commit is contained in:
1 parent
b4c2664c5e
commit
e4d624d8ab
11 files changed
+197
-38
No files matched your search
@@ -1,14 +1,17 @@
|
||||
package mekanism.common.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.transmitters.IGridTransmitter;
|
||||
import mekanism.api.transmitters.TransmissionType;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
@@ -144,4 +147,60 @@ public final class PipeUtils
|
||||
|
||||
return acceptors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits fluid from a central block by splitting the received stack among the sides given.
|
||||
* @param sides - the list of sides to output from
|
||||
* @param stack - the stack to output
|
||||
* @param from - the TileEntity to output from
|
||||
* @return the amount of gas emitted
|
||||
*/
|
||||
public static int emit(List<ForgeDirection> sides, FluidStack stack, TileEntity from)
|
||||
{
|
||||
if(stack == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
List<IFluidHandler> availableAcceptors = new ArrayList<IFluidHandler>();
|
||||
IFluidHandler[] possibleAcceptors = getConnectedAcceptors(from);
|
||||
|
||||
for(int i = 0; i < possibleAcceptors.length; i++)
|
||||
{
|
||||
IFluidHandler handler = possibleAcceptors[i];
|
||||
|
||||
if(handler != null && handler.canFill(ForgeDirection.getOrientation(i).getOpposite(), stack.getFluid()))
|
||||
{
|
||||
availableAcceptors.add(handler);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.shuffle(availableAcceptors);
|
||||
|
||||
int toSend = stack.amount;
|
||||
int prevSending = toSend;
|
||||
|
||||
if(!availableAcceptors.isEmpty())
|
||||
{
|
||||
int divider = availableAcceptors.size();
|
||||
int remaining = toSend % divider;
|
||||
int sending = (toSend-remaining)/divider;
|
||||
|
||||
for(IFluidHandler acceptor : availableAcceptors)
|
||||
{
|
||||
int currentSending = sending;
|
||||
|
||||
if(remaining > 0)
|
||||
{
|
||||
currentSending++;
|
||||
remaining--;
|
||||
}
|
||||
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(Arrays.asList(possibleAcceptors).indexOf(acceptor)).getOpposite();
|
||||
toSend -= acceptor.fill(dir, new FluidStack(stack.getFluid(), currentSending), true);
|
||||
}
|
||||
}
|
||||
|
||||
return prevSending-toSend;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user