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.
@@ -716,6 +716,7 @@ declare class DefaultBlockStates implements MinecraftAsset {
716
716
 
717
717
  interface EntityModel {
718
718
  key: BasicAssetKey;
719
+ texture?: AssetKey;
719
720
  layer: EntityModelLayer;
720
721
  id: string;
721
722
  }
@@ -748,6 +749,7 @@ interface EntityModelCube {
748
749
  declare class Entities {
749
750
  static getEntityList(): Promise<string[]>;
750
751
  static getEntity(modelKey: BasicAssetKey, textureKey?: BasicAssetKey, options?: EntityModelOptions): Promise<Maybe<EntityModel>>;
752
+ static resolveTexture(modelKey: BasicAssetKey): Promise<Maybe<AssetKey>>;
751
753
  /** @deprecated Use getEntityList(); block entities share the entity dataset. */
752
754
  static getBlockList(): Promise<string[]>;
753
755
  /** @deprecated Use getEntity(); block entities share the entity dataset. */
@@ -1291,6 +1293,7 @@ declare class Caching {
1291
1293
  static readonly defaultBlockStatesCache: AsyncLoadingCache<CacheKey, DefaultBlockStates>;
1292
1294
  static readonly blockTintCache: AsyncLoadingCache<CacheKey, number>;
1293
1295
  static readonly entityModelCache: AsyncLoadingCache<CacheKey, EntityModelFile>;
1296
+ static readonly entityTextureCache: AsyncLoadingCache<CacheKey, AssetKey>;
1294
1297
  private static createAssetCache;
1295
1298
  /** Every cache above, so clear()/end() can never fall out of sync with the field list again. */
1296
1299
  private static get all();
@@ -716,6 +716,7 @@ declare class DefaultBlockStates implements MinecraftAsset {
716
716
 
717
717
  interface EntityModel {
718
718
  key: BasicAssetKey;
719
+ texture?: AssetKey;
719
720
  layer: EntityModelLayer;
720
721
  id: string;
721
722
  }
@@ -748,6 +749,7 @@ interface EntityModelCube {
748
749
  declare class Entities {
749
750
  static getEntityList(): Promise<string[]>;
750
751
  static getEntity(modelKey: BasicAssetKey, textureKey?: BasicAssetKey, options?: EntityModelOptions): Promise<Maybe<EntityModel>>;
752
+ static resolveTexture(modelKey: BasicAssetKey): Promise<Maybe<AssetKey>>;
751
753
  /** @deprecated Use getEntityList(); block entities share the entity dataset. */
752
754
  static getBlockList(): Promise<string[]>;
753
755
  /** @deprecated Use getEntity(); block entities share the entity dataset. */
@@ -1291,6 +1293,7 @@ declare class Caching {
1291
1293
  static readonly defaultBlockStatesCache: AsyncLoadingCache<CacheKey, DefaultBlockStates>;
1292
1294
  static readonly blockTintCache: AsyncLoadingCache<CacheKey, number>;
1293
1295
  static readonly entityModelCache: AsyncLoadingCache<CacheKey, EntityModelFile>;
1296
+ static readonly entityTextureCache: AsyncLoadingCache<CacheKey, AssetKey>;
1294
1297
  private static createAssetCache;
1295
1298
  /** Every cache above, so clear()/end() can never fall out of sync with the field list again. */
1296
1299
  private static get all();
@@ -561,6 +561,9 @@ var Caching = class _Caching {
561
561
  static {
562
562
  this.entityModelCache = _Caching.createAssetCache();
563
563
  }
564
+ static {
565
+ this.entityTextureCache = _Caching.createAssetCache();
566
+ }
564
567
  static createAssetCache() {
565
568
  return import_loading_cache.Caches.builder().expireAfterWrite(import_time.Time.minutes(10)).expireAfterAccess(import_time.Time.minutes(5)).expirationInterval(import_time.Time.seconds(30)).buildAsync();
566
569
  }
@@ -584,7 +587,8 @@ var Caching = class _Caching {
584
587
  this.listAssetCache,
585
588
  this.defaultBlockStatesCache,
586
589
  this.blockTintCache,
587
- this.entityModelCache
590
+ this.entityModelCache,
591
+ this.entityTextureCache
588
592
  ];
589
593
  }
590
594
  static clear() {
@@ -2882,7 +2886,35 @@ var Entities = class {
2882
2886
  if (!layer) {
2883
2887
  throw new MineRenderError(`Entity ${model.id} has no layer "${layerName}". Available layers: ${Object.keys(model.layers).join(", ")}`);
2884
2888
  }
2885
- return { key: textureKey ?? modelKey, layer, id: model.id };
2889
+ let texture;
2890
+ if (textureKey) {
2891
+ const path2 = isAssetKey(textureKey) ? textureKey.getFullPath() : textureKey.path;
2892
+ 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);
2893
+ } else {
2894
+ texture = await this.resolveTexture(modelKey);
2895
+ }
2896
+ return { key: textureKey ?? modelKey, texture, layer, id: model.id };
2897
+ }
2898
+ static async resolveTexture(modelKey) {
2899
+ const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
2900
+ const key = new AssetKey(modelKey.namespace, path, void 0, void 0, "entity-models", ".json");
2901
+ return Caching.entityTextureCache.get(key.serialize(), async () => {
2902
+ const name = path.split("/").pop();
2903
+ for (const candidate of [path, `${path}/${name}`]) {
2904
+ const texture = new AssetKey(modelKey.namespace, candidate, "textures", "entity", "assets", ".png");
2905
+ if (await ModelTextures.get(texture)) return texture;
2906
+ }
2907
+ const listKey = new AssetKey(modelKey.namespace, "_list", `${name}_variant`, void 0, "data", ".json");
2908
+ const list = await AssetLoader.get(listKey, "list" /* LIST */);
2909
+ const files = list?.files.filter((file2) => file2.endsWith(".json") && file2 !== "_list.json");
2910
+ const file = files?.find((file2) => file2 === "temperate.json") ?? files?.[0];
2911
+ if (!file) return void 0;
2912
+ const variantKey = new AssetKey(modelKey.namespace, file.slice(0, -5), `${name}_variant`, void 0, "data", ".json");
2913
+ const variant = await AssetLoader.get(variantKey, "json" /* JSON */);
2914
+ const assets = variant?.assets;
2915
+ const textureId = variant?.asset_id ?? (typeof assets?.wild === "string" ? assets.wild : Object.values(assets ?? {}).find((value) => typeof value === "string"));
2916
+ return typeof textureId === "string" ? AssetKey.parse("textures", textureId) : void 0;
2917
+ });
2886
2918
  }
2887
2919
  /** @deprecated Use getEntityList(); block entities share the entity dataset. */
2888
2920
  static getBlockList() {
@@ -3331,6 +3363,7 @@ var EntityObject = class _EntityObject extends SceneObject {
3331
3363
  super.dispose();
3332
3364
  }
3333
3365
  get textureKey() {
3366
+ if (this.entity.texture) return this.entity.texture;
3334
3367
  const key = this.entity.key;
3335
3368
  return new AssetKey(
3336
3369
  key.namespace,