JCM:Scripting:Documentation:Resource Loading
Views
Actions
Namespaces
Variants
Tools
Resource Loading
NTE/JCM provides several methods for controlling the loading and retrieval of resources within resource packs in JavaScript scripts.
Code written in the top-level space outside of functions will be executed when a resource pack is loaded and can be used to initialize resources such as models, textures, etc. Resources that should not be different for each train (such as models and such) are recommended to be stored in global variables to avoid excessive memory usage when loading a copy of the same content for each train.
Identifier (ResourceLocation)
Minecraft uses a Identifier to identify files in a resource pack. Many but not all functions only accept Identifier
paths rather than strings. To create a Identifier
, you can use the following functions:
Functions | Description |
---|---|
static Resources.id(idStr: string): Identifier
|
Converts the string to the appropriate Identifier
e.g. |
static Resources.idr(relPath: string): Identifier
|
Converts the string to Identifier relative to the directory that the currently executed script are located in
e.g. |
Model Loading
Model loading is not implemented in JCM for now.
Loading AWT Resources
These functions load the resources used to draw dynamic textures via the Java AWT.
Functions | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
static Resources.getSystemFont(name: string): Font
|
Get a system or MTR built-in font.
| ||||||||||||
static Resources.readFont(path: Identifier): Font
|
| ||||||||||||
static Resources.readBufferedImage(path: Identifier): BufferedImage
|
Loads an image file as an AWT BufferedImage. | ||||||||||||
static Resources.getFontRenderContext(): FontRenderContext
|
Get an AWT FontRenderContext. |
Reading resource files
Functions | Description |
---|---|
static Resources.readString(location: Identifier): string?
|
Reads the contents of a resource file as a string. Returns null if reading fails. |