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.
@@ -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
  }
@@ -724,6 +725,7 @@ interface EntityModelFile extends MinecraftAsset {
724
725
  }
725
726
  interface EntityModelLayer {
726
727
  texture: [number, number];
728
+ textureLocation?: string;
727
729
  root: EntityModelPart;
728
730
  }
729
731
  interface EntityModelPart {
@@ -747,6 +749,7 @@ interface EntityModelCube {
747
749
  declare class Entities {
748
750
  static getEntityList(): Promise<string[]>;
749
751
  static getEntity(modelKey: BasicAssetKey, textureKey?: BasicAssetKey, options?: EntityModelOptions): Promise<Maybe<EntityModel>>;
752
+ static resolveTexture(modelKey: BasicAssetKey): Promise<Maybe<AssetKey>>;
750
753
  /** @deprecated Use getEntityList(); block entities share the entity dataset. */
751
754
  static getBlockList(): Promise<string[]>;
752
755
  /** @deprecated Use getEntity(); block entities share the entity dataset. */
@@ -1290,6 +1293,7 @@ declare class Caching {
1290
1293
  static readonly defaultBlockStatesCache: AsyncLoadingCache<CacheKey, DefaultBlockStates>;
1291
1294
  static readonly blockTintCache: AsyncLoadingCache<CacheKey, number>;
1292
1295
  static readonly entityModelCache: AsyncLoadingCache<CacheKey, EntityModelFile>;
1296
+ static readonly entityTextureCache: AsyncLoadingCache<CacheKey, AssetKey>;
1293
1297
  private static createAssetCache;
1294
1298
  /** Every cache above, so clear()/end() can never fall out of sync with the field list again. */
1295
1299
  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
  }
@@ -724,6 +725,7 @@ interface EntityModelFile extends MinecraftAsset {
724
725
  }
725
726
  interface EntityModelLayer {
726
727
  texture: [number, number];
728
+ textureLocation?: string;
727
729
  root: EntityModelPart;
728
730
  }
729
731
  interface EntityModelPart {
@@ -747,6 +749,7 @@ interface EntityModelCube {
747
749
  declare class Entities {
748
750
  static getEntityList(): Promise<string[]>;
749
751
  static getEntity(modelKey: BasicAssetKey, textureKey?: BasicAssetKey, options?: EntityModelOptions): Promise<Maybe<EntityModel>>;
752
+ static resolveTexture(modelKey: BasicAssetKey): Promise<Maybe<AssetKey>>;
750
753
  /** @deprecated Use getEntityList(); block entities share the entity dataset. */
751
754
  static getBlockList(): Promise<string[]>;
752
755
  /** @deprecated Use getEntity(); block entities share the entity dataset. */
@@ -1290,6 +1293,7 @@ declare class Caching {
1290
1293
  static readonly defaultBlockStatesCache: AsyncLoadingCache<CacheKey, DefaultBlockStates>;
1291
1294
  static readonly blockTintCache: AsyncLoadingCache<CacheKey, number>;
1292
1295
  static readonly entityModelCache: AsyncLoadingCache<CacheKey, EntityModelFile>;
1296
+ static readonly entityTextureCache: AsyncLoadingCache<CacheKey, AssetKey>;
1293
1297
  private static createAssetCache;
1294
1298
  /** Every cache above, so clear()/end() can never fall out of sync with the field list again. */
1295
1299
  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,37 @@ 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 if (layer.textureLocation !== void 0) {
2853
+ texture = AssetKey.parse("textures", layer.textureLocation.replace(/^([^:]+:)?textures\//, "$1"));
2854
+ } else {
2855
+ texture = await this.resolveTexture(modelKey);
2856
+ }
2857
+ return { key: textureKey ?? modelKey, texture, layer, id: model.id };
2858
+ }
2859
+ static async resolveTexture(modelKey) {
2860
+ const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
2861
+ const key = new AssetKey(modelKey.namespace, path, void 0, void 0, "entity-models", ".json");
2862
+ return Caching.entityTextureCache.get(key.serialize(), async () => {
2863
+ const name = path.split("/").pop();
2864
+ for (const candidate of [path, `${path}/${name}`]) {
2865
+ const texture = new AssetKey(modelKey.namespace, candidate, "textures", "entity", "assets", ".png");
2866
+ if (await ModelTextures.get(texture)) return texture;
2867
+ }
2868
+ const listKey = new AssetKey(modelKey.namespace, "_list", `${name}_variant`, void 0, "data", ".json");
2869
+ const list = await AssetLoader.get(listKey, "list" /* LIST */);
2870
+ const files = list?.files.filter((file2) => file2.endsWith(".json") && file2 !== "_list.json");
2871
+ const file = files?.find((file2) => file2 === "temperate.json") ?? files?.[0];
2872
+ if (!file) return void 0;
2873
+ const variantKey = new AssetKey(modelKey.namespace, file.slice(0, -5), `${name}_variant`, void 0, "data", ".json");
2874
+ const variant = await AssetLoader.get(variantKey, "json" /* JSON */);
2875
+ const assets = variant?.assets;
2876
+ const textureId = variant?.asset_id ?? (typeof assets?.wild === "string" ? assets.wild : Object.values(assets ?? {}).find((value) => typeof value === "string"));
2877
+ return typeof textureId === "string" ? AssetKey.parse("textures", textureId) : void 0;
2878
+ });
2847
2879
  }
2848
2880
  /** @deprecated Use getEntityList(); block entities share the entity dataset. */
2849
2881
  static getBlockList() {
@@ -3288,6 +3320,7 @@ var _EntityObject = class _EntityObject extends SceneObject {
3288
3320
  super.dispose();
3289
3321
  }
3290
3322
  get textureKey() {
3323
+ if (this.entity.texture) return this.entity.texture;
3291
3324
  const key = this.entity.key;
3292
3325
  return new AssetKey(
3293
3326
  key.namespace,