Package Exports
- @xmcl/resource-manager
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@xmcl/resource-manager) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Resource Manager
Usage
Load Minecraft Resource
You can use this module in nodejs/electron:
import { openFileSystem } from "@xmcl/system";
import { ResourcePack, Resource } from "@xmcl/resourcepack";
import { ResourceManager, ResourceLocation } from "@xmcl/resource-manager"
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();Load Minecraft Block Model
You can use this to load Minecraft block model and texture just like Minecraft.
import { ResourcePack, Resource, BlockModel } from "@xmcl/resourcepack";
import { ResourceManager, ModelLoader } from "@xmcl/resource-manager";
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"];