minerender 2.1.0-alpha.116 → 2.1.0-alpha.117

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.
@@ -1348,6 +1348,7 @@ interface MineRenderDataManifest {
1348
1348
  interface ResolvedMineRenderData {
1349
1349
  requestedVersion: string;
1350
1350
  version: string;
1351
+ /** Registry lookup root. Rootless requests still allow registered sources to override this URL. */
1351
1352
  root: string;
1352
1353
  manifest: MineRenderDataManifest;
1353
1354
  }
@@ -1357,7 +1358,8 @@ declare class MineRenderData {
1357
1358
  static get<K extends keyof MineRenderDatasets>(dataset: K, root?: string): Promise<MineRenderDatasets[K]>;
1358
1359
  /**
1359
1360
  * Uses the exact version when published. Otherwise, selects the nearest patch in the same
1360
- * release line (older on ties), then the latest earlier release. Unpublished snapshots reject.
1361
+ * release line (older on ties), then the latest earlier release or the oldest published release.
1362
+ * Unpublished snapshots reject.
1361
1363
  */
1362
1364
  static resolve(root?: string): Promise<ResolvedMineRenderData>;
1363
1365
  private static manifest;
@@ -1394,7 +1396,6 @@ declare class Models {
1394
1396
  static componentValue(components: Record<string, unknown>, id: string): unknown;
1395
1397
  private static snapshotContext;
1396
1398
  private static applyDefaults;
1397
- private static sourceCheck;
1398
1399
  private static contextKey;
1399
1400
  private static snapshotJson;
1400
1401
  private static propertyValue;
@@ -3624,7 +3625,6 @@ declare class AnvilParser {
3624
3625
  * @returns The chunk with absolute coordinates, or `undefined` if the region has no chunk there.
3625
3626
  */
3626
3627
  static parseChunk(data: RegionInput, localX: number, localZ: number, options?: AnvilParseOptions): Promise<AnvilChunk | undefined>;
3627
- private static assetGuard;
3628
3628
  /**
3629
3629
  * Decodes one chunk from an `entities/r.x.z.mca` file without migrating its NBT.
3630
3630
  * @param localX - Chunk x within the region, from 0 to 31.
@@ -1348,6 +1348,7 @@ interface MineRenderDataManifest {
1348
1348
  interface ResolvedMineRenderData {
1349
1349
  requestedVersion: string;
1350
1350
  version: string;
1351
+ /** Registry lookup root. Rootless requests still allow registered sources to override this URL. */
1351
1352
  root: string;
1352
1353
  manifest: MineRenderDataManifest;
1353
1354
  }
@@ -1357,7 +1358,8 @@ declare class MineRenderData {
1357
1358
  static get<K extends keyof MineRenderDatasets>(dataset: K, root?: string): Promise<MineRenderDatasets[K]>;
1358
1359
  /**
1359
1360
  * Uses the exact version when published. Otherwise, selects the nearest patch in the same
1360
- * release line (older on ties), then the latest earlier release. Unpublished snapshots reject.
1361
+ * release line (older on ties), then the latest earlier release or the oldest published release.
1362
+ * Unpublished snapshots reject.
1361
1363
  */
1362
1364
  static resolve(root?: string): Promise<ResolvedMineRenderData>;
1363
1365
  private static manifest;
@@ -1394,7 +1396,6 @@ declare class Models {
1394
1396
  static componentValue(components: Record<string, unknown>, id: string): unknown;
1395
1397
  private static snapshotContext;
1396
1398
  private static applyDefaults;
1397
- private static sourceCheck;
1398
1399
  private static contextKey;
1399
1400
  private static snapshotJson;
1400
1401
  private static propertyValue;
@@ -3624,7 +3625,6 @@ declare class AnvilParser {
3624
3625
  * @returns The chunk with absolute coordinates, or `undefined` if the region has no chunk there.
3625
3626
  */
3626
3627
  static parseChunk(data: RegionInput, localX: number, localZ: number, options?: AnvilParseOptions): Promise<AnvilChunk | undefined>;
3627
- private static assetGuard;
3628
3628
  /**
3629
3629
  * Decodes one chunk from an `entities/r.x.z.mca` file without migrating its NBT.
3630
3630
  * @param localX - Chunk x within the region, from 0 to 31.
@@ -1663,7 +1663,8 @@ var init_MineRenderData = __esm({
1663
1663
  }
1664
1664
  /**
1665
1665
  * Uses the exact version when published. Otherwise, selects the nearest patch in the same
1666
- * release line (older on ties), then the latest earlier release. Unpublished snapshots reject.
1666
+ * release line (older on ties), then the latest earlier release or the oldest published release.
1667
+ * Unpublished snapshots reject.
1667
1668
  */
1668
1669
  static async resolve(root) {
1669
1670
  const requestRoot = root?.replace(/\/+$/, "");
@@ -1672,11 +1673,11 @@ var init_MineRenderData = __esm({
1672
1673
  const scope = AssetLoader.persistentScope;
1673
1674
  return this.cached(`resolve:${requestRoot === void 0 ? "sources" : "explicit"}:${root}`, scope, defaultRoot, async () => {
1674
1675
  const requestedVersion = root.slice(root.lastIndexOf("/") + 1);
1675
- let manifest = await this.manifest(root, release(requestedVersion) ? requestedVersion : void 0, requestRoot);
1676
+ let manifest = await this.manifest(root, requestRoot !== void 0 && release(requestedVersion) ? requestedVersion : void 0, requestRoot);
1676
1677
  if (manifest) return { requestedVersion, version: manifest.minecraftVersion, root, manifest };
1677
1678
  const requested = release(requestedVersion);
1678
- if (!requested || compare(requested, [1, 16, 5]) < 0) {
1679
- throw new Error(`No MineRender data is published for ${requestedVersion}; automatic fallback requires a release from 1.16.5 onward`);
1679
+ if (!requested) {
1680
+ throw new Error(`No MineRender data is published for ${requestedVersion}; automatic fallback requires a release`);
1680
1681
  }
1681
1682
  const base = root.slice(0, root.lastIndexOf("/"));
1682
1683
  const index = await this.cached(`versions:${base}`, scope, defaultRoot, async () => {
@@ -1686,9 +1687,9 @@ var init_MineRenderData = __esm({
1686
1687
  }
1687
1688
  return value.versions;
1688
1689
  });
1689
- const versions = index.map((entry) => ({ name: entry.name, number: release(entry.name) })).filter((entry) => !!entry.number && compare(entry.number, [1, 16, 5]) >= 0).sort((left, right) => compare(left.number, right.number));
1690
+ const versions = index.map((entry) => ({ name: entry.name, number: release(entry.name) })).filter((entry) => !!entry.number).sort((left, right) => compare(left.number, right.number));
1690
1691
  const sameLine = versions.filter((entry) => entry.number[0] === requested[0] && entry.number[1] === requested[1]);
1691
- const selected = sameLine.sort((left, right) => Math.abs((left.number[2] ?? 0) - (requested[2] ?? 0)) - Math.abs((right.number[2] ?? 0) - (requested[2] ?? 0)) || compare(left.number, right.number))[0] ?? versions.filter((entry) => compare(entry.number, requested) <= 0).pop();
1692
+ const selected = sameLine.sort((left, right) => Math.abs((left.number[2] ?? 0) - (requested[2] ?? 0)) - Math.abs((right.number[2] ?? 0) - (requested[2] ?? 0)) || compare(left.number, right.number))[0] ?? versions.filter((entry) => compare(entry.number, requested) <= 0).pop() ?? versions[0];
1692
1693
  if (!selected) throw new Error(`No compatible MineRender data is published for ${requestedVersion}`);
1693
1694
  const resolvedRoot = `${base}/${selected.name}`;
1694
1695
  manifest = await this.manifest(resolvedRoot, selected.name, resolvedRoot);
@@ -1804,12 +1805,7 @@ var init_BannerPatterns = __esm({
1804
1805
  static async getLayers(value, target, root) {
1805
1806
  if (value === void 0) return [];
1806
1807
  if (!Array.isArray(value)) throw new Error("banner_patterns must be an array");
1807
- const activeRoot = AssetLoader.ROOT, scope = AssetLoader.persistentScope;
1808
- const checkSources = () => {
1809
- if (activeRoot !== AssetLoader.ROOT || scope !== AssetLoader.persistentScope) throw new Error("Asset sources changed while loading banner patterns; retry the request");
1810
- };
1811
1808
  const colors = value.length ? await this.getColors(root) : void 0;
1812
- checkSources();
1813
1809
  return Promise.all(value.slice(0, 16).map(async (layer) => {
1814
1810
  if (!layer || typeof layer !== "object" || Array.isArray(layer)) throw new Error("Each banner pattern requires a pattern and dye color");
1815
1811
  if (typeof layer.color !== "string" || !Object.prototype.hasOwnProperty.call(colors, layer.color)) throw new Error(`Unsupported dye color ${layer.color}`);
@@ -1819,7 +1815,6 @@ var init_BannerPatterns = __esm({
1819
1815
  const id = this.identifier(pattern2);
1820
1816
  const key = new AssetKey(id.namespace, id.getFullPath(), "banner_pattern", void 0, "data", ".json", root);
1821
1817
  pattern2 = await Caching.bannerPatternCache.get(key.serialize(), () => AssetLoader.get(key, "json" /* JSON */));
1822
- checkSources();
1823
1818
  if (!pattern2) throw new Error(`Missing banner pattern ${layer.pattern}`);
1824
1819
  }
1825
1820
  if (!pattern2 || typeof pattern2 !== "object" || Array.isArray(pattern2) || typeof pattern2.translation_key !== "string") throw new Error("Banner patterns require asset_id and translation_key");
@@ -2108,30 +2103,24 @@ var init_Models = __esm({
2108
2103
  }).then((r) => r?.files ?? []);
2109
2104
  }
2110
2105
  static async loadAndMerge(key, context = {}) {
2111
- const checkSources = this.sourceCheck();
2112
2106
  const model = key.type === "item" ? await this.getItemModel(key, context) : await this.getRaw(key);
2113
2107
  if (!model) {
2114
2108
  return void 0;
2115
2109
  }
2116
2110
  const merged = await ModelMerger.mergeWithParents(model);
2117
- checkSources();
2118
2111
  return merged;
2119
2112
  }
2120
2113
  static async getItemModel(key, context = {}) {
2121
- const checkSources = this.sourceCheck();
2122
2114
  const preview = this.snapshotContext(key, context);
2123
2115
  const dataKey = await this.applyDefaults(key, preview);
2124
- checkSources();
2125
2116
  return this.getPreparedItemModel(key, preview, dataKey);
2126
2117
  }
2127
2118
  static async getPreparedItemModel(key, preview, dataKey) {
2128
- const checkSources = this.sourceCheck();
2129
2119
  const itemId = `${key.namespace}:${key.path}`;
2130
2120
  const itemKey2 = new AssetKey(key.namespace, key.path, "items", void 0, key.rootType, ".json", key.root);
2131
2121
  const cacheKey = itemKey2.serialize() + this.contextKey(preview) + dataKey;
2132
2122
  const model = await this.PERSISTENT_CACHE.getOrLoad(`${this.ITEM_CACHE_VERSION}:${AssetLoader.persistentKey(cacheKey)}`, async () => {
2133
2123
  const result = await AssetLoader.getFirst([itemKey2, key], "json" /* JSON */);
2134
- checkSources();
2135
2124
  if (!result) return void 0;
2136
2125
  if (result.key.assetType !== "items") return { ...result.asset, key, itemId, components: preview.components };
2137
2126
  const load = async (selected) => {
@@ -2150,10 +2139,8 @@ var init_Models = __esm({
2150
2139
  return { ...model3, itemId, components: preview.components, ...selected.special && { special: selected.special }, ...selected.tints && { tints: selected.tints } };
2151
2140
  };
2152
2141
  const model2 = await load(this.selectItemModel(result.asset.model, key, preview));
2153
- checkSources();
2154
2142
  return model2;
2155
2143
  });
2156
- checkSources();
2157
2144
  const restore = (model2) => ({
2158
2145
  ...model2,
2159
2146
  key: Object.assign(new AssetKey("", ""), model2.key),
@@ -2217,22 +2204,14 @@ var init_Models = __esm({
2217
2204
  }
2218
2205
  static async applyDefaults(key, preview) {
2219
2206
  if (key.type !== "item") return "";
2220
- const root = AssetLoader.ROOT, scope = AssetLoader.persistentScope;
2221
2207
  const resolved = await MineRenderData.resolve(key.root);
2222
2208
  const defaults = await ItemDefaults.get(`${key.namespace}:${key.path}`, key.root);
2223
2209
  preview.components = { ...defaults, ...preview.components };
2224
2210
  if (resolved.manifest.dataVersion < 3337 && key.namespace === DEFAULT_NAMESPACE && ["potion", "splash_potion", "lingering_potion"].includes(key.path) && !Object.prototype.hasOwnProperty.call(preview.components, "minecraft:enchantment_glint_override") && await ItemTints.hasPotionEffects(preview.components["minecraft:potion_contents"], key.root)) {
2225
2211
  preview.components["minecraft:enchantment_glint_override"] = true;
2226
2212
  }
2227
- if (AssetLoader.ROOT !== root || AssetLoader.persistentScope !== scope) throw new Error("Asset sources changed while loading item defaults; retry the request");
2228
2213
  return `|data:${resolved.root}:${resolved.manifest.datasets.itemDefaults?.sha256}:${resolved.manifest.datasets.potionColors?.sha256}`;
2229
2214
  }
2230
- static sourceCheck() {
2231
- const root = AssetLoader.ROOT, scope = AssetLoader.persistentScope;
2232
- return () => {
2233
- if (AssetLoader.ROOT !== root || AssetLoader.persistentScope !== scope) throw new Error("Asset sources changed while loading item models; retry the request");
2234
- };
2235
- }
2236
2215
  static contextKey(context) {
2237
2216
  const itemReferences = Object.fromEntries(Object.entries(context.itemReferences).map(([id, key]) => [id, key.serialize()]));
2238
2217
  return `|${this.ITEM_CACHE_VERSION}:${JSON.stringify(this.snapshotJson({ ...context, itemReferences }))}`;
@@ -2419,7 +2398,6 @@ var init_Models = __esm({
2419
2398
  * @param key - Model key, for example `AssetKey.parse("models", "minecraft:item/diamond_sword")`.
2420
2399
  */
2421
2400
  static async getMerged(key, context = {}) {
2422
- const checkSources = this.sourceCheck();
2423
2401
  if (!key.assetType) {
2424
2402
  key.assetType = "models";
2425
2403
  }
@@ -2428,15 +2406,12 @@ var init_Models = __esm({
2428
2406
  }
2429
2407
  const preview = this.snapshotContext(key, context);
2430
2408
  const dataKey = await this.applyDefaults(key, preview);
2431
- checkSources();
2432
2409
  const keyStr = AssetLoader.persistentKey(key.serialize() + (key.type === "item" ? this.contextKey(preview) + dataKey : ""));
2433
2410
  const model = await Caching.mergedModelCache.get(keyStr, async () => {
2434
2411
  const raw = key.type === "item" ? await this.getPreparedItemModel(key, preview, dataKey) : await this.getRaw(key);
2435
2412
  const merged = raw ? await ModelMerger.mergeWithParents(raw) : void 0;
2436
- checkSources();
2437
2413
  return merged;
2438
2414
  });
2439
- checkSources();
2440
2415
  return model;
2441
2416
  }
2442
2417
  /** Alias for {@link getMerged}. */
@@ -12584,7 +12559,6 @@ init_AssetKey();
12584
12559
  init_ModelCulling();
12585
12560
  init_FluidGeometry();
12586
12561
  init_MineRenderData();
12587
- init_AssetLoader();
12588
12562
  init_Entities();
12589
12563
  var BlockObject = class _BlockObject extends SceneObject {
12590
12564
  constructor(blockState3, options) {
@@ -12614,19 +12588,12 @@ var BlockObject = class _BlockObject extends SceneObject {
12614
12588
  });
12615
12589
  }
12616
12590
  async init() {
12617
- const root = AssetLoader.ROOT, scope = AssetLoader.persistentScope;
12618
- const checkSources = () => {
12619
- if (root !== AssetLoader.ROOT || scope !== AssetLoader.persistentScope) throw new Error("Asset sources changed while loading a block; retry the request");
12620
- };
12621
12591
  this._fluidRules = await MineRenderData.get("fluids", this.blockState.key?.root);
12622
- checkSources();
12623
12592
  if (this.options.applyDefaultState) {
12624
12593
  this._setState(await BlockStateResolver.defaults(this.blockState));
12625
- checkSources();
12626
12594
  }
12627
12595
  if (this.options.initialState !== void 0) this._setState(this.options.initialState);
12628
12596
  await this.recreateModels();
12629
- checkSources();
12630
12597
  }
12631
12598
  dispose() {
12632
12599
  this.clearModels();
@@ -16539,7 +16506,6 @@ init_util2();
16539
16506
  // src/world/AnvilParser.ts
16540
16507
  init_MineRenderError();
16541
16508
  init_MineRenderData();
16542
- init_AssetLoader();
16543
16509
  init_NBTHelper();
16544
16510
 
16545
16511
  // src/world/ChunkData.ts
@@ -16810,14 +16776,12 @@ var AnvilParser = class {
16810
16776
  /** Decodes all stored chunks. Gzip, zlib, LZ4, and uncompressed payloads are supported. */
16811
16777
  static async parse(data, options = {}) {
16812
16778
  options = { ...options };
16813
- const checkSources = this.assetGuard();
16814
16779
  options.signal?.throwIfAborted();
16815
16780
  const bytes = this.bytes(data);
16816
16781
  const chunks = [];
16817
16782
  for (const location of this.locations(bytes)) {
16818
16783
  chunks.push(await this.abortable(this.readChunk(bytes, location, options), options.signal));
16819
16784
  }
16820
- checkSources();
16821
16785
  return { chunks };
16822
16786
  }
16823
16787
  /**
@@ -16828,22 +16792,12 @@ var AnvilParser = class {
16828
16792
  */
16829
16793
  static async parseChunk(data, localX, localZ, options = {}) {
16830
16794
  options = { ...options };
16831
- const checkSources = this.assetGuard();
16832
16795
  options.signal?.throwIfAborted();
16833
16796
  const bytes = this.bytes(data);
16834
16797
  const location = this.location(bytes, localX, localZ);
16835
16798
  const chunk = location ? await this.abortable(this.readChunk(bytes, location, options), options.signal) : void 0;
16836
- checkSources();
16837
16799
  return chunk;
16838
16800
  }
16839
- static assetGuard() {
16840
- const root = AssetLoader.ROOT, scope = AssetLoader.persistentScope;
16841
- return () => {
16842
- if (AssetLoader.ROOT !== root || AssetLoader.persistentScope !== scope) {
16843
- throw new MineRenderError("Asset sources changed while parsing Anvil data; retry the request");
16844
- }
16845
- };
16846
- }
16847
16801
  /**
16848
16802
  * Decodes one chunk from an `entities/r.x.z.mca` file without migrating its NBT.
16849
16803
  * @param localX - Chunk x within the region, from 0 to 31.
@@ -17564,7 +17518,6 @@ function resolveSavedEntity(entity) {
17564
17518
 
17565
17519
  // src/world/_entities/WorldEntities.ts
17566
17520
  init_BannerPatterns();
17567
- init_AssetLoader();
17568
17521
  var WorldEntities = class {
17569
17522
  constructor(scene) {
17570
17523
  this.scene = scene;
@@ -17572,10 +17525,6 @@ var WorldEntities = class {
17572
17525
  }
17573
17526
  /** Captures column ownership before asynchronous block or asset loading starts. */
17574
17527
  prepare(entities = [], column) {
17575
- const root = AssetLoader.ROOT, scope = AssetLoader.persistentScope;
17576
- const checkSources = () => {
17577
- if (root !== AssetLoader.ROOT || scope !== AssetLoader.persistentScope) throw new Error("Asset sources changed while loading saved entities; retry the request");
17578
- };
17579
17528
  const placements = entities.flatMap((entity) => {
17580
17529
  const resolved = resolveSavedEntity(entity);
17581
17530
  if (!resolved) return [];
@@ -17591,17 +17540,13 @@ var WorldEntities = class {
17591
17540
  let object4;
17592
17541
  try {
17593
17542
  if (!current()) return;
17594
- checkSources();
17595
17543
  const models = await Entities.getEntityList();
17596
- checkSources();
17597
17544
  if (!models.includes(placement.key.path) || !current()) return;
17598
17545
  const model = await Entities.getEntity(placement.key, placement.texture, { when: placement.when });
17599
- checkSources();
17600
17546
  if (!model || !current()) return;
17601
17547
  let tints = placement.tints;
17602
17548
  if (placement.woolDye) {
17603
17549
  const dye = (await BannerPatterns.getColors(placement.key.root))[placement.woolDye];
17604
- checkSources();
17605
17550
  const tint = placement.woolDye === "white" ? 15132390 : Math.floor((dye >> 16 & 255) * 0.75) << 16 | Math.floor((dye >> 8 & 255) * 0.75) << 8 | Math.floor((dye & 255) * 0.75);
17606
17551
  tints = { ...tints, wool_color: tint };
17607
17552
  }
@@ -17611,7 +17556,6 @@ var WorldEntities = class {
17611
17556
  object4.position.fromArray(placement.position).multiplyScalar(16).addScalar(-8);
17612
17557
  object4.rotation.y = placement.yaw;
17613
17558
  await object4.init();
17614
- checkSources();
17615
17559
  if (!current()) return;
17616
17560
  placement.owner.add(object4);
17617
17561
  this.scene.add(object4);