@mizius/minecraft 0.0.0-stage → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +159 -3
- package/artifacts/minecraft-control-1.21.10.jar +0 -0
- package/artifacts/minecraft-control-1.21.11.jar +0 -0
- package/artifacts/minecraft-control-1.21.4.jar +0 -0
- package/artifacts/minecraft-control-1.21.5.jar +0 -0
- package/artifacts/minecraft-control-1.21.6.jar +0 -0
- package/artifacts/minecraft-control-1.21.7.jar +0 -0
- package/artifacts/minecraft-control-1.21.8.jar +0 -0
- package/artifacts/minecraft-control-1.21.9.jar +0 -0
- package/artifacts/minecraft-control-26.1.1.jar +0 -0
- package/artifacts/minecraft-control-26.1.2.jar +0 -0
- package/artifacts/minecraft-control-26.1.jar +0 -0
- package/artifacts/minecraft-control-26.2.jar +0 -0
- package/artifacts/minecraft-control-26.3.jar +0 -0
- package/compatibility.json +109 -0
- package/dist/core.js +70 -0
- package/dist/download.js +99 -0
- package/dist/index.js +302 -0
- package/dist/install.js +360 -0
- package/dist/launch.js +165 -0
- package/dist/process.js +149 -0
- package/dist/update.js +376 -0
- package/package.json +40 -4
- package/skills/minecraft/SKILL.md +64 -0
package/README.md
CHANGED
|
@@ -1,3 +1,159 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# @mizius/minecraft
|
|
2
|
+
|
|
3
|
+
`@mizius/minecraft` is a Windows or Linux x64 command line tool for launching and controlling an isolated Minecraft Java client. It installs Minecraft, Fabric Loader, Java, and the bundled control mod into a managed directory. The CLI sends commands to the running game over loopback.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Windows or Linux x64.
|
|
8
|
+
- Node.js 22 or newer.
|
|
9
|
+
- A network connection on first launch to download Minecraft, Fabric Loader, Java, libraries, and assets.
|
|
10
|
+
|
|
11
|
+
The CLI starts an offline profile. It does not sign in to a Microsoft account. Multiplayer servers and Realms that require an authenticated account will reject this profile. Local single player works without account authentication. The cached client can start without a network connection after its required files have downloaded. Each new `minecraft launch` checks GitHub for a CLI update for up to five seconds. If GitHub is unavailable, launch continues with the installed version.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
Download `minecraft.tgz` from the [latest GitHub release](https://github.com/miziusLabs/Minecraft/releases/latest). Open a terminal in the download directory and install the package globally with npm.
|
|
16
|
+
|
|
17
|
+
```powershell
|
|
18
|
+
npm install --global ./minecraft.tgz
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Run `minecraft update` to install the latest stable CLI release now. The CLI also installs new releases automatically before starting a new Minecraft client, then resumes the launch command. Automatic update failures leave the installed CLI in place and do not block a launch. No npm account or GitHub token is required for a public GitHub release.
|
|
22
|
+
|
|
23
|
+
```powershell
|
|
24
|
+
minecraft update
|
|
25
|
+
minecraft update --json
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The update command reports the previous and installed package versions and whether it installed an update. Self-updates require the global npm installation shown above.
|
|
29
|
+
|
|
30
|
+
List supported versions and the current default.
|
|
31
|
+
|
|
32
|
+
```powershell
|
|
33
|
+
minecraft versions --json
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Launch the default version, 26.3.
|
|
37
|
+
|
|
38
|
+
```powershell
|
|
39
|
+
minecraft launch --username Agent --json
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Select 26.2 explicitly.
|
|
43
|
+
|
|
44
|
+
```powershell
|
|
45
|
+
minecraft launch 26.2 --username Agent
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The launch command waits for the local command endpoint and returns the client process, instance directory, log path, and port. Use `minecraft status --json` to inspect the running client. Use `minecraft stop` to stop it before switching versions.
|
|
49
|
+
|
|
50
|
+
The bundled mod supports every stable Minecraft Java release from 1.21.4 through 26.3. This includes 1.21.4 through 1.21.11 and 26.1, 26.1.1, 26.1.2, 26.2, and 26.3. The CLI accepts only versions listed by `minecraft versions`.
|
|
51
|
+
|
|
52
|
+
Launch Minecraft 1.21.4 explicitly.
|
|
53
|
+
|
|
54
|
+
```powershell
|
|
55
|
+
minecraft launch 1.21.4 --username Agent
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Control the game
|
|
59
|
+
|
|
60
|
+
Run a CLI command after launch. Every command returns JSON, and `--json` prints compact JSON for agent use.
|
|
61
|
+
|
|
62
|
+
```powershell
|
|
63
|
+
minecraft control state --json
|
|
64
|
+
minecraft control screenshot --output .\screen.png
|
|
65
|
+
minecraft control record start --json
|
|
66
|
+
minecraft control record stop --json
|
|
67
|
+
minecraft control join localhost:25565
|
|
68
|
+
minecraft control click 640 360 --button left
|
|
69
|
+
minecraft control key W --action hold
|
|
70
|
+
minecraft control key W --action release
|
|
71
|
+
minecraft control type "hello"
|
|
72
|
+
minecraft control logs warn --limit 20
|
|
73
|
+
minecraft control batch '[{"command":"key","arguments":{"key":"W","action":"hold"},"delay_ms":1000},{"command":"key","arguments":{"key":"W","action":"release"}]'
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`minecraft control state` reports the current screen, connection, window dimensions, held inputs, player position, and recording state. `minecraft control screenshot` saves a PNG in the current directory. By default it uses a timestamped filename. Use `--output` to select a path.
|
|
77
|
+
|
|
78
|
+
`minecraft control record start` begins a silent MP4 recording of the game view. It records at 10 FPS by default, accepts `--fps` from 1 to 20, and scales output to fit within 1280 by 720 pixels. `minecraft control record stop` finalizes the recording. Both commands return the file path as JSON. Recordings are saved in the current Minecraft instance's `recordings` directory and stop automatically after ten minutes. If encoding falls behind, the recorder drops frames and the video plays shorter than the elapsed recording time. The stop response reports `dropped_frames`, the video's `duration_ms`, and wall-clock `elapsed_ms`.
|
|
79
|
+
|
|
80
|
+
`minecraft stop` finalizes an active recording before closing the client.
|
|
81
|
+
|
|
82
|
+
Coordinates use screenshot pixels with the origin at the top left. `minecraft control click` accepts `left`, `right`, or `middle`. Keys accept GLFW names such as `W`, `LEFT_SHIFT`, `ENTER`, and `ESCAPE`, or a numeric GLFW code. A key press releases after a short tap. Use `--action hold` and `--action release` for sustained movement. Held keys and buttons expire after 30 seconds without a game command.
|
|
83
|
+
|
|
84
|
+
Use `minecraft control execute <command>` only when the connected server grants the required permission. Use `minecraft control logs [query]` to read recent client log lines. A query matches a case-insensitive literal substring. `minecraft control batch` accepts a JSON array of commands and runs them in order without interleaving other controls. Recording commands cannot be included in a batch.
|
|
85
|
+
|
|
86
|
+
Run `minecraft --help` for all commands and options. Agents call these commands through their shell without a separate host configuration.
|
|
87
|
+
|
|
88
|
+
## Managed files and settings
|
|
89
|
+
|
|
90
|
+
On Windows, the CLI stores downloaded files, per-version instances, logs, and process state under `%LOCALAPPDATA%\mizius\Minecraft`. Set `mizius_minecraft_home` to use a different root. Each Minecraft version gets a separate instance directory.
|
|
91
|
+
|
|
92
|
+
The CLI creates settings only when an instance has no `options.txt`. It opens a 1280 by 720 window with GUI scale 2 and FOV 90. Sprint uses R. Master volume is muted, and pause on focus loss is disabled. The CLI leaves existing `options.txt` files in place.
|
|
93
|
+
|
|
94
|
+
Graphics use the Custom preset, with clouds, ambient occlusion, and entity shadows off. Render distance is 8 chunks, simulation distance is 5 chunks, and the frame rate is capped at 60 FPS. Java uses a 4 GB maximum heap.
|
|
95
|
+
|
|
96
|
+
The default command port is 8765. If another program uses it, leave that program running and choose a free port with `--port`.
|
|
97
|
+
|
|
98
|
+
```powershell
|
|
99
|
+
minecraft launch --username Agent --port 18766
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The CLI reserves loopback TCP port 18765 while it installs, starts, or stops a client to serialize lifecycle operations across managed directories. Keep that port free. Do not use it as the command port.
|
|
103
|
+
|
|
104
|
+
Set `MINECRAFT_CONTROL_TOKEN` in the environment to require bearer-token authorization on the local command endpoint. The CLI sends the token automatically.
|
|
105
|
+
|
|
106
|
+
## Development
|
|
107
|
+
|
|
108
|
+
From the `cli` directory, install dependencies and compile the TypeScript.
|
|
109
|
+
|
|
110
|
+
```powershell
|
|
111
|
+
npm install
|
|
112
|
+
npm run build
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
The CLI sources and tests live here. The Fabric mod and its Gradle wrapper live in `../mod`. The agent skill source lives in `../skills/minecraft/SKILL.md`. `npm run build` compiles the CLI and copies the skill into the package staging directory `skills/minecraft`.
|
|
116
|
+
|
|
117
|
+
`npm pack` builds the CLI and the Gradle project in `../mod`. It creates one mod JAR for each supported Minecraft version, then updates their SHA-256 values in `compatibility.json`. Minecraft 1.21.x uses Java 21. Minecraft 26.x uses Java 25. The package includes the compiled CLI, all 13 mod JARs, the compatibility manifest, README, and skill. It has no `preinstall`, `install`, or `prepare` hook. Installing the package does not download Minecraft or start the game. The CLI checks for updates only when `minecraft update` or `minecraft launch` runs.
|
|
118
|
+
|
|
119
|
+
Run the CLI test suite with `npm test`.
|
|
120
|
+
|
|
121
|
+
## Publishing
|
|
122
|
+
|
|
123
|
+
The `release.yml` workflow runs on pushes to `main` and supports manual runs on `main` through GitHub Actions. It compares the version in the repository's `project.properties` file with the latest published GitHub release. A newer stable version triggers a build. If there is no release yet, it publishes the first stable version. Equal versions, older versions, and prerelease versions skip the build. Release lookup errors fail the workflow.
|
|
124
|
+
|
|
125
|
+
Update the `version` property in `../project.properties`. Sync the CLI package metadata before installing dependencies. The build command also syncs it automatically.
|
|
126
|
+
|
|
127
|
+
```powershell
|
|
128
|
+
node scripts/sync-version.mjs
|
|
129
|
+
npm ci
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Commit `project.properties`, `package.json`, and `package-lock.json`, then merge into `main`.
|
|
133
|
+
|
|
134
|
+
When a release is needed, the workflow runs the Windows CLI tests, packages the CLI, and checks installation. Packaging builds the mod JAR that the CLI bundles. After checks pass, it creates the tag `v<version>` at the tested commit and attaches the tested `minecraft.tgz` archive without rebuilding it. Release notes list merged pull request titles under `## Changes`. When GitHub has no merged pull request notes, they list commit subjects since the previous release tag. They omit contributor names and URLs. Existing release tags must not be reused.
|
|
135
|
+
|
|
136
|
+
Publishing uses the workflow's built-in `GITHUB_TOKEN` with `contents: write`. The repository must allow that permission and tag creation. The public repository lets users download release assets without authentication.
|
|
137
|
+
|
|
138
|
+
## Linux setup
|
|
139
|
+
|
|
140
|
+
On Linux, managed data defaults to `$XDG_DATA_HOME/mizius/Minecraft`, or
|
|
141
|
+
`~/.local/share/mizius/Minecraft` when `XDG_DATA_HOME` is unset. The
|
|
142
|
+
`mizius_minecraft_home` override works on both platforms. Linux requires glibc,
|
|
143
|
+
an X11 or Wayland display, OpenGL or Vulkan drivers, and the LWJGL desktop libraries.
|
|
144
|
+
On Ubuntu 24.04, install the desktop dependencies with
|
|
145
|
+
`apt-get install libgl1-mesa-dri libglx-mesa0 libxrandr2 libxcursor1 libxi6 libxinerama1 libasound2t64 libegl1 libopengl0 libvulkan1 mesa-vulkan-drivers`.
|
|
146
|
+
Java downloads automatically. For a headless session, install `xvfb` and keep
|
|
147
|
+
its display server running for the lifetime of the client.
|
|
148
|
+
|
|
149
|
+
```sh
|
|
150
|
+
Xvfb :99 -screen 0 1280x720x24 -nolisten tcp -noreset > /tmp/minecraft-xvfb.log 2>&1 &
|
|
151
|
+
export DISPLAY=:99
|
|
152
|
+
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-$(mktemp -d)}"
|
|
153
|
+
export LIBGL_ALWAYS_SOFTWARE=1
|
|
154
|
+
minecraft launch --json
|
|
155
|
+
minecraft control state --json
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
This uses Mesa software rendering rather than a physical GPU. Minecraft 26.3
|
|
159
|
+
can use software Vulkan when the virtual display cannot provide its OpenGL context.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
{
|
|
2
|
+
"defaultVersion": "26.3",
|
|
3
|
+
"versions": {
|
|
4
|
+
"1.21.4": {
|
|
5
|
+
"loader": "0.20.1",
|
|
6
|
+
"java": 21,
|
|
7
|
+
"mod": {
|
|
8
|
+
"file": "artifacts/minecraft-control-1.21.4.jar",
|
|
9
|
+
"sha256": "7bf25554a0f49bb8ed2a4f302ad700ba9ee768f6491574344c367b455d060dfb"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"1.21.5": {
|
|
13
|
+
"loader": "0.20.1",
|
|
14
|
+
"java": 21,
|
|
15
|
+
"mod": {
|
|
16
|
+
"file": "artifacts/minecraft-control-1.21.5.jar",
|
|
17
|
+
"sha256": "2519329561ce26cfe3a2a94c15f1e3c792420dd08b9d5417836e9dc342038e80"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"1.21.6": {
|
|
21
|
+
"loader": "0.20.1",
|
|
22
|
+
"java": 21,
|
|
23
|
+
"mod": {
|
|
24
|
+
"file": "artifacts/minecraft-control-1.21.6.jar",
|
|
25
|
+
"sha256": "83ec4eeb6f37af7812e686abd8da0d85ed82bed7697c7b41555b83b2d2805c64"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"1.21.7": {
|
|
29
|
+
"loader": "0.20.1",
|
|
30
|
+
"java": 21,
|
|
31
|
+
"mod": {
|
|
32
|
+
"file": "artifacts/minecraft-control-1.21.7.jar",
|
|
33
|
+
"sha256": "9b99b26297fd4a2621b70fe7812e1f49e648625799a2e228208920e4b1d01206"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"1.21.8": {
|
|
37
|
+
"loader": "0.20.1",
|
|
38
|
+
"java": 21,
|
|
39
|
+
"mod": {
|
|
40
|
+
"file": "artifacts/minecraft-control-1.21.8.jar",
|
|
41
|
+
"sha256": "37cba629393da724fea07efd5f761fb26dec24318d200ae3d11cad7334cb14ea"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"1.21.9": {
|
|
45
|
+
"loader": "0.20.1",
|
|
46
|
+
"java": 21,
|
|
47
|
+
"mod": {
|
|
48
|
+
"file": "artifacts/minecraft-control-1.21.9.jar",
|
|
49
|
+
"sha256": "022240af34dc38a6eeeba53c9b8dda0ee5fddc58890f87f4110d154ca6e56473"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"1.21.10": {
|
|
53
|
+
"loader": "0.20.1",
|
|
54
|
+
"java": 21,
|
|
55
|
+
"mod": {
|
|
56
|
+
"file": "artifacts/minecraft-control-1.21.10.jar",
|
|
57
|
+
"sha256": "a5422b0a3f86c25b106585647b4bff15cc22939d9afc381756d9a66a80f2f9a7"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"1.21.11": {
|
|
61
|
+
"loader": "0.20.1",
|
|
62
|
+
"java": 21,
|
|
63
|
+
"mod": {
|
|
64
|
+
"file": "artifacts/minecraft-control-1.21.11.jar",
|
|
65
|
+
"sha256": "55c9957d9469090f8cc80d4e138abbd045a59f1b0aac415e00c5893ac9873294"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"26.1": {
|
|
69
|
+
"loader": "0.20.1",
|
|
70
|
+
"java": 25,
|
|
71
|
+
"mod": {
|
|
72
|
+
"file": "artifacts/minecraft-control-26.1.jar",
|
|
73
|
+
"sha256": "50192f1808d389ef81d98bbfd0e630bc80f59e2774eb0dd4bf03bb361d2ae26b"
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"26.1.1": {
|
|
77
|
+
"loader": "0.20.1",
|
|
78
|
+
"java": 25,
|
|
79
|
+
"mod": {
|
|
80
|
+
"file": "artifacts/minecraft-control-26.1.1.jar",
|
|
81
|
+
"sha256": "88477a7220e5583a4b4131b0eab826053d6cff2542216694fc8144c8c85b0993"
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
"26.1.2": {
|
|
85
|
+
"loader": "0.20.1",
|
|
86
|
+
"java": 25,
|
|
87
|
+
"mod": {
|
|
88
|
+
"file": "artifacts/minecraft-control-26.1.2.jar",
|
|
89
|
+
"sha256": "9231af97b98f18743ca91e4454e752c91a079a654168405aa401d03cc9a5d2ca"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"26.2": {
|
|
93
|
+
"loader": "0.20.1",
|
|
94
|
+
"java": 25,
|
|
95
|
+
"mod": {
|
|
96
|
+
"file": "artifacts/minecraft-control-26.2.jar",
|
|
97
|
+
"sha256": "bf15df649fc3bd02379120c9fb649f4aeb3c8d89607d468c39773b8fdec6f52f"
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
"26.3": {
|
|
101
|
+
"loader": "0.20.1",
|
|
102
|
+
"java": 25,
|
|
103
|
+
"mod": {
|
|
104
|
+
"file": "artifacts/minecraft-control-26.3.jar",
|
|
105
|
+
"sha256": "14eed2eea0f306b063cb2f83baf84cf4d50f045e8ea00daffa44060c1b0c4272"
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdir, readFile, writeFile, rename, access } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
export async function readManifest(packageRoot) {
|
|
5
|
+
const value = JSON.parse(await readFile(path.join(packageRoot, 'compatibility.json'), 'utf8'));
|
|
6
|
+
if (!value.defaultVersion || !value.versions || Object.keys(value.versions).length === 0
|
|
7
|
+
|| !Object.hasOwn(value.versions, value.defaultVersion)) {
|
|
8
|
+
throw new Error('Incomplete package compatibility manifest. Build the release package first.');
|
|
9
|
+
}
|
|
10
|
+
for (const [version, compatibility] of Object.entries(value.versions)) {
|
|
11
|
+
if (!version || !compatibility || typeof compatibility.loader !== 'string'
|
|
12
|
+
|| !Number.isSafeInteger(compatibility.java) || compatibility.java < 8
|
|
13
|
+
|| typeof compatibility.mod?.file !== 'string' || !compatibility.mod.file
|
|
14
|
+
|| !/^[0-9a-f]{64}$/i.test(compatibility.mod.sha256)) {
|
|
15
|
+
throw new Error(`Incomplete package compatibility metadata for Minecraft ${version}. Build the release package first.`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
export function resolveVersion(manifest, requested) {
|
|
21
|
+
const version = requested ?? manifest.defaultVersion;
|
|
22
|
+
if (!Object.hasOwn(manifest.versions, version)) {
|
|
23
|
+
throw new Error(`No compatible bundled mod for Minecraft ${version}. Run minecraft versions.`);
|
|
24
|
+
}
|
|
25
|
+
if (!/^[A-Za-z0-9._-]+$/.test(version))
|
|
26
|
+
throw new Error('Invalid Minecraft version identifier.');
|
|
27
|
+
return { version, compatibility: manifest.versions[version] };
|
|
28
|
+
}
|
|
29
|
+
export function offlineUuid(username) {
|
|
30
|
+
if (!/^[A-Za-z0-9_]{3,16}$/.test(username))
|
|
31
|
+
throw new Error('Username must contain 3 to 16 letters, digits, or underscores.');
|
|
32
|
+
const bytes = createHash('md5').update(`OfflinePlayer:${username}`, 'utf8').digest();
|
|
33
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x30;
|
|
34
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
35
|
+
const hex = bytes.toString('hex');
|
|
36
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
37
|
+
}
|
|
38
|
+
export function defaultOptions(_version, dataVersion) {
|
|
39
|
+
if (!Number.isSafeInteger(dataVersion) || dataVersion < 1446) {
|
|
40
|
+
throw new Error('A valid Minecraft options data version is required.');
|
|
41
|
+
}
|
|
42
|
+
// Minecraft stores FOV as (degrees - 70) / 40, rather than literal degrees.
|
|
43
|
+
return [
|
|
44
|
+
`version:${dataVersion}`,
|
|
45
|
+
'fullscreen:false', 'overrideWidth:1280', 'overrideHeight:720', 'guiScale:2',
|
|
46
|
+
'fov:0.5', 'key_key.sprint:key.keyboard.r', 'pauseOnLostFocus:false',
|
|
47
|
+
'soundCategory_master:0.0', 'onboardAccessibility:false', 'tutorialStep:none',
|
|
48
|
+
// Preset callbacks do not apply during startup, so write their individual settings.
|
|
49
|
+
'graphicsPreset:"custom"', 'renderDistance:8', 'simulationDistance:5', 'renderClouds:false',
|
|
50
|
+
'ao:false', 'biomeBlendRadius:1', 'entityShadows:false', 'entityDistanceScaling:0.75',
|
|
51
|
+
'mipmapLevels:2', 'particles:1', 'cloudRange:32', 'cutoutLeaves:false',
|
|
52
|
+
'improvedTransparency:false', 'weatherRadius:5', 'maxAnisotropyBit:1', 'textureFiltering:0',
|
|
53
|
+
'prioritizeChunkUpdates:0', 'menuBackgroundBlurriness:2',
|
|
54
|
+
'maxFps:60', 'enableVsync:false', 'joinedFirstServer:true', 'skipMultiplayerWarning:true',
|
|
55
|
+
].join('\n') + '\n';
|
|
56
|
+
}
|
|
57
|
+
export async function initializeOptions(instance, version, dataVersion) {
|
|
58
|
+
await mkdir(instance, { recursive: true });
|
|
59
|
+
try {
|
|
60
|
+
await access(path.join(instance, 'options.txt'));
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
catch { /* First launch. */ }
|
|
64
|
+
await writeFile(path.join(instance, 'options.txt'), defaultOptions(version, dataVersion), { flag: 'wx' });
|
|
65
|
+
}
|
|
66
|
+
export async function writeJson(file, value) {
|
|
67
|
+
const temporary = `${file}.${randomUUID()}.tmp`;
|
|
68
|
+
await writeFile(temporary, JSON.stringify(value, null, 2) + '\n');
|
|
69
|
+
await rename(temporary, file);
|
|
70
|
+
}
|
package/dist/download.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { createReadStream, createWriteStream } from 'node:fs';
|
|
3
|
+
import { mkdir, readFile, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { dirname } from 'node:path';
|
|
5
|
+
import { Readable, Transform } from 'node:stream';
|
|
6
|
+
import { pipeline } from 'node:stream/promises';
|
|
7
|
+
export async function fetchJson(url) {
|
|
8
|
+
const response = await fetch(url, { signal: AbortSignal.timeout(60_000) });
|
|
9
|
+
if (!response.ok)
|
|
10
|
+
throw new Error(`Download failed with HTTP ${response.status} for ${url}`);
|
|
11
|
+
return await response.json();
|
|
12
|
+
}
|
|
13
|
+
export async function atomicWrite(path, data) {
|
|
14
|
+
await mkdir(dirname(path), { recursive: true });
|
|
15
|
+
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
16
|
+
try {
|
|
17
|
+
await writeFile(temporary, data, { flag: 'wx' });
|
|
18
|
+
await rename(temporary, path);
|
|
19
|
+
}
|
|
20
|
+
finally {
|
|
21
|
+
await rm(temporary, { force: true });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export async function validFile(path, source) {
|
|
25
|
+
try {
|
|
26
|
+
const info = await stat(path);
|
|
27
|
+
if (!info.isFile() || (source.size !== undefined && source.size !== info.size))
|
|
28
|
+
return false;
|
|
29
|
+
const expected = source.sha256 ?? source.sha1;
|
|
30
|
+
if (!expected)
|
|
31
|
+
return false;
|
|
32
|
+
const hash = createHash(source.sha256 ? 'sha256' : 'sha1');
|
|
33
|
+
for await (const chunk of createReadStream(path))
|
|
34
|
+
hash.update(chunk);
|
|
35
|
+
return hash.digest('hex') === expected.toLowerCase();
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (error.code === 'ENOENT')
|
|
39
|
+
return false;
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** A cache entry becomes visible only after the complete download passes verification. */
|
|
44
|
+
export async function download(path, source) {
|
|
45
|
+
if (!source.sha1 && !source.sha256)
|
|
46
|
+
throw new Error(`Missing checksum for ${source.url}`);
|
|
47
|
+
if (await validFile(path, source))
|
|
48
|
+
return;
|
|
49
|
+
await mkdir(dirname(path), { recursive: true });
|
|
50
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
51
|
+
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
52
|
+
try {
|
|
53
|
+
const response = await fetch(source.url, { signal: AbortSignal.timeout(300_000) });
|
|
54
|
+
if (!response.ok || !response.body)
|
|
55
|
+
throw new Error(`HTTP ${response.status} for ${source.url}`);
|
|
56
|
+
const hash = createHash(source.sha256 ? 'sha256' : 'sha1');
|
|
57
|
+
let size = 0;
|
|
58
|
+
const verify = new Transform({ transform(chunk, _encoding, callback) {
|
|
59
|
+
hash.update(chunk);
|
|
60
|
+
size += chunk.length;
|
|
61
|
+
callback(null, chunk);
|
|
62
|
+
} });
|
|
63
|
+
await pipeline(Readable.fromWeb(response.body), verify, createWriteStream(temporary, { flags: 'wx' }));
|
|
64
|
+
if (hash.digest('hex') !== (source.sha256 ?? source.sha1).toLowerCase()
|
|
65
|
+
|| (source.size !== undefined && size !== source.size)) {
|
|
66
|
+
throw new Error(`Checksum or size mismatch for ${source.url}`);
|
|
67
|
+
}
|
|
68
|
+
await rename(temporary, path);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
if (attempt === 2)
|
|
73
|
+
throw new Error(`Could not download ${source.url}`, { cause: error });
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
await rm(temporary, { force: true });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export async function readJson(path) {
|
|
81
|
+
return JSON.parse(await readFile(path, 'utf8'));
|
|
82
|
+
}
|
|
83
|
+
export async function parallel(items, action, concurrency = 12) {
|
|
84
|
+
let index = 0;
|
|
85
|
+
let failure;
|
|
86
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, async () => {
|
|
87
|
+
while (index < items.length && !failure) {
|
|
88
|
+
const item = items[index++];
|
|
89
|
+
try {
|
|
90
|
+
await action(item);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
failure = error;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}));
|
|
97
|
+
if (failure)
|
|
98
|
+
throw failure;
|
|
99
|
+
}
|