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.
@@ -715,6 +715,7 @@ declare class DefaultBlockStates implements MinecraftAsset {
715
715
 
716
716
  interface EntityModel {
717
717
  key: BasicAssetKey;
718
+ texture?: AssetKey;
718
719
  layer: EntityModelLayer;
719
720
  id: string;
720
721
  }
@@ -747,6 +748,7 @@ interface EntityModelCube {
747
748
  declare class Entities {
748
749
  static getEntityList(): Promise<string[]>;
749
750
  static getEntity(modelKey: BasicAssetKey, textureKey?: BasicAssetKey, options?: EntityModelOptions): Promise<Maybe<EntityModel>>;
751
+ static resolveTexture(modelKey: BasicAssetKey): Promise<Maybe<AssetKey>>;
750
752
  /** @deprecated Use getEntityList(); block entities share the entity dataset. */
751
753
  static getBlockList(): Promise<string[]>;
752
754
  /** @deprecated Use getEntity(); block entities share the entity dataset. */
@@ -1290,6 +1292,7 @@ declare class Caching {
1290
1292
  static readonly defaultBlockStatesCache: AsyncLoadingCache<CacheKey, DefaultBlockStates>;
1291
1293
  static readonly blockTintCache: AsyncLoadingCache<CacheKey, number>;
1292
1294
  static readonly entityModelCache: AsyncLoadingCache<CacheKey, EntityModelFile>;
1295
+ static readonly entityTextureCache: AsyncLoadingCache<CacheKey, AssetKey>;
1293
1296
  private static createAssetCache;
1294
1297
  /** Every cache above, so clear()/end() can never fall out of sync with the field list again. */
1295
1298
  private static get all();
@@ -715,6 +715,7 @@ declare class DefaultBlockStates implements MinecraftAsset {
715
715
 
716
716
  interface EntityModel {
717
717
  key: BasicAssetKey;
718
+ texture?: AssetKey;
718
719
  layer: EntityModelLayer;
719
720
  id: string;
720
721
  }
@@ -747,6 +748,7 @@ interface EntityModelCube {
747
748
  declare class Entities {
748
749
  static getEntityList(): Promise<string[]>;
749
750
  static getEntity(modelKey: BasicAssetKey, textureKey?: BasicAssetKey, options?: EntityModelOptions): Promise<Maybe<EntityModel>>;
751
+ static resolveTexture(modelKey: BasicAssetKey): Promise<Maybe<AssetKey>>;
750
752
  /** @deprecated Use getEntityList(); block entities share the entity dataset. */
751
753
  static getBlockList(): Promise<string[]>;
752
754
  /** @deprecated Use getEntity(); block entities share the entity dataset. */
@@ -1290,6 +1292,7 @@ declare class Caching {
1290
1292
  static readonly defaultBlockStatesCache: AsyncLoadingCache<CacheKey, DefaultBlockStates>;
1291
1293
  static readonly blockTintCache: AsyncLoadingCache<CacheKey, number>;
1292
1294
  static readonly entityModelCache: AsyncLoadingCache<CacheKey, EntityModelFile>;
1295
+ static readonly entityTextureCache: AsyncLoadingCache<CacheKey, AssetKey>;
1293
1296
  private static createAssetCache;
1294
1297
  /** Every cache above, so clear()/end() can never fall out of sync with the field list again. */
1295
1298
  private static get all();
@@ -568,7 +568,8 @@ var _Caching = class _Caching {
568
568
  this.listAssetCache,
569
569
  this.defaultBlockStatesCache,
570
570
  this.blockTintCache,
571
- this.entityModelCache
571
+ this.entityModelCache,
572
+ this.entityTextureCache
572
573
  ];
573
574
  }
574
575
  static clear() {
@@ -612,6 +613,7 @@ _Caching.listAssetCache = _Caching.createAssetCache();
612
613
  _Caching.defaultBlockStatesCache = _Caching.createAssetCache();
613
614
  _Caching.blockTintCache = _Caching.createAssetCache();
614
615
  _Caching.entityModelCache = _Caching.createAssetCache();
616
+ _Caching.entityTextureCache = _Caching.createAssetCache();
615
617
  var Caching = _Caching;
616
618
 
617
619
  // src/Geometries.ts
@@ -2843,7 +2845,35 @@ var Entities = class {
2843
2845
  if (!layer) {
2844
2846
  throw new MineRenderError(`Entity ${model.id} has no layer "${layerName}". Available layers: ${Object.keys(model.layers).join(", ")}`);
2845
2847
  }
2846
- return { key: textureKey ?? modelKey, layer, id: model.id };
2848
+ let texture;
2849
+ if (textureKey) {
2850
+ const path2 = isAssetKey(textureKey) ? textureKey.getFullPath() : textureKey.path;
2851
+ 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);
2852
+ } else {
2853
+ texture = await this.resolveTexture(modelKey);
2854
+ }
2855
+ return { key: textureKey ?? modelKey, texture, layer, id: model.id };
2856
+ }
2857
+ static async resolveTexture(modelKey) {
2858
+ const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
2859
+ const key = new AssetKey(modelKey.namespace, path, void 0, void 0, "entity-models", ".json");
2860
+ return Caching.entityTextureCache.get(key.serialize(), async () => {
2861
+ const name = path.split("/").pop();
2862
+ for (const candidate of [path, `${path}/${name}`]) {
2863
+ const texture = new AssetKey(modelKey.namespace, candidate, "textures", "entity", "assets", ".png");
2864
+ if (await ModelTextures.get(texture)) return texture;
2865
+ }
2866
+ const listKey = new AssetKey(modelKey.namespace, "_list", `${name}_variant`, void 0, "data", ".json");
2867
+ const list = await AssetLoader.get(listKey, "list" /* LIST */);
2868
+ const files = list?.files.filter((file2) => file2.endsWith(".json") && file2 !== "_list.json");
2869
+ const file = files?.find((file2) => file2 === "temperate.json") ?? files?.[0];
2870
+ if (!file) return void 0;
2871
+ const variantKey = new AssetKey(modelKey.namespace, file.slice(0, -5), `${name}_variant`, void 0, "data", ".json");
2872
+ const variant = await AssetLoader.get(variantKey, "json" /* JSON */);
2873
+ const assets = variant?.assets;
2874
+ const textureId = variant?.asset_id ?? (typeof assets?.wild === "string" ? assets.wild : Object.values(assets ?? {}).find((value) => typeof value === "string"));
2875
+ return typeof textureId === "string" ? AssetKey.parse("textures", textureId) : void 0;
2876
+ });
2847
2877
  }
2848
2878
  /** @deprecated Use getEntityList(); block entities share the entity dataset. */
2849
2879
  static getBlockList() {
@@ -3288,6 +3318,7 @@ var _EntityObject = class _EntityObject extends SceneObject {
3288
3318
  super.dispose();
3289
3319
  }
3290
3320
  get textureKey() {
3321
+ if (this.entity.texture) return this.entity.texture;
3291
3322
  const key = this.entity.key;
3292
3323
  return new AssetKey(
3293
3324
  key.namespace,