minerender 2.1.0-alpha.24 → 2.1.0-alpha.25

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.
@@ -407,6 +407,9 @@ var Caching = class _Caching {
407
407
  static {
408
408
  this.entityModelCache = _Caching.createAssetCache();
409
409
  }
410
+ static {
411
+ this.entityTextureCache = _Caching.createAssetCache();
412
+ }
410
413
  static createAssetCache() {
411
414
  return Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
412
415
  }
@@ -430,7 +433,8 @@ var Caching = class _Caching {
430
433
  this.listAssetCache,
431
434
  this.defaultBlockStatesCache,
432
435
  this.blockTintCache,
433
- this.entityModelCache
436
+ this.entityModelCache,
437
+ this.entityTextureCache
434
438
  ];
435
439
  }
436
440
  static clear() {
@@ -2728,7 +2732,35 @@ var Entities = class {
2728
2732
  if (!layer) {
2729
2733
  throw new MineRenderError(`Entity ${model.id} has no layer "${layerName}". Available layers: ${Object.keys(model.layers).join(", ")}`);
2730
2734
  }
2731
- return { key: textureKey ?? modelKey, layer, id: model.id };
2735
+ let texture;
2736
+ if (textureKey) {
2737
+ const path2 = isAssetKey(textureKey) ? textureKey.getFullPath() : textureKey.path;
2738
+ 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);
2739
+ } else {
2740
+ texture = await this.resolveTexture(modelKey);
2741
+ }
2742
+ return { key: textureKey ?? modelKey, texture, layer, id: model.id };
2743
+ }
2744
+ static async resolveTexture(modelKey) {
2745
+ const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
2746
+ const key = new AssetKey(modelKey.namespace, path, void 0, void 0, "entity-models", ".json");
2747
+ return Caching.entityTextureCache.get(key.serialize(), async () => {
2748
+ const name = path.split("/").pop();
2749
+ for (const candidate of [path, `${path}/${name}`]) {
2750
+ const texture = new AssetKey(modelKey.namespace, candidate, "textures", "entity", "assets", ".png");
2751
+ if (await ModelTextures.get(texture)) return texture;
2752
+ }
2753
+ const listKey = new AssetKey(modelKey.namespace, "_list", `${name}_variant`, void 0, "data", ".json");
2754
+ const list = await AssetLoader.get(listKey, "list" /* LIST */);
2755
+ const files = list?.files.filter((file2) => file2.endsWith(".json") && file2 !== "_list.json");
2756
+ const file = files?.find((file2) => file2 === "temperate.json") ?? files?.[0];
2757
+ if (!file) return void 0;
2758
+ const variantKey = new AssetKey(modelKey.namespace, file.slice(0, -5), `${name}_variant`, void 0, "data", ".json");
2759
+ const variant = await AssetLoader.get(variantKey, "json" /* JSON */);
2760
+ const assets = variant?.assets;
2761
+ const textureId = variant?.asset_id ?? (typeof assets?.wild === "string" ? assets.wild : Object.values(assets ?? {}).find((value) => typeof value === "string"));
2762
+ return typeof textureId === "string" ? AssetKey.parse("textures", textureId) : void 0;
2763
+ });
2732
2764
  }
2733
2765
  /** @deprecated Use getEntityList(); block entities share the entity dataset. */
2734
2766
  static getBlockList() {
@@ -3177,6 +3209,7 @@ var EntityObject = class _EntityObject extends SceneObject {
3177
3209
  super.dispose();
3178
3210
  }
3179
3211
  get textureKey() {
3212
+ if (this.entity.texture) return this.entity.texture;
3180
3213
  const key = this.entity.key;
3181
3214
  return new AssetKey(
3182
3215
  key.namespace,