Difference between revisions of "JCM:Scripting/Resource Loading"
Views
Actions
Namespaces
Variants
Tools
(Created page with "= 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 excess...") |
|||
Line 20: | Line 20: | ||
== Model Loading == | == Model Loading == | ||
Please note that the current API is somewhat simplistic and does not offer fine-grained control like in MTR 3/NTE. | |||
{| class="wikitable" | |||
!Functions | |||
!Description | |||
|- | |||
|<code>static ModelManager.loadModel(id: Identifier, flipV: boolean): ScriptedModel</code> | |||
|Load an OBJ/bbmodel model from a path and upload to the GPU. | |||
Set flipV to true if your texture is rendered incorrectly. | |||
|} | |||
== Loading AWT Resources == | == Loading AWT Resources == |
Revision as of 14:13, 6 February 2025
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
Please note that the current API is somewhat simplistic and does not offer fine-grained control like in MTR 3/NTE.
Functions | Description |
---|---|
static ModelManager.loadModel(id: Identifier, flipV: boolean): ScriptedModel
|
Load an OBJ/bbmodel model from a path and upload to the GPU.
Set flipV to true if your texture is rendered incorrectly. |
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. |