use of buildcraft.api.core.IFluidFilter in project BuildCraft by BuildCraft.
the class BoardRobotFluidCarrier method update.
@Override
public void update() {
if (!robotHasFluid()) {
IFluidFilter filter = ActionRobotFilter.getGateFluidFilter(robot.getLinkedStation());
startDelegateAI(new AIRobotGotoStationAndLoadFluids(robot, filter));
} else {
startDelegateAI(new AIRobotGotoStationAndUnloadFluids(robot));
}
}
use of buildcraft.api.core.IFluidFilter in project BuildCraft by BuildCraft.
the class FluidUtilBC method move.
/**
* @param max The maximum amount of fluid to move.
* @return The fluidstack that was moved, or null if no fluid was moved.
*/
@Nullable
public static FluidStack move(IFluidHandler from, IFluidHandler to, int max) {
if (from == null || to == null) {
return null;
}
FluidStack toDrainPotential;
if (from instanceof IFluidHandlerAdv) {
IFluidFilter filter = f -> to.fill(f, false) > 0;
toDrainPotential = ((IFluidHandlerAdv) from).drain(filter, max, false);
} else {
toDrainPotential = from.drain(max, false);
}
int accepted = to.fill(toDrainPotential, false);
if (accepted <= 0) {
return null;
}
FluidStack toDrain = new FluidStack(toDrainPotential, accepted);
FluidStack drained = from.drain(toDrain, true);
if (!toDrain.isFluidEqual(drained) || toDrain.amount != drained.amount) {
String detail = "(To Drain = " + StringUtilBC.fluidToString(toDrain);
detail += ",\nactually drained = " + StringUtilBC.fluidToString(drained) + ")";
detail += ",\nIFluidHandler (from) = " + from.getClass() + "(" + from + ")";
detail += ",\nIFluidHandler (to) = " + to.getClass() + "(" + to + ")";
throw new IllegalStateException("Drained fluid did not equal expected fluid!\n" + detail);
}
int actuallyAccepted = to.fill(drained, true);
if (actuallyAccepted != accepted) {
String detail = "(actually accepted = " + actuallyAccepted + ", accepted = " + accepted + ")";
throw new IllegalStateException("Mismatched IFluidHandler implementations!\n" + detail);
}
return new FluidStack(drained, accepted);
}
Aggregations