Skip to content

Resourcepack Module

npm versionDownloadsInstall sizenpmBuild Status

Provide function to read resource pack.


Parse ResourcePack Basic Info

Read pack metadata from file:

import { ResourcePack, PackMeta } from "@xmcl/resourcepack"
const fileFullPath = "path/to/pack/";
const pack: PackMeta.Pack = await ResourcePack.readPackMeta(fileFullPath);
// or you want read from folder, same function call
const dirFullPath = "path/to/pack/some-pack";
const fromFolder: PackMeta.Pack = await ResourcePack.readPackMeta(dirFullPath);

// if you have already read the file, don't want to reopen the file
// the file path will be only used for resource pack name
const fileContentBuffer: Buffer;
const fromBuff: PackMeta.Pack = await ResourcePack.readPackMeta(fileFullPath, fileContentBuffer);

Read pack icon:

import { ResourcePack, PackMeta } from "@xmcl/resourcepack"
const fileFullPath = "path/to/pack/";
const pack: Uint8Array = await ResourcePack.readIcon(fileFullPath);

Put them together in efficent way (don't open resource pack again and again):

import { ResourcePack, PackMeta } from "@xmcl/resourcepack"
const fileFullPath = "path/to/pack/";
const res = await;
const pack: PackMeta.Pack = await ResourcePack.readPackMeta(res);
const icon: Uint8Array = await ResourcePack.readIcon(res);

// or

const pack: PackMeta.Pack = await;
const icon: Uint8Array = await res.icon();

Read ResourcePack Content

You can read resource pack content just like Minecraft:

import { ResourcePack, ResourceLocation } from "@xmcl/resourcepack"
const fileFullPath = "path/to/pack/";
const pack: ResourcePack = await;

// this is almost the same with original Minecraft
// this get the dirt texture png -> minecraft:textures/block/dirt.png
const resLocation: ResourceLocation = ResourceLocation.ofTexturePath("block/dirt");

console.log(resLocation); // minecraft:textures/block/dirt.png

const resource: Resource | undefined = await pack.get(resLocation);
if (resource) {
    const binaryContent: Uint8Array = await;
    // this is the metadata for resource, like animated texture metadata.
    const metadata: PackMeta = await resource.readMetadata();

Load Minecraft Block Model

You can use this to load Minecraft block model and texture just like Minecraft.

import { ResourcePack, Resource, BlockModel,ResourceManager, ModelLoader } from "@xmcl/resourcepack"; 
import { openFileSystem } from "@xmcl/system";

const man = new ResourceManager();
const resourcePack = new ResourcePack(await openFileSystem("/path/to/"));
// setup resource pack

const loader = new ModelLoader(man);

await loader.loadModel("block/grass"); // load grass model
await loader.loadModel("block/stone"); // load stone model
// ... load whatever you want model

const textures: Record<string, Resource> = loader.textures;
const models: Record<string, BlockModel.Resolved> = loader.models;

const resolvedModel: BlockModel.Resolved = models["block/grass"];

Load Minecraft Resource

You can use this module in nodejs/electron:

import { openFileSystem } from "@xmcl/system"; 
import { ResourcePack, Resource, ResourceManager, ResourceLocation  } from "@xmcl/resourcepack"; 
const manager: ResourceManager = new ResourceManager();

// add a resource source which load resource from file
await manager.addResourcePack(new ResourcePack(await openFileSystem('/base/path')));

// load grass block model resource; it will load file at `assets/${location.domain}/${location.path}`
// which is '/base/path/assets/minecraft/models/block/grass.json'
// same logic with minecraft
const resource = await manager.get(ResourceLocation.ofModelPath('block/grass'));

const content: string = await"utf-8"); // your resource content
const modelJSON = JSON.parse(content);

The resource manager will do the simplest cache for same resource location.

You can clear the cache by:


🧾 Classes

🤝 Interfaces

🗃️ Namespaces

🏭 Functions


readIcon(resourcePack: string | Uint8Array | FileSystem): Promise<Uint8Array>

Read the resource pack icon png binary.


  • resourcePack: string | Uint8Array | FileSystem The absolute path of the resource pack file, or a buffer, or a opened resource pack.

Return Type

  • Promise<Uint8Array>

Defined in: packages/resourcepack/index.ts:47


readPackMeta(resourcePack: string | Uint8Array | FileSystem): Promise<Pack>

Read the resource pack metadata from zip file or directory.

If you have already read the data of the zip file, you can pass it as the second parameter. The second parameter will be ignored on reading directory.


  • resourcePack: string | Uint8Array | FileSystem The absolute path of the resource pack file, or a buffer, or a opened resource pack.

Return Type

  • Promise<Pack>

Defined in: packages/resourcepack/index.ts:27


readPackMetaAndIcon(resourcePack: string | Uint8Array | FileSystem): Promise<Object>

Read both metadata and icon


  • resourcePack: string | Uint8Array | FileSystem

Return Type

  • Promise<Object>

Defined in: packages/resourcepack/index.ts:62