minerender 2.1.0-alpha.20 → 2.1.0-alpha.21

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.
@@ -412,6 +412,7 @@ var _Caching = class _Caching {
412
412
  this.blockStateCache,
413
413
  this.listAssetCache,
414
414
  this.defaultBlockStatesCache,
415
+ this.blockTintCache,
415
416
  this.entityModelsCache
416
417
  ];
417
418
  }
@@ -454,6 +455,7 @@ _Caching.modelTextureAtlasCache = Caches.builder().expireAfterWrite(Time.minutes
454
455
  _Caching.blockStateCache = Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
455
456
  _Caching.listAssetCache = _Caching.createAssetCache();
456
457
  _Caching.defaultBlockStatesCache = _Caching.createAssetCache();
458
+ _Caching.blockTintCache = _Caching.createAssetCache();
457
459
  _Caching.entityModelsCache = _Caching.createAssetCache();
458
460
  var Caching = _Caching;
459
461
 
@@ -3620,6 +3622,91 @@ function isQuadArray(obj) {
3620
3622
  return Array.isArray(obj) && obj.length === 4;
3621
3623
  }
3622
3624
 
3625
+ // src/model/block/blockTints.json
3626
+ var blockTints_default = {
3627
+ "minecraft:large_fern": { source: "grass" },
3628
+ "minecraft:tall_grass": { source: "grass" },
3629
+ "minecraft:grass_block": { source: "grass" },
3630
+ "minecraft:fern": { source: "grass" },
3631
+ "minecraft:grass": { source: "grass" },
3632
+ "minecraft:short_grass": { source: "grass" },
3633
+ "minecraft:potted_fern": { source: "grass" },
3634
+ "minecraft:bush": { source: "grass" },
3635
+ "minecraft:pink_petals": { source: "grass", untinted: [0] },
3636
+ "minecraft:wildflowers": { source: "grass", untinted: [0] },
3637
+ "minecraft:spruce_leaves": { source: "constant", color: 6396257 },
3638
+ "minecraft:birch_leaves": { source: "constant", color: 8431445 },
3639
+ "minecraft:oak_leaves": { source: "constant", color: 4764952 },
3640
+ "minecraft:jungle_leaves": { source: "constant", color: 4764952 },
3641
+ "minecraft:acacia_leaves": { source: "constant", color: 4764952 },
3642
+ "minecraft:dark_oak_leaves": { source: "constant", color: 4764952 },
3643
+ "minecraft:vine": { source: "constant", color: 4764952 },
3644
+ "minecraft:mangrove_leaves": { source: "constant", color: 4764952 },
3645
+ "minecraft:leaf_litter": { source: "constant", color: 6044722 },
3646
+ "minecraft:water_cauldron": { source: "constant", color: 4159204 },
3647
+ "minecraft:redstone_wire": { source: "redstone" },
3648
+ "minecraft:attached_melon_stem": { source: "constant", color: 14731036 },
3649
+ "minecraft:attached_pumpkin_stem": { source: "constant", color: 14731036 },
3650
+ "minecraft:melon_stem": { source: "stem" },
3651
+ "minecraft:pumpkin_stem": { source: "stem" },
3652
+ "minecraft:lily_pad": { source: "constant", color: 7455580 }
3653
+ };
3654
+
3655
+ // src/model/block/BlockTints.ts
3656
+ var rules = blockTints_default;
3657
+ var BlockTints = class {
3658
+ /** Resolves block preview colors without biome context; explicit tints take precedence. */
3659
+ static async get(key, state, model, tints) {
3660
+ const rule = key && rules[key.toNamespacedString()];
3661
+ if (!key || !rule) return tints;
3662
+ const indices = /* @__PURE__ */ new Set();
3663
+ for (const element of model.elements ?? []) {
3664
+ for (const face of Object.values(element.faces)) {
3665
+ const index = face?.tintindex;
3666
+ if (index !== void 0 && index >= 0 && tints?.[index] === void 0 && !rule.untinted?.includes(index)) {
3667
+ indices.add(index);
3668
+ }
3669
+ }
3670
+ }
3671
+ if (!indices.size) return tints;
3672
+ let color;
3673
+ switch (rule.source) {
3674
+ case "constant":
3675
+ color = rule.color;
3676
+ break;
3677
+ case "grass":
3678
+ color = await this.grassColor(key);
3679
+ break;
3680
+ case "redstone": {
3681
+ const power = Number(state.power ?? 0) / 15;
3682
+ const red = power * 0.6 + (power > 0 ? 0.4 : 0.3);
3683
+ const green = Math.max(0, power * power * 0.7 - 0.5);
3684
+ const blue = Math.max(0, power * power * 0.6 - 0.7);
3685
+ color = Math.floor(red * 255) << 16 | Math.floor(green * 255) << 8 | Math.floor(blue * 255);
3686
+ break;
3687
+ }
3688
+ case "stem": {
3689
+ const age = Number(state.age ?? 0);
3690
+ color = age * 32 << 16 | 255 - age * 8 << 8 | age * 4;
3691
+ break;
3692
+ }
3693
+ }
3694
+ return { ...Object.fromEntries([...indices].map((index) => [index, color])), ...tints };
3695
+ }
3696
+ static async grassColor(origin) {
3697
+ const key = AssetKey.parse("textures", "minecraft:colormap/grass", origin);
3698
+ return await Caching.blockTintCache.get(key.serialize(), async () => {
3699
+ const image = await ModelTextures.get(key);
3700
+ if (!image) throw new MineRenderError(`Missing grass colormap: ${key.toNamespacedString()}`);
3701
+ if (image.width !== 256 || image.height !== 256) {
3702
+ throw new MineRenderError("Grass colormaps must be 256 \xD7 256 pixels");
3703
+ }
3704
+ const [red, green, blue] = image.data.getImageData(127, 127, 1, 1).data;
3705
+ return red << 16 | green << 8 | blue;
3706
+ });
3707
+ }
3708
+ };
3709
+
3623
3710
  // src/model/scene/ModelObject.ts
3624
3711
  import { BoxGeometry as BoxGeometry5, BufferAttribute as BufferAttribute4, Color as Color3, Euler as Euler4, Matrix4 as Matrix45 } from "three";
3625
3712
 
@@ -4464,6 +4551,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
4464
4551
  const model = await Models.getMerged(AssetKey.parse("models", variant.model));
4465
4552
  const options = {
4466
4553
  ...this.options,
4554
+ tints: model ? await BlockTints.get(this.blockState.key, this.state, model, this.options.tints) : this.options.tints,
4467
4555
  uvLockRotation: variant.uvlock && (rotation.x !== 0 || rotation.y !== 0) ? [rotation.x, rotation.y, rotation.z] : void 0
4468
4556
  };
4469
4557
  const obj = await this.scene.addModel(model, options);
@@ -6990,6 +7078,7 @@ export {
6990
7078
  BlockEntityModels,
6991
7079
  BlockObject,
6992
7080
  BlockStates,
7081
+ BlockTints,
6993
7082
  BrowserArchiveProxy,
6994
7083
  BrowserCache,
6995
7084
  BrowserEnv,