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.
@@ -1500,7 +1500,7 @@ var init_Models = __esm({
1500
1500
  }
1501
1501
  static async getItemModel(key) {
1502
1502
  const itemKey = new AssetKey(key.namespace, key.path, "items", void 0, key.rootType, ".json", key.root);
1503
- const model = await this.PERSISTENT_CACHE.getOrLoad(AssetLoader.persistentKey(itemKey.serialize()), async () => {
1503
+ const model = await this.PERSISTENT_CACHE.getOrLoad(`item-v2:${AssetLoader.persistentKey(itemKey.serialize())}`, async () => {
1504
1504
  const result = await AssetLoader.getFirst([itemKey, key], "json" /* JSON */);
1505
1505
  if (!result) return void 0;
1506
1506
  if (result.key.assetType !== "items") return { ...result.asset, key };
@@ -1509,7 +1509,7 @@ var init_Models = __esm({
1509
1509
  modelKey.root = key.root;
1510
1510
  const model2 = await this.getRaw(modelKey);
1511
1511
  if (!model2) throw new Error(`Item ${key.toNamespacedString()} references missing model ${selected.model}`);
1512
- return selected.special ? { ...model2, special: selected.special } : model2;
1512
+ return { ...model2, ...selected.special && { special: selected.special }, ...selected.tints && { tints: selected.tints } };
1513
1513
  });
1514
1514
  return model ? { ...model, key: Object.assign(new AssetKey("", ""), model.key) } : void 0;
1515
1515
  }
@@ -1520,7 +1520,7 @@ var init_Models = __esm({
1520
1520
  }
1521
1521
  switch (node.type.replace(/^minecraft:/, "")) {
1522
1522
  case "model":
1523
- if (typeof node.model === "string" && node.model) return { model: node.model };
1523
+ if (typeof node.model === "string" && node.model) return { model: node.model, tints: node.tints };
1524
1524
  break;
1525
1525
  case "special": {
1526
1526
  if (!node.base || !node.model || typeof node.model !== "object") break;
@@ -4925,6 +4925,87 @@ var init_GuiLight = __esm({
4925
4925
  }
4926
4926
  });
4927
4927
 
4928
+ // src/texture/Colormaps.ts
4929
+ var Colormaps;
4930
+ var init_Colormaps = __esm({
4931
+ "src/texture/Colormaps.ts"() {
4932
+ init_AssetKey();
4933
+ init_ModelTextures();
4934
+ init_Caching();
4935
+ init_MineRenderError();
4936
+ Colormaps = class {
4937
+ /** Samples the selected resource pack's grass colormap using Minecraft's climate coordinates. */
4938
+ static async grassColor(origin, temperature = 0.5, downfall = 1) {
4939
+ const key = AssetKey.parse("textures", "minecraft:colormap/grass", origin);
4940
+ const temp = Math.fround(temperature);
4941
+ const rain = Math.fround(downfall) * temp;
4942
+ const x = Math.floor((1 - temp) * 255), y = Math.floor((1 - rain) * 255);
4943
+ return await Caching.blockTintCache.get(`${key.serialize()}|${x},${y}`, async () => {
4944
+ const image = await ModelTextures.get(key);
4945
+ if (!image) throw new MineRenderError(`Missing grass colormap: ${key.toNamespacedString()}`);
4946
+ if (image.width !== 256 || image.height !== 256) {
4947
+ throw new MineRenderError("Grass colormaps must be 256 \xD7 256 pixels");
4948
+ }
4949
+ const [red, green, blue] = image.data.getImageData(x, y, 1, 1).data;
4950
+ return red << 16 | green << 8 | blue;
4951
+ });
4952
+ }
4953
+ };
4954
+ }
4955
+ });
4956
+
4957
+ // src/model/ItemTints.ts
4958
+ var ItemTints;
4959
+ var init_ItemTints = __esm({
4960
+ "src/model/ItemTints.ts"() {
4961
+ init_MineRenderError();
4962
+ init_Colormaps();
4963
+ ItemTints = class {
4964
+ /** Resolves preview colors from item definitions; explicit per-index colors take precedence. */
4965
+ static async get(model, tints) {
4966
+ const sources = model.tints;
4967
+ if (!sources?.length) return tints;
4968
+ const colors = { ...tints };
4969
+ await Promise.all(sources.map(async (source, index) => {
4970
+ if (colors[index] !== void 0) return;
4971
+ switch (source.type) {
4972
+ case "constant":
4973
+ case "minecraft:constant":
4974
+ colors[index] = this.rgb(source.value);
4975
+ break;
4976
+ case "grass":
4977
+ case "minecraft:grass":
4978
+ colors[index] = await Colormaps.grassColor(model.key, source.temperature, source.downfall);
4979
+ break;
4980
+ case "dye":
4981
+ case "minecraft:dye":
4982
+ case "potion":
4983
+ case "minecraft:potion":
4984
+ case "map_color":
4985
+ case "minecraft:map_color":
4986
+ case "firework":
4987
+ case "minecraft:firework":
4988
+ case "team":
4989
+ case "minecraft:team":
4990
+ case "custom_model_data":
4991
+ case "minecraft:custom_model_data":
4992
+ colors[index] = this.rgb(source.default);
4993
+ break;
4994
+ default:
4995
+ throw new MineRenderError(`Unsupported item tint source ${source.type}`);
4996
+ }
4997
+ }));
4998
+ return colors;
4999
+ }
5000
+ static rgb(color) {
5001
+ if (!Array.isArray(color)) return color & 16777215;
5002
+ const [red, green, blue] = color.map((channel) => Math.floor(Math.fround(Math.fround(channel) * 255)));
5003
+ return red << 16 | green << 8 | blue;
5004
+ }
5005
+ };
5006
+ }
5007
+ });
5008
+
4928
5009
  // src/model/scene/ModelObject.ts
4929
5010
  import { BoxGeometry as BoxGeometry5, BufferAttribute as BufferAttribute5, Color as Color8, Euler as Euler6, Matrix4 as Matrix49 } from "three";
4930
5011
  function isModelObject(obj) {
@@ -4947,6 +5028,7 @@ var init_ModelObject = __esm({
4947
5028
  init_SpecialItems();
4948
5029
  init_EntityObject();
4949
5030
  init_GuiLight();
5031
+ init_ItemTints();
4950
5032
  p7 = prefix("ModelObject");
4951
5033
  ModelObject = class _ModelObject extends SceneObject {
4952
5034
  constructor(originalModel, options) {
@@ -4965,6 +5047,7 @@ var init_ModelObject = __esm({
4965
5047
  this.DEFAULT_OPTIONS = (0, import_ts_deepmerge5.default)({}, SceneObject.DEFAULT_OPTIONS, {});
4966
5048
  }
4967
5049
  async init() {
5050
+ this.options.tints = await ItemTints.get(this.originalModel, this.options.tints);
4968
5051
  const special = this.originalModel.special;
4969
5052
  if (special) {
4970
5053
  const parts = await SpecialItems.getParts(special, this.originalModel.key?.root);
@@ -8812,6 +8895,7 @@ function isInstanceable(obj) {
8812
8895
  init_DisplayPosition();
8813
8896
  init_DisplayTransforms();
8814
8897
  init_GuiLight();
8898
+ init_ItemTints();
8815
8899
  init_Model();
8816
8900
  init_ModelCulling();
8817
8901
  init_ModelGenerator();
@@ -8909,10 +8993,7 @@ var BlockStateResolver = class {
8909
8993
  };
8910
8994
 
8911
8995
  // src/model/block/BlockTints.ts
8912
- init_AssetKey();
8913
- init_ModelTextures();
8914
- init_Caching();
8915
- init_MineRenderError();
8996
+ init_Colormaps();
8916
8997
 
8917
8998
  // src/model/block/blockTints.json
8918
8999
  var blockTints_default = {
@@ -8967,7 +9048,7 @@ var BlockTints = class {
8967
9048
  color = rule.color;
8968
9049
  break;
8969
9050
  case "grass":
8970
- color = await this.grassColor(key);
9051
+ color = await Colormaps.grassColor(key);
8971
9052
  break;
8972
9053
  case "redstone": {
8973
9054
  const power = Number(state.power ?? 0) / 15;
@@ -8985,18 +9066,6 @@ var BlockTints = class {
8985
9066
  }
8986
9067
  return { ...Object.fromEntries([...indices].map((index) => [index, color])), ...tints };
8987
9068
  }
8988
- static async grassColor(origin) {
8989
- const key = AssetKey.parse("textures", "minecraft:colormap/grass", origin);
8990
- return await Caching.blockTintCache.get(key.serialize(), async () => {
8991
- const image = await ModelTextures.get(key);
8992
- if (!image) throw new MineRenderError(`Missing grass colormap: ${key.toNamespacedString()}`);
8993
- if (image.width !== 256 || image.height !== 256) {
8994
- throw new MineRenderError("Grass colormaps must be 256 \xD7 256 pixels");
8995
- }
8996
- const [red, green, blue] = image.data.getImageData(127, 127, 1, 1).data;
8997
- return red << 16 | green << 8 | blue;
8998
- });
8999
- }
9000
9069
  };
9001
9070
 
9002
9071
  // src/model/block/scene/BlockObject.ts
@@ -12252,6 +12321,7 @@ var SkinObject = class extends SceneObject {
12252
12321
 
12253
12322
  // src/renderer/MineRenderScene.ts
12254
12323
  init_EntityObject();
12324
+ init_ItemTints();
12255
12325
  var MineRenderScene = class _MineRenderScene extends Scene5 {
12256
12326
  constructor(options) {
12257
12327
  super();
@@ -12347,6 +12417,7 @@ var MineRenderScene = class _MineRenderScene extends Scene5 {
12347
12417
  }
12348
12418
  }
12349
12419
  async addModel(model, options, parent = this) {
12420
+ options = { ...options, tints: await ItemTints.get(model, options?.tints) };
12350
12421
  return this.addSceneObject(model, () => new ModelObject(model, options), options, parent);
12351
12422
  }
12352
12423
  async addBlock(blockState, options, parent = this) {
@@ -13617,6 +13688,7 @@ var Skins = class {
13617
13688
  };
13618
13689
 
13619
13690
  // src/texture/index.ts
13691
+ init_Colormaps();
13620
13692
  init_TextureAtlas();
13621
13693
  init_TextureLoader();
13622
13694
  init_Textures();
@@ -14501,6 +14573,7 @@ export {
14501
14573
  CanvasImage,
14502
14574
  Chunk,
14503
14575
  ChunkData,
14576
+ Colormaps,
14504
14577
  CubeFace,
14505
14578
  CubeFaceIndex,
14506
14579
  DEFAULT_ELEMENTS,
@@ -14526,6 +14599,7 @@ export {
14526
14599
  ImageLoader,
14527
14600
  InstanceManager,
14528
14601
  InstanceReference,
14602
+ ItemTints,
14529
14603
  MapControls,
14530
14604
  Materials,
14531
14605
  Meshes,