Search in sources :

Example 1 with AdvancedFluidHandler

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);
}
Also used : AdvancedFluidHandler(mods.railcraft.common.fluids.AdvancedFluidHandler) FluidStack(net.minecraftforge.fluids.FluidStack) EntityLocomotiveSteam(mods.railcraft.common.carts.EntityLocomotiveSteam) IFluidCart(mods.railcraft.api.carts.IFluidCart)

Example 2 with AdvancedFluidHandler

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));
    }
}
Also used : AdvancedFluidHandler(mods.railcraft.common.fluids.AdvancedFluidHandler) FluidStack(net.minecraftforge.fluids.FluidStack)

Example 3 with AdvancedFluidHandler

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;
}
Also used : AdvancedFluidHandler(mods.railcraft.common.fluids.AdvancedFluidHandler) FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) EntityMinecart(net.minecraft.entity.item.EntityMinecart) IMultiButtonState(mods.railcraft.common.gui.buttons.IMultiButtonState) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 4 with AdvancedFluidHandler

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));
}
Also used : AdvancedFluidHandler(mods.railcraft.common.fluids.AdvancedFluidHandler) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidCart(mods.railcraft.api.carts.IFluidCart) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 5 with AdvancedFluidHandler

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;
}
Also used : AdvancedFluidHandler(mods.railcraft.common.fluids.AdvancedFluidHandler) Fluid(net.minecraftforge.fluids.Fluid)

Aggregations

AdvancedFluidHandler (mods.railcraft.common.fluids.AdvancedFluidHandler)5 FluidStack (net.minecraftforge.fluids.FluidStack)4 IFluidCart (mods.railcraft.api.carts.IFluidCart)2 Fluid (net.minecraftforge.fluids.Fluid)2 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)2 EntityLocomotiveSteam (mods.railcraft.common.carts.EntityLocomotiveSteam)1 IMultiButtonState (mods.railcraft.common.gui.buttons.IMultiButtonState)1 EntityMinecart (net.minecraft.entity.item.EntityMinecart)1