本文整理汇总了Java中net.minecraftforge.fluids.FluidUtil.tryFillContainer方法的典型用法代码示例。如果您正苦于以下问题:Java FluidUtil.tryFillContainer方法的具体用法?Java FluidUtil.tryFillContainer怎么用?Java FluidUtil.tryFillContainer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.fluids.FluidUtil
的用法示例。
在下文中一共展示了FluidUtil.tryFillContainer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onBlockActivated
import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
@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);
}
示例2: tryFluidExtraction
import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
/**
* Attempt to extract fluid from the given fluid handler into the given fluid-containing item.
*
* @param srcHandler fluid handler into which to place the fluid
* @param destStack the fluid container item to extract from
* @param returnedItems the modified fluid container after extraction
* @return true if any fluid was moved, false otherwise
*/
public static boolean tryFluidExtraction(IFluidHandler srcHandler, ItemStack destStack, NonNullList<ItemStack> returnedItems) {
FluidActionResult result = FluidUtil.tryFillContainer(destStack, srcHandler, 1000, null, true);
if (result.isSuccess()) {
returnedItems.add(result.getResult());
destStack.shrink(1);
return true;
} else {
return false;
}
}
示例3: tryEmptyOrFillContainer
import net.minecraftforge.fluids.FluidUtil; //导入方法依赖的package包/类
public static FluidActionResult tryEmptyOrFillContainer(ItemStack stack, IFluidHandler handler, int maxTransfer, EntityPlayer player) {
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;
}
}