minerender 2.1.0-alpha.60 → 2.1.0-alpha.61

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.
package/dist/bundle.js CHANGED
@@ -33790,7 +33790,7 @@ var MineRender = (() => {
33790
33790
  }
33791
33791
  static async getItemModel(key) {
33792
33792
  const itemKey = new AssetKey(key.namespace, key.path, "items", void 0, key.rootType, ".json", key.root);
33793
- const model = await this.PERSISTENT_CACHE.getOrLoad(AssetLoader.persistentKey(itemKey.serialize()), async () => {
33793
+ const model = await this.PERSISTENT_CACHE.getOrLoad(`item-v2:${AssetLoader.persistentKey(itemKey.serialize())}`, async () => {
33794
33794
  const result = await AssetLoader.getFirst([itemKey, key], "json" /* JSON */);
33795
33795
  if (!result) return void 0;
33796
33796
  if (result.key.assetType !== "items") return { ...result.asset, key };
@@ -33799,7 +33799,7 @@ var MineRender = (() => {
33799
33799
  modelKey.root = key.root;
33800
33800
  const model2 = await this.getRaw(modelKey);
33801
33801
  if (!model2) throw new Error(`Item ${key.toNamespacedString()} references missing model ${selected.model}`);
33802
- return selected.special ? { ...model2, special: selected.special } : model2;
33802
+ return { ...model2, ...selected.special && { special: selected.special }, ...selected.tints && { tints: selected.tints } };
33803
33803
  });
33804
33804
  return model ? { ...model, key: Object.assign(new AssetKey("", ""), model.key) } : void 0;
33805
33805
  }
@@ -33810,7 +33810,7 @@ var MineRender = (() => {
33810
33810
  }
33811
33811
  switch (node.type.replace(/^minecraft:/, "")) {
33812
33812
  case "model":
33813
- if (typeof node.model === "string" && node.model) return { model: node.model };
33813
+ if (typeof node.model === "string" && node.model) return { model: node.model, tints: node.tints };
33814
33814
  break;
33815
33815
  case "special": {
33816
33816
  if (!node.base || !node.model || typeof node.model !== "object") break;
@@ -80541,6 +80541,93 @@ ${shader.fragmentShader}`.replace(
80541
80541
  }
80542
80542
  });
80543
80543
 
80544
+ // src/texture/Colormaps.ts
80545
+ var Colormaps;
80546
+ var init_Colormaps = __esm({
80547
+ "src/texture/Colormaps.ts"() {
80548
+ init_dirname();
80549
+ init_buffer2();
80550
+ init_process2();
80551
+ init_AssetKey();
80552
+ init_ModelTextures();
80553
+ init_Caching();
80554
+ init_MineRenderError();
80555
+ Colormaps = class {
80556
+ /** Samples the selected resource pack's grass colormap using Minecraft's climate coordinates. */
80557
+ static async grassColor(origin, temperature = 0.5, downfall = 1) {
80558
+ const key = AssetKey.parse("textures", "minecraft:colormap/grass", origin);
80559
+ const temp = Math.fround(temperature);
80560
+ const rain = Math.fround(downfall) * temp;
80561
+ const x4 = Math.floor((1 - temp) * 255), y5 = Math.floor((1 - rain) * 255);
80562
+ return await Caching.blockTintCache.get(`${key.serialize()}|${x4},${y5}`, async () => {
80563
+ const image = await ModelTextures.get(key);
80564
+ if (!image) throw new MineRenderError(`Missing grass colormap: ${key.toNamespacedString()}`);
80565
+ if (image.width !== 256 || image.height !== 256) {
80566
+ throw new MineRenderError("Grass colormaps must be 256 \xD7 256 pixels");
80567
+ }
80568
+ const [red, green, blue] = image.data.getImageData(x4, y5, 1, 1).data;
80569
+ return red << 16 | green << 8 | blue;
80570
+ });
80571
+ }
80572
+ };
80573
+ }
80574
+ });
80575
+
80576
+ // src/model/ItemTints.ts
80577
+ var ItemTints;
80578
+ var init_ItemTints = __esm({
80579
+ "src/model/ItemTints.ts"() {
80580
+ init_dirname();
80581
+ init_buffer2();
80582
+ init_process2();
80583
+ init_MineRenderError();
80584
+ init_Colormaps();
80585
+ ItemTints = class {
80586
+ /** Resolves preview colors from item definitions; explicit per-index colors take precedence. */
80587
+ static async get(model, tints) {
80588
+ const sources = model.tints;
80589
+ if (!sources?.length) return tints;
80590
+ const colors = { ...tints };
80591
+ await Promise.all(sources.map(async (source, index) => {
80592
+ if (colors[index] !== void 0) return;
80593
+ switch (source.type) {
80594
+ case "constant":
80595
+ case "minecraft:constant":
80596
+ colors[index] = this.rgb(source.value);
80597
+ break;
80598
+ case "grass":
80599
+ case "minecraft:grass":
80600
+ colors[index] = await Colormaps.grassColor(model.key, source.temperature, source.downfall);
80601
+ break;
80602
+ case "dye":
80603
+ case "minecraft:dye":
80604
+ case "potion":
80605
+ case "minecraft:potion":
80606
+ case "map_color":
80607
+ case "minecraft:map_color":
80608
+ case "firework":
80609
+ case "minecraft:firework":
80610
+ case "team":
80611
+ case "minecraft:team":
80612
+ case "custom_model_data":
80613
+ case "minecraft:custom_model_data":
80614
+ colors[index] = this.rgb(source.default);
80615
+ break;
80616
+ default:
80617
+ throw new MineRenderError(`Unsupported item tint source ${source.type}`);
80618
+ }
80619
+ }));
80620
+ return colors;
80621
+ }
80622
+ static rgb(color2) {
80623
+ if (!Array.isArray(color2)) return color2 & 16777215;
80624
+ const [red, green, blue] = color2.map((channel) => Math.floor(Math.fround(Math.fround(channel) * 255)));
80625
+ return red << 16 | green << 8 | blue;
80626
+ }
80627
+ };
80628
+ }
80629
+ });
80630
+
80544
80631
  // src/model/scene/ModelObject.ts
80545
80632
  function isModelObject(obj) {
80546
80633
  return obj.isModelObject;
@@ -80566,6 +80653,7 @@ ${shader.fragmentShader}`.replace(
80566
80653
  init_SpecialItems();
80567
80654
  init_EntityObject();
80568
80655
  init_GuiLight();
80656
+ init_ItemTints();
80569
80657
  p10 = prefix("ModelObject");
80570
80658
  _ModelObject = class _ModelObject extends SceneObject {
80571
80659
  constructor(originalModel, options) {
@@ -80581,6 +80669,7 @@ ${shader.fragmentShader}`.replace(
80581
80669
  this.addEventListener("removed", () => this.updateAnimationSubscription());
80582
80670
  }
80583
80671
  async init() {
80672
+ this.options.tints = await ItemTints.get(this.originalModel, this.options.tints);
80584
80673
  const special = this.originalModel.special;
80585
80674
  if (special) {
80586
80675
  const parts = await SpecialItems.getParts(special, this.originalModel.key?.root);
@@ -83855,6 +83944,7 @@ ${shader.fragmentShader}`.replace(
83855
83944
  CanvasImage: () => CanvasImage,
83856
83945
  Chunk: () => Chunk,
83857
83946
  ChunkData: () => ChunkData,
83947
+ Colormaps: () => Colormaps,
83858
83948
  CubeFace: () => CubeFace,
83859
83949
  CubeFaceIndex: () => CubeFaceIndex,
83860
83950
  DEFAULT_ELEMENTS: () => DEFAULT_ELEMENTS,
@@ -83880,6 +83970,7 @@ ${shader.fragmentShader}`.replace(
83880
83970
  ImageLoader: () => ImageLoader,
83881
83971
  InstanceManager: () => InstanceManager,
83882
83972
  InstanceReference: () => InstanceReference,
83973
+ ItemTints: () => ItemTints,
83883
83974
  MapControls: () => MapControls,
83884
83975
  Materials: () => Materials,
83885
83976
  Meshes: () => Meshes,
@@ -87614,6 +87705,7 @@ property list uchar int vertex_index
87614
87705
 
87615
87706
  // src/model/index.ts
87616
87707
  init_GuiLight();
87708
+ init_ItemTints();
87617
87709
  init_Model();
87618
87710
  init_ModelCulling();
87619
87711
 
@@ -87744,10 +87836,7 @@ property list uchar int vertex_index
87744
87836
  init_dirname();
87745
87837
  init_buffer2();
87746
87838
  init_process2();
87747
- init_AssetKey();
87748
- init_ModelTextures();
87749
- init_Caching();
87750
- init_MineRenderError();
87839
+ init_Colormaps();
87751
87840
 
87752
87841
  // src/model/block/blockTints.json
87753
87842
  var blockTints_default = {
@@ -87802,7 +87891,7 @@ property list uchar int vertex_index
87802
87891
  color2 = rule.color;
87803
87892
  break;
87804
87893
  case "grass":
87805
- color2 = await this.grassColor(key);
87894
+ color2 = await Colormaps.grassColor(key);
87806
87895
  break;
87807
87896
  case "redstone": {
87808
87897
  const power = Number(state.power ?? 0) / 15;
@@ -87820,18 +87909,6 @@ property list uchar int vertex_index
87820
87909
  }
87821
87910
  return { ...Object.fromEntries([...indices].map((index) => [index, color2])), ...tints };
87822
87911
  }
87823
- static async grassColor(origin) {
87824
- const key = AssetKey.parse("textures", "minecraft:colormap/grass", origin);
87825
- return await Caching.blockTintCache.get(key.serialize(), async () => {
87826
- const image = await ModelTextures.get(key);
87827
- if (!image) throw new MineRenderError(`Missing grass colormap: ${key.toNamespacedString()}`);
87828
- if (image.width !== 256 || image.height !== 256) {
87829
- throw new MineRenderError("Grass colormaps must be 256 \xD7 256 pixels");
87830
- }
87831
- const [red, green, blue] = image.data.getImageData(127, 127, 1, 1).data;
87832
- return red << 16 | green << 8 | blue;
87833
- });
87834
- }
87835
87912
  };
87836
87913
 
87837
87914
  // src/model/block/scene/index.ts
@@ -91145,6 +91222,7 @@ property list uchar int vertex_index
91145
91222
 
91146
91223
  // src/renderer/MineRenderScene.ts
91147
91224
  init_EntityObject();
91225
+ init_ItemTints();
91148
91226
  var _MineRenderScene = class _MineRenderScene extends Scene {
91149
91227
  constructor(options) {
91150
91228
  super();
@@ -91237,6 +91315,7 @@ property list uchar int vertex_index
91237
91315
  }
91238
91316
  }
91239
91317
  async addModel(model, options, parent = this) {
91318
+ options = { ...options, tints: await ItemTints.get(model, options?.tints) };
91240
91319
  return this.addSceneObject(model, () => new ModelObject(model, options), options, parent);
91241
91320
  }
91242
91321
  async addBlock(blockState, options, parent = this) {
@@ -94298,6 +94377,7 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
94298
94377
  init_dirname();
94299
94378
  init_buffer2();
94300
94379
  init_process2();
94380
+ init_Colormaps();
94301
94381
  init_TextureAtlas();
94302
94382
  init_TextureLoader();
94303
94383
  init_Textures();