@Override
public int testCarts(List<EntityMinecart> carts) {
for (EntityMinecart cart : carts) {
if (cart instanceof IFluidHandler) {
TankToolkit tank = new TankToolkit((IFluidHandler) cart);
boolean liquidMatches = false;
Fluid filterFluid = getFilterLiquid();
FluidStack tankLiquid = tank.drain(ForgeDirection.UNKNOWN, 1, false);
if (filterFluid == null)
liquidMatches = true;
else if (Fluids.areEqual(filterFluid, tankLiquid))
liquidMatches = true;
else if (tank.canPutFluid(ForgeDirection.UNKNOWN, new FluidStack(filterFluid, 1)))
liquidMatches = true;
boolean quantityMatches = false;
ButtonState state = buttonController.getButtonState();
switch (state) {
case VOID:
quantityMatches = true;
break;
case EMPTY:
if (filterFluid != null && tank.isTankEmpty(filterFluid))
quantityMatches = true;
else if (filterFluid == null && tank.areTanksEmpty())
quantityMatches = true;
break;
case NOT_EMPTY:
if (filterFluid != null && tank.getFluidQty(filterFluid) > 0)
quantityMatches = true;
else if (filterFluid == null && tank.isFluidInTank())
quantityMatches = true;
break;
case FULL:
if (filterFluid != null && tank.isTankFull(filterFluid))
quantityMatches = true;
else if (filterFluid == null && tank.areTanksFull())
quantityMatches = true;
break;
default:
float level = filterFluid != null ? tank.getFluidLevel(filterFluid) : tank.getFluidLevel();
switch (state) {
case ANALOG:
return (int) (FULL_POWER * level);
case QUARTER:
quantityMatches = level >= 0.25f;