API reference / @jsprismarine/script-host / host/pack
host/pack
Interfaces
ScriptConfig
Defined in: script-host/src/host/pack.ts:185
The configuration of every script module, read from a BDS config/ folder.
Methods
module()
module(
moduleUuid):ScriptModuleConfig
Defined in: script-host/src/host/pack.ts:187
What applies to the script module with this UUID.
Parameters
moduleUuid
string
Returns
reload()?
optionalreload():ScriptConfig
Defined in: script-host/src/host/pack.ts:192
Reads the folder again, as @minecraft/server-admin's reloadScriptingConfig asks. Left out, a reload keeps what was read.
Returns
ScriptModuleConfig
Defined in: script-host/src/host/pack.ts:175
What config/ says about one script module.
Properties
allowedModules
readonlyallowedModules: readonlystring[]
Defined in: script-host/src/host/pack.ts:177
allowed_modules from permissions.json.
secrets
readonlysecrets:Readonly<Record<string,string>>
Defined in: script-host/src/host/pack.ts:181
secrets.json, which @minecraft/server-admin's secrets reads.
variables
readonlyvariables:Readonly<Record<string,unknown>>
Defined in: script-host/src/host/pack.ts:179
variables.json, which @minecraft/server-admin's variables reads.
ScriptPack
Defined in: script-host/src/host/pack.ts:15
A behavior pack whose manifest has a script module.
Properties
dependencies
readonlydependencies: readonlyModuleDependency[]
Defined in: script-host/src/host/pack.ts:29
The native modules the manifest declares, such as @minecraft/server.
directory
readonlydirectory:string
Defined in: script-host/src/host/pack.ts:17
The pack's directory.
entry
readonlyentry:string
Defined in: script-host/src/host/pack.ts:27
The script module's entry, relative to the pack, such as scripts/main.js.
moduleUuid
readonlymoduleUuid:string
Defined in: script-host/src/host/pack.ts:25
The script module's UUID, which names its folder under config/.
name
readonlyname:string
Defined in: script-host/src/host/pack.ts:19
The header name, which BDS's content log names the pack by.
uuid
readonlyuuid:string
Defined in: script-host/src/host/pack.ts:23
The header UUID.
version
readonlyversion:string
Defined in: script-host/src/host/pack.ts:21
The header version, such as 1.0.0.
Variables
DEFAULT_ALLOWED_MODULES
constDEFAULT_ALLOWED_MODULES: readonlystring[]
Defined in: script-host/src/host/pack.ts:165
The modules a world may use when its config/default/permissions.json is missing: the list that file holds in the pinned BDS archive.
Functions
packLabel()
packLabel(
pack):string
Defined in: script-host/src/host/pack.ts:33
How BDS's resolution messages name a pack: its header name and version, such as my pack - 1.0.0.
Parameters
pack
Returns
string
packModulePath()
packModulePath(
pack,base,specifier):string
Defined in: script-host/src/host/pack.ts:137
The path of a pack's file that a script's import reaches, as BDS resolves it, with / between folders. A specifier that starts with . is read from the importing module's folder, and any other from the pack's scripts folder, so items/item.handler imported anywhere is scripts/items/item.handler.js. A path that names no file gains .js when that names one, as ./close_open_vent reaches close_open_vent.js. Every spelling of a file gives the same path, so the file is one module however it is imported.
Parameters
pack
The pack the importing module belongs to.
base
string
The importing module's path in the pack.
specifier
string
The specifier as the import wrote it, which does not start with @.
Returns
string
The path, which names no file when the import reaches none.
packScripts()
packScripts(
pack):Map<string,string>
Defined in: script-host/src/host/pack.ts:149
Every JavaScript file of a pack's scripts folder, by its path relative to the pack.
Parameters
pack
Returns
Map<string, string>
readPackBytes()
readPackBytes(
pack,path):Uint8Array<ArrayBufferLike> |undefined
Defined in: script-host/src/host/pack.ts:108
Reads a binary file of a pack, such as a GameTest's .mcstructure, under the same rule as readPackFile.
Parameters
pack
path
string
Returns
Uint8Array<ArrayBufferLike> | undefined
Undefined when the file is missing or outside the pack.
readPackFile()
readPackFile(
pack,path):string|undefined
Defined in: script-host/src/host/pack.ts:98
Reads a file of a pack, by its path relative to the pack. A symbolic link counts by where it points, so a link to a file outside the pack reads nothing.
Parameters
pack
path
string
Returns
string | undefined
Its text, or undefined when it does not exist or the path leaves the pack.
readScriptConfig()
readScriptConfig(
directory,warn?):ScriptConfig
Defined in: script-host/src/host/pack.ts:232
Reads a BDS config/ folder: default/ for every pack, and a folder named after a script module's UUID for that module. A file in a module's folder replaces the same file in default/, as the config-permissions scenario of the parity suite records BDS doing for permissions.json; BDS documents no merge for the other two files either.
Parameters
directory
string | undefined
The config/ folder, or undefined for a server without one.
warn?
(message) => void
Where BDS's warnings about the files go, such as a secret that is not a string.
Returns
Throws
When a file there is not a JSON object.
readScriptPack()
readScriptPack(
directory):ScriptPack|undefined
Defined in: script-host/src/host/pack.ts:47
Reads a behavior pack's manifest.
Parameters
directory
string
The pack's directory, holding manifest.json.
Returns
ScriptPack | undefined
The pack, or undefined when it has no manifest or no script module with an entry.
Throws
When the manifest is not JSON, or its header lacks a name, a UUID or a version.