Search in sources :

Example 11 with IFluidHandler

use of net.minecraftforge.fluids.capability.IFluidHandler 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 12 with IFluidHandler

use of net.minecraftforge.fluids.capability.IFluidHandler in project Witchworks by Um-Mitternacht.

the class ItemRitual method onFinish.

@SuppressWarnings("ConstantConditions")
@Override
public void onFinish(TileKettle tile, World world, BlockPos pos) {
    for (int i = 0; i < 20; i++) {
        final float x = pos.getX() + 0.2F + MathHelper.clamp(world.rand.nextFloat(), 0F, 0.5F);
        final float y = pos.getY() + 0.2F + world.rand.nextFloat();
        final float z = pos.getZ() + 0.2F + MathHelper.clamp(world.rand.nextFloat(), 0F, 0.5F);
        PacketHandler.spawnParticle(ParticleF.STEAM, world, x, y, z, 10, 0, 0, 0);
    }
    if (!stack.isEmpty()) {
        if (tile.getContainer().isEmpty()) {
            tile.setContainer(stack);
        } else {
            spawnItem(world, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D);
        }
    }
    world.playSound(null, pos, SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 1F, 1F);
    IFluidHandler handler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);
    handler.drain(1000, true);
}
Also used : IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 13 with IFluidHandler

use of net.minecraftforge.fluids.capability.IFluidHandler in project Overloaded by CJ-MC-Mods.

the class BlockInfiniteWaterSource method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote && hand == EnumHand.MAIN_HAND) {
        TileEntity te = worldIn.getTileEntity(pos);
        if (te != null && te instanceof TileInfiniteWaterSource) {
            IFluidHandler handler = te.getCapability(FLUID_HANDLER_CAPABILITY, facing);
            // FluidUtil.interactWithFluidHandler(playerIn.getHeldItem(hand), te.getCapability(FLUID_HANDLER_CAPABILITY, facing), playerIn);
            FluidActionResult result = FluidUtil.tryFillContainerAndStow(playerIn.getHeldItem(hand), handler, null, Integer.MAX_VALUE, playerIn);
            if (result.isSuccess())
                playerIn.setHeldItem(hand, result.getResult());
        }
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidActionResult(net.minecraftforge.fluids.FluidActionResult) TileInfiniteWaterSource(com.cjm721.overloaded.block.tile.TileInfiniteWaterSource) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 14 with IFluidHandler

use of net.minecraftforge.fluids.capability.IFluidHandler in project MinecraftForge by MinecraftForge.

the class FluidUtil method tryPickUpFluid.

/**
     * Attempts to pick up a fluid in the world and put it in an empty container item.
     *
     * @param emptyContainer The empty container to fill.
     *                       Will not be modified directly, if modifications are necessary a modified copy is returned in the result.
     * @param playerIn       The player filling the container. Optional.
     * @param worldIn        The world the fluid is in.
     * @param pos            The position of the fluid in the world.
     * @param side           The side of the fluid that is being drained.
     * @return a {@link FluidActionResult} holding the result and the resulting container.
     */
@Nonnull
public static FluidActionResult tryPickUpFluid(@Nonnull ItemStack emptyContainer, @Nullable EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side) {
    if (emptyContainer.isEmpty() || worldIn == null || pos == null) {
        return FluidActionResult.FAILURE;
    }
    IBlockState state = worldIn.getBlockState(pos);
    Block block = state.getBlock();
    if (block instanceof IFluidBlock || block instanceof BlockLiquid) {
        IFluidHandler targetFluidHandler = FluidUtil.getFluidHandler(worldIn, pos, side);
        if (targetFluidHandler != null) {
            FluidActionResult fluidActionResult = FluidUtil.tryFillContainer(emptyContainer, targetFluidHandler, Integer.MAX_VALUE, playerIn, true);
            if (fluidActionResult.isSuccess()) {
                return fluidActionResult;
            }
        }
    }
    return FluidActionResult.FAILURE;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) Block(net.minecraft.block.Block) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) Nonnull(javax.annotation.Nonnull)

Example 15 with IFluidHandler

use of net.minecraftforge.fluids.capability.IFluidHandler in project MinecraftForge by MinecraftForge.

the class FluidHandlerConcatenate method fill.

@Override
public int fill(FluidStack resource, boolean doFill) {
    if (resource == null || resource.amount <= 0)
        return 0;
    resource = resource.copy();
    int totalFillAmount = 0;
    for (IFluidHandler handler : subHandlers) {
        int fillAmount = handler.fill(resource, doFill);
        totalFillAmount += fillAmount;
        resource.amount -= fillAmount;
        if (resource.amount <= 0)
            break;
    }
    return totalFillAmount;
}
Also used : IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Aggregations

IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)28 FluidStack (net.minecraftforge.fluids.FluidStack)16 TileEntity (net.minecraft.tileentity.TileEntity)12 ItemStack (net.minecraft.item.ItemStack)11 EnumFacing (net.minecraft.util.EnumFacing)10 BlockPos (net.minecraft.util.math.BlockPos)7 IBlockState (net.minecraft.block.state.IBlockState)3 IFluidTankProperties (net.minecraftforge.fluids.capability.IFluidTankProperties)3 ArrayList (java.util.ArrayList)2 Nonnull (javax.annotation.Nonnull)2 AdvancedFluidHandler (mods.railcraft.common.fluids.AdvancedFluidHandler)2 Block (net.minecraft.block.Block)2 BlockLiquid (net.minecraft.block.BlockLiquid)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 Fluid (net.minecraftforge.fluids.Fluid)2 FluidActionResult (net.minecraftforge.fluids.FluidActionResult)2 FermenterRecipe (blusunrize.immersiveengineering.api.crafting.FermenterRecipe)1 MixerRecipe (blusunrize.immersiveengineering.api.crafting.MixerRecipe)1 RefineryRecipe (blusunrize.immersiveengineering.api.crafting.RefineryRecipe)1 SqueezerRecipe (blusunrize.immersiveengineering.api.crafting.SqueezerRecipe)1