minerender 2.1.0-alpha.12 → 2.1.0-alpha.14

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.
@@ -241,7 +241,7 @@ registerNodeEnv();
241
241
  // src/Axis.ts
242
242
  import { Vector3 } from "three";
243
243
  var Axis = /* @__PURE__ */ ((Axis3) => {
244
- Axis3["X"] = "X";
244
+ Axis3["X"] = "x";
245
245
  Axis3["Y"] = "y";
246
246
  Axis3["Z"] = "z";
247
247
  return Axis3;
@@ -249,7 +249,7 @@ var Axis = /* @__PURE__ */ ((Axis3) => {
249
249
  var AXES = Object.values(Axis);
250
250
  function axisToVec3(axis) {
251
251
  switch (axis) {
252
- case "X" /* X */:
252
+ case "x" /* X */:
253
253
  return new Vector3(1, 0, 0);
254
254
  case "y" /* Y */:
255
255
  return new Vector3(0, 1, 0);
@@ -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__",
@@ -1179,9 +1179,9 @@ var ModelMerger = class {
1179
1179
  const models = await this.collectAllParents(model);
1180
1180
  let merged = {};
1181
1181
  for (let parentModel of models) {
1182
- merged = (0, import_ts_deepmerge.default)(merged, parentModel);
1182
+ merged = import_ts_deepmerge.default.withOptions({ mergeArrays: false }, merged, parentModel);
1183
1183
  }
1184
- merged = (0, import_ts_deepmerge.default)(merged, model);
1184
+ merged = import_ts_deepmerge.default.withOptions({ mergeArrays: false }, merged, model);
1185
1185
  merged.hierarchy = models.map((m) => m.parent).filter((p12) => `${p12}`);
1186
1186
  merged.hierarchy.push(`${merged.parent}`);
1187
1187
  return merged;
@@ -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
  /**
@@ -1408,7 +1441,7 @@ function applyElementRotation(rotation, geometry) {
1408
1441
  const origin = new Vector32(rotation.origin[0], rotation.origin[1], rotation.origin[2]);
1409
1442
  geometry.translate(-origin.x, -origin.y, -origin.z);
1410
1443
  switch (rotation.axis) {
1411
- case "X" /* X */:
1444
+ case "x" /* X */:
1412
1445
  geometry.rotateX(toRadians(rotation.angle));
1413
1446
  break;
1414
1447
  case "y" /* Y */:
@@ -1439,7 +1472,7 @@ function applyModelPartRotation(modelPart, geometry) {
1439
1472
  }
1440
1473
  function applyGenericRotation(axis, rotation, obj) {
1441
1474
  switch (axis) {
1442
- case "X" /* X */:
1475
+ case "x" /* X */:
1443
1476
  obj.rotateOnAxis(new Vector32(1, 0, 0), toRadians(rotation));
1444
1477
  break;
1445
1478
  case "y" /* Y */:
@@ -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;
@@ -2334,17 +2385,13 @@ var UVMapper = class {
2334
2385
  this.setCubeFaceUvInArray(uv, faceIndex * 4, [0, 1, 8 / size, (size - 8) / size]);
2335
2386
  continue;
2336
2387
  }
2388
+ if (!face.texture) continue;
2337
2389
  if (!face.uv) {
2338
2390
  face.uv = this.getFallbackUv(element, faceName);
2339
2391
  }
2340
- let faceTexture = face.texture;
2341
- let texPosition;
2342
- let texSize;
2343
- if (faceTexture) {
2344
- faceTexture = faceTexture.substr(1);
2345
- texPosition = positions[faceTexture] || [0, 0];
2346
- texSize = sizes[faceTexture] || [16, 16];
2347
- }
2392
+ const faceTexture = face.texture.substr(1);
2393
+ const texPosition = positions[faceTexture] || [0, 0];
2394
+ const texSize = sizes[faceTexture] || [16, 16];
2348
2395
  let texPosV = new Vector2(texPosition[0], texPosition[1]);
2349
2396
  const [tl, tr, bl, br] = this.expandAndRotateMcUvs(face.uv, face.rotation, texSize[0], texSize[1]);
2350
2397
  tl.add(texPosV);