Search in sources :

Example 11 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCEu.

the class CoverDigitalInterface method getFluidCapability.

public IFluidHandler getFluidCapability() {
    TileEntity te = getCoveredTE();
    IFluidHandler capability = te == null ? null : te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, getCoveredFacing());
    if (capability == null && this.coverHolder instanceof MultiblockControllerBase) {
        List<IFluidTank> input = ((MultiblockControllerBase) this.coverHolder).getAbilities(MultiblockAbility.IMPORT_FLUIDS);
        List<IFluidTank> output = ((MultiblockControllerBase) this.coverHolder).getAbilities(MultiblockAbility.EXPORT_FLUIDS);
        List<IFluidTank> list = new ArrayList<>();
        if (input.size() > 0) {
            list.addAll(input);
        }
        if (output.size() > 0) {
            list.addAll(output);
        }
        capability = new FluidTankList(true, list);
    }
    return capability;
}
Also used : MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) IFastRenderMetaTileEntity(gregtech.api.metatileentity.IFastRenderMetaTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) ArrayList(java.util.ArrayList) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) IFluidTank(net.minecraftforge.fluids.IFluidTank)

Example 12 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCEu.

the class LargeTurbineWorkableHandler method updateTanks.

public void updateTanks() {
    FuelMultiblockController controller = (FuelMultiblockController) this.metaTileEntity;
    List<IFluidHandler> tanks = controller.getNotifiedFluidInputList();
    for (IFluidTank tank : controller.getAbilities(MultiblockAbility.IMPORT_FLUIDS)) {
        tanks.add((FluidTank) tank);
    }
}
Also used : FuelMultiblockController(gregtech.api.metatileentity.multiblock.FuelMultiblockController) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) IFluidTank(net.minecraftforge.fluids.IFluidTank)

Example 13 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCEu.

the class FluidTankList method drain.

@Nullable
@Override
public FluidStack drain(FluidStack resource, boolean doDrain) {
    if (resource == null || resource.amount <= 0) {
        return null;
    }
    resource = resource.copy();
    FluidStack totalDrained = null;
    for (IFluidTank handler : fluidTanks) {
        if (!resource.isFluidEqual(handler.getFluid())) {
            continue;
        }
        FluidStack drain = handler.drain(resource.amount, doDrain);
        if (drain == null) {
            continue;
        }
        if (totalDrained == null) {
            totalDrained = drain;
        } else
            totalDrained.amount += drain.amount;
        resource.amount -= drain.amount;
        if (resource.amount == 0)
            break;
    }
    return totalDrained;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) IFluidTank(net.minecraftforge.fluids.IFluidTank) Nullable(javax.annotation.Nullable)

Example 14 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCEu.

the class FluidTankList method fillTanksImpl.

// fills exactly one tank if multi-filling is not allowed
// and as much tanks as possible otherwise
// note that it will always try to fill tanks with same fluid first
private int fillTanksImpl(FluidStack resource, boolean doFill) {
    int totalFilled = 0;
    // first, try to fill tanks that already have same fluid type
    for (IFluidTank handler : fluidTanks) {
        if (resource.isFluidEqual(handler.getFluid())) {
            int filledAmount = handler.fill(resource, doFill);
            totalFilled += filledAmount;
            resource.amount -= filledAmount;
            // if filling multiple tanks is not allowed, or resource is empty, return now
            if (!allowSameFluidFill() || resource.amount == 0)
                return totalFilled;
        }
    }
    // otherwise, try to fill empty tanks
    for (IFluidTank handler : fluidTanks) {
        if (handler.getFluidAmount() == 0) {
            int filledAmount = handler.fill(resource, doFill);
            totalFilled += filledAmount;
            resource.amount -= filledAmount;
            if (!allowSameFluidFill() || resource.amount == 0)
                return totalFilled;
        }
    }
    return totalFilled;
}
Also used : IFluidTank(net.minecraftforge.fluids.IFluidTank)

Example 15 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project GregTech by GregTechCEu.

the class FluidTankList method drain.

@Nullable
@Override
public FluidStack drain(int maxDrain, boolean doDrain) {
    if (maxDrain == 0) {
        return null;
    }
    FluidStack totalDrained = null;
    for (IFluidTank handler : fluidTanks) {
        if (totalDrained == null) {
            totalDrained = handler.drain(maxDrain, doDrain);
            if (totalDrained != null)
                maxDrain -= totalDrained.amount;
        } else {
            FluidStack copy = totalDrained.copy();
            copy.amount = maxDrain;
            if (!copy.isFluidEqual(handler.getFluid()))
                continue;
            FluidStack drain = handler.drain(copy.amount, doDrain);
            if (drain != null) {
                totalDrained.amount += drain.amount;
                maxDrain -= drain.amount;
            }
        }
        if (maxDrain <= 0)
            break;
    }
    return totalDrained;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) IFluidTank(net.minecraftforge.fluids.IFluidTank) Nullable(javax.annotation.Nullable)

Aggregations

IFluidTank (net.minecraftforge.fluids.IFluidTank)58 FluidStack (net.minecraftforge.fluids.FluidStack)30 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)10 FluidTank (net.minecraftforge.fluids.FluidTank)9 Nullable (javax.annotation.Nullable)6 Block (net.minecraft.block.Block)6 ItemStack (net.minecraft.item.ItemStack)6 TileEntity (net.minecraft.tileentity.TileEntity)5 NBTBase (net.minecraft.nbt.NBTBase)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 NBTTagList (net.minecraft.nbt.NBTTagList)4 INBTSerializable (net.minecraftforge.common.util.INBTSerializable)4 Recipe (gregtech.api.recipes.Recipe)3 ArrayList (java.util.ArrayList)3 IItemHandlerModifiable (net.minecraftforge.items.IItemHandlerModifiable)3 FluidTankTileEntity (com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity)2 FluidTankGT (gregapi.fluid.FluidTankGT)2 OreDictItemData (gregapi.oredict.OreDictItemData)2 FuelRecipe (gregtech.api.recipes.recipes.FuelRecipe)2 BlockLiquid (net.minecraft.block.BlockLiquid)2