FluidActionResult result = FluidUtil.tryEmptyContainerAndStow(heldItem, fluidHandler, playerInventory, Fluid.BUCKET_VOLUME, playerIn); if(result.isSuccess()) { playerIn.setHeldItem(hand, result.getResult());
/** * Attempts to drain the item to an IFluidHandler. * * @param stack The stack to drain from. * @param handler The IFluidHandler to fill. * @param player The player using the item. * @param hand The hand the player is holding the item in. * @return If the interaction was successful. */ public static boolean drainItemToHandler(ItemStack stack, IFluidHandler handler, EntityPlayer player, EnumHand hand) { if (stack.isEmpty() || handler == null || player == null) { return false; } IItemHandler playerInv = new InvWrapper(player.inventory); FluidActionResult result = FluidUtil.tryEmptyContainerAndStow(stack, handler, playerInv, Integer.MAX_VALUE, player); if (result.isSuccess()) { player.setHeldItem(hand, result.getResult()); return true; } return false; }
if (this.origin != null && doAdd) { IItemHandler itemHandler = new InvWrapper(this.origin); fluidActionResult = FluidUtil.tryEmptyContainerAndStow(singleCopy, fluidHandler, itemHandler, Fluid.BUCKET_VOLUME, player, doAdd); if (!fluidActionResult.isSuccess()) { fluidActionResult = FluidUtil.tryFillContainerAndStow(singleCopy, fluidHandler, itemHandler, Fluid.BUCKET_VOLUME, player, doAdd);