List of usage examples for net.minecraftforge.fluids FluidUtil tryFillContainer
@Nonnull public static FluidActionResult tryFillContainer(@Nonnull ItemStack container, IFluidHandler fluidSource, int maxAmount, @Nullable PlayerEntity player, boolean doFill)
From source file:com.buuz135.industrial.tile.block.BlackHoleTankBlock.java
License:Open Source License
@Override public boolean onBlockActivated(@Nullable World worldIn, @Nullable BlockPos pos, @Nullable IBlockState state, @Nullable EntityPlayer playerIn, @Nullable EnumHand hand, @Nullable EnumFacing facing, float hitX, float hitY, float hitZ) { if (playerIn != null && hand != null && worldIn != null && pos != null) { ItemStack stack = playerIn.getHeldItem(hand); if (!stack.isEmpty() && stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null) && worldIn.getTileEntity(pos) instanceof BlackHoleTankTile) { BlackHoleTankTile tile = (BlackHoleTankTile) worldIn.getTileEntity(pos); FluidActionResult result = FluidUtil.tryFillContainer(stack, (IFluidHandler) tile.getTank(), Integer.MAX_VALUE, playerIn, true); if (result.isSuccess()) { stack.shrink(1);/*from w w w. j a v a 2 s. c om*/ if (stack.isEmpty()) { playerIn.setHeldItem(hand, result.result); } else { playerIn.addItemStackToInventory(result.result); } return true; } } } return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ); }
From source file:com.buuz135.industrial.utils.ItemStackUtils.java
License:Open Source License
public static void fillItemFromTank(ItemStackHandler fluidItems, IFluidTank tank) { if (tank.getFluid() == null) return;//from w ww . j a v a 2s .c o m ItemStack stack = fluidItems.getStackInSlot(0).copy(); if (!stack.isEmpty()) { if (stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) { FluidActionResult result = FluidUtil.tryFillContainer(stack, (IFluidHandler) tank, tank.getCapacity(), null, false); if (result.isSuccess() && (fluidItems.getStackInSlot(1).isEmpty() || (ItemHandlerHelper.canItemStacksStack(result.getResult(), fluidItems.getStackInSlot(1)) && result.getResult().getCount() + fluidItems.getStackInSlot(1).getCount() <= result .getResult().getMaxStackSize()))) { result = FluidUtil.tryFillContainer(stack, (IFluidHandler) tank, tank.getCapacity(), null, true); if (fluidItems.getStackInSlot(1).isEmpty()) { fluidItems.setStackInSlot(1, result.getResult()); } else { fluidItems.getStackInSlot(1).grow(1); } fluidItems.getStackInSlot(0).shrink(1); } } } }
From source file:com.elytradev.thermionics.transport.FluidTransport.java
License:Open Source License
public static FluidActionResult tryEmptyOrFillContainer(ItemStack stack, IFluidHandler handler, int maxTransfer, EntityPlayer player) {//w ww . j a va 2s .c om FluidActionResult result = FluidUtil.tryEmptyContainer(stack, handler, maxTransfer, player, true); if (result.success) { return result; } else { FluidActionResult resultFill = FluidUtil.tryFillContainer(stack, handler, maxTransfer, player, true); return resultFill; } }
From source file:com.teambrmodding.neotech.common.blocks.storage.BlockFluidStorage.java
License:Creative Commons License
/** * Called when the block is broken, allows us to drop items from inventory * @param worldIn The world//w ww . j a v a2 s .c o m * @param pos The pos * @param state The state */ @Override public boolean removedByPlayer(IBlockState state, World worldIn, BlockPos pos, EntityPlayer player, boolean willHarvest) { if (!worldIn.isRemote && worldIn.getTileEntity(pos) instanceof TileBasicTank) { TileBasicTank savableTile = (TileBasicTank) worldIn.getTileEntity(pos); ItemStack stack = FluidUtil.tryFillContainer(getStackDroppedByWrench(worldIn, pos), savableTile, savableTile.tanks[TileBasicTank.TANK].getCapacity(), null, true).getResult(); if (stack == null) stack = getStackDroppedByWrench(worldIn, pos); WorldUtils.dropStack(worldIn, stack, pos); worldIn.removeTileEntity(pos); // Cancel drop logic worldIn.setBlockToAir(pos); return true; } return false; }