@zardoy/flying-squid 0.0.130 → 0.0.132

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.
@@ -3,8 +3,8 @@ import { DataRegistry } from 'minecraft-worldgen/dist/data/registry';
3
3
  * Vanilla game data the server needs at run time and `minecraft-data` does not have: loot tables and cooking recipes (smelting, blasting, smoking).
4
4
  * It reads the datapack layers like minecraft-worldgen does (a `DataRegistry`):
5
5
  * 1. the vanilla client jar (node: `MC_WORLDGEN_VANILLA_JAR` / `~/.cache/mc-worldgen/client.jar`, or `options.gameDataJars`),
6
- * 2. zip URL(s) of `globalThis.__MC_GAMEDATA_URL` (browser hosts; a string, a list or a function returning one; a small zip with `data/minecraft/loot_table/chests` and the cooking `data/minecraft/recipe`
7
- * files is enough, it is not the worldgen pack),
6
+ * 2. zip URL(s) of `globalThis.__MC_GAMEDATA_URL` (browser hosts; a string, a list or a function returning one; a JSON bundle of `data/minecraft/loot_table/chests/*` and the cooking
7
+ * `data/minecraft/recipe/*` files (`{ "<path>": json }`, about 10 KB gzipped) or a zip of them is enough, it is not the worldgen pack),
8
8
  * 3. datapack zips in `<worldFolder>/datapacks/`,
9
9
  * 4. `options.lootTables` (`{ 'minecraft:chests/foo': {...} }` or a function) which wins over everything.
10
10
  * Without any of them loot tables are unknown (chests with a `LootTable` stay as they are) and a built-in list of the vanilla cooking recipes is used.
@@ -54,8 +54,14 @@ class GameData {
54
54
  for (const url of Array.isArray(urls) ? urls : urls ? [urls] : []) {
55
55
  try {
56
56
  const res = await fetch(url);
57
- if (res.ok)
58
- this.registry.addZipBuffer(`gamedata:${url}`.slice(0, 80), new Uint8Array(await res.arrayBuffer()));
57
+ if (!res.ok)
58
+ continue;
59
+ const bytes = new Uint8Array(await res.arrayBuffer());
60
+ // a JSON bundle `{ "data/minecraft/loot_table/chests/x.json": {...}, ... }` (much smaller than a zip: the tables compress well together) or a datapack zip
61
+ if (bytes[0] === 0x7B)
62
+ this.registry.addVirtualFiles(`gamedata:${url}`.slice(0, 80), JSON.parse(new TextDecoder().decode(bytes)));
63
+ else
64
+ this.registry.addZipBuffer(`gamedata:${url}`.slice(0, 80), bytes);
59
65
  }
60
66
  catch { }
61
67
  }
@@ -222,6 +222,34 @@ function generation(options = {}) {
222
222
  }
223
223
  }
224
224
  }
225
+ // block entities of the generator: loot tables of chests / dispensers (minecraft-worldgen >= the version with ChunkData.blockEntities); the containers module rolls the loot when one is opened
226
+ if (data.blockEntities?.length) {
227
+ const flattened = registry.supportFeature?.('theFlattening') !== false;
228
+ chunk.blockEntities ??= {};
229
+ for (const be of data.blockEntities) {
230
+ if (!be.lootTable || be.y < minY || be.y >= minY + worldHeight)
231
+ continue;
232
+ const name = be.id.replace(/^minecraft:/, '');
233
+ pos.set(be.x, be.y, be.z);
234
+ // the block of this version at the position has to be the container (blocks newer than the version are replaced by stone / air)
235
+ if (registry.blocksByStateId[chunk.getBlockStateId(pos)]?.name !== name)
236
+ continue;
237
+ const legacyId = { chest: 'Chest', dispenser: 'Trap' }[name];
238
+ if (!flattened && !legacyId)
239
+ continue;
240
+ const wx = chunkX * 16 + be.x;
241
+ const wz = chunkZ * 16 + be.z;
242
+ const seed = BigInt.asUintN(64, be.lootSeed ?? 0n);
243
+ chunk.blockEntities[`${wx},${be.y},${wz}`] = {
244
+ id: { type: 'string', value: flattened ? be.id : legacyId },
245
+ x: { type: 'int', value: wx },
246
+ y: { type: 'int', value: be.y },
247
+ z: { type: 'int', value: wz },
248
+ LootTable: { type: 'string', value: be.lootTable },
249
+ LootTableSeed: { type: 'long', value: [Number(BigInt.asIntN(32, seed >> 32n)), Number(BigInt.asIntN(32, seed))] }
250
+ };
251
+ }
252
+ }
225
253
  // light computed by the generator (minecraft-worldgen >= the version with ChunkData.skyLight): sections of 2048 nibble bytes, from info.minY up
226
254
  if (data.skyLight && data.blockLight && typeof chunk._loadSkyLightNibbles === 'function') {
227
255
  const firstSection = info.minY >> 4;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zardoy/flying-squid",
3
3
  "description": "A minecraft server written in TS",
4
- "version": "0.0.130",
4
+ "version": "0.0.132",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "bin": "dist/app.js",
@@ -28,7 +28,7 @@
28
28
  "flatmap": "^0.0.3",
29
29
  "long": "^5.1.0",
30
30
  "mc-bridge": "^0.1.1",
31
- "minecraft-worldgen": "^0.1.2",
31
+ "minecraft-worldgen": "^0.1.3",
32
32
  "minecraft-data": "^3.95.0",
33
33
  "minecraft-protocol": "^1.60.1",
34
34
  "mkdirp": "^2.1.3",