[go: up one dir, main page]

Skip to content

An NPM package to facilitate importing and viewing of modern Minecraft schematics.

License

Notifications You must be signed in to change notification settings

CyberFlameGO/SchematicWebViewer

 
 

Repository files navigation

SchematicWebViewer

An NPM package to facilitate importing and viewing of modern Minecraft schematics.

Originally by cpdt and was available here.

Usage

This library requires a complete Minecraft resource pack in order to function. This means a resource pack that include all models, blockstates, and textures. As most resource packs only include what they have changed, they do not fit this criteria. Luckily, the Minecraft client jar file is formatted in the same way as a resource pack.

To use this on your site, create a canvas element in your HTML that is able to be queried in the JavaScript.

<canvas id="schematicRenderer" , width="500," height="500"></canvas>
renderSchematic(document.querySelector('#schematicRenderer'), SCHEMATIC_FILE, {
    size: 500,
    renderArrow: false,
    renderBars: false,
    corsBypassUrl: 'https://url-to-cors-anywhere/'
});

The renderSchematic function takes a few options.

The first argument is the canvas element to render to.

The second argument is a schematic file encoded in Base64. The schematic format must be supported by SchematicJS.

The final argument is an options object that allows configuring various settings about how the schematic is rendered. The following properties are on the object,

interface SchematicRenderOptions {
    size?: number; // Force the size of the canvas viewport, if not present use canvas size
    corsBypassUrl: string; // A url of a cors-anywhere instance to allow access to MC server jars
    resourcePacks?: string[]; // A list of resource pack URLs in priority order
    renderBars?: boolean; // Whether a grid should be rendered
    renderArrow?: boolean; // Whether an arrow to show direction should be rendered
    orbit?: boolean; // Whether the view should automatically rotate when not being dragged by the user
    antialias?: boolean; // Whether antialiasing should be enabled
    backgroundColor?: number | 'transparent'; // Background color of the canvas (default: 0xffffff)
}

Notes on Cors-Anywhere

Due to the way this works, it must have access to a Minecraft jar file. As redistribution of this file would be a breach of the license, and Mojang uses CORS on their download site, a cors-anywhere instance must be used to allow access to these jar files.

About

An NPM package to facilitate importing and viewing of modern Minecraft schematics.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 96.4%
  • JavaScript 3.2%
  • HTML 0.4%