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.
@@ -1139,7 +1139,7 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
1139
1139
  }
1140
1140
  toString() {
1141
1141
  let a = [
1142
- typeof this.root !== "undefined" || AssetLoader.ROOT !== DEFAULT_ROOT ? this.root ?? AssetLoader.ROOT : "__root__",
1142
+ this.root ?? AssetLoader.ROOT,
1143
1143
  this.rootType ?? "__rootType__",
1144
1144
  this.assetType ?? "__assetType__",
1145
1145
  this.type ?? "__type__",
@@ -1189,6 +1189,7 @@ var ModelMerger = class {
1189
1189
  }
1190
1190
  const models = [];
1191
1191
  const parentKey = AssetKey.parse("models", model.parent);
1192
+ parentKey.root = model.key?.root;
1192
1193
  const parentModel = await Models.getRaw(parentKey);
1193
1194
  if (parentModel) {
1194
1195
  models.unshift(parentModel);
@@ -1218,26 +1219,58 @@ var Models = class _Models {
1218
1219
  return this._persistentCache ?? (this._persistentCache = PersistentCache.open("minerender-models"));
1219
1220
  }
1220
1221
  static async getItemList() {
1221
- const key = new AssetKey(
1222
- DEFAULT_NAMESPACE,
1223
- "_list",
1224
- "models",
1225
- "item",
1226
- "assets",
1227
- ".json",
1228
- DEFAULT_ROOT
1229
- );
1230
- return Caching.listAssetCache.get(key.serialize(), () => {
1231
- return AssetLoader.get(key, "list" /* LIST */);
1222
+ const key = new AssetKey(DEFAULT_NAMESPACE, "_list", "items");
1223
+ const legacyKey = new AssetKey(DEFAULT_NAMESPACE, "_list", "models", "item");
1224
+ return Caching.listAssetCache.get(key.serialize(), async () => {
1225
+ return (await AssetLoader.getFirst([key, legacyKey], "list" /* LIST */))?.asset;
1232
1226
  }).then((r) => r?.files ?? []);
1233
1227
  }
1234
1228
  static async loadAndMerge(key) {
1235
- const model = await this.getRaw(key);
1229
+ const model = key.type === "item" ? await this.getItemModel(key) : await this.getRaw(key);
1236
1230
  if (!model) {
1237
1231
  return void 0;
1238
1232
  }
1239
1233
  return ModelMerger.mergeWithParents(model);
1240
1234
  }
1235
+ static async getItemModel(key) {
1236
+ const itemKey = new AssetKey(key.namespace, key.path, "items", void 0, key.rootType, ".json", key.root);
1237
+ const model = await this.PERSISTENT_CACHE.getOrLoad(itemKey.serialize(), async () => {
1238
+ const result = await AssetLoader.getFirst([itemKey, key], "json" /* JSON */);
1239
+ if (!result) return void 0;
1240
+ if (result.key.assetType !== "items") return { ...result.asset, key };
1241
+ const reference = this.defaultItemModel(result.asset.model, key);
1242
+ const modelKey = AssetKey.parse("models", reference);
1243
+ modelKey.root = key.root;
1244
+ const model2 = await this.getRaw(modelKey);
1245
+ if (!model2) throw new Error(`Item ${key.toNamespacedString()} references missing model ${reference}`);
1246
+ return model2;
1247
+ });
1248
+ return model ? { ...model, key: Object.assign(new AssetKey("", ""), model.key) } : void 0;
1249
+ }
1250
+ // Item previews use the GUI context, false conditions, and zero numeric properties.
1251
+ static defaultItemModel(node, key) {
1252
+ if (!node || typeof node.type !== "string") {
1253
+ throw new Error(`Unsupported item model definition for ${key.toNamespacedString()}`);
1254
+ }
1255
+ switch (node.type.replace(/^minecraft:/, "")) {
1256
+ case "model":
1257
+ if (typeof node.model === "string" && node.model) return node.model;
1258
+ break;
1259
+ case "condition":
1260
+ return this.defaultItemModel(node.on_false, key);
1261
+ case "select": {
1262
+ 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;
1263
+ return this.defaultItemModel(selected ?? node.fallback, key);
1264
+ }
1265
+ case "range_dispatch": {
1266
+ const selected = node.entries?.reduce((match, entry) => {
1267
+ return entry.threshold <= 0 && (!match || entry.threshold >= match.threshold) ? entry : match;
1268
+ }, void 0);
1269
+ return this.defaultItemModel(selected?.model ?? node.fallback, key);
1270
+ }
1271
+ }
1272
+ throw new Error(`Unsupported item model ${node?.type ?? "definition"} for ${key.toNamespacedString()}`);
1273
+ }
1241
1274
  static async getRaw(key) {
1242
1275
  if (!key.assetType) {
1243
1276
  key.assetType = "models";
@@ -1344,7 +1377,7 @@ var DefaultBlockStates = class {
1344
1377
  };
1345
1378
 
1346
1379
  // src/assets/Assets.ts
1347
- var DEFAULT_ROOT = "https://assets.mcasset.cloud/1.17.1";
1380
+ var DEFAULT_ROOT = "https://assets.mcasset.cloud/1.21.11";
1348
1381
  var DEFAULT_NAMESPACE = "minecraft";
1349
1382
  var Assets = class {
1350
1383
  /**
@@ -1762,11 +1795,29 @@ var _AssetLoader = class _AssetLoader {
1762
1795
  }
1763
1796
  /** Returns the first defined result in source-priority order, without merging assets. */
1764
1797
  static async get(key, parser) {
1798
+ const keys = [key];
1799
+ if (key.rootType === "data" && (key.assetType === "structure" || key.assetType === "structures")) {
1800
+ keys.push(new AssetKey(
1801
+ key.namespace,
1802
+ key.path,
1803
+ key.assetType === "structure" ? "structures" : "structure",
1804
+ key.type,
1805
+ key.rootType,
1806
+ key.extension,
1807
+ key.root
1808
+ ));
1809
+ }
1810
+ return (await this.getFirst(keys, parser))?.asset;
1811
+ }
1812
+ /** Tries each path within a source before considering lower-priority sources. */
1813
+ static async getFirst(keys, parser) {
1765
1814
  const sources = [...this._SOURCES];
1766
1815
  for (const source of sources) {
1767
- const result = await source.source.get(key, parser);
1768
- if (result !== void 0) {
1769
- return result;
1816
+ for (const key of keys) {
1817
+ const result = await source.source.get(key, parser);
1818
+ if (result !== void 0) {
1819
+ return { key, asset: result };
1820
+ }
1770
1821
  }
1771
1822
  }
1772
1823
  return void 0;