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.
@@ -1142,7 +1142,7 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
1142
1142
  }
1143
1143
  toString() {
1144
1144
  let a = [
1145
- typeof this.root !== "undefined" || AssetLoader.ROOT !== DEFAULT_ROOT ? this.root ?? AssetLoader.ROOT : "__root__",
1145
+ this.root ?? AssetLoader.ROOT,
1146
1146
  this.rootType ?? "__rootType__",
1147
1147
  this.assetType ?? "__assetType__",
1148
1148
  this.type ?? "__type__",
@@ -1192,6 +1192,7 @@ var ModelMerger = class {
1192
1192
  }
1193
1193
  const models = [];
1194
1194
  const parentKey = AssetKey.parse("models", model.parent);
1195
+ parentKey.root = model.key?.root;
1195
1196
  const parentModel = await Models.getRaw(parentKey);
1196
1197
  if (parentModel) {
1197
1198
  models.unshift(parentModel);
@@ -1221,26 +1222,58 @@ var Models = class _Models {
1221
1222
  return this._persistentCache ??= PersistentCache.open("minerender-models");
1222
1223
  }
1223
1224
  static async getItemList() {
1224
- const key = new AssetKey(
1225
- DEFAULT_NAMESPACE,
1226
- "_list",
1227
- "models",
1228
- "item",
1229
- "assets",
1230
- ".json",
1231
- DEFAULT_ROOT
1232
- );
1233
- return Caching.listAssetCache.get(key.serialize(), () => {
1234
- return AssetLoader.get(key, "list" /* LIST */);
1225
+ const key = new AssetKey(DEFAULT_NAMESPACE, "_list", "items");
1226
+ const legacyKey = new AssetKey(DEFAULT_NAMESPACE, "_list", "models", "item");
1227
+ return Caching.listAssetCache.get(key.serialize(), async () => {
1228
+ return (await AssetLoader.getFirst([key, legacyKey], "list" /* LIST */))?.asset;
1235
1229
  }).then((r) => r?.files ?? []);
1236
1230
  }
1237
1231
  static async loadAndMerge(key) {
1238
- const model = await this.getRaw(key);
1232
+ const model = key.type === "item" ? await this.getItemModel(key) : await this.getRaw(key);
1239
1233
  if (!model) {
1240
1234
  return void 0;
1241
1235
  }
1242
1236
  return ModelMerger.mergeWithParents(model);
1243
1237
  }
1238
+ static async getItemModel(key) {
1239
+ const itemKey = new AssetKey(key.namespace, key.path, "items", void 0, key.rootType, ".json", key.root);
1240
+ const model = await this.PERSISTENT_CACHE.getOrLoad(itemKey.serialize(), async () => {
1241
+ const result = await AssetLoader.getFirst([itemKey, key], "json" /* JSON */);
1242
+ if (!result) return void 0;
1243
+ if (result.key.assetType !== "items") return { ...result.asset, key };
1244
+ const reference = this.defaultItemModel(result.asset.model, key);
1245
+ const modelKey = AssetKey.parse("models", reference);
1246
+ modelKey.root = key.root;
1247
+ const model2 = await this.getRaw(modelKey);
1248
+ if (!model2) throw new Error(`Item ${key.toNamespacedString()} references missing model ${reference}`);
1249
+ return model2;
1250
+ });
1251
+ return model ? { ...model, key: Object.assign(new AssetKey("", ""), model.key) } : void 0;
1252
+ }
1253
+ // Item previews use the GUI context, false conditions, and zero numeric properties.
1254
+ static defaultItemModel(node, key) {
1255
+ if (!node || typeof node.type !== "string") {
1256
+ throw new Error(`Unsupported item model definition for ${key.toNamespacedString()}`);
1257
+ }
1258
+ switch (node.type.replace(/^minecraft:/, "")) {
1259
+ case "model":
1260
+ if (typeof node.model === "string" && node.model) return node.model;
1261
+ break;
1262
+ case "condition":
1263
+ return this.defaultItemModel(node.on_false, key);
1264
+ case "select": {
1265
+ 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;
1266
+ return this.defaultItemModel(selected ?? node.fallback, key);
1267
+ }
1268
+ case "range_dispatch": {
1269
+ const selected = node.entries?.reduce((match, entry) => {
1270
+ return entry.threshold <= 0 && (!match || entry.threshold >= match.threshold) ? entry : match;
1271
+ }, void 0);
1272
+ return this.defaultItemModel(selected?.model ?? node.fallback, key);
1273
+ }
1274
+ }
1275
+ throw new Error(`Unsupported item model ${node?.type ?? "definition"} for ${key.toNamespacedString()}`);
1276
+ }
1244
1277
  static async getRaw(key) {
1245
1278
  if (!key.assetType) {
1246
1279
  key.assetType = "models";
@@ -1347,7 +1380,7 @@ var DefaultBlockStates = class {
1347
1380
  };
1348
1381
 
1349
1382
  // src/assets/Assets.ts
1350
- var DEFAULT_ROOT = "https://assets.mcasset.cloud/1.17.1";
1383
+ var DEFAULT_ROOT = "https://assets.mcasset.cloud/1.21.11";
1351
1384
  var DEFAULT_NAMESPACE = "minecraft";
1352
1385
  var Assets = class {
1353
1386
  /**
@@ -1790,11 +1823,29 @@ var AssetLoader = class {
1790
1823
  }
1791
1824
  /** Returns the first defined result in source-priority order, without merging assets. */
1792
1825
  static async get(key, parser) {
1826
+ const keys = [key];
1827
+ if (key.rootType === "data" && (key.assetType === "structure" || key.assetType === "structures")) {
1828
+ keys.push(new AssetKey(
1829
+ key.namespace,
1830
+ key.path,
1831
+ key.assetType === "structure" ? "structures" : "structure",
1832
+ key.type,
1833
+ key.rootType,
1834
+ key.extension,
1835
+ key.root
1836
+ ));
1837
+ }
1838
+ return (await this.getFirst(keys, parser))?.asset;
1839
+ }
1840
+ /** Tries each path within a source before considering lower-priority sources. */
1841
+ static async getFirst(keys, parser) {
1793
1842
  const sources = [...this._SOURCES];
1794
1843
  for (const source of sources) {
1795
- const result = await source.source.get(key, parser);
1796
- if (result !== void 0) {
1797
- return result;
1844
+ for (const key of keys) {
1845
+ const result = await source.source.get(key, parser);
1846
+ if (result !== void 0) {
1847
+ return { key, asset: result };
1848
+ }
1798
1849
  }
1799
1850
  }
1800
1851
  return void 0;