use of mods.railcraft.common.fluids.AdvancedFluidHandler in project Railcraft by Railcraft.
the class TileFluidLoader method processCart.
@Override
protected void processCart(EntityMinecart cart) {
if (cart instanceof EntityLocomotiveSteam) {
EntityLocomotiveSteam loco = (EntityLocomotiveSteam) cart;
if (!loco.isSafeToFill()) {
retractPipe();
return;
}
}
AdvancedFluidHandler tankCart = getFluidHandler(cart, EnumFacing.UP);
if (tankCart == null)
return;
boolean cartNeedsFilling = cartNeedsFilling(tankCart);
if (cartNeedsFilling && needsPipe)
extendPipe();
else
retractPipe();
setProcessing(false);
if (cartNeedsFilling && (!needsPipe || pipeIsExtended())) {
FluidStack moved = FluidUtil.tryFluidTransfer(tankCart, tank, RailcraftConfig.getTankCartFillRate(), true);
setProcessing(Fluids.isNotEmpty(moved));
}
if (isProcessing())
setPowered(false);
if (cart instanceof IFluidCart)
((IFluidCart) cart).setFilling(isProcessing());
if (tankCart.isTankFull(tank.getFluidType()))
setResetTimer(RESET_WAIT);
}
use of mods.railcraft.common.fluids.AdvancedFluidHandler in project Railcraft by Railcraft.
the class TileFluidUnloader method processCart.
@Override
protected void processCart(EntityMinecart cart) {
AdvancedFluidHandler tankCart = getFluidHandler(cart, EnumFacing.DOWN);
if (tankCart != null) {
FluidStack moved = FluidUtil.tryFluidTransfer(tank, tankCart, RailcraftConfig.getTankCartFillRate(), true);
setProcessing(Fluids.isNotEmpty(moved));
}
}
use of mods.railcraft.common.fluids.AdvancedFluidHandler in project Railcraft by Railcraft.
the class DetectorTank method testCarts.
@Override
public int testCarts(List<EntityMinecart> carts) {
for (EntityMinecart cart : carts) {
IFluidHandler fluidHandler = FluidTools.getFluidHandler(null, cart);
if (fluidHandler != null) {
AdvancedFluidHandler tank = new AdvancedFluidHandler(fluidHandler);
boolean liquidMatches = false;
Fluid filterFluid = getFilterFluid();
FluidStack tankLiquid = tank.drain(1, false);
if (filterFluid == null)
liquidMatches = true;
else if (Fluids.areEqual(filterFluid, tankLiquid))
liquidMatches = true;
else if (tank.canPutFluid(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;
break;
case HALF:
quantityMatches = level >= 0.5f;
break;
case MOST:
quantityMatches = level >= 0.75f;
break;
case LESS_THAN_QUARTER:
quantityMatches = level < 0.25f;
break;
case LESS_THAN_HALF:
quantityMatches = level < 0.5f;
break;
case LESS_THAN_MOST:
quantityMatches = level < 0.75f;
break;
case LESS_THAN_FULL:
quantityMatches = level < 1f;
break;
}
}
return liquidMatches && quantityMatches ? FULL_POWER : NO_POWER;
}
}
return NO_POWER;
}
use of mods.railcraft.common.fluids.AdvancedFluidHandler in project Railcraft by Railcraft.
the class TrainTransferHelper method canAcceptPushedFluid.
private boolean canAcceptPushedFluid(EntityMinecart requester, EntityMinecart cart, Fluid fluid) {
IFluidHandler fluidHandler = FluidTools.getFluidHandler(EnumFacing.UP, cart);
if (fluidHandler == null)
return false;
if (cart instanceof IFluidCart)
return ((IFluidCart) cart).canAcceptPushedFluid(requester, fluid);
AdvancedFluidHandler advancedFluidHandler = new AdvancedFluidHandler(fluidHandler);
return advancedFluidHandler.canPutFluid(new FluidStack(fluid, 1));
}
use of mods.railcraft.common.fluids.AdvancedFluidHandler in project Railcraft by Railcraft.
the class TileFluidLoader method hasWorkForCart.
@Override
protected boolean hasWorkForCart(EntityMinecart cart) {
if (!pipeIsRetracted())
return true;
AdvancedFluidHandler tankCart = getFluidHandler(cart, EnumFacing.UP);
if (tankCart == null)
return false;
Fluid fluid = getFluidHandled();
switch(redstoneController().getButtonState()) {
case COMPLETE:
return !tankCart.isTankFull(fluid);
case PARTIAL:
return tankCart.isTankEmpty(fluid);
}
return false;
}
Aggregations