@nkduy/mc-asset-loader 0.0.0-stage → 1.6.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/LICENSE +373 -0
- package/README.md +453 -2
- package/dist/mc-asset-loader.min.js +11 -0
- package/index.d.ts +344 -0
- package/package.json +52 -4
- package/src/bedrock.js +54 -0
- package/src/cache.js +127 -0
- package/src/index.js +471 -0
- package/src/inflate.js +168 -0
- package/src/jar.js +267 -0
- package/src/local.js +62 -0
- package/src/manifest.js +442 -0
- package/src/objects.js +18 -0
- package/src/opfs-cache.js +153 -0
- package/src/source.js +68 -0
- package/src/store.js +69 -0
- package/src/util.js +105 -0
- package/src/version.js +160 -0
- package/src/zip.js +253 -0
- package/src/zlib-node.js +15 -0
package/README.md
CHANGED
|
@@ -1,3 +1,454 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nkduy/mc-asset-loader
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Fetch anything from any Minecraft: Java Edition version ever released, in Node.js and the browser. List versions, download assets, search files, and export whole versions.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
* Every version Mojang has published, from the earliest alphas to the latest snapshot
|
|
8
|
+
* Bedrock Edition support, served from the official bedrock-samples releases
|
|
9
|
+
* An asset index mode, serving the Java asset indexes as standalone versions
|
|
10
|
+
* Textures, models, blockstates, item definitions, sounds, structures, and languages
|
|
11
|
+
* Both resource pack and data pack assets included
|
|
12
|
+
* Search and filter files, with the best matches sorted first
|
|
13
|
+
* A built-in cache: download a version once, and later lookups are near instant
|
|
14
|
+
* Game code is never downloaded, so fetches are quick and exports stay small
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
For Node.js, or the browser through a bundler:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @nkduy/mc-asset-loader
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Or in the browser, import it straight from a [CDN](https://www.jsdelivr.com/package/npm/mc-asset-loader):
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
import MinecraftAssets from "https://cdn.jsdelivr.net/npm/@nkduy/mc-asset-loader/+esm"
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
import MinecraftAssets from "@nkduy/mc-asset-loader"
|
|
34
|
+
|
|
35
|
+
const assets = new MinecraftAssets()
|
|
36
|
+
|
|
37
|
+
const png = await assets.getTexture("block/stone") // png bytes
|
|
38
|
+
const model = await assets.getModel("block/stone") // parsed json
|
|
39
|
+
const files = await assets.list("assets/minecraft/textures") // every texture the version has
|
|
40
|
+
const hits = await assets.search("stone", { extension: "png" })
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`version` is a version id, or one of three keywords, and defaults to `"release"`:
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
new MinecraftAssets({ version: "26.1.2" }) // an exact version id
|
|
47
|
+
new MinecraftAssets({ version: "release" }) // the latest release, the default
|
|
48
|
+
new MinecraftAssets({ version: "snapshot" }) // the newest snapshot, even when a newer release exists
|
|
49
|
+
new MinecraftAssets({ version: "newest" }) // release or snapshot, whichever is newer
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Every method also takes `{ version }` to request a specific version for that one call:
|
|
53
|
+
|
|
54
|
+
```js
|
|
55
|
+
const old = await assets.getTexture("blocks/stone", { version: "1.8.9" })
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Nothing is fetched until a call needs it. Listing a version costs a small partial request, and the first file read downloads the useful part of the version's jar: range requests skip game code and other unwanted files, which are around 70% of the total size. After that, every read, search, and export of that version is served from memory and the cache.
|
|
59
|
+
|
|
60
|
+
## Documentation
|
|
61
|
+
|
|
62
|
+
### new MinecraftAssets(options)
|
|
63
|
+
|
|
64
|
+
All options are optional:
|
|
65
|
+
|
|
66
|
+
| Option | Default | Description |
|
|
67
|
+
|---|---|---|
|
|
68
|
+
| `type` | `"java"` | What to serve: `"java"`, `"assets"`, or `"bedrock"`. See [Asset index mode](#asset-index-mode) and [Bedrock edition](#bedrock-edition) |
|
|
69
|
+
| `version` | `"release"` | The default version: an id, `"release"`, `"snapshot"`, or `"newest"` |
|
|
70
|
+
| `objects` | `false` | Include [asset objects](#asset-objects) in listings and reads by default |
|
|
71
|
+
| `cacheDir` | OS temp folder | Where the built-in cache lives (Node.js) |
|
|
72
|
+
| `cacheSize` | 1 GB | Cap on the built-in cache in bytes, least recently used purged first. `Infinity` never purges |
|
|
73
|
+
| `cacheKey` | | Namespaces the built-in cache, so separate instances can keep separate caches |
|
|
74
|
+
| `cacheAPI` | | Use [your own cache](#your-own-cache) in place of the built-in cache |
|
|
75
|
+
| `proxy` | | A URL prefix, or a function given the URL and returning the one to request. See [Browser](#browser) |
|
|
76
|
+
| `manifest` | | The listing to use instead of fetching it: Mojang's version manifest, or GitHub's releases array for `bedrock`. See [Your own manifest](#your-own-manifest) |
|
|
77
|
+
| `manifestExpiry` | response headers | How long in milliseconds to trust a fetched manifest. `Infinity` keeps one copy for the whole session |
|
|
78
|
+
| `onManifestProgress` | | Called with a 0 to 1 ratio while the manifest is built. Only `assets`, which resolves every version's asset index and takes hundreds of requests |
|
|
79
|
+
| `onManifestUpdate` | | Serves an expired manifest from the cache and refetches it in the background, calling this with `assets.manifest` once a changed one is in place. Browser only. Without it an expired manifest is awaited |
|
|
80
|
+
| `minecraftDir` | auto-detected | Serve from the local `.minecraft` installation when it has the file, before downloading. A string sets the folder, `false` disables. See [Local .minecraft](#local-minecraft) |
|
|
81
|
+
|
|
82
|
+
### Versions
|
|
83
|
+
|
|
84
|
+
`assets.manifest` reads Mojang's version manifest. It is fetched on first use, cached, and trusted until its `manifestExpiry`, so quick restarts do not refetch it. The methods below all live on `assets.manifest`:
|
|
85
|
+
|
|
86
|
+
| Method | Description |
|
|
87
|
+
|---|---|
|
|
88
|
+
| `.versions(filter?)` | Every version, newest first. See [Filters](#filters) |
|
|
89
|
+
| `.version(id)` | One version by id or keyword. Returns `null` when the version is unknown |
|
|
90
|
+
| `.latest()` | `{ release, snapshot, newest }` |
|
|
91
|
+
| `.details(id)` | The raw per-version JSON. This includes the jar and asset index URLs, JVM arguments, required libraries, and more |
|
|
92
|
+
| `.update(manifest?)` | Replace the in-memory manifest, or call with nothing to trigger an early refresh |
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
const { release, snapshot } = await assets.manifest.latest()
|
|
96
|
+
const version = await assets.manifest.version("26.1.2")
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`assets.version` can be updated at any time. Use `.setVersion(id)` to replace the version used by default for future calls. It returns the [version entry](#version-entries):
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
await assets.setVersion("snapshot")
|
|
103
|
+
assets.version // "26.3-snapshot-10"
|
|
104
|
+
assets.channel // "snapshot"
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Both `.version` and `.channel` read from the in-memory manifest, so they start `null` until a call has fetched it.
|
|
108
|
+
|
|
109
|
+
### Filters
|
|
110
|
+
|
|
111
|
+
`versions()` takes a type keyword, a function, or an array of either. Arrays are combined, without duplicates. `VersionType` holds the keywords:
|
|
112
|
+
|
|
113
|
+
```js
|
|
114
|
+
import MinecraftAssets, { VersionType } from "@nkduy/mc-asset-loader"
|
|
115
|
+
|
|
116
|
+
await assets.manifest.versions(VersionType.RELEASE) // "release"
|
|
117
|
+
await assets.manifest.versions([VersionType.SNAPSHOT, VersionType.BETA]) // "snapshot" and "old_beta"
|
|
118
|
+
await assets.manifest.versions(all => all.filter(v => v.id.startsWith("26."))) // 2026 releases
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
| Keyword | Matches | Description |
|
|
122
|
+
|---|---|---|
|
|
123
|
+
| `RELEASE` | `release` | Full releases |
|
|
124
|
+
| `SNAPSHOT` | `snapshot` | Snapshots, pre-releases, and release candidates |
|
|
125
|
+
| `BETA` | `old_beta` | The beta era, b1.0 to b1.8.1 |
|
|
126
|
+
| `ALPHA` | `old_alpha` | The alpha era and everything before it, back to rd-132211 |
|
|
127
|
+
| `MAIN` | custom | The newest patch of each minor line (the Nether Update as `1.16.5`, the Copper Age as `1.21.10`). Useful for a version picker of "unique" game versions |
|
|
128
|
+
| `MODERN` | custom | Versions with the modern `assets/` layout, 13w24a and later. See [Version entries](#version-entries) |
|
|
129
|
+
|
|
130
|
+
Your own keywords can be added through standard assignments:
|
|
131
|
+
|
|
132
|
+
```js
|
|
133
|
+
VersionType.RC = all => all.filter(v => v.id.includes("-rc"))
|
|
134
|
+
await assets.manifest.versions(VersionType.RC)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Version entries
|
|
138
|
+
|
|
139
|
+
A version entry contains the data for that version from the manifest, alongside version-scoped versions of the asset methods.
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
const v = await assets.manifest.version("1.8.9")
|
|
143
|
+
await v.getTexture("blocks/stone")
|
|
144
|
+
await assets.getTexture("blocks/stone", { version: "1.8.9" })
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Supported methods are `details`, `list`, `search`, `file`, `read`, every getter, `loadObjects`, and `export`.
|
|
148
|
+
|
|
149
|
+
`legacyLayout` is a custom property set on versions. It is `true` for versions before 13w24a, where the jar had no `assets/` folder, and all assets sat within the root. The getters (except `.getLang()`) do not work on versions with the legacy asset layout, so use `.read()` instead. `LEGACY_ASSETS_BEFORE` is exported as the timestamp of that cutoff.
|
|
150
|
+
|
|
151
|
+
### Your own manifest
|
|
152
|
+
|
|
153
|
+
If you already fetch the manifest yourself, you can pass it in as `manifest` to the constructor. Use `assets.manifest.update(json)` to update it later with a newer version. When a manifest was provided by you, it will not expire and relies on you to keep it refreshed. `.update()` with no argument refetches from Mojang and hands control back to the library.
|
|
154
|
+
|
|
155
|
+
What to hand over is whatever that type is built from, not the list it ends up with:
|
|
156
|
+
|
|
157
|
+
| Type | Pass |
|
|
158
|
+
|---|---|
|
|
159
|
+
| `java` | Mojang's version manifest |
|
|
160
|
+
| `assets` | Mojang's version manifest, the same document |
|
|
161
|
+
| `bedrock` | The array GitHub's releases endpoint returns |
|
|
162
|
+
|
|
163
|
+
`assets` lists asset indexes rather than versions, and works them out by reading each version's details, so the manifest you provide is the input to that. The index list itself stays the library's to build and cache, and it will read those details, from the cache when they are there and over the network when they are not.
|
|
164
|
+
|
|
165
|
+
### Files
|
|
166
|
+
|
|
167
|
+
| Method | Description |
|
|
168
|
+
|---|---|
|
|
169
|
+
| `.list(folder?, options?)` | Every file in the version, in a flat list, sorted by path. With a folder, only the files beneath it |
|
|
170
|
+
| `.list(folder?, { folders: true })` | `{ files, folders }`, the direct contents of one folder: the files as [file entries](#file-entries), the subfolders as [folder entries](#folder-entries) |
|
|
171
|
+
| `.search(query, options?)` | Files matching a query. See [Search](#search) |
|
|
172
|
+
| `.file(path, options?)` | One [file entry](#file-entries), or `null` |
|
|
173
|
+
| `.read(path, options?)` | The bytes of one file as a `Uint8Array`, or `null` |
|
|
174
|
+
|
|
175
|
+
All of them take `{ version, objects }`. `read` also takes `prefer`, see [Asset objects](#asset-objects).
|
|
176
|
+
|
|
177
|
+
```js
|
|
178
|
+
await assets.list() // every file, flat
|
|
179
|
+
await assets.list("assets/minecraft/textures") // every file beneath a folder, flat
|
|
180
|
+
await assets.list({ folders: true }) // browse the root: { files, folders }
|
|
181
|
+
await assets.list("assets/minecraft", { folders: true }) // browse a folder
|
|
182
|
+
await assets.search("stone", { extension: "png" }) // best matches first
|
|
183
|
+
await assets.file("assets/minecraft/textures/block/stone.png") // one entry, nothing downloaded yet
|
|
184
|
+
await assets.read("data/minecraft/loot_table/blocks/stone.json") // one file's bytes
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### File entries
|
|
188
|
+
|
|
189
|
+
Each file is `{ path, source, size, crc, hash }`. The `source` is where it came from: `"jar"` or `"object"`. `crc` is only there on jar files, and `hash` only on [asset objects](#asset-objects). `source` only exists on the `"java"` type, since bedrock and assets files all come from one place. File entries also get `read()` and `raw()` methods:
|
|
190
|
+
|
|
191
|
+
```js
|
|
192
|
+
const stone = await assets.file("assets/minecraft/textures/block/stone.png")
|
|
193
|
+
stone.size // 157
|
|
194
|
+
await stone.read() // the bytes
|
|
195
|
+
await stone.raw() // the bytes as stored: { compression: "deflate-raw" | null, bytes }
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
`raw()` skips decompression, for handing files to a worker or another zip cheaply. `readZip` entries have it too.
|
|
199
|
+
|
|
200
|
+
### Folder entries
|
|
201
|
+
|
|
202
|
+
`folder.list()` can be used to list files from this folder instead of from the root. Same formatting as the main list method.
|
|
203
|
+
|
|
204
|
+
Folder entries are `{ path, source, objects }`, where `path` is the full path from the root, `source` is `"jar"`, `"object"`, or `"both"`, covering every file beneath it (`"java"` type only, like on files), and `objects` is the setting the folder was listed with.
|
|
205
|
+
|
|
206
|
+
Folders have the `list`, `search`, `file`, and `read` methods for getting files directly from the folder. These automatically use the folder's `objects` setting unless it is manually overridden.
|
|
207
|
+
|
|
208
|
+
```js
|
|
209
|
+
const { folders } = await assets.list("assets/minecraft", { folders: true })
|
|
210
|
+
const textures = folders.find(f => f.path.endsWith("/textures"))
|
|
211
|
+
|
|
212
|
+
await textures.search("stone", { extension: "png" }) // scoped beneath textures/
|
|
213
|
+
await textures.read("block/stone.png")
|
|
214
|
+
await textures.list() // every file beneath textures/
|
|
215
|
+
await textures.list("block") // every file beneath textures/block/
|
|
216
|
+
await textures.list("block", { folders: true }) // browse textures/block/
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Asset objects
|
|
220
|
+
|
|
221
|
+
Sounds, languages, the panoramas, and a few other files are not stored in the jar. They are served individually from a separate host, by hash, listed in each version's asset index. They are big (around 480 MB combined for a modern version), and cost an extra fetch to list, so they are opt in. Pass `objects: true` to the constructor, or to any call:
|
|
222
|
+
|
|
223
|
+
```js
|
|
224
|
+
const everything = await assets.list({ objects: true })
|
|
225
|
+
const harp = await assets.file("assets/minecraft/sounds/note/harp.ogg", { objects: true })
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
With objects on, the listing merges the jar and the objects into one view, each file appearing once. `getSound`, `getLang`, and `loadObjects` never need the flag, they use objects automatically.
|
|
229
|
+
|
|
230
|
+
Some files exist in both the jar and the objects: the title screen panoramas for example. The object copy is used by default. Pass `prefer: "jar"` to `read` to take the jar copy instead.
|
|
231
|
+
|
|
232
|
+
`loadObjects` bulk downloads asset objects. It returns a `Map` with file paths as the keys and the downloaded bytes as the values. A failed download is missing from the map rather than thrown.
|
|
233
|
+
|
|
234
|
+
| Option | Default | Description |
|
|
235
|
+
|---|---|---|
|
|
236
|
+
| `filter` | | A function given each path, or an array of paths and/or file entries |
|
|
237
|
+
| `concurrency` | `32` | How many downloads can run at once |
|
|
238
|
+
| `onProgress` | | Called with `(done, total)` as each file finishes |
|
|
239
|
+
| `cache` | `true` | Add the downloaded objects to the cache |
|
|
240
|
+
| `version` | | Same as everywhere else |
|
|
241
|
+
|
|
242
|
+
```js
|
|
243
|
+
const notes = await assets.loadObjects({ filter: p => p.includes("/sounds/note/"), onProgress: (done, total) => {} })
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Search
|
|
247
|
+
|
|
248
|
+
```js
|
|
249
|
+
await assets.search("stone", { extension: "png", limit: 10 })
|
|
250
|
+
await assets.search("", { root: "assets/minecraft/models/block" }) // everything under a folder
|
|
251
|
+
await assets.search(/panorama_\d/) // a RegExp works too
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Searching is managed by `mc-path-search-sort`
|
|
255
|
+
|
|
256
|
+
| Option | Default | Description |
|
|
257
|
+
|---|---|---|
|
|
258
|
+
| `root` | | Only paths starting with this prefix, from the top of the tree: `"assets/minecraft/models"` means inside that exact folder |
|
|
259
|
+
| `path` | | Only paths passing through these folders, wherever they sit: `"block"` means under any `block/` folder, however deep |
|
|
260
|
+
| `extension` | | Only these file types: one extension or several, leading dot optional |
|
|
261
|
+
| `filter` | | Your own predicate over the path, only called for what already matched |
|
|
262
|
+
| `limit` | | Cap on results, applied after sorting |
|
|
263
|
+
| `folders` | `true` | Also match folder names: files inside a matching folder rank after name matches |
|
|
264
|
+
| `caseSensitive` | `false` | Case matters, except for the `extension` filter; RegExp queries ignore it |
|
|
265
|
+
| `spaces` | `"_"` | What a typed space becomes, e.g. `"_"` for underscore-named files; RegExp queries ignore it |
|
|
266
|
+
| `version`, `objects` | | Same as everywhere else |
|
|
267
|
+
|
|
268
|
+
Results come back sorted into a sensible order, best matches first.
|
|
269
|
+
|
|
270
|
+
A namespace prefix in the query is stripped, so `minecraft:stone` and `stone` search the same.
|
|
271
|
+
|
|
272
|
+
### Getters
|
|
273
|
+
|
|
274
|
+
Getters are shortcuts for the most commonly wanted file types, using identifiers instead of paths. Paths do still work if provided.
|
|
275
|
+
|
|
276
|
+
`<ns>` in the table below is the id's namespace: `minecraft` by default, or the `namespace` option when given. A prefix on the id overrides both: `getTexture("namespace:id")` reads from `assets/namespace/textures/id`.
|
|
277
|
+
|
|
278
|
+
| Method | Reads from | Returns |
|
|
279
|
+
|---|---|---|
|
|
280
|
+
| `.getTexture(id, options?)` | `assets/<ns>/textures/` | The png bytes. With `meta: true`, `{ data, meta }` where `meta` is the parsed `.mcmeta` or `null` |
|
|
281
|
+
| `.getModel(id, options?)` | `assets/<ns>/models/` | Parsed json |
|
|
282
|
+
| `.getBlockstate(id, options?)` | `assets/<ns>/blockstates/` | Parsed json |
|
|
283
|
+
| `.getItemDefinition(id, options?)` | `assets/<ns>/items/` | Parsed json |
|
|
284
|
+
| `.getSound(id, options?)` | `assets/<ns>/sounds/` | The ogg bytes |
|
|
285
|
+
| `.getStructure(id, options?)` | `data/<ns>/structure/` | The structure nbt bytes. Supports older pack layouts too |
|
|
286
|
+
| `.getLang(code, options?)` | `assets/<ns>/lang/` | A key to string object, older `.lang` files included |
|
|
287
|
+
|
|
288
|
+
Identifiers can be written however you have them: the namespace, the kind folder, and the extension are each optional, and a full path works too:
|
|
289
|
+
|
|
290
|
+
```js
|
|
291
|
+
await assets.getTexture("block/stone")
|
|
292
|
+
await assets.getTexture("block/stone.png")
|
|
293
|
+
await assets.getModel("minecraft:block/stone")
|
|
294
|
+
await assets.getBlockstate("blockstates/stone")
|
|
295
|
+
await assets.getSound("minecraft:sounds/note/pling")
|
|
296
|
+
await assets.getStructure("igloo/top.nbt")
|
|
297
|
+
await assets.getTexture("assets/minecraft/textures/block/stone.png")
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### Export
|
|
301
|
+
|
|
302
|
+
Use the `export` function to export all the files to a zip or a folder. Fetches anything that is not already cached. When `dir` is not provided it returns a zip file.
|
|
303
|
+
|
|
304
|
+
| Option | Default | Description |
|
|
305
|
+
|---|---|---|
|
|
306
|
+
| `filter` | | A function given each path, or an array of paths and/or file entries |
|
|
307
|
+
| `dir` | | Node.js: write a folder tree here instead of returning a zip. Returns the number of files written |
|
|
308
|
+
| `objects` | | Include the [asset object](#asset-objects) files too |
|
|
309
|
+
| `concurrency` | `32` | How many fetches can run at once |
|
|
310
|
+
| `onProgress` | | Called with `(done, total)` as each file finishes |
|
|
311
|
+
| `version` | | Same as everywhere else |
|
|
312
|
+
|
|
313
|
+
```js
|
|
314
|
+
const zip = await assets.export({ filter: p => p.includes("note_block") })
|
|
315
|
+
const count = await assets.export({ dir: "./out", version: "b1.7.3" })
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### Local .minecraft
|
|
319
|
+
|
|
320
|
+
In Node.js, the `"java"` and `"assets"` types check the local `.minecraft` installation before downloading anything: version jars, asset indexes, and asset objects are all served straight from disk when the launcher already has them. This is on by default at the platform's standard location, `minecraftDir: "path/to/.minecraft"` points it somewhere else, and `minecraftDir: false` turns it off.
|
|
321
|
+
|
|
322
|
+
### Caching
|
|
323
|
+
|
|
324
|
+
Everything Mojang serves except the version manifest is immutable and named by hash, so it is cached forever and never revalidated. The manifest is cached with its expiry. Once it has expired, a browser serves the cached copy straight away and refreshes it in the background, while Node.js waits for the fresh copy.
|
|
325
|
+
|
|
326
|
+
| Method | Description |
|
|
327
|
+
|---|---|
|
|
328
|
+
| `.loadJar(options?)` | Downloads a version's jar data immediately instead of waiting for the first read. `onProgress` is called with `(done, total)` in bytes, for a loading bar |
|
|
329
|
+
| `.cacheStats()` | The cache as `{ files, size }` in bytes |
|
|
330
|
+
| `.listCache()` | Every cached file as `{ key, size }`, biggest first |
|
|
331
|
+
| `.clearCache(key?)` | Clears the full cache, or just one file when passed its key |
|
|
332
|
+
| `.setCacheSize(bytes)` | Changes the cache limit and evicts down to it. `null` disables eviction |
|
|
333
|
+
|
|
334
|
+
```js
|
|
335
|
+
await assets.loadJar({ version: "26.1.2", onProgress: (done, total) => {} })
|
|
336
|
+
|
|
337
|
+
await assets.cacheStats() // { files: 212, size: 48213096 }
|
|
338
|
+
const [biggest] = await assets.listCache()
|
|
339
|
+
await assets.clearCache(biggest.key)
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### Your own cache
|
|
343
|
+
|
|
344
|
+
Pass `cacheAPI` to replace the built-in cache with anything that can store bytes:
|
|
345
|
+
|
|
346
|
+
```js
|
|
347
|
+
const assets = new MinecraftAssets({
|
|
348
|
+
cacheAPI: {
|
|
349
|
+
read: key => store.get(key), // Uint8Array, or undefined
|
|
350
|
+
write: (key, bytes) => store.set(key, bytes),
|
|
351
|
+
delete: key => store.delete(key), // optional, powers clearCache(key)
|
|
352
|
+
clear: () => store.clear(), // optional, powers clearCache()
|
|
353
|
+
list: () => Array.from(store, ([key, bytes]) => ({ key, size: bytes.length })) // optional, powers cacheStats() and listCache()
|
|
354
|
+
}
|
|
355
|
+
})
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
Keys are strings starting `meta/` or `blobs/`, and values are always a `Uint8Array`. `cacheStats()` and `listCache()` are `null` when `list()` is not provided.
|
|
359
|
+
|
|
360
|
+
### Browser
|
|
361
|
+
|
|
362
|
+
As of the time this was created, the version manifest, version details, and jar hosts all allow cross-origin requests. These can all be fetched directly without the need for a proxy. The asset objects host sends no CORS headers at all, so a CORS proxy server must be used to access them:
|
|
363
|
+
|
|
364
|
+
```js
|
|
365
|
+
const assets = new MinecraftAssets({
|
|
366
|
+
proxy: url => url.includes("resources.download.minecraft.net") ? "https://my-proxy/" + url : false
|
|
367
|
+
})
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
A string is used as a prefix on every request. A function can be used for more advanced URLs, or to proxy specific URLs only. Returning `false` requests the original URL directly, without the proxy.
|
|
371
|
+
|
|
372
|
+
### Asset index mode
|
|
373
|
+
|
|
374
|
+
Pass `type: "assets"` to serve the Java [asset indexes](#asset-objects) on their own. The version list becomes the asset index versions instead of the game versions, and content is just the files in the index, with no jar involved:
|
|
375
|
+
|
|
376
|
+
```js
|
|
377
|
+
const assets = new MinecraftAssets({ type: "assets" })
|
|
378
|
+
|
|
379
|
+
await assets.manifest.versions() // one entry per asset index: "34", "1.19", "legacy", "pre-1.6", ...
|
|
380
|
+
await assets.getSound("note/pling")
|
|
381
|
+
await assets.getLang("de_de")
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
Many game versions share one index, so the list is short (around 56 entries). Each entry keeps the index's own metadata: `sha1`, `url`, `size`, `totalSize` (the combined size of every file it points at), plus `first` and `last`, the game versions that introduced it and most recently used it. An index counts as `"release"` when any release uses it, and `"snapshot"` when only snapshots do. Building the list means sampling game version details to find where the indexes change, a few hundred small fetches, so the first call takes a moment; after that it is all cached.
|
|
385
|
+
|
|
386
|
+
Everything works from the index's own file list: `list`, `search`, `read`, `export`, and the getters. All entries are object-backed, so the `objects` flag is ignored. What resolves is whatever the index actually holds, which is sounds and non-English translations on modern indexes (everything else lives in the jar), plus icons, music, and `.lang` files on the older ones. `getTexture`, `getModel`, `getBlockstate`, `getItemDefinition`, and `getStructure` are usually `null` since that content never left the jar. `loadJar` prefetches every file in the index with byte progress.
|
|
387
|
+
|
|
388
|
+
In a browser this mode needs the [proxy](#browser) for content, since everything comes from the asset objects host.
|
|
389
|
+
|
|
390
|
+
### Bedrock edition
|
|
391
|
+
|
|
392
|
+
Pass `type: "bedrock"` to serve Bedrock Edition instead, from Mojang's official [bedrock-samples](https://github.com/Mojang/bedrock-samples) releases:
|
|
393
|
+
|
|
394
|
+
```js
|
|
395
|
+
const assets = new MinecraftAssets({ type: "bedrock" })
|
|
396
|
+
|
|
397
|
+
await assets.getTexture("blocks/stone")
|
|
398
|
+
await assets.getModel("entity/allay")
|
|
399
|
+
await assets.getLang("en_US")
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
Versions come from the GitHub releases, and previews are the `"snapshot"` channel. The GitHub API is touched as little as possible to try and avoid the strict rate limits.
|
|
403
|
+
|
|
404
|
+
Each version is a single zip. It is downloaded whole on first use, cached, and everything is served from it. The first touch of a version costs the full download (roughly 150 MB) and everything after is instant. `loadJar` forces the download with byte progress, though `total` can be `null` when the server does not declare a length.
|
|
405
|
+
|
|
406
|
+
The getters map to Bedrock's own layout:
|
|
407
|
+
|
|
408
|
+
| Method | Reads from |
|
|
409
|
+
|---|---|
|
|
410
|
+
| `.getTexture(id, options?)` | `resource_pack/textures/`, `.png` with a `.tga` fallback. `meta: true` returns the `.texture_set.json` sidecar |
|
|
411
|
+
| `.getModel(id, options?)` | `resource_pack/models/`, `.geo.json` with a `.json` fallback |
|
|
412
|
+
| `.getBlockstate(id, options?)` | `behavior_pack/blocks/` |
|
|
413
|
+
| `.getItemDefinition(id, options?)` | `behavior_pack/items/` |
|
|
414
|
+
| `.getSound(id, options?)` | `resource_pack/sounds/`, `.fsb` with an `.ogg` fallback |
|
|
415
|
+
| `.getLang(code, options?)` | `resource_pack/texts/` |
|
|
416
|
+
| `.getStructure(id, options?)` | Nothing. `bedrock-samples` ships no structure files, so this is always `null` |
|
|
417
|
+
|
|
418
|
+
Bedrock has no namespaces: a `minecraft:` prefix is accepted and stripped, and any other namespace is a miss. There are no [asset objects](#asset-objects) in bedrock, so the `objects` flag is ignored and `loadObjects` givs you nothing.
|
|
419
|
+
|
|
420
|
+
In a browser, the zip hosts send no CORS headers, so bedrock mode needs the [proxy](#browser) for content. The version list needs no proxy.
|
|
421
|
+
|
|
422
|
+
### Module exports
|
|
423
|
+
|
|
424
|
+
```js
|
|
425
|
+
import MinecraftAssets, { VersionType, LEGACY_ASSETS_BEFORE, readZip, writeZip } from "@nkduy/mc-asset-loader"
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
| Export | Description |
|
|
429
|
+
|---|---|
|
|
430
|
+
| `MinecraftAssets` | The class. The default export |
|
|
431
|
+
| `VersionType` | The [filter keywords](#filters) |
|
|
432
|
+
| `LEGACY_ASSETS_BEFORE` | The 13w24a timestamp, marking which jars use the [legacy layout](#version-entries) |
|
|
433
|
+
| `readZip(bytes)` | The library's zip reader. Parses any zip into `{ path, size, crc }` entries with a `read()` method, decompressing nothing until an entry is read |
|
|
434
|
+
| `writeZip(files, options?)` | The library's zip writer. Takes a `Map` or plain object of path to bytes, or an array of entries with `read()`, so a `readZip` result or the library's own [file entries](#file-entries) repack directly. Entries that also carry `raw()`, `crc` and `size` are copied as stored, so nothing is decompressed or recompressed |
|
|
435
|
+
|
|
436
|
+
```js
|
|
437
|
+
const entries = readZip(bytes) // [{ path, size, crc }], each with read()
|
|
438
|
+
const icon = await entries.find(e => e.path === "pack.png").read()
|
|
439
|
+
|
|
440
|
+
const zip = await writeZip({ "pack.mcmeta": mcmetaBytes, "pack.png": iconBytes })
|
|
441
|
+
const textures = await writeZip(await assets.list("assets/minecraft/textures/block"))
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
`writeZip` options:
|
|
445
|
+
|
|
446
|
+
| Option | Default | Description |
|
|
447
|
+
|---|---|---|
|
|
448
|
+
| `compress` | `true` | `false` stores everything uncompressed, faster for already-compressed files. Copied entries keep their stored form either way |
|
|
449
|
+
| `concurrency` | `32` | How many files can pack at once |
|
|
450
|
+
| `onProgress` | | Called with `(done, total)` as each file finishes |
|
|
451
|
+
|
|
452
|
+
## License
|
|
453
|
+
|
|
454
|
+
[MPL-2.0](LICENSE) © NKDuy
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var Ne=Object.create;var Dt=Object.defineProperty;var Re=Object.getOwnPropertyDescriptor;var $e=Object.getOwnPropertyNames;var Pe=Object.getPrototypeOf,Be=Object.prototype.hasOwnProperty;var Ft=(s,t)=>()=>(s&&(t=s(s=0)),t);var ee=(s,t)=>()=>(t||s((t={exports:{}}).exports,t),t.exports),se=(s,t)=>{for(var e in t)Dt(s,e,{get:t[e],enumerable:!0})},We=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of $e(t))!Be.call(s,n)&&n!==e&&Dt(s,n,{get:()=>t[n],enumerable:!(r=Re(t,n))||r.enumerable});return s};var re=(s,t,e)=>(e=s!=null?Ne(Pe(s)):{},We(t||!s||!s.__esModule?Dt(e,"default",{value:s,enumerable:!0}):e,s));async function M(s,t,e){let r=Array.from(s),n=0,i=Array.from({length:Math.max(1,Math.min(t,r.length))},async()=>{for(;n<r.length;){let a=n++;await e(r[a],a)}});await Promise.all(i)}function ut(s=8){let t=performance.now()+s;return async()=>{performance.now()<t||(await new Promise(e=>setTimeout(e,0)),t=performance.now()+s)}}function at(s){let t=String(s).split("/");return t.length>=2?t[t.length-2]:String(s)}function Nt(s){if(s==null)return()=>!0;if(typeof s=="function")return t=>!!s(t);if(Array.isArray(s)){let t=new Set(s.map(e=>typeof e=="string"?e:e?.path));return e=>t.has(e)}throw new TypeError("filter must be a function or an array of paths/entries")}function $(s,t,e){if(s[t])return s[t];let r=Promise.resolve().then(e);return s[t]=r,r.catch(()=>{s[t]===r&&(s[t]=null)}),r}function J(s,t,e){let r=s.get(t);return r||(r=Promise.resolve().then(e),s.set(t,r),r.catch(()=>{s.get(t)===r&&s.delete(t)})),r}async function At(s,t,e){if(!s.body){let c=new Uint8Array(await s.arrayBuffer());return t?.(c.length),c}let r=s.body.getReader();if(e!=null){let c=new Uint8Array(e),l=0;for(;;){let{done:f,value:h}=await r.read();if(f)break;if(l+h.length>c.length){let y=new Uint8Array(Math.max(c.length*2,l+h.length));y.set(c.subarray(0,l)),c=y}c.set(h,l),l+=h.length,t?.(h.length)}return l===c.length?c:c.subarray(0,l)}let n=[],i=0;for(;;){let{done:c,value:l}=await r.read();if(c)break;n.push(l),i+=l.length,t?.(l.length)}let a=new Uint8Array(i),o=0;for(let c of n)a.set(c,o),o+=c.length;return a}function Z(s,t,e){Object.defineProperty(s,t,{value:e,enumerable:!1,configurable:!0,writable:!0})}var R,ht,Y,T,P=Ft(()=>{R=typeof process<"u"&&typeof process.versions?.node=="string",ht=new Intl.Collator,Y=new TextEncoder,T=new TextDecoder});var ye=ee(()=>{});var ke=ee(()=>{});var ve={};se(ve,{OpfsCache:()=>Zt});var Oe,Ms,Vt,Ds,Zt,Ue=Ft(()=>{P();Oe=["meta","blobs"],Ms=/[^A-Za-z0-9_.%-]/g,Vt=s=>encodeURIComponent(s).replace(Ms,t=>"%"+t.charCodeAt(0).toString(16).toUpperCase().padStart(2,"0")),Ds=s=>decodeURIComponent(s),Zt=class{constructor(t,{maxSize:e=1e9,key:r}={}){this.name=t||"mc-asset-loader",this.key=r,this.maxSize=e??1/0,this._root=null,this._index=null,this._scan=null,this._touched=new Map,this._dirs=new Map,this._evicting=null,this._rootDir().catch(()=>{})}_rootDir(){return this._root??=navigator.storage.getDirectory().then(t=>t.getDirectoryHandle(this.name,{create:!0})).then(t=>this.key?t.getDirectoryHandle(this.key,{create:!0}):t)}_dir(t){this._rootDir();let e=this._dirs.get(t);return e||(e=this._root.then(r=>r.getDirectoryHandle(t,{create:!0})),this._dirs.set(t,e),e.catch(()=>this._dirs.delete(t))),e}async _ready(){return this._index?this._index:(this._scan||(this._scan=this._load().then(t=>this._index=t)),this._scan)}async _load(){let t=new Map;for(let e of Oe){let r=await this._dir(e);for await(let[n,i]of r.entries()){if(i.kind!=="file")continue;let a=await i.getFile(),o=e+"/"+n;t.set(o,{size:a.size,mtime:this._touched.get(o)??a.lastModified})}}return t}_touch(t,e){let r=Date.now();if(this._touched.set(t,r),this._index){let n=this._index.get(t);n?n.mtime=r:this._index.set(t,{size:e,mtime:r})}}async get(t,e){let r=Vt(e),n;try{n=await(await(await this._dir(t)).getFileHandle(r)).getFile()}catch{return}let i=new Uint8Array(await n.arrayBuffer());return this._touch(t+"/"+r,i.length),t==="meta"?JSON.parse(T.decode(i)):i}async set(t,e,r){let n=Vt(e),i=t==="meta"?Y.encode(JSON.stringify(r)):r,o=await(await(await this._dir(t)).getFileHandle(n,{create:!0})).createWritable();try{await o.write(i)}finally{await o.close()}let c=t+"/"+n;this._touched.set(c,Date.now()),this._index&&this._index.set(c,{size:i.length,mtime:Date.now()}),this._evictLater()}_evictLater(){!isFinite(this.maxSize)||this._evicting||(this._evicting=new Promise(t=>setTimeout(t,0)).then(()=>this._ready()).then(()=>this._evict()).catch(()=>{}).finally(()=>{this._evicting=null}))}async delete(t,e){let r=Vt(e);this._index?.delete(t+"/"+r),this._touched.delete(t+"/"+r),await(await this._dir(t)).removeEntry(r).catch(()=>{})}async list(){let t=await this._ready();return Array.from(t.entries()).map(([e,r])=>{let n=e.indexOf("/");return{key:e.slice(0,n+1)+Ds(e.slice(n+1)),size:r.size}})}async clear(){this._index=null,this._scan=null,this._touched.clear(),this._dirs.clear();let t=await this._rootDir();for(let e of Oe)await t.removeEntry(e,{recursive:!0}).catch(()=>{})}async setMaxSize(t){this.maxSize=t??1/0,isFinite(this.maxSize)&&(await this._ready(),await this._evict())}async _evict(){if(!isFinite(this.maxSize))return;let t=this._index,e=0;for(let n of t.values())e+=n.size;if(e<=this.maxSize)return;let r=Array.from(t.entries()).sort((n,i)=>n[1].mtime-i[1].mtime);for(let[n,i]of r){if(e<=this.maxSize)break;t.delete(n),e-=i.size;let[a,o]=n.split("/");await(await this._dir(a)).removeEntry(o).catch(()=>{})}}}});var Me={};se(Me,{LocalInstall:()=>Gt,defaultMinecraftDir:()=>Rs});import Tt from"node:fs";import Ht from"node:os";import nt from"node:path";import Le from"node:crypto";function Rs(){return process.platform==="win32"?nt.join(process.env.APPDATA??nt.join(Ht.homedir(),"AppData","Roaming"),".minecraft"):process.platform==="darwin"?nt.join(Ht.homedir(),"Library","Application Support","minecraft"):nt.join(Ht.homedir(),".minecraft")}function Te(s){return Le.createHash("sha1").update(s).digest("hex")}async function $s(s){let t=Le.createHash("sha1");for await(let e of Tt.createReadStream(s))t.update(e);return t.digest("hex")}var Gt,De=Ft(()=>{P();Gt=class{constructor(t,e){this.dir=t,this.store=e}async object(t){try{let e=await Tt.promises.readFile(nt.join(this.dir,"assets","objects",t.slice(0,2),t));if(Te(e)===t)return e}catch{}return null}async index(t,e){if(!e)return null;try{let r=await Tt.promises.readFile(nt.join(this.dir,"assets","indexes",t+".json"));if(Te(r)===e)return JSON.parse(T.decode(r))}catch{}return null}async jar(t,e){if(!e?.sha1)return null;let r=nt.join(this.dir,"versions",t,t+".jar");try{let n=await Tt.promises.stat(r);if(e.size!=null&&n.size!==e.size)return null;let i="local_jar_"+e.sha1,a=await this.store.get("meta",i);return a?.size===n.size&&a.mtime===n.mtimeMs?r:await $s(r)!==e.sha1?null:(await this.store.set("meta",i,{size:n.size,mtime:n.mtimeMs}),r)}catch{return null}}}});function Je(s,t){if(s===t)return 0;let e=s.length,r=t.length,n=0,i=0;for(;n<e&&i<r;){let a=s.charCodeAt(n),o=t.charCodeAt(i);if(a>=48&&a<=57&&o>=48&&o<=57){let c=n;for(;c<e&&s.charCodeAt(c)===48;)c++;let l=i;for(;l<r&&t.charCodeAt(l)===48;)l++;let f=c;for(;f<e;){let _=s.charCodeAt(f);if(_<48||_>57)break;f++}let h=l;for(;h<r;){let _=t.charCodeAt(h);if(_<48||_>57)break;h++}let y=f-c,u=h-l;if(y!==u)return y-u;for(let _=0;_<y;_++){let b=s.charCodeAt(c+_)-t.charCodeAt(l+_);if(b)return b}let d=f-n,m=h-i;if(d!==m)return d-m;n=f,i=h;continue}if(a!==o)return a-o;n++,i++}return e-n-(r-i)}function It(s){return s.indexOf("\\")===-1?s:s.replaceAll("\\","/")}function Ke(s){for(let t=0;t<s.length;t++){let e=s.charCodeAt(t);if(e>=65&&e<=90)return s.toLowerCase()}return s}function qe(s,t){let e=s.length-t.length;if(e<0)return!1;for(let r=0;r<t.length;r++){let n=s.charCodeAt(e+r);if(n>=65&&n<=90&&(n+=32),n!==t.charCodeAt(r))return!1}return!0}function xt(s){return s>=97&&s<=122||s>=48&&s<=57||s>=65&&s<=90||s>=128}function gt(s,t,e){return xt(s.charCodeAt(t-1))?2:xt(s.charCodeAt(e))?1:0}function Ve(s){let t=-1;for(let a=0;a<s.length;a++){let o=s.charCodeAt(a);if(o>=48&&o<=57){t=a;break}}if(t===-1)return s;let e="",r=0,n=t,i=s.length;for(;n<i;){let a=s.charCodeAt(n);if(a>=48&&a<=57){n>r&&(e+=s.slice(r,n));let o=n;for(;n<i&&s.charCodeAt(n)===48;)n++;let c=n;for(;n<i;){let h=s.charCodeAt(n);if(h<48||h>57)break;n++}let l=n-c,f=n-o;e+="/"+String.fromCharCode(1+(l<40?l:40))+s.slice(c,n)+String.fromCharCode(1+(f<40?f:40)),r=n}else n++}return r<i&&(e+=s.slice(r)),e}function Ze(s,t){if(s.tier!==t.tier)return s.tier-t.tier;if(s.tier===3){if(s.fq!==t.fq)return s.fq-t.fq;if(s.word!==t.word)return s.word-t.word;if(s.fpos!==t.fpos)return s.fpos-t.fpos;let e=bt(s)-bt(t);return e||ne(s,t)||(s.nkey<t.nkey?-1:s.nkey>t.nkey?1:0)}return s.word!==t.word?s.word-t.word:s.nkey===t.nkey?bt(s)-bt(t)||ne(s,t):s.nkey<t.nkey?-1:1}function bt(s){if(s.depth!==-1)return s.depth;let t=0,e=s.ls;if(e!==-1){t=1;let r=s.full;for(let n=0;n<e;n++)r.charCodeAt(n)===47&&t++}return s.depth=t}function ne(s,t){let e=s.segs??=s.ls===-1?[]:s.full.slice(0,s.ls).split("/"),r=t.segs??=t.ls===-1?[]:t.full.slice(0,t.ls).split("/"),n=e.length<r.length?e.length:r.length;for(let i=0;i<n;i++){let a=Je(e[i],r[i]);if(a)return a}return 0}function He(s,t,{root:e=null,path:r=null,extension:n=null,filter:i=null,limit:a=null,folders:o=!0,caseSensitive:c=!1,spaces:l=null}={}){let f=null,h="",y="";if(t instanceof RegExp){let p=t.flags.replace("y","");p.includes("g")||(p+="g"),f=new RegExp(t.source,p)}else{let p=String(t??"").trim();c||(p=p.toLowerCase()),l!=null&&(p=p.replaceAll(" ",String(l))),p=p.replaceAll("\\","/").replace(/^\/+/,"");let g=p.lastIndexOf("/");if(g===-1?h=p:(h=p.slice(g+1),y=p.slice(0,g).replace(/\/+$/,"")+"/"),!h&&y&&!o)return[]}let u=h.length,d=null;if(n!=null){let p=Array.isArray(n)?n:[n];d=new Array(p.length);for(let g=0;g<p.length;g++){let j=String(p[g]);d[g]=(j.charCodeAt(0)===46?j:"."+j).toLowerCase()}}let m=null,_=null;e&&(_=It(String(e)).replace(/\/+$/,""),m=_+"/");let b=null,x=null,A=null,k=null;r&&(b=It(String(r)).replace(/\/+$/,""),x=b+"/",A="/"+x,k="/"+b);let S=[],z=Array.isArray(s)?s:Array.from(s);for(let p=0;p<z.length;p++){let g=z[p],j=It(typeof g=="string"?g:g.path);if(m&&!(j.startsWith(m)||j===_)||x&&!(j.startsWith(x)||j.includes(A)||j.endsWith(k)||j===b))continue;let O=c?j:Ke(j);if(d){let C=!1;for(let E=0;E<d.length;E++)if(c?qe(O,d[E]):O.endsWith(d[E])){C=!0;break}if(!C)continue}if(y!==""&&!O.includes(y))continue;let B=O.lastIndexOf("/"),v=O.slice(B+1),it=0,W=0,G=0,Mt=0;if(f){let C=B+1,E=v.lastIndexOf("."),L=4,F=3,X=3,q=3,V=0,I;for(;(I=f.exec(j))!==null;){if(I[0].length===0){f.lastIndex++;continue}let U=I.index,mt=U+I[0].length;if(mt>C){let N=2;if(U<=C){let ft=mt-C;N=ft===v.length||E>0&&ft===E?0:1}let tt=gt(j,U,mt);if((N<L||N===L&&tt<F)&&(L=N,F=tt,L===0&&F===0)){f.lastIndex=0;break}}else if(o&&B>0&&(L>3&&(L=3),X>0)){let N=mt;j.charCodeAt(N-1)===47&&N--;let tt=2;N>U&&(U===0||j.charCodeAt(U-1)===47)&&(tt=j.charCodeAt(N)===47&&j.indexOf("/",U)>=N?0:1);let ft=gt(j,U,N);(tt<X||tt===X&&ft<q)&&(X=tt,q=ft,V=U)}}if(L===4)continue;if(it=L,W=L===3?q:F,L===3){G=X;for(let U=0;U<V;U++)j.charCodeAt(U)===47&&Mt++}}else if(u!==0)if(v===h||v.length>u&&v.charCodeAt(u)===46&&v.startsWith(h)&&v.indexOf(".",u+1)===-1)it=0;else if(v.startsWith(h))it=1,W=xt(v.charCodeAt(u))?1:0;else if(v.includes(h)){it=2,W=2;for(let C=v.indexOf(h);C!==-1;C=v.indexOf(h,C+1)){let E=gt(v,C,C+u);if(E<W&&(W=E,W===0))break}}else if(o&&B>0){let C=O.indexOf(h);if(C===-1||C+u>B)continue;it=3,G=3,W=3;let E=0,L=0;for(;E<B;){let F=O.indexOf("/",E);(F===-1||F>B)&&(F=B);let X=F-E;if(X>=u){let q=3,V=2;if(O.startsWith(h,E))q=X===u?0:1,V=xt(O.charCodeAt(E+u))?1:0;else for(let I=O.indexOf(h,E);I!==-1&&I+u<=F;I=O.indexOf(h,I+1)){q=2;let U=gt(O,I,I+u);if(U<V&&(V=U,V===0))break}if((q<G||q===G&&V<W)&&(G=q,W=V,Mt=L,G===0))break}E=F+1,L++}if(G===3)continue}else continue;i&&!i(g)||S.push({it:g,nkey:Ve(v),full:O,ls:B,depth:-1,tier:it,word:W,fq:G,fpos:Mt,segs:null})}S.sort(Ze);let K=a!=null&&a<S.length?a:S.length,w=new Array(K);for(let p=0;p<K;p++)w[p]=S[p].it;return w}var ie=He;P();var ae="https://piston-meta.mojang.com/mc/game/version_manifest_v2.json",oe="https://api.github.com/repos/Mojang/bedrock-samples/releases",ue=Date.parse("2013-06-13T15:32:23+00:00"),ce=600*1e3,le="asset_indexes",Ge=["1.20.4","1.20.6","1.21.3","1.21.4","1.21.5","1.21.8","1.21.10","1.21.11"];function Xe(s,t){if(t){let[r,n,i]=s.split(".");return`${r}.${n}.${Math.floor((parseInt(i)||0)/10)*10}`}let e=/^(\d+)\.(\d+)/.exec(s);return e?e[1]+"."+e[2]:s}function fe(s){let t=s.assets?.find(e=>e.name.endsWith("-full.zip"));return{id:s.tag_name.replace(/^v/,""),type:s.prerelease?"snapshot":"release",releaseTime:s.published_at,tag:s.tag_name,zip:t?{url:t.browser_download_url,size:t.size}:{url:`https://github.com/Mojang/bedrock-samples/archive/refs/tags/${s.tag_name}.zip`,size:null,archive:!0}}}function Ye(s){let t=s.some(a=>a.zip),e=s.filter(a=>a.type==="release"),r=new Set,n=new Set;for(let a of e){let o=Xe(a.id,t);n.has(o)||(n.add(o),r.add(a))}if(!t)for(let a of e)Ge.includes(a.id)&&r.add(a);let i=s.find(a=>a.type==="snapshot");return i&&(!e[0]||Date.parse(i.releaseTime)>Date.parse(e[0].releaseTime))&&r.add(i),s.filter(a=>r.has(a))}var Qe={RELEASE:"release",SNAPSHOT:"snapshot",BETA:"old_beta",ALPHA:"old_alpha",MAIN:Ye,MODERN:s=>s.filter(t=>!t.legacyLayout)};function de(s,t){if(t==null)return s.slice();if(typeof t=="string")return s.filter(e=>e.type===t);if(typeof t=="function")return t(s);if(Array.isArray(t)){let e=new Set;for(let r of t)for(let n of de(s,r))e.add(n);return s.filter(r=>e.has(r))}throw new TypeError("Unsupported version filter")}function ts(s){if(!s)return ce;let t=s.get("cache-control"),e=t&&/max-age=(\d+)/i.exec(t);if(e){let n=parseInt(s.get("age")??"0",10)||0;return Math.max(0,(Number(e[1])-n)*1e3)}let r=s.get("expires");if(r){let n=Date.parse(r),i=Date.parse(s.get("date")??"");if(!Number.isNaN(n))return Math.max(0,n-(Number.isNaN(i)?Date.now():i))}return ce}var et=s=>s.sha1??(s.url?at(s.url):s.id),es={search:"arg",file:"arg",read:"arg",getTexture:"arg",getModel:"arg",getBlockstate:"arg",getItemDefinition:"arg",getSound:"arg",getLang:"arg",getStructure:"arg",loadJar:"opts",loadObjects:"opts",export:"opts"},he=new WeakMap,dt=Symbol("state"),jt=class{constructor(t,e){Object.assign(this,e),this.legacyLayout=Date.parse(e.releaseTime)<ue,this[dt]=Object.freeze({manifest:t})}details(){return this[dt].manifest.details(this)}list(t,e){let r=this[dt].manifest.mc;return r._isFolderArg(t)?r.list(t,{...e,version:this}):r.list({...t,version:this})}};for(let[s,t]of Object.entries(es))jt.prototype[s]=t==="arg"?function(e,r){return this[dt].manifest.mc[s](e,{...r,version:this})}:function(e){return this[dt].manifest.mc[s]({...e,version:this})};function ss(s,t){if(s.entries.length!==t.entries.length)return!1;for(let e=0;e<s.entries.length;e++)if(s.entries[e]!==t.entries[e])return!1;return!0}var St=class{constructor(t,{manifest:e,manifestExpiry:r,onProgress:n,onUpdate:i}={}){this.mc=t,this._expiry=r,this._onProgress=n,this._onUpdate=i,this._state=null,this._owned=!1,this._expiresAt=0,this._pending=null,this._persisted=null,this._details=new Map,this._source=null,e!=null&&this._adopt(e)}get _cacheKey(){return this.mc._type==="bedrock"?"bedrock_manifest":this.mc._type==="assets"?"assets_manifest":"manifest"}async _current(){if(this._owned)return this._state;if(this._state&&Date.now()<this._expiresAt)return this._state;let t;if(!this._state)if(t=await this.mc._store.get("meta",this._cacheKey),!(t?.json?.versions&&typeof t.time=="number"))t=void 0;else{let e=t.time+this._effectiveTtl(t.ttl);if((Date.now()<e||!R)&&(this._state=this._build(t.json),this._owned=!1,this._expiresAt=e,Date.now()<e))return this._state}if(this._state&&!R&&this._onUpdate){if(!this._pending){let e=this._state;this._pending=this._fetch().then(r=>{ss(e,r)||this._onUpdate(this)}).catch(()=>{}).finally(()=>{this._pending=null})}return this._state}this._pending||(this._pending=this._fetch().finally(()=>{this._pending=null}));try{return await this._pending}catch(e){if(this._state)return this._state;if(t)return this._state=this._build(t.json),this._owned=!1,this._expiresAt=0,this._state;throw e}}_effectiveTtl(t){return this._expiry===void 0?t:this._expiry==null?1/0:this._expiry}async _fetch(){let{json:t,headers:e}=this.mc._type==="bedrock"?await this._fetchBedrock():this.mc._type==="assets"?await this._fetchAssets():await this._fetchJava(),r=this._build(t),n=ts(e);return this._state=r,this._owned=!1,this._expiresAt=Date.now()+this._effectiveTtl(n),this._persisted=this.mc._store.set("meta",this._cacheKey,{time:Date.now(),ttl:n,json:t}),r}async _fetchJava(){let t=await this.mc._request(ae);return{json:await t.json(),headers:t.headers}}async _fetchBedrock(){let t=[],e,r=1;for(;;){let n=await this.mc._request(`${oe}?per_page=100&page=${r++}`),i=await n.json();for(let a of i)t.push(fe(a));if(e=n.headers,i.length<100)break}return{json:{versions:t},headers:e}}async _fetchAssets(){let t=this._source?null:await this.mc._request(ae),r=(this._source??await t.json()).versions,n=this.mc._store,i=new Array(r.length),a=new Map,o=this.mc,c=this._onProgress,l=0,f=0,h=-1,y=()=>{let w=f?++l/f:1,p=Math.round(w*100);p===h&&l<f||(h=p,c?.(w))},u=await n.get("meta",le)??{},d=0,m=()=>d?n.set("meta",le,u).then(()=>{d=0}):null;function _(w){return J(a,w,async()=>{let p=at(r[w].url);if(!(p in u)){let g=await(await o._request(r[w].url)).json();u[p]=g.assetIndex??null,d++}return i[w]=u[p]})}function b(w){let p=new Date(w.releaseTime),g=p.getUTCMonth();return g===2&&p.getUTCDate()>=25||g===3&&p.getUTCDate()<=7}let x=[];for(let w=0;w<r.length;w++)(w===0||w===r.length-1||r[w].type==="release"||b(r[w]))&&x.push(w);let A=[],k=new Set;for(let w=1;w<x.length;w++){let p=x[w-1]+1,g=x[w]-1;g<p||(A.push([p,g]),k.add(p).add(g))}f=x.length+k.size+A.length,h=0,c?.(0),await M(x,32,async w=>{await _(w),y()}),m(),await M(Array.from(k),32,async w=>{await _(w),y()}),m();async function S(w,p){if(p-w<1)return;if(p-w-1<=2){await Promise.all(Array.from({length:p-w+1},(B,v)=>_(w+v)));return}let[g,j]=await Promise.all([_(w),_(p)]);if(g?.id===j?.id)return;let O=w+p>>1;await _(O),await Promise.all([S(w,O),S(O,p)])}await Promise.all(A.map(async([w,p])=>{await S(w,p),y()})),await m();for(let w=1;w<r.length;w++)i[w]===void 0&&(i[w]=i[w-1]);let z=new Map;for(let w=r.length-1;w>=0;w--){let p=r[w],g=i[w];if(!g)continue;let j=z.get(g.id);j?(p.type==="release"&&(j.type="release"),j.last=p.id):z.set(g.id,{id:g.id,type:p.type==="release"?"release":"snapshot",releaseTime:p.releaseTime,sha1:g.sha1,url:g.url,size:g.size,totalSize:g.totalSize,first:p.id,last:p.id})}return{json:{versions:Array.from(z.values()).sort((w,p)=>Date.parse(p.releaseTime)-Date.parse(w.releaseTime))},headers:t?.headers}}_adopt(t){if(this.mc._type==="bedrock"){if(!Array.isArray(t)||t.some(r=>typeof r?.tag_name!="string"))throw new TypeError("Not a releases array");this._state=this._build({versions:t.map(fe)}),this._owned=!0,this._expiresAt=1/0;return}if(!t||typeof t!="object"||!Array.isArray(t.versions))throw new TypeError("Not a version manifest");let e=JSON.parse(JSON.stringify(t));if(this.mc._type==="assets"){this._source=e;return}this._state=this._build(e),this._owned=!0,this._expiresAt=1/0}_build(t){if(!t||!Array.isArray(t.versions))throw new TypeError("Not a version manifest");let e=new Map;if(this._state)for(let i of this._state.entries)e.set(et(i),i);let r=t.versions.map(i=>{let a=e.get(et(i));return a&&he.get(a)===JSON.stringify(i)?a:this._enrich(i)}),n=new Map;for(let i of r)n.has(i.id)||n.set(i.id,i);return{entries:r,byId:n}}_enrich(t){let e=new jt(this,t);return he.set(e,JSON.stringify(t)),e}async versions(t){let{entries:e}=await this._current();return de(e,t)}async version(t){let e=await this._current();return t==="release"||t==="snapshot"||t==="newest"?this._latest(e)[t]:e.byId.get(t)??null}async latest(){return this._latest(await this._current())}_latest({entries:t}){return{release:t.find(e=>e.type==="release")??null,snapshot:t.find(e=>e.type==="snapshot")??null,newest:t[0]??null}}peek(t){let e=this._state;if(!e)return null;if(t==="release"||t==="snapshot"||t==="newest")return this._latest(e)[t];let r=typeof t=="object"&&t!==null?t.id:t;return e.byId.get(r)??null}async update(t){t!==void 0&&(this._adopt(t),this.mc._type!=="assets")||await this._fetch()}async resolve(t){if(t==="release"||t==="snapshot"||t==="newest"){let n=(await this.latest())[t];if(!n)throw new Error(`No ${t} version in the manifest`);return n}let e=typeof t=="object"&&t!==null?t.id:t,r=await this.version(e);if(r)return r;if(typeof t=="object"&&t!==null&&t.url)return t;throw new Error(`Unknown version "${e}"`)}async details(t){let e=await this.resolve(t),r=et(e);return J(this._details,r,()=>this._fetchDetails(e,r))}async _fetchDetails(t,e){let r=this.mc._store,n=this.mc._type,i=(n==="bedrock"?"bedrock_details_":n==="assets"?"index_":"details_")+e,a=await r.get("meta",i);if(a&&typeof a=="object")return a;let c=await(await this.mc._request(n==="bedrock"?`${oe}/tags/${t.tag}`:t.url)).json();return r.set("meta",i,c),c}};P();var rs=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258],ns=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],is=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],as=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],os=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],zt=9,Rt=1<<zt,cs=Rt-1;function pt(s,t){let e=new Uint16Array(16);for(let c=0;c<t;c++)e[s[c]]++;e[0]=0;let r=new Uint16Array(16),n=new Uint16Array(16),i=0;for(let c=1;c<16;c++)r[c]=r[c-1]+e[c-1],i=i+e[c-1]<<1,n[c]=i;let a=new Uint16Array(t),o=new Uint16Array(Rt);for(let c=0;c<t;c++){let l=s[c];if(!l)continue;a[r[l]++]=c;let f=n[l]++;if(l>zt)continue;let h=0;for(let u=0;u<l;u++)h|=(f>>u&1)<<l-1-u;let y=l<<9|c;for(let u=h;u<Rt;u+=1<<l)o[u]=y}return{count:e,symbol:a,fast:o}}var yt=new Uint8Array(288);yt.fill(8,0,144);yt.fill(9,144,256);yt.fill(7,256,280);yt.fill(8,280,288);var ls=pt(yt,288),fs=pt(new Uint8Array(30).fill(5),30);function pe(s,t){let e=new Uint8Array(t??Math.max(1024,s.length*4)),r=0,n=0,i=0,a=0,o=s.length;function c(y){for(;a<y;){if(n>o+4)throw new Error("Truncated deflate data");i|=(n<o?s[n]:0)<<a,n++,a+=8}}function l(y){a<y&&c(y);let u=i&(1<<y)-1;return i>>>=y,a-=y,u}function f(y){a<zt&&c(zt);let u=y.fast[i&cs];if(u){let x=u>>9;return i>>>=x,a-=x,u&511}let d=0,m=0,_=0,b=y.count;for(let x=1;x<=15;x++){d|=l(1);let A=b[x];if(d-A<m)return y.symbol[_+(d-m)];_+=A,m+=A,m<<=1,d<<=1}throw new Error("Invalid deflate data")}function h(y){if(y<=e.length)return;let u=new Uint8Array(Math.max(y,e.length*2));u.set(e.subarray(0,r)),e=u}for(;;){let y=l(1),u=l(2);if(u===0){n-=a>>3,i=0,a=0;let d=s[n]|s[n+1]<<8;if(n+=4,n+d>o)throw new Error("Truncated deflate data");h(r+d),e.set(s.subarray(n,n+d),r),n+=d,r+=d}else if(u===1||u===2){let d=ls,m=fs;if(u===2){let _=l(5)+257,b=l(5)+1,x=l(4)+4,A=new Uint8Array(320);for(let z=0;z<x;z++)A[os[z]]=l(3);let k=pt(A,19);A.fill(0);let S=0;for(;S<_+b;){let z=f(k);if(z<16)A[S++]=z;else{let K,w=0;z===16?(w=A[S-1],K=3+l(2)):z===17?K=3+l(3):K=11+l(7),A.fill(w,S,S+K),S+=K}}d=pt(A,_),m=pt(A.subarray(_),b)}for(;;){let _=f(d);if(_<256)r>=e.length&&h(r+1),e[r++]=_;else{if(_===256)break;{let b=_-257,x=rs[b]+l(ns[b]),A=f(m),k=is[A]+l(as[A]);h(r+x);let S=r-k;for(let z=0;z<x;z++)e[r++]=e[S++]}}}}else throw new Error("Invalid deflate block type");if(y)break}return r===e.length?e:e.subarray(0,r)}var hs=1<<20,us=67324752,me=33639248,ge=101010256,H=(s,t)=>s[t]|s[t+1]<<8,D=(s,t)=>(s[t]|s[t+1]<<8|s[t+2]<<16|s[t+3]<<24)>>>0,st=(s,t)=>D(s,t)+D(s,t+4)*4294967296,ds,be=()=>ds??=Promise.resolve().then(()=>re(ye(),1));async function xe(s,t){let e=t.writable.getWriter();return e.write(s).catch(()=>{}),e.close().catch(()=>{}),new Uint8Array(await new Response(t.readable).arrayBuffer())}async function $t(s){return R?(await be()).inflateRaw(s):xe(s,new DecompressionStream("deflate-raw"))}async function ps(s,t){return R?(await be()).deflateRaw(s,t):xe(s,new CompressionStream("deflate-raw"))}var Ae=new Int32Array(256);for(let s=0;s<256;s++){let t=s;for(let e=0;e<8;e++)t=t&1?3988292384^t>>>1:t>>>1;Ae[s]=t}function ys(s){let t=-1;for(let e=0;e<s.length;e++)t=Ae[(t^s[e])&255]^t>>>8;return(t^-1)>>>0}function kt(s){for(let t=s.length-22;t>=0;t--)if(D(s,t)===ge)return t;return-1}function Ot(s,t){return{count:H(s,t+10),cdSize:D(s,t+12),cdOffset:D(s,t+16)}}function Pt(s){let t=[],e=0;for(;e+46<=s.length&&D(s,e)===me;){let r=H(s,e+28),n=H(s,e+30),i=H(s,e+32),a={path:T.decode(s.subarray(e+46,e+46+r)),method:H(s,e+10),crc:D(s,e+16),compressedSize:D(s,e+20),size:D(s,e+24),offset:D(s,e+42),nameLen:r};if(a.size===4294967295||a.compressedSize===4294967295||a.offset===4294967295){let o=e+46+r,c=o+n;for(;o+4<=c;){let l=H(s,o),f=H(s,o+2);if(l===1){let h=o+4;a.size===4294967295&&(a.size=st(s,h),h+=8),a.compressedSize===4294967295&&(a.compressedSize=st(s,h),h+=8),a.offset===4294967295&&(a.offset=st(s,h));break}o+=4+f}}t.push(a),e+=46+r+n+i}return t}function Bt(s){let t=kt(s);if(t<0)throw new Error("Not a zip file");let e=Ot(s,t);if((e.count===65535||e.cdSize===4294967295||e.cdOffset===4294967295)&&t>=20&&D(s,t-20)===117853008){let r=st(s,t-12);r+56<=s.length&&D(s,r)===101075792&&(e={count:st(s,r+32),cdSize:st(s,r+40),cdOffset:st(s,r+48)})}return{...e,entries:Pt(s.subarray(e.cdOffset,e.cdOffset+e.cdSize))}}function ws(s,t){let e=t.offset;return e+30+H(s,e+26)+H(s,e+28)}function ot(s,t){let e=ws(s,t);return s.subarray(e,e+t.compressedSize)}function Wt(s,t){return t.method===0?s.slice():t.size<=hs?pe(s,t.size):null}async function wt(s,t){return Wt(s,t)??$t(s)}function _s(s,t){return wt(ot(s,t),t)}var we=0,_e=33;async function Jt(s,t=ut()){if(s.length>65535)throw new Error("Too many entries for a plain zip");let e=[],r=[],n=0;for(let f of s){await t();let h=Y.encode(f.path),y=new Uint8Array(30+h.length),u=new DataView(y.buffer);u.setUint32(0,us,!0),u.setUint16(4,20,!0),u.setUint16(8,f.method,!0),u.setUint16(10,we,!0),u.setUint16(12,_e,!0),u.setUint32(14,f.crc,!0),u.setUint32(18,f.compressedSize,!0),u.setUint32(22,f.size,!0),u.setUint16(26,h.length,!0),u.setUint16(28,0,!0),y.set(h,30);let d=new Uint8Array(46+h.length),m=new DataView(d.buffer);m.setUint32(0,me,!0),m.setUint16(4,20,!0),m.setUint16(6,20,!0),m.setUint16(10,f.method,!0),m.setUint16(12,we,!0),m.setUint16(14,_e,!0),m.setUint32(16,f.crc,!0),m.setUint32(20,f.compressedSize,!0),m.setUint32(24,f.size,!0),m.setUint16(28,h.length,!0),m.setUint32(42,n,!0),d.set(h,46),e.push(y,f.data),r.push(d),n+=y.length+f.data.length}let i=r.reduce((f,h)=>f+h.length,0);if(n+i>4294967295)throw new Error("Archive too large for a plain zip");let a=new Uint8Array(22),o=new DataView(a.buffer);o.setUint32(0,ge,!0),o.setUint16(8,s.length,!0),o.setUint16(10,s.length,!0),o.setUint32(12,i,!0),o.setUint32(16,n,!0);let c=new Uint8Array(n+i+22),l=0;for(let f of e.concat(r,[a]))c.set(f,l),l+=f.length,await t();return c}async function Et(s,t,e=!0){let r=ys(t),n=t,i=0;if(e&&t.length>0){let a=await ps(t);a.length<t.length&&(n=a,i=8)}return{path:s,method:i,crc:r,size:t.length,compressedSize:n.length,data:n}}function ms(s){let t=s instanceof Uint8Array?s:new Uint8Array(s);return Bt(t).entries.filter(e=>!e.path.endsWith("/")).map(e=>{let r={path:e.path,size:e.size,crc:e.crc},n;return Z(r,"read",()=>n??=_s(t,e)),Z(r,"raw",async()=>({compression:e.method===8?"deflate-raw":null,bytes:ot(t,e)})),r})}async function gs(s,t){let{compression:e,bytes:r}=await t.raw();return{path:s,method:e?8:0,crc:t.crc,size:t.size,compressedSize:r.length,data:r}}function bs(s){return typeof s.raw=="function"&&typeof s.crc=="number"&&typeof s.size=="number"}async function xs(s,{compress:t=!0,concurrency:e=32,onProgress:r}={}){let n=s instanceof Map?Array.from(s):Array.isArray(s)?s.map(c=>[c.path,c]):Object.entries(s),i=new Array(n.length),a=ut(),o=0;return await M(n,e,async([c,l],f)=>{i[f]=l instanceof Uint8Array?await Et(c,l,t):bs(l)?await gs(c,l):await Et(c,await l.read(),t),r?.(++o,n.length),await a()}),Jt(i,a)}P();var ct=class{constructor({url:t,size:e,request:r,store:n}){this.url=t,this.size=e,this.request=r,this.store=n,this._listing=null,this._list=null,this._buffer=null,this._held=null,this._persisted=null,this._persistedMeta=null,this._progress=null,this._reads=new Map}buffer(){return $(this,"_buffer",async()=>this._held=await this._loadBuffer())}listing(){return $(this,"_listing",async()=>this._list=await this._loadListing())}async load(t){this._progress=t;try{let[,e]=await Promise.all([this.listing(),this.buffer()]);if(t){let r=Array.isArray(e)?e.reduce((n,i)=>n+i.bytes.length,0):e.length;t(r,r)}}finally{this._progress=null}}async settled(){await this._persisted,await this._list?.sorting,await this._persistedMeta}async extract(t){let e=await this.raw(t);return e?wt(e.data,e.entry):null}read(t){let e=this._reads.get(t);if(e)return e;if(!this._list||!this._held)return J(this._reads,t,()=>this.extract(t));let r;try{let n=this.rawSync(t),i=n&&Wt(n.data,n.entry);r=n?i?Promise.resolve(i):$t(n.data):Promise.resolve(null)}catch(n){r=Promise.reject(n)}return this._reads.set(t,r),r.catch(()=>{this._reads.get(t)===r&&this._reads.delete(t)}),r}};P();var As=65536,js=4<<20,Ss=4096,zs=65536,Es=6,je=1245791053,Q=8,rt=16,ks=s=>s.endsWith("/");function Os(s,t){return ks(s)?!1:t?!s.endsWith(".class")&&!s.startsWith("META-INF/"):s.startsWith("assets/")||s.startsWith("data/")?!s.endsWith("/.mcassetsroot"):s==="pack.png"||s==="pack.mcmeta"||s==="version.json"}function vs(s){let t=s.reduce((i,a)=>i+a.bytes.length,0),e=new Uint8Array(Q+s.length*rt+t),r=new DataView(e.buffer);r.setUint32(0,je,!0),r.setUint32(4,s.length,!0);let n=Q+s.length*rt;return s.forEach((i,a)=>{r.setFloat64(Q+a*rt,i.start,!0),r.setFloat64(Q+a*rt+8,i.bytes.length,!0),e.set(i.bytes,n),n+=i.bytes.length}),e}function Us(s,t){if(s.length<Q)return null;let e=new DataView(s.buffer,s.byteOffset,s.byteLength);if(e.getUint32(0,!0)!==je)return null;let r=e.getUint32(4,!0),n=Q+r*rt;if(r===0||n>s.length)return null;let i=[];for(let o=0;o<r;o++){let c=e.getFloat64(Q+o*rt,!0),l=e.getFloat64(Q+o*rt+8,!0);if(n+l>s.length||c+l>t)return null;i.push({start:c,bytes:s.subarray(n,n+l)}),n+=l}let a=i[i.length-1];return a.start+a.bytes.length===t?i:null}var vt=class extends ct{constructor(t){super(t),this.sha1=t.sha1,this.legacyLayout=t.legacyLayout,this.local=t.local??null,this._cached=null,this._tail=null,this._whole=null}get metaKey(){return"jar_"+this.sha1}get blobKey(){return"jar_"+this.sha1}async _range(t,e,r){if(this.local)try{return await this._readLocal(t,e,r)}catch{this.local=null}let n=e-t;if(this._whole)return r?.(n),this._whole.subarray(t,e);let i=await this.request(this.url,{headers:{Range:`bytes=${t}-${e-1}`},cache:"no-store"});if(i.status===200){let o=new Uint8Array(await i.arrayBuffer());if(o.length!==this.size)throw new Error(`Ranged request refused (200, ${o.length} bytes for the whole jar) by ${this.url}`);return this._whole=o,r?.(n),o.subarray(t,e)}let a=r&&i.body?await At(i,r,n):new Uint8Array(await i.arrayBuffer());if(i.status!==206||a.length!==n)throw new Error(`Ranged request refused (${i.status}, ${a.length} bytes for ${n}) by ${this.url}`);return r&&!i.body&&r(n),a}async _readLocal(t,e,r){let i=await(await import("node:fs/promises")).open(this.local,"r");try{let a=new Uint8Array(e-t),{bytesRead:o}=await i.read(a,0,a.length,t);if(o!==a.length)throw new Error("Short read");return r?.(a.length),a}finally{await i.close()}}cached(){return $(this,"_cached",()=>this._loadCached())}async _loadCached(){let t=await this.store.get("blobs",this.blobKey);if(!t)return null;let e=Us(t,this.size);return e||await this.store.delete("blobs",this.blobKey),e}async _loadListing(){let t=await this.store.get("meta",this.metaKey);if(t?.entries&&t.size===this.size)return this._inflateListing(t);let e=await this.cached();return e?this._listingFromZip(this._parseTail(e[e.length-1])):this._probe()}_parseTail(t){let e=kt(t.bytes);if(e<0)throw new Error("No zip end record found in "+this.url);let r=Ot(t.bytes,e);return{...r,entries:Pt(t.bytes.subarray(r.cdOffset-t.start,r.cdOffset-t.start+r.cdSize))}}_inflateListing({entries:t,cdOffset:e,cdSize:r,sorted:n}){let i=new Map;for(let[a,o,c,l,f,h]of t)i.set(a,{path:a,offset:o,compressedSize:c,size:l,method:f,crc:h});return{entries:i,cdOffset:e,cdSize:r,sorted:!!n}}_listingFromZip({entries:t,cdOffset:e,cdSize:r}){let n=new Map;for(let a of t)Os(a.path,this.legacyLayout)&&n.set(a.path,a);let i={entries:n,cdOffset:e,cdSize:r,sorted:!1};return i.sorting=new Promise(a=>setTimeout(a,0)).then(()=>{let a=Array.from(n.values()).sort((o,c)=>ht.compare(o.path,c.path));i.order=a.map(o=>o.path),i.sorted=!0,this._persistedMeta=this.store.set("meta",this.metaKey,{size:this.size,cdOffset:e,cdSize:r,sorted:!0,entries:a.map(o=>[o.path,o.offset,o.compressedSize,o.size,o.method,o.crc])})}),i}async _probe(){let t=Math.max(0,this.size-Math.min(js,Math.max(As,Math.round(this.size/10)))),e=await this._range(t,this.size),r=kt(e);if(r<0)throw new Error("No zip end record found in "+this.url);let n=Ot(e,r),i={start:t,bytes:e};if(n.cdOffset<t){let a=await this._range(n.cdOffset,t),o=new Uint8Array(this.size-n.cdOffset);o.set(a,0),o.set(e,t-n.cdOffset),i={start:n.cdOffset,bytes:o}}return this._tail=i,this._listingFromZip(this._parseTail(i))}async _loadBuffer(){let t=await this.cached(),{entries:e,cdOffset:r}=await this.listing();if(t){if(this._covers(t,e))return t;await this.store.delete("blobs",this.blobKey).catch(()=>{})}let n=this._tail,i=Array.from(e.values()).filter(f=>!n||f.offset<n.start).map(f=>this._entryRange(f,this.size));n||i.push([r,this.size]);let a=Cs(i,zs),o=this._progress,c;if(o){let f=a.reduce((y,[u,d])=>y+d-u,0),h=0;o(0,f),c=y=>o(h+=y,f)}let l=[];return await M(a,Es,async([f,h])=>{l.push({start:f,bytes:await this._range(f,h,c)})}),n&&l.push(n),l.sort((f,h)=>f.start-h.start),this.local||(this._persisted=this._persist(l)),l}async _persist(t){try{await this.store.set("blobs",this.blobKey,vs(t))}catch{}}_entryRange(t,e){let r=t.offset+30+(t.nameLen??Y.encode(t.path).length)+t.compressedSize+Ss;return[t.offset,Math.min(e,r)]}_covers(t,e){for(let r of e.values()){let n=t.findLast(l=>l.start<=r.offset);if(!n)return!1;let i=r.offset-n.start,a=n.bytes;if(i+30>a.length)return!1;let o=a[i+26]|a[i+27]<<8,c=a[i+28]|a[i+29]<<8;if(i+30+o+c+r.compressedSize>a.length)return!1}return!0}async raw(t){return this._list&&this._held?this.rawSync(t):(await Promise.all([this.listing(),this.buffer()]),this.rawSync(t))}rawSync(t){let e=this._list.entries.get(t);if(!e)return null;let n=this._held.findLast(i=>i.start<=e.offset);return{entry:e,data:ot(n.bytes,{...e,offset:e.offset-n.start})}}};function Cs(s,t){let e=s.filter(n=>n[1]>n[0]).sort((n,i)=>n[0]-i[0]),r=[];for(let[n,i]of e){let a=r[r.length-1];a&&n-a[1]<=t?a[1]=Math.max(a[1],i):r.push([n,i])}return r}P();var Ts=s=>s.startsWith(".github/")||s===".gitignore"||!s.includes("/")&&s.toLowerCase().endsWith(".md"),Ut=class extends ct{constructor(t){super(t),this.archive=t.archive,this.key=t.key}get blobKey(){return"bedrock_"+this.key}async _loadBuffer(){let t=await this.store.get("blobs",this.blobKey);if(t)return t;let e=await this.request(this.url),r=this.size??(Number(e.headers.get("content-length"))||null),n=0,i=await At(e,this._progress?a=>this._progress(n+=a,r):void 0);return this._persisted=this.store.set("blobs",this.blobKey,i).catch(()=>{}),i}async _loadListing(){let t=await this.buffer(),e=new Map;for(let r of Bt(t).entries){if(r.path.endsWith("/"))continue;let n=r.path;if(this.archive){let i=n.indexOf("/");if(i<0)continue;n=n.slice(i+1)}!n||Ts(n)||e.set(n,{...r,path:n})}return{entries:e}}async raw(t){return await this.listing(),this.rawSync(t)}rawSync(t){let e=this._list.entries.get(t);return e?{entry:e,data:ot(this._held,e)}:null}};var Ls="https://resources.download.minecraft.net/";function Se(s){let t=s?.objects??{},e=Object.keys(t),n=e.some(a=>a.startsWith("minecraft/"))?"assets/":"assets/minecraft/",i=new Map;for(let a of e){let{hash:o,size:c}=t[a];if(typeof o!="string")continue;let l=a==="pack.mcmeta"?a:n+a;i.set(l,{hash:o,size:c})}return i}var ze=s=>Ls+s.slice(0,2)+"/"+s;P();var Ct=class{constructor(t,e){this.mc=t,this.entry=e,this.key=et(e),this._details=null,this._jar=null,this._jarValue=null,this._index=null,this._listings=new Map}details(){return $(this,"_details",()=>this.mc.manifest.details(this.entry))}jar(){return $(this,"_jar",async()=>this._jarValue=await this._openJar())}async _openJar(){if(this.mc._type==="assets")throw new Error("Asset index versions have no jar");if(this.mc._type==="bedrock"){let n=this.entry.zip;if(!n?.url)throw new Error(`Version "${this.entry.id}" has no download`);return new Ut({url:n.url,size:n.size,archive:n.archive,key:this.entry.tag??this.entry.id,request:(i,a)=>this.mc._request(i,a),store:this.mc._store})}let e=(await this.details()).downloads?.client;if(!e?.url)throw new Error(`Version "${this.entry.id}" has no client jar`);let r=await this.mc._local();return new vt({url:e.url,size:e.size,sha1:e.sha1??at(e.url),local:r?await r.jar(this.entry.id,e):null,legacyLayout:this.entry.legacyLayout,request:(n,i)=>this.mc._request(n,i),store:this.mc._store})}index(){return $(this,"_index",async()=>{if(this.mc._type==="bedrock")return null;let t=this.mc._type==="assets"?this.entry:(await this.details()).assetIndex,e=t?.url;if(!e)return null;let r=this.mc._store,n="index_"+(t.sha1??at(e)),i=await r.get("meta",n);if(!i?.objects){let a=await this.mc._local();i=a?await a.index(t.id,t.sha1):null,i?.objects||(i=await(await this.mc._request(e)).json(),r.set("meta",n,i))}return Se(i)})}listing(t){this.mc._type!=="java"&&(t=!1);let e=t?"on":"off";return J(this._listings,e,()=>this._buildListing(!!t))}async _buildListing(t){if(this.mc._type==="assets"){let f=await this.index(),h=new Map;for(let[d,m]of f)h.set(d,this._fileEntry(d,null,m));let y=Object.freeze(Array.from(h.values()).sort((d,m)=>ht.compare(d.path,m.path))),u;return{files:y,byPath:h,get paths(){return u??=Object.freeze(y.map(d=>d.path))}}}let e=await this.jar(),[r,n]=await Promise.all([e.listing(),t?this.index():null]);!r.sorted&&r.sorting&&await r.sorting;let{entries:i}=r,a=new Map;for(let[f,h]of i)a.set(f,this._fileEntry(f,h,n?.get(f)));if(n)for(let[f,h]of n)a.has(f)||a.set(f,this._fileEntry(f,null,h));let o;!n&&r.order?o=r.order.map(f=>a.get(f)):(o=Array.from(a.values()),(!r.sorted||n)&&o.sort((f,h)=>ht.compare(f.path,h.path)));let c=Object.freeze(o),l;return{files:c,byPath:a,get paths(){return l??=Object.freeze(c.map(f=>f.path))}}}_fileEntry(t,e,r){return new qt(this,t,e,r)}readJar(t){let e=this._jarValue;return e?e.read(t):this.jar().then(r=>r.read(t))}async file(t,e){let{byPath:r}=await this.listing(e);return r.get(t)??null}async read(t,e,r){let n=await this.file(t,e);return n?n.read({prefer:r}):null}},Kt=Symbol("state"),qt=class{constructor(t,e,r,n){this.path=e,t.mc._type==="java"&&(this.source=n?"object":"jar"),this.size=(n??r).size,n?this.hash=n.hash:this.crc=r.crc,this[Kt]=Object.freeze({ctx:t,jar:r,obj:n})}read({prefer:t}={}){let{ctx:e,jar:r,obj:n}=this[Kt];return r&&(!n||t==="jar")?e.readJar(this.path):e.mc._readObject(n.hash)}raw({prefer:t}={}){let{ctx:e,jar:r,obj:n}=this[Kt];if(!(r&&(!n||t==="jar")))return e.mc._readObject(n.hash).then(o=>({compression:null,bytes:o}));let a=e._jarValue;return a?._list&&a._held?Promise.resolve(Ee(a.rawSync(this.path))):e.jar().then(o=>o.raw(this.path)).then(Ee)}};function Ee(s){return s?{compression:s.entry.method===8?"deflate-raw":null,bytes:s.data}:null}P();async function lt(s){try{return await s()}catch{return}}function Fs(s){if(s instanceof Uint8Array)return s;if(s instanceof ArrayBuffer)return new Uint8Array(s);if(ArrayBuffer.isView(s))return new Uint8Array(s.buffer,s.byteOffset,s.byteLength);throw new TypeError("cacheAPI.read must return bytes")}function Is(s){return{async get(t,e){let r=await s.read?.(t+"/"+e);if(r==null)return;let n=Fs(r);return t==="meta"?JSON.parse(T.decode(n)):n},async set(t,e,r){await s.write?.(t+"/"+e,t==="meta"?Y.encode(JSON.stringify(r)):r)},async delete(t,e){await s.delete?.(t+"/"+e)},async list(){let t=await s.list?.();return t==null?void 0:Array.from(t,e=>({key:String(e.key),size:Number(e.size)||0}))},async clear(){await s.clear?.()},async setMaxSize(){}}}function Ns(s,t,e){let r,n=()=>r??=R?Promise.resolve().then(()=>re(ke(),1)).then(i=>new i.FileCache(s,{maxSize:t,key:e})):Promise.resolve().then(()=>(Ue(),ve)).then(i=>new i.OpfsCache(s,{maxSize:t,key:e}));return n().catch(()=>{}),{get:async(i,a)=>(await n()).get(i,a),set:async(i,a,o)=>(await n()).set(i,a,o),delete:async(i,a)=>(await n()).delete(i,a),list:async()=>(await n()).list(),clear:async()=>(await n()).clear(),setMaxSize:async i=>(await n()).setMaxSize(i)}}function Ce({cacheAPI:s,cacheDir:t,cacheSize:e,cacheKey:r}={}){let n=s?Is(s):Ns(t,e,r);return{get:(i,a)=>lt(()=>n.get(i,a)),set:(i,a,o)=>lt(()=>n.set(i,a,o)),delete:(i,a)=>lt(()=>n.delete(i,a)),list:async()=>await lt(()=>n.list())??null,clear:()=>lt(()=>n.clear()),setMaxSize:i=>lt(()=>n.setMaxSize(i))}}P();var _t=s=>String(s).replace(/\\/g,"/").replace(/^(\.\/)+/,"").replace(/^\/+|\/+$/g,""),Fe=s=>s.slice(s.lastIndexOf("/")+1);function Ps(s){if(typeof s!="string")return s;let t=s.trim(),e=t.indexOf(":");return e>=0&&!t.slice(0,e).includes("/")?t.slice(e+1):t}function Xt(s,t,e,r){let n=String(s).trim().replace(/\\/g,"/").replace(/^\/+/,"");if(!n.startsWith("assets/")){let i=r??"minecraft",a=n,o=n.indexOf(":");o>=0&&!n.slice(0,o).includes("/")&&(i=n.slice(0,o)||i,a=n.slice(o+1)),a.startsWith(t+"/")&&(a=a.slice(t.length+1)),n=`assets/${i}/${t}/${a}`}return n.toLowerCase().endsWith(e)||(n+=e),n}function Ie(s){let t={};for(let e of s.split(/\r?\n/)){let r=e.trim();if(!r||r.startsWith("#"))continue;let n=r.indexOf("=");n<0||(t[r.slice(0,n).trim()]=r.slice(n+1))}return t}function Yt(s,t){if(t!=null&&t!=="minecraft")return null;let e=String(s).trim().replace(/\\/g,"/").replace(/^\/+/,""),r=e.indexOf(":");if(r>=0&&!e.slice(0,r).includes("/")){if(e.slice(0,r)!=="minecraft")return null;e=e.slice(r+1)}return e}function Qt(s,t,e,r){if(s==null)return[];if(s.startsWith("resource_pack/")||s.startsWith("behavior_pack/"))return[s];s.startsWith(e+"/")&&(s=s.slice(e.length+1));let n=s.toLowerCase();return r.some(i=>n.endsWith(i))?[`${t}/${e}/${s}`]:r.map(i=>`${t}/${e}/${s}${i}`)}var Lt=s=>s!=null&&typeof s=="object"&&typeof s.path=="string",te=class{constructor({type:t="java",cacheDir:e,cacheSize:r,cacheKey:n,cacheAPI:i,proxy:a,version:o,manifest:c,manifestExpiry:l,onManifestProgress:f,onManifestUpdate:h,objects:y,minecraftDir:u}={}){if(t!=="java"&&t!=="assets"&&t!=="bedrock")throw new TypeError(`Unknown type "${t}"`);this._type=t,this._version=o??"release",this._objects=!!y,this._proxy=a,this._minecraftDir=u,this._localInstall=null,this._store=Ce({cacheAPI:i,cacheDir:e,cacheSize:r,cacheKey:n}),this.manifest=new St(this,{manifest:c,manifestExpiry:l,onProgress:f,onUpdate:h}),this._contexts=new Map,this._objectReads=new Map,this._objectFetches=new Map}_local(){return $(this,"_localInstall",async()=>{if(!R||this._minecraftDir===!1||this._type==="bedrock")return null;let{LocalInstall:t,defaultMinecraftDir:e}=await Promise.resolve().then(()=>(De(),Me));return new t(typeof this._minecraftDir=="string"?this._minecraftDir:e(),this._store)})}async _request(t,e){let r=t;typeof this._proxy=="function"?r=this._proxy(t)||t:this._proxy&&(r=this._proxy+t);let n;try{n=await fetch(r,e)}catch(i){throw R?i:new Error(`Fetch failed for ${r}. If this is a cross-origin request, the host may not allow it and a proxy is needed (see the proxy option)`,{cause:i})}if(!n.ok)throw new Error(`HTTP ${n.status} fetching ${t}`);return n}_fetchObject(t,e=!0){if(!e)return this._loadObject(t,!1);let r=J(this._objectFetches,t,()=>this._loadObject(t,!0));return r.finally(()=>{this._objectFetches.get(t)===r&&this._objectFetches.delete(t)}),r}async _loadObject(t,e){if(e){let a=await this._store.get("blobs",t);if(a)return a}let r=await this._local();if(r){let a=await r.object(t);if(a)return a}let n=await this._request(ze(t)),i=new Uint8Array(await n.arrayBuffer());return e&&this._store.set("blobs",t,i),i}_readObject(t){return J(this._objectReads,t,()=>this._fetchObject(t))}get version(){return this.manifest.peek(this._version)?.id??null}async setVersion(t){let e=t??"release",r=await this.manifest.resolve(e);return this._version=e,r}get channel(){return this.manifest.peek(this._version)?.type??null}async _ctx(t){let e=await this.manifest.resolve(t??this._version),r=et(e),n=this._contexts.get(r);return n||(n=new Ct(this,e),this._contexts.set(r,n)),n}_isFolderArg(t){return typeof t=="string"||Lt(t)}list(t,e){let r=this._isFolderArg(t)?t:null,n=(r?e:t)??{};return n.folders?this._browse(r??"",n):this._list(r,n)}async _list(t,{version:e,objects:r}={}){let n=t&&typeof t=="object"?t._context:null,i=await this._ctx(e??n?.version),{files:a}=await i.listing(r??n?.objects??this._objects),o=t?_t(typeof t=="string"?t:t.path):"";return o?a.filter(c=>c.path.startsWith(o+"/")):a}async _browse(t,{version:e,objects:r}={}){let n=_t(typeof t=="string"?t:t.path),i=typeof t=="object"?t._context:null,a=await this._ctx(e??i?.version),o=r??i?.objects??this._objects,{files:c}=await a.listing(o),l=n?n+"/":"",f=[],h=new Map;for(let u of c){if(!u.path.startsWith(l))continue;let d=u.path.slice(l.length),m=d.indexOf("/");if(m<0){f.push(u);continue}let _=d.slice(0,m),b=h.get(_);b||h.set(_,b={jar:!1,object:!1}),u.source&&(b[u.source]=!0)}let y=Array.from(h).map(([u,d])=>this._folderEntry(l+u,this._type==="java"?d.jar&&d.object?"both":d.jar?"jar":"object":void 0,a,o));return{files:f,folders:y}}_folderEntry(t,e,r,n){let i=e?{path:t,source:e,objects:n}:{path:t,objects:n},a={version:r.entry,objects:n};function o(c){let l=_t(c);return l===t||l.startsWith(t+"/")?l:t+"/"+l}return Z(i,"_context",a),Z(i,"list",(c,l)=>{let f=this._isFolderArg(c)?o(typeof c=="string"?c:c.path):t,h=(this._isFolderArg(c)?l:c)??{};return this.list(f,{...h,...a,objects:h.objects??n})}),Z(i,"search",(c,l)=>this.search(c,{...l,...a,objects:l?.objects??n,root:t})),Z(i,"file",c=>this.file(o(c),a)),Z(i,"read",(c,l)=>Lt(c)?this.read(c,{...l,...a}):this.read(o(c),{...l,...a})),i}async search(t,{version:e,objects:r,spaces:n="_",...i}={}){let a=await this._ctx(e),{paths:o,byPath:c}=await a.listing(r??this._objects);return ie(o,Ps(t??""),{...i,spaces:n}).map(l=>c.get(l))}async file(t,{version:e,objects:r}={}){return(await this._ctx(e)).file(_t(t),r??this._objects)}async read(t,{version:e,objects:r,prefer:n}={}){if(Lt(t)&&typeof t.read=="function")return t.read({prefer:n});let i=Lt(t)?t.path:t;return(await this._ctx(e)).read(_t(i),r??this._objects,n)}async _readFirst(t,e){for(let r of e){let n=await t.read(r,!1);if(n)return{path:r,bytes:n}}return null}async getTexture(t,{version:e,meta:r,prefer:n,namespace:i}={}){let a=await this._ctx(e);if(this._type==="bedrock"){let f=await this._readFirst(a,Qt(Yt(t,i),"resource_pack","textures",[".png",".tga"]));if(!f)return null;if(!r)return f.bytes;let h=await a.read(f.path.replace(/\.(png|tga)$/i,"")+".texture_set.json",!1);return{data:f.bytes,meta:h?JSON.parse(T.decode(h)):null}}let o=Xt(t,"textures",".png",i),c=await a.read(o,this._objects,n);if(!c)return null;if(!r)return c;let l=await a.read(o+".mcmeta",this._objects,n);return{data:c,meta:l?JSON.parse(T.decode(l)):null}}async _json(t,e,{version:r,namespace:n}={},i){let a=await this._ctx(r);if(this._type==="bedrock"){let c=await this._readFirst(a,Qt(Yt(t,n),i.base,i.kind,i.exts));return c?JSON.parse(T.decode(c.bytes)):null}let o=await a.read(Xt(t,e,".json",n),this._objects);return o?JSON.parse(T.decode(o)):null}getModel(t,e){return this._json(t,"models",e,{base:"resource_pack",kind:"models",exts:[".geo.json",".json"]})}getBlockstate(t,e){return this._json(t,"blockstates",e,{base:"behavior_pack",kind:"blocks",exts:[".block.json",".json"]})}getItemDefinition(t,e){return this._json(t,"items",e,{base:"behavior_pack",kind:"items",exts:[".json"]})}async getStructure(t,{version:e,namespace:r}={}){if(this._type==="bedrock")return null;let n=await this._ctx(e),i=String(t).trim().replace(/\\/g,"/").replace(/^\/+/,"");if(i.toLowerCase().endsWith(".nbt")||(i+=".nbt"),i.startsWith("data/")||i.startsWith("assets/"))return n.read(i,this._objects);let a=r??"minecraft",o=i.indexOf(":");o>=0&&!i.slice(0,o).includes("/")&&(a=i.slice(0,o)||a,i=i.slice(o+1)),i=i.replace(/^structures?\//,"");for(let c of[`data/${a}/structure/`,`data/${a}/structures/`,`assets/${a}/structures/`]){let l=await n.read(c+i,this._objects);if(l)return l}return null}async getSound(t,{version:e,namespace:r}={}){let n=await this._ctx(e);if(this._type==="bedrock"){let i=await this._readFirst(n,Qt(Yt(t,r),"resource_pack","sounds",[".fsb",".ogg"]));return i?i.bytes:null}return n.read(Xt(t,"sounds",".ogg",r),!0)}async _bedrockLang(t,e,r){if(r!=null&&r!=="minecraft")return null;let{files:n}=await t.listing(!1),i=Fe(String(e).replace(/\\/g,"/")).replace(/\.lang$/i,"").toLowerCase();for(let a of n){if(!a.path.startsWith("resource_pack/texts/"))continue;let o=/^([^/]*)\.lang$/i.exec(a.path.slice(20));if(o&&o[1].toLowerCase()===i)return Ie(T.decode(await a.read()))}return null}async getLang(t,{version:e,namespace:r="minecraft"}={}){let n=await this._ctx(e);if(this._type==="bedrock")return this._bedrockLang(n,t,r);let{files:i}=await n.listing(!0),a=String(t).replace(/\\/g,"/"),o=a.indexOf(":");o>=0&&!a.slice(0,o).includes("/")&&(r=a.slice(0,o)||r,a=a.slice(o+1));let c=Fe(a).replace(/\.(json|lang)$/i,"").toLowerCase(),l=[`assets/${r}/lang/`];n.entry.legacyLayout&&l.push("lang/");let f=null,h=null;for(let d of i)for(let m of l){if(!d.path.startsWith(m))continue;let _=d.path.slice(m.length),b=/^([^/]*)\.(json|lang)$/i.exec(_);!b||b[1].toLowerCase()!==c||(b[2].toLowerCase()==="json"?f??=d:h??=d)}let y=f??h;if(!y)return null;let u=T.decode(await y.read());return y===f?JSON.parse(u):Ie(u)}async loadJar({version:t,onProgress:e}={}){let r=await this._ctx(t);if(this._type==="assets"){let{files:i}=await r.listing(!1),a=i.reduce((c,l)=>c+l.size,0),o=0;e?.(0,a),await M(i,32,async c=>{try{await this._fetchObject(c.hash)}catch{}e?.(o+=c.size,a)});return}let n=await r.jar();r.listing(this._objects).catch(()=>{}),await n.load(e)}async loadObjects({version:t,filter:e,concurrency:r=32,onProgress:n,cache:i=!0}={}){let o=await(await this._ctx(t)).index(),c=Nt(e),l=o?Array.from(o).filter(([u])=>c(u)):[],f=new Array(l.length),h=0;await M(l,r,async([,{hash:u}],d)=>{try{f[d]=await this._fetchObject(u,i)}catch{}n?.(++h,l.length)});let y=new Map;return l.forEach(([u],d)=>{f[d]&&y.set(u,f[d])}),y}async export({version:t,filter:e,dir:r,objects:n,concurrency:i=32,onProgress:a}={}){let o=await this._ctx(t),{files:c}=await o.listing(n??this._objects),l=Nt(e),f=c.filter(_=>l(_.path)),h=f.some(_=>!_.hash)?await o.jar():null;h&&await h.buffer();let y=0,u=()=>a?.(++y,f.length);if(r==null){let _=new Array(f.length),b=ut();return await M(f,i,async(x,A)=>{if(x.hash)_[A]=await Et(x.path,await this._fetchObject(x.hash));else{let{entry:k,data:S}=await h.raw(x.path);_[A]={path:x.path,method:k.method,crc:k.crc,size:k.size,compressedSize:k.compressedSize,data:S}}u(),await b()}),Jt(_,b)}let[d,m]=await Promise.all([import("node:fs/promises"),import("node:path")]);return await M(f,i,async _=>{let b;if(_.hash)b=await this._fetchObject(_.hash);else{let{entry:A,data:k}=await h.raw(_.path);b=await wt(k,A)}let x=m.join(r,..._.path.split("/"));await d.mkdir(m.dirname(x),{recursive:!0}),await d.writeFile(x,b),u()}),f.length}async cacheStats(){let t=await this._store.list();if(!t)return null;let e=0;for(let r of t)e+=r.size;return{files:t.length,size:e}}async listCache(){let t=await this._store.list();return t?t.sort((e,r)=>r.size-e.size):null}setCacheSize(t){return this._store.setMaxSize(t)}async clearCache(t){for(let n of this._contexts.values())await(await n._jar?.catch(()=>null))?.settled();if(t==null)return this._store.clear();let e=String(t),r=e.indexOf("/");return this._store.delete(e.slice(0,r),e.slice(r+1))}};export{ue as LEGACY_ASSETS_BEFORE,Qe as VersionType,te as default,ms as readZip,xs as writeZip};
|
|
2
|
+
/*! Bundled license information:
|
|
3
|
+
|
|
4
|
+
@nkduy/mc-path-search-sort/dist/mc-path-search-sort.min.js:
|
|
5
|
+
(*!
|
|
6
|
+
* @nkduy/mc-path-search-sort
|
|
7
|
+
* Version : 1.2.0
|
|
8
|
+
* License : MPL-2.0
|
|
9
|
+
* Copyright: 2026 NKDuy
|
|
10
|
+
*)
|
|
11
|
+
*/
|