minerender 2.1.0-alpha.12 → 2.1.0-alpha.13

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/dist/bundle.js CHANGED
@@ -67173,7 +67173,7 @@ return ${compiler2.callType("value", tagType)}
67173
67173
  }
67174
67174
  toString() {
67175
67175
  let a4 = [
67176
- typeof this.root !== "undefined" || AssetLoader.ROOT !== DEFAULT_ROOT ? this.root ?? AssetLoader.ROOT : "__root__",
67176
+ this.root ?? AssetLoader.ROOT,
67177
67177
  this.rootType ?? "__rootType__",
67178
67178
  this.assetType ?? "__assetType__",
67179
67179
  this.type ?? "__type__",
@@ -67223,6 +67223,7 @@ return ${compiler2.callType("value", tagType)}
67223
67223
  }
67224
67224
  const models = [];
67225
67225
  const parentKey = AssetKey.parse("models", model.parent);
67226
+ parentKey.root = model.key?.root;
67226
67227
  const parentModel = await Models.getRaw(parentKey);
67227
67228
  if (parentModel) {
67228
67229
  models.unshift(parentModel);
@@ -67255,26 +67256,58 @@ return ${compiler2.callType("value", tagType)}
67255
67256
  return this._persistentCache ?? (this._persistentCache = PersistentCache.open("minerender-models"));
67256
67257
  }
67257
67258
  static async getItemList() {
67258
- const key = new AssetKey(
67259
- DEFAULT_NAMESPACE,
67260
- "_list",
67261
- "models",
67262
- "item",
67263
- "assets",
67264
- ".json",
67265
- DEFAULT_ROOT
67266
- );
67267
- return Caching.listAssetCache.get(key.serialize(), () => {
67268
- return AssetLoader.get(key, "list" /* LIST */);
67259
+ const key = new AssetKey(DEFAULT_NAMESPACE, "_list", "items");
67260
+ const legacyKey = new AssetKey(DEFAULT_NAMESPACE, "_list", "models", "item");
67261
+ return Caching.listAssetCache.get(key.serialize(), async () => {
67262
+ return (await AssetLoader.getFirst([key, legacyKey], "list" /* LIST */))?.asset;
67269
67263
  }).then((r5) => r5?.files ?? []);
67270
67264
  }
67271
67265
  static async loadAndMerge(key) {
67272
- const model = await this.getRaw(key);
67266
+ const model = key.type === "item" ? await this.getItemModel(key) : await this.getRaw(key);
67273
67267
  if (!model) {
67274
67268
  return void 0;
67275
67269
  }
67276
67270
  return ModelMerger.mergeWithParents(model);
67277
67271
  }
67272
+ static async getItemModel(key) {
67273
+ const itemKey = new AssetKey(key.namespace, key.path, "items", void 0, key.rootType, ".json", key.root);
67274
+ const model = await this.PERSISTENT_CACHE.getOrLoad(itemKey.serialize(), async () => {
67275
+ const result = await AssetLoader.getFirst([itemKey, key], "json" /* JSON */);
67276
+ if (!result) return void 0;
67277
+ if (result.key.assetType !== "items") return { ...result.asset, key };
67278
+ const reference = this.defaultItemModel(result.asset.model, key);
67279
+ const modelKey = AssetKey.parse("models", reference);
67280
+ modelKey.root = key.root;
67281
+ const model2 = await this.getRaw(modelKey);
67282
+ if (!model2) throw new Error(`Item ${key.toNamespacedString()} references missing model ${reference}`);
67283
+ return model2;
67284
+ });
67285
+ return model ? { ...model, key: Object.assign(new AssetKey("", ""), model.key) } : void 0;
67286
+ }
67287
+ // Item previews use the GUI context, false conditions, and zero numeric properties.
67288
+ static defaultItemModel(node, key) {
67289
+ if (!node || typeof node.type !== "string") {
67290
+ throw new Error(`Unsupported item model definition for ${key.toNamespacedString()}`);
67291
+ }
67292
+ switch (node.type.replace(/^minecraft:/, "")) {
67293
+ case "model":
67294
+ if (typeof node.model === "string" && node.model) return node.model;
67295
+ break;
67296
+ case "condition":
67297
+ return this.defaultItemModel(node.on_false, key);
67298
+ case "select": {
67299
+ const selected = node.property?.replace(/^minecraft:/, "") === "display_context" ? node.cases?.find((entry) => Array.isArray(entry.when) ? entry.when.includes("gui") : entry.when === "gui")?.model : void 0;
67300
+ return this.defaultItemModel(selected ?? node.fallback, key);
67301
+ }
67302
+ case "range_dispatch": {
67303
+ const selected = node.entries?.reduce((match, entry) => {
67304
+ return entry.threshold <= 0 && (!match || entry.threshold >= match.threshold) ? entry : match;
67305
+ }, void 0);
67306
+ return this.defaultItemModel(selected?.model ?? node.fallback, key);
67307
+ }
67308
+ }
67309
+ throw new Error(`Unsupported item model ${node?.type ?? "definition"} for ${key.toNamespacedString()}`);
67310
+ }
67278
67311
  static async getRaw(key) {
67279
67312
  if (!key.assetType) {
67280
67313
  key.assetType = "models";
@@ -67384,7 +67417,7 @@ return ${compiler2.callType("value", tagType)}
67384
67417
  };
67385
67418
 
67386
67419
  // src/assets/Assets.ts
67387
- var DEFAULT_ROOT = "https://assets.mcasset.cloud/1.17.1";
67420
+ var DEFAULT_ROOT = "https://assets.mcasset.cloud/1.21.11";
67388
67421
  var DEFAULT_NAMESPACE = "minecraft";
67389
67422
  var Assets = class {
67390
67423
  /**
@@ -77317,11 +77350,29 @@ return ${compiler2.callType("value", tagType)}
77317
77350
  }
77318
77351
  /** Returns the first defined result in source-priority order, without merging assets. */
77319
77352
  static async get(key, parser) {
77353
+ const keys = [key];
77354
+ if (key.rootType === "data" && (key.assetType === "structure" || key.assetType === "structures")) {
77355
+ keys.push(new AssetKey(
77356
+ key.namespace,
77357
+ key.path,
77358
+ key.assetType === "structure" ? "structures" : "structure",
77359
+ key.type,
77360
+ key.rootType,
77361
+ key.extension,
77362
+ key.root
77363
+ ));
77364
+ }
77365
+ return (await this.getFirst(keys, parser))?.asset;
77366
+ }
77367
+ /** Tries each path within a source before considering lower-priority sources. */
77368
+ static async getFirst(keys, parser) {
77320
77369
  const sources = [...this._SOURCES];
77321
77370
  for (const source of sources) {
77322
- const result = await source.source.get(key, parser);
77323
- if (result !== void 0) {
77324
- return result;
77371
+ for (const key of keys) {
77372
+ const result = await source.source.get(key, parser);
77373
+ if (result !== void 0) {
77374
+ return { key, asset: result };
77375
+ }
77325
77376
  }
77326
77377
  }
77327
77378
  return void 0;