Search in sources :

Example 31 with IFluidTank

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

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 32 with IFluidTank

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

the class FuelRecipeLogic method getFuels.

@Override
public Collection<IFuelInfo> getFuels() {
    if (!isReadyForRecipes())
        return Collections.emptySet();
    final IMultipleTankHandler fluidTanks = this.fluidTank.get();
    if (fluidTanks == null)
        return Collections.emptySet();
    final LinkedHashMap<String, IFuelInfo> fuels = new LinkedHashMap<>();
    // Fuel capacity is all tanks
    int fuelCapacity = 0;
    for (IFluidTank fluidTank : fluidTanks) {
        fuelCapacity += fluidTank.getCapacity();
    }
    for (IFluidTank fluidTank : fluidTanks) {
        final FluidStack tankContents = fluidTank.drain(Integer.MAX_VALUE, false);
        if (tankContents == null || tankContents.amount <= 0)
            continue;
        int fuelRemaining = tankContents.amount;
        FuelRecipe recipe = findRecipe(tankContents);
        if (recipe == null)
            continue;
        int amountPerRecipe = calculateFuelAmount(recipe);
        int duration = calculateRecipeDuration(recipe);
        long fuelBurnTime = (duration * fuelRemaining) / amountPerRecipe;
        FluidFuelInfo fuelInfo = (FluidFuelInfo) fuels.get(tankContents.getUnlocalizedName());
        if (fuelInfo == null) {
            fuelInfo = new FluidFuelInfo(tankContents, fuelRemaining, fuelCapacity, amountPerRecipe, fuelBurnTime);
            fuels.put(tankContents.getUnlocalizedName(), fuelInfo);
        } else {
            fuelInfo.addFuelRemaining(fuelRemaining);
            fuelInfo.addFuelBurnTime(fuelBurnTime);
        }
    }
    return fuels.values();
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) FuelRecipe(gregtech.api.recipes.recipes.FuelRecipe) IFluidTank(net.minecraftforge.fluids.IFluidTank) LinkedHashMap(java.util.LinkedHashMap)

Example 33 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project pnc-repressurized by TeamPneumatic.

the class RenderPlasticMixer method render.

@Override
public void render(TileEntityPlasticMixer te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
    IFluidTank tank = te.getTank();
    if (tank.getFluidAmount() == 0)
        return;
    GlStateManager.pushMatrix();
    GlStateManager.translate(x, y, z);
    GlStateManager.enableBlend();
    GlStateManager.disableAlpha();
    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    AxisAlignedBB bounds = getRenderBounds(tank);
    PneumaticCraftUtils.renderFluid(tank.getFluid().getFluid(), bounds);
    GlStateManager.disableBlend();
    GlStateManager.enableAlpha();
    GlStateManager.popMatrix();
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IFluidTank(net.minecraftforge.fluids.IFluidTank)

Example 34 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project ForestryMC by ForestryMC.

the class BiogasSlot method getToolTip.

@Override
public ToolTip getToolTip(int mouseX, int mouseY) {
    ToolTip toolTip = new ToolTip();
    IFluidTank tank = getTank();
    if (tank != null) {
        FluidStack fluid = tank.getFluid();
        if (fluid == null) {
            toolTip.add(Translator.translateToLocal("for.gui.empty"));
        } else {
            toolTip.add(fluid.getLocalizedName());
        }
    }
    return toolTip;
}
Also used : ToolTip(forestry.core.gui.tooltips.ToolTip) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidTank(net.minecraftforge.fluids.IFluidTank)

Example 35 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project ForestryMC by ForestryMC.

the class ContainerLiquidTanksHelper method handlePipetteClick.

@Override
public void handlePipetteClick(int slot, EntityPlayerMP player) {
    ItemStack itemstack = player.inventory.getItemStack();
    Item held = itemstack.getItem();
    if (!(held instanceof IToolPipette)) {
        return;
    }
    IToolPipette pipette = (IToolPipette) held;
    IFluidTank tank = tile.getTankManager().getTank(slot);
    int liquidAmount = tank.getFluidAmount();
    IFluidHandlerItem fluidHandlerItem = FluidUtil.getFluidHandler(itemstack);
    if (fluidHandlerItem != null) {
        if (pipette.canPipette(itemstack) && liquidAmount > 0) {
            if (liquidAmount > 0) {
                if (tank instanceof FluidTank) {
                    FluidStack fillAmount = ((FluidTank) tank).drainInternal(Fluid.BUCKET_VOLUME, false);
                    int filled = fluidHandlerItem.fill(fillAmount, true);
                    tank.drain(filled, true);
                    player.inventory.setItemStack(fluidHandlerItem.getContainer());
                    player.updateHeldItem();
                }
            }
        } else {
            FluidStack potential = fluidHandlerItem.drain(Integer.MAX_VALUE, false);
            if (potential != null) {
                if (tank instanceof FluidTank) {
                    int fill = ((FluidTank) tank).fillInternal(potential, true);
                    fluidHandlerItem.drain(fill, true);
                    player.inventory.setItemStack(fluidHandlerItem.getContainer());
                    player.updateHeldItem();
                }
            }
        }
    }
}
Also used : FluidTank(net.minecraftforge.fluids.FluidTank) IFluidTank(net.minecraftforge.fluids.IFluidTank) Item(net.minecraft.item.Item) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) FluidStack(net.minecraftforge.fluids.FluidStack) IToolPipette(forestry.api.core.IToolPipette) ItemStack(net.minecraft.item.ItemStack) IFluidTank(net.minecraftforge.fluids.IFluidTank)

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