UNPKG

@xmcl/resourcepack

Version:
120 lines 4.11 kB
/** * The resource pack module to read Minecraft resource pack just like Minecraft in-game. * * You can open the ResourcePack by {@link ResourcePack.open} and get resource by {@link ResourcePack.get}. * * Or you can just load resource pack metadata by {@link readPackMetaAndIcon}. * * @packageDocumentation */ import { FileSystem } from '@xmcl/system'; import { PackMeta } from './format'; /** * The Minecraft used object to map the game resource location. */ export declare class ResourceLocation { readonly domain: string; readonly path: string; static deconstruct(path: string, appendPath?: string): ResourceLocation; /** * build from texture path */ static ofTexturePath(location: string | ResourceLocation): ResourceLocation; /** * build from model path */ static ofBlockModelPath(location: string | ResourceLocation): ResourceLocation; static ofItemModelPath(location: string | ResourceLocation): ResourceLocation; static ofModelPath(location: string | ResourceLocation): ResourceLocation; /** * build from block state path */ static ofBlockStatePath(location: string | ResourceLocation): ResourceLocation; /** * from absoluted path */ static fromPath(location: string | ResourceLocation): ResourceLocation; static getAssetsPath(location: string | ResourceLocation): string; constructor(domain: string, path: string); toString(): string; } /** * The resource in the resource pack on a `ResourceLocation` * @see {@link ResourceLocation} */ export interface Resource { /** * The absolute location of the resource */ readonly location: ResourceLocation; /** * The real resource url which is used for reading the content of it. */ readonly url: string; /** * Read the resource content */ read(): Promise<Uint8Array>; read(encoding: undefined): Promise<Uint8Array>; read(encoding: 'utf-8' | 'base64'): Promise<string>; read(encoding?: 'utf-8' | 'base64'): Promise<Uint8Array | string>; /** * Read the metadata of the resource */ readMetadata(): Promise<PackMeta>; } /** * The Minecraft resource pack. Providing the loading resource from `ResourceLocation` function. * It's a wrap of `FileSystem` which provides cross node/browser accssing. * * @see {@link ResourceLocation} * @see {@link FileSystem} */ export declare class ResourcePack { readonly fs: FileSystem; constructor(fs: FileSystem); /** * Load the resource content * @param location The resource location * @param type The output type of the resource */ load(location: ResourceLocation, type?: 'utf-8' | 'base64'): Promise<Uint8Array | string | undefined>; /** * Load the resource metadata which is localted at <resource-path>.mcmeta */ loadMetadata(location: ResourceLocation): Promise<any>; /** * Get the url of the resource location. * Please notice that this is depended on `FileSystem` implementation of the `getUrl`. * * @returns The absolute url like `file://` or `http://` depending on underlaying `FileSystem`. * @see {@link FileSystem} */ getUrl(location: ResourceLocation): string; /** * Get the resource on the resource location. * * It can be undefined if there is no resource at that location. * @param location THe resource location */ get(location: ResourceLocation): Promise<Resource | undefined>; /** * Does the resource pack has the resource */ has(location: ResourceLocation): Promise<boolean>; /** * The owned domain. You can think about the modids. */ domains(): Promise<string[]>; /** * The pack info, just like resource pack */ info(): Promise<PackMeta.Pack>; /** * The icon of the resource pack */ icon(): Promise<Uint8Array>; private getPath; static open(resourcePack: string | Uint8Array | FileSystem): Promise<ResourcePack>; } //# sourceMappingURL=resourcePack.d.ts.map