npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@xmcl/resourcepack

v1.2.3

Published

A Minecraft resource pack parser

Downloads

300

Readme

Resourcepack Module

npm version Downloads Install size npm Build Status

Provide function to read resource pack.

Usage

Parse ResourcePack Basic Info

Read pack metadata from file:

import { ResourcePack, PackMeta } from "@xmcl/resourcepack"
const fileFullPath = "path/to/pack/some-pack.zip";
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/some-pack.zip";
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/some-pack.zip";
const res = await ResourcePack.open(fileFullPath);
const pack: PackMeta.Pack = await ResourcePack.readPackMeta(res);
const icon: Uint8Array = await ResourcePack.readIcon(res);

// or

const pack: PackMeta.Pack = await res.info();
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/some-pack.zip";
const pack: ResourcePack = await ResourcePack.open(fileFullPath);

// 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 resource.read();
    // 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/resource-pack.zip"));
// setup resource pack
man.addResourcePack(resourcePack);

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 resource.read("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:

manager.clearCache();