Java Code Examples for net.minecraftforge.fluids.FluidUtil#tryFillContainer()

The following examples show how to use net.minecraftforge.fluids.FluidUtil#tryFillContainer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GTHelperFluid.java    From GT-Classic with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static boolean doClickableFluidContainerFillThings(EntityPlayer player, EnumHand hand, World world,
		BlockPos pos, IC2Tank tank) {
	ItemStack playerStack = player.getHeldItem(hand);
	if (!playerStack.isEmpty()) {
		FluidActionResult result = FluidUtil.tryFillContainer(playerStack, tank, tank.getCapacity(), player, true);
		if (result.isSuccess()) {
			playerStack.shrink(1);
			ItemStack resultStack = result.getResult();
			if (!resultStack.isEmpty()) {
				if (!player.inventory.addItemStackToInventory(resultStack)) {
					player.dropItem(resultStack, false);
				}
			}
			return true;
		}
	}
	return false;
}
 
Example 2
Source File: BlockBTank.java    From BetterChests with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
	ItemStack original = player.getHeldItem(hand);
	if (!original.isEmpty()) {
		ItemStack stack = original.copy();
		stack.setCount(1);
		TileEntity tank = getTileEntity(world, pos);
		if (tank instanceof TileEntityBTank) {
			IFluidHandler handler = ((TileEntityBTank) tank).getFluidHandler();
			FluidActionResult result = FluidUtil.tryEmptyContainer(stack, handler, Fluid.BUCKET_VOLUME, player, true);
			if (!result.success) {
				result = FluidUtil.tryFillContainer(stack, handler, Fluid.BUCKET_VOLUME, player, true);
			}
			if (result.success) {
				original.setCount(original.getCount() - 1);
				stack = InvUtil.putStackInInventory(result.result, player.inventory, true, false, false, null);
				if (!stack.isEmpty()) {
					WorldUtil.dropItemsRandom(world, stack, player.getPosition());
				}
				return true;
			}
		}
	}
	return super.onBlockActivated(world, pos, state, player, hand, facing, hitX, hitY, hitZ);
}
 
Example 3
Source File: MetaTileEntity.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean fillContainerFromInternalTank(IItemHandlerModifiable importItems, IItemHandlerModifiable exportItems, int inputSlot, int outputSlot) {
    ItemStack emptyContainer = importItems.extractItem(inputSlot, 1, true);
    FluidActionResult result = FluidUtil.tryFillContainer(emptyContainer, exportFluids, Integer.MAX_VALUE, null, false);
    if (result.isSuccess()) {
        ItemStack remainingItem = result.getResult();
        if (!remainingItem.isEmpty() && !exportItems.insertItem(outputSlot, remainingItem, true).isEmpty())
            return false;
        FluidUtil.tryFillContainer(emptyContainer, exportFluids, Integer.MAX_VALUE, null, true);
        importItems.extractItem(inputSlot, 1, false);
        exportItems.insertItem(outputSlot, remainingItem, false);
        return true;
    }
    return false;
}