Mod Library Symbols
This page contains documentation for symbols in the standard library of the JsonPatcher mod. These symbols interact more directly with minecraft than those found in the language stdlib. Unless something is otherwise stated, everything here should be available to all code ran by the mod.
Namespace metapatch
Library metapatch.lib
Location: metapatch
A special library available to metapatch patches. Provides tools to create, query and remove files on a higher level.
Function metapatch.lib.deleteFile
Type: (path: string) -> null
Deletes the file at the specified path.
Function metapatch.lib.deleteFiles
Type: (target: patch.PatchTarget) -> null
Deletes files matching the specified target selector.
The syntax of the selector is the same as is used in the @target
metadata, except that only one target is supported.
Function metapatch.lib.searchFiles
Type: (target: patch.PatchTarget) -> object{}
Searches for files matching the specified target selector.
The syntax of the selector is the same as is used in the @target
metadata, except that only one target is supported.
The returned data is a map of file paths to their contents.
This method is most performant when the target has a path specified, as it allows minecraft to skip ahead when looking for files.
Function metapatch.lib.getFile
Type: (path: string) -> object
Reads the file at the specified path and returns its content as json.
Function metapatch.lib.getFiles
Type: (path: string) -> object[]
Reads the file at the specified path as well as all overriden versions, and returns their contents as json.
Function metapatch.lib.addFile
Type: (path: string, content: object) -> null
Creates a file at the specified path with the specified content, converted to json.
Metadata tag metapatch.metapatch
Type: null
Requires any(libgroup(+minecraft-data), libgroup(+minecraft-assets))
Turns the current script into a metapatch script.
This allows the script to create, query and remove files on a higher level
trough the "metapatch"
library. The library must be imported, unlike on older versions.
Namespace patch
Type patch.ObjectTarget
of object
An object describing an advanced target. All present properties must match for this target to match.
Property patch.ObjectTarget.path
Type: string | patch.TargetPath
This property is optional and may not be present
Either a string to match the path of the file exactly, or an object describing the path as a beginning and end.
Property patch.ObjectTarget.regex
Type: string
This property is optional and may not be present
A regular expression to match the entire path of the file including namespace.
Property patch.ObjectTarget.namespace
Type: string
This property is optional and may not be present
The namespace of the file, matched exactly.
Type alias patch.PatchTarget
= string | ObjectTarget
A single target can be a string or an object.
When set to a string the whole path of the file must match it exactly.
When set to an object, the path is matched against the properties of the object.
See patch.ObjectTarget
for details.
Type patch.TargetPath
of object
An object describing the path of the file as a beginning and end. The beginning is matched against the start of the path, and the end is matched against the end of the path. Both properties must be present and must match exactly.
Property patch.TargetPath.end
Type: string
The end of the path, matched against the end of the path. Can be set to an empty string to always match.
Property patch.TargetPath.begin
Type: string
The beginning of the path, matched against the start of the path. Can be set to an empty string to always match.
Metadata tag patch.target
Type: patch.PatchTarget | patch.PatchTarget[]
Requires any(libgroup(+minecraft-data), libgroup(+minecraft-assets))
Specifies which files a patch modifies. When this metadata is found on scripts loaded from suitable locations, they are loaded as patches and get to modify json files.
Can either be set to a single target, or an array of targets. When set to an array, files are patched when any of the targets match.
Namespace script
Type script.LibraryMetadata
of object
Property script.LibraryMetadata.shared
Type: boolean
This property is optional and may not be present
Metadata tag script.enabled
Type: boolean
The @enabled
metadata tag can be used to disable scripts.
When set to false
, the script will not run at all and in some cases not even parsed.
This is useful for debugging, providing an alternative to commenting out code.
Metadata tag script.init
Type: string
Requires libgroup(+jsonpatcher:global_scripts)
Makes a script execute while the game is loading. Depending on the value, scripts are executed at different points in time:
"main"
: Causes the script to run during mod init."client"
: Causes the script to run during client init.- Any other value is considered invalid
Metadata tag script.library
Type: null | script.LibraryMetadata
Requires libgroup(+jsonpatcher:global_scripts)
Makes a global script available as a library to other global scripts as well as regular patches.
If the global script is loaded from the jsonpatcher/scripts
folder within the minecraftinstance folder,
the library location gains the scripts:global:
prefix. If the script is loaded from within a mod,
it gains the mod:MOD_ID:
prefix, where MOD_ID
is the mod's id. For example mod:jsonpatcher:example
.
This is not applicable to, and won't do anything for, regular patches. They are already always available as libraries to each other.
Metadata tag script.priority
Type: number
Specifies in which order scripts are loaded. Scripts with higher priority run after scripts with lower priority. The default priority is 0.
Note that priority only applies between scripts that are ran for the same reason.
For example, you cannot change the ordering between a "client"
init script and a "main"
init script.