How to use @xmcl/resourcepack - 3 common examples

To help you get started, we’ve selected a few @xmcl/resourcepack examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Voxelum / minecraft-launcher-core-node / packages / resource-manager / model-loader.ts View on Github external
async loadModel(modelPath: string): Promise {
        const res = await this.manager.load(ResourceLocation.ofModelPath(modelPath));
        if (!res) { throw new Error(`Model ${modelPath} (${ResourceLocation.ofModelPath(modelPath)}) not found`); }
        const raw = JSON.parse(System.bufferToText(res.content)) as BlockModel;

        if (!raw.textures) { raw.textures = {}; }

        if (raw.parent) {
            const parentModel = await this.loadModel(raw.parent);
            if (!parentModel) { throw new Error(`Missing parent model ${raw.parent} for ${location.toString()}`); }
            if (!raw.elements) { raw.elements = parentModel.elements; }
            if (!raw.ambientocclusion) { raw.ambientocclusion = parentModel.ambientocclusion; }
            if (!raw.display) { raw.display = parentModel.display; }
            if (!raw.overrides) { raw.overrides = parentModel.overrides; }

            if (parentModel.textures) { Object.assign(raw.textures, parentModel.textures); }
        }
github Voxelum / minecraft-launcher-core-node / packages / resource-manager / model-loader.ts View on Github external
async loadModel(modelPath: string): Promise {
        const res = await this.manager.load(ResourceLocation.ofModelPath(modelPath));
        if (!res) { throw new Error(`Model ${modelPath} (${ResourceLocation.ofModelPath(modelPath)}) not found`); }
        const raw = JSON.parse(System.bufferToText(res.content)) as BlockModel;

        if (!raw.textures) { raw.textures = {}; }

        if (raw.parent) {
            const parentModel = await this.loadModel(raw.parent);
            if (!parentModel) { throw new Error(`Missing parent model ${raw.parent} for ${location.toString()}`); }
            if (!raw.elements) { raw.elements = parentModel.elements; }
            if (!raw.ambientocclusion) { raw.ambientocclusion = parentModel.ambientocclusion; }
            if (!raw.display) { raw.display = parentModel.display; }
            if (!raw.overrides) { raw.overrides = parentModel.overrides; }

            if (parentModel.textures) { Object.assign(raw.textures, parentModel.textures); }
        }

        raw.ambientocclusion = raw.ambientocclusion || false;
github Voxelum / minecraft-launcher-core-node / packages / resource-manager / model-loader.ts View on Github external
if (parentModel.textures) { Object.assign(raw.textures, parentModel.textures); }
        }

        raw.ambientocclusion = raw.ambientocclusion || false;
        raw.overrides = raw.overrides || [];

        delete raw.parent;

        const model: BlockModel.Resolved = raw as any;
        this.models[modelPath] = model;

        const reg = this.textures;
        for (const variant of Object.keys(model.textures)) {
            const texPath = ModelLoader.findRealTexturePath(model, variant);
            if (texPath) {
                const load = await this.manager.load(ResourceLocation.ofTexturePath(texPath));
                if (load) {
                    reg[texPath] = load;
                }
            }
        }
        return model;
    }
}

@xmcl/resourcepack

A Minecraft resource pack parser

MIT
Latest version published 12 months ago

Package Health Score

59 / 100
Full package analysis