minerender 2.1.0-alpha.24 → 2.1.0-alpha.26

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.
@@ -413,7 +413,8 @@ var _Caching = class _Caching {
413
413
  this.listAssetCache,
414
414
  this.defaultBlockStatesCache,
415
415
  this.blockTintCache,
416
- this.entityModelCache
416
+ this.entityModelCache,
417
+ this.entityTextureCache
417
418
  ];
418
419
  }
419
420
  static clear() {
@@ -457,6 +458,7 @@ _Caching.listAssetCache = _Caching.createAssetCache();
457
458
  _Caching.defaultBlockStatesCache = _Caching.createAssetCache();
458
459
  _Caching.blockTintCache = _Caching.createAssetCache();
459
460
  _Caching.entityModelCache = _Caching.createAssetCache();
461
+ _Caching.entityTextureCache = _Caching.createAssetCache();
460
462
  var Caching = _Caching;
461
463
 
462
464
  // src/Geometries.ts
@@ -2688,7 +2690,37 @@ var Entities = class {
2688
2690
  if (!layer) {
2689
2691
  throw new MineRenderError(`Entity ${model.id} has no layer "${layerName}". Available layers: ${Object.keys(model.layers).join(", ")}`);
2690
2692
  }
2691
- return { key: textureKey ?? modelKey, layer, id: model.id };
2693
+ let texture;
2694
+ if (textureKey) {
2695
+ const path2 = isAssetKey(textureKey) ? textureKey.getFullPath() : textureKey.path;
2696
+ texture = isAssetKey(textureKey) && textureKey.assetType === "textures" && path2.startsWith("entity/") ? textureKey : new AssetKey(textureKey.namespace, path2, "textures", "entity", "assets", ".png", isAssetKey(textureKey) ? textureKey.root : void 0);
2697
+ } else if (layer.textureLocation !== void 0) {
2698
+ texture = AssetKey.parse("textures", layer.textureLocation.replace(/^([^:]+:)?textures\//, "$1"));
2699
+ } else {
2700
+ texture = await this.resolveTexture(modelKey);
2701
+ }
2702
+ return { key: textureKey ?? modelKey, texture, layer, id: model.id };
2703
+ }
2704
+ static async resolveTexture(modelKey) {
2705
+ const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
2706
+ const key = new AssetKey(modelKey.namespace, path, void 0, void 0, "entity-models", ".json");
2707
+ return Caching.entityTextureCache.get(key.serialize(), async () => {
2708
+ const name = path.split("/").pop();
2709
+ for (const candidate of [path, `${path}/${name}`]) {
2710
+ const texture = new AssetKey(modelKey.namespace, candidate, "textures", "entity", "assets", ".png");
2711
+ if (await ModelTextures.get(texture)) return texture;
2712
+ }
2713
+ const listKey = new AssetKey(modelKey.namespace, "_list", `${name}_variant`, void 0, "data", ".json");
2714
+ const list = await AssetLoader.get(listKey, "list" /* LIST */);
2715
+ const files = list?.files.filter((file2) => file2.endsWith(".json") && file2 !== "_list.json");
2716
+ const file = files?.find((file2) => file2 === "temperate.json") ?? files?.[0];
2717
+ if (!file) return void 0;
2718
+ const variantKey = new AssetKey(modelKey.namespace, file.slice(0, -5), `${name}_variant`, void 0, "data", ".json");
2719
+ const variant = await AssetLoader.get(variantKey, "json" /* JSON */);
2720
+ const assets = variant?.assets;
2721
+ const textureId = variant?.asset_id ?? (typeof assets?.wild === "string" ? assets.wild : Object.values(assets ?? {}).find((value) => typeof value === "string"));
2722
+ return typeof textureId === "string" ? AssetKey.parse("textures", textureId) : void 0;
2723
+ });
2692
2724
  }
2693
2725
  /** @deprecated Use getEntityList(); block entities share the entity dataset. */
2694
2726
  static getBlockList() {
@@ -3133,6 +3165,7 @@ var _EntityObject = class _EntityObject extends SceneObject {
3133
3165
  super.dispose();
3134
3166
  }
3135
3167
  get textureKey() {
3168
+ if (this.entity.texture) return this.entity.texture;
3136
3169
  const key = this.entity.key;
3137
3170
  return new AssetKey(
3138
3171
  key.namespace,