Example usage for net.minecraftforge.fluids FluidUtil interactWithFluidHandler

List of usage examples for net.minecraftforge.fluids FluidUtil interactWithFluidHandler

Introduction

In this page you can find the example usage for net.minecraftforge.fluids FluidUtil interactWithFluidHandler.

Prototype

public static boolean interactWithFluidHandler(@Nonnull PlayerEntity player, @Nonnull Hand hand,
        @Nonnull IFluidHandler handler) 

Source Link

Document

Used to handle the common case of a player holding a fluid item and right-clicking on a fluid handler.

Usage

From source file:blusunrize.immersiveengineering.common.blocks.metal.TileEntitySheetmetalTank.java

@Override
public boolean interact(EnumFacing side, EntityPlayer player, EnumHand hand, ItemStack heldItem, float hitX,
        float hitY, float hitZ) {
    TileEntitySheetmetalTank master = this.master();
    if (master != null) {
        if (FluidUtil.interactWithFluidHandler(player, hand, master.tank)) {
            this.updateMasterBlock(null, true);
            return true;
        }//from  w  w  w.  j  a  va2s. co m
    }
    return false;
}

From source file:blusunrize.immersiveengineering.common.blocks.wooden.TileEntityWoodenBarrel.java

@Override
public boolean interact(EnumFacing side, EntityPlayer player, EnumHand hand, ItemStack heldItem, float hitX,
        float hitY, float hitZ) {
    FluidStack f = FluidUtil.getFluidContained(heldItem);
    boolean metal = this instanceof TileEntityMetalBarrel;
    if (f != null)
        if (!metal && f.getFluid().isGaseous(f)) {
            ChatUtils.sendServerNoSpamMessages(player,
                    new TextComponentTranslation(Lib.CHAT_INFO + "noGasAllowed"));
            return true;
        } else if (!metal && f.getFluid().getTemperature(f) >= TileEntityWoodenBarrel.IGNITION_TEMPERATURE) {
            ChatUtils.sendServerNoSpamMessages(player, new TextComponentTranslation(Lib.CHAT_INFO + "tooHot"));
            return true;
        }//from ww  w  .j  a v  a  2  s  . c om

    if (FluidUtil.interactWithFluidHandler(player, hand, tank)) {
        this.markDirty();
        this.markContainingBlockForUpdate(null);
        return true;
    }
    return false;
}

From source file:com.teambrmodding.assistedprogression.common.item.PipetteItem.java

License:Creative Commons License

/**
 * This is called when the item is used, before the block is activated.
 *
 * @return Return PASS to allow vanilla handling, any other to skip normal code.
 *//*from   w  ww .j  av a  2s  .  c o  m*/
@Override
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) {
    if (!context.getWorld().isRemote) {
        if (stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null).isPresent()
                && context.getWorld().getTileEntity(context.getPos()) != null
                && context.getWorld().getTileEntity(context.getPos())
                        .getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, context.getFace())
                        .isPresent()) {
            IFluidHandler fluidTile = context.getWorld().getTileEntity(context.getPos())
                    .getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, context.getFace())
                    .orElse(null);
            if (FluidUtil.interactWithFluidHandler(context.getPlayer(), context.getHand(), fluidTile)) {
                context.getWorld().notifyBlockUpdate(context.getPos(),
                        context.getWorld().getBlockState(context.getPos()),
                        context.getWorld().getBlockState(context.getPos()), 3);
                return ActionResultType.SUCCESS;
            }
        }
    }
    return ActionResultType.PASS;
}

From source file:com.teambrmodding.neotech.common.blocks.machines.BlockMachine.java

License:Creative Commons License

/**
 * Called when the block is clicked on//from www  .j a va  2  s  .  co  m
 * @return True to prevent future logic
 */
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
        EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    // Make sure our machine is reachable
    if (worldIn.getTileEntity(pos) != null && worldIn.getTileEntity(pos) instanceof AbstractMachine) {
        AbstractMachine machine = (AbstractMachine) worldIn.getTileEntity(pos);

        // First interact with fluid handlers
        if (machine.isFluidHandler()) {
            IFluidHandler fluidHandler = machine.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY,
                    null);
            FluidActionResult result = FluidUtil.interactWithFluidHandler(playerIn.getHeldItem(hand),
                    fluidHandler, playerIn);
            if (result.isSuccess()) {
                playerIn.setHeldItem(hand, result.getResult());
                return true;
            }
        }

        // Open a GUI
        if (!playerIn.isSneaking()) {
            playerIn.openGui(Bookshelf.INSTANCE, 0, worldIn, pos.getX(), pos.getY(), pos.getZ());
            return true;
        }
    }
    return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}

From source file:com.teambrmodding.neotech.common.blocks.storage.BlockFluidStorage.java

License:Creative Commons License

/**
 * Called when the block is clicked on/*from  ww  w . j  a va2  s .c om*/
 * @return True to prevent future logic
 */
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
        EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    // Make sure our storage is reachable
    if (worldIn.getTileEntity(pos) != null && worldIn.getTileEntity(pos) instanceof TileBasicTank) {
        TileBasicTank fluidStorage = (TileBasicTank) worldIn.getTileEntity(pos);

        // First interact with fluid handlers
        IFluidHandler fluidHandler = fluidStorage.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY,
                null);
        FluidActionResult result = FluidUtil.interactWithFluidHandler(playerIn.getHeldItem(hand), fluidHandler,
                playerIn);
        if (result.isSuccess()) {
            playerIn.setHeldItem(hand, result.getResult());
            return true;
        }

        // We want to display in chat the current levels
        if (worldIn.isRemote && fluidStorage.tanks[TileBasicTank.TANK].getFluid() != null) {
            FluidStack fluidStack = fluidStorage.tanks[TileBasicTank.TANK].getFluid();
            if (fluidStack.getFluid() != null) {
                String display = fluidStack.getLocalizedName() + ": "
                        + ClientUtils.formatNumber(fluidStorage.tanks[TileBasicTank.TANK].getFluidAmount())
                        + " / "
                        + ClientUtils.formatNumber(fluidStorage.tanks[TileBasicTank.TANK].getCapacity());
                playerIn.sendMessage(new TextComponentString(display));
            }
        }
    }
    return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}

From source file:de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase.java

protected boolean tryUseItemOnTank(EntityPlayer player, EnumHand hand, FluidTank tank) {
    ItemStack heldItem = player.getHeldItem(hand);

    if (StackUtil.isValid(heldItem)) {
        FluidActionResult result = FluidUtil.interactWithFluidHandler(heldItem, tank, player);
        if (result.isSuccess()) {
            player.setHeldItem(hand, result.getResult());
            return true;
        }//from  w  ww  . j  ava2  s  . co m
    }

    return false;
}