Java 类net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper 实例源码

项目:CustomWorldGen    文件:FluidUtil.java   
/**
 * Helper method to get an IFluidHandler for at a block position.
 *
 * Returns null if there is no valid fluid handler.
 */
@Nullable
public static IFluidHandler getFluidHandler(World world, BlockPos blockPos, @Nullable EnumFacing side)
{
    IBlockState state = world.getBlockState(blockPos);
    Block block = state.getBlock();

    if (block.hasTileEntity(state))
    {
        TileEntity tileEntity = world.getTileEntity(blockPos);
        if (tileEntity != null && tileEntity.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side))
        {
            return tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
        }
    }
    else if (block instanceof IFluidBlock)
    {
        return new FluidBlockWrapper((IFluidBlock) block, world, blockPos);
    }
    else if (block instanceof BlockLiquid)
    {
        return new BlockLiquidWrapper((BlockLiquid) block, world, blockPos);
    }

    return null;
}
项目:BetterWithAddons    文件:TileEntityAqueductWater.java   
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
    if(capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY)
        return (T)new FluidBlockWrapper(ModBlocks.aqueductWater, world, pos);

    return super.getCapability(capability, facing);
}