minerender 2.1.0-alpha.80 → 2.1.0-alpha.83

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.
@@ -300,6 +300,9 @@ var init_Caching = __esm({
300
300
  static {
301
301
  this.fontCache = _Caching.createAssetCache();
302
302
  }
303
+ static {
304
+ this.bannerPatternCache = _Caching.createAssetCache();
305
+ }
303
306
  static createAssetCache() {
304
307
  return Caches.builder().expireAfterWrite(Time.minutes(10)).expireAfterAccess(Time.minutes(5)).expirationInterval(Time.seconds(30)).buildAsync();
305
308
  }
@@ -327,7 +330,8 @@ var init_Caching = __esm({
327
330
  this.entityTextureCache,
328
331
  this.entityAnimationCache,
329
332
  this.blockEntityIndexCache,
330
- this.fontCache
333
+ this.fontCache,
334
+ this.bannerPatternCache
331
335
  ];
332
336
  }
333
337
  /** Invalidates in-memory entries so later lookups reload them. Persisted entries are retained. */
@@ -991,6 +995,7 @@ var init_Materials = __esm({
991
995
  material.depthWrite = false;
992
996
  break;
993
997
  case "eyes":
998
+ case "no_outline":
994
999
  material.transparent = true;
995
1000
  material.alphaTest = 0;
996
1001
  material.depthWrite = false;
@@ -1579,6 +1584,79 @@ var init_AssetParsers = __esm({
1579
1584
  }
1580
1585
  });
1581
1586
 
1587
+ // src/assets/BannerPatterns.ts
1588
+ var DYE_COLORS, BannerPatterns;
1589
+ var init_BannerPatterns = __esm({
1590
+ "src/assets/BannerPatterns.ts"() {
1591
+ init_AssetKey();
1592
+ init_AssetLoader();
1593
+ init_AssetParsers();
1594
+ init_Caching();
1595
+ DYE_COLORS = Object.freeze({
1596
+ white: 16383998,
1597
+ orange: 16351261,
1598
+ magenta: 13061821,
1599
+ light_blue: 3847130,
1600
+ yellow: 16701501,
1601
+ lime: 8439583,
1602
+ pink: 15961002,
1603
+ gray: 4673362,
1604
+ light_gray: 10329495,
1605
+ cyan: 1481884,
1606
+ purple: 8991416,
1607
+ blue: 3949738,
1608
+ brown: 8606770,
1609
+ green: 6192150,
1610
+ red: 11546150,
1611
+ black: 1908001
1612
+ });
1613
+ BannerPatterns = class {
1614
+ /** Lists namespaced pattern IDs from the selected namespace's data directory. */
1615
+ static async getList(namespace = "minecraft", root) {
1616
+ const collect = async (path) => {
1617
+ const prefix2 = path ? `${path}/` : "";
1618
+ const key = new AssetKey(namespace, `${prefix2}_list`, "banner_pattern", void 0, "data", ".json", root);
1619
+ const list2 = await Caching.listAssetCache.get(key.serialize(), () => AssetLoader.get(key, "list" /* LIST */));
1620
+ if (!list2) return [];
1621
+ const files = list2.files.filter((file) => file.endsWith(".json") && file !== "_list.json").map((file) => `${namespace}:${prefix2}${file.slice(0, -5)}`);
1622
+ const children = await Promise.all(list2.directories.map((directory) => collect(`${prefix2}${directory}`)));
1623
+ return [...files, ...children.flat()];
1624
+ };
1625
+ return collect("");
1626
+ }
1627
+ /** Returns the named dye's sRGB value, rejecting unknown colors. */
1628
+ static getColor(color2) {
1629
+ if (typeof color2 !== "string" || !Object.prototype.hasOwnProperty.call(DYE_COLORS, color2)) throw new Error(`Unsupported dye color ${color2}`);
1630
+ return DYE_COLORS[color2];
1631
+ }
1632
+ /** Resolves the first 16 layers of a `banner_patterns` component, preserving their order. */
1633
+ static async getLayers(value, target, root) {
1634
+ if (value === void 0) return [];
1635
+ if (!Array.isArray(value)) throw new Error("banner_patterns must be an array");
1636
+ return Promise.all(value.slice(0, 16).map(async (layer) => {
1637
+ if (!layer || typeof layer !== "object" || Array.isArray(layer)) throw new Error("Each banner pattern requires a pattern and dye color");
1638
+ const color2 = this.getColor(layer.color);
1639
+ let pattern2 = layer.pattern;
1640
+ if (typeof pattern2 === "string") {
1641
+ const id = this.identifier(pattern2);
1642
+ const key = new AssetKey(id.namespace, id.getFullPath(), "banner_pattern", void 0, "data", ".json", root);
1643
+ pattern2 = await Caching.bannerPatternCache.get(key.serialize(), () => AssetLoader.get(key, "json" /* JSON */));
1644
+ if (!pattern2) throw new Error(`Missing banner pattern ${layer.pattern}`);
1645
+ }
1646
+ if (!pattern2 || typeof pattern2 !== "object" || Array.isArray(pattern2) || typeof pattern2.translation_key !== "string") throw new Error("Banner patterns require asset_id and translation_key");
1647
+ const asset2 = this.identifier(pattern2.asset_id);
1648
+ return { color: color2, texture: new AssetKey(asset2.namespace, `${target}/${asset2.getFullPath()}`, "textures", "entity", "assets", ".png", root) };
1649
+ }));
1650
+ }
1651
+ static identifier(value) {
1652
+ if (typeof value !== "string" || !/^(?:[a-z0-9_.-]+:)?[a-z0-9_./-]+$/.test(value)) throw new Error(`Invalid banner-pattern identifier ${value}`);
1653
+ const [namespace, path] = value.includes(":") ? value.split(":") : ["minecraft", value];
1654
+ return new AssetKey(namespace, path);
1655
+ }
1656
+ };
1657
+ }
1658
+ });
1659
+
1582
1660
  // src/assets/Models.ts
1583
1661
  var Models;
1584
1662
  var init_Models = __esm({
@@ -1591,6 +1669,7 @@ var init_Models = __esm({
1591
1669
  init_AssetKey();
1592
1670
  init_AssetParsers();
1593
1671
  init_DisplayPosition();
1672
+ init_BannerPatterns();
1594
1673
  Models = class _Models {
1595
1674
  // opened lazily: touching the store at import time would hit IndexedDB/disk just for loading
1596
1675
  // the library, and would require an EnvProvider before any entry has had a chance to register
@@ -1780,6 +1859,19 @@ var init_Models = __esm({
1780
1859
  if (!node.base || !node.model || typeof node.model !== "object") break;
1781
1860
  const special = node.model;
1782
1861
  switch (special.type) {
1862
+ case "banner":
1863
+ case "minecraft:banner":
1864
+ if (typeof special.color === "string" && Object.prototype.hasOwnProperty.call(DYE_COLORS, special.color)) return { model: node.base, special };
1865
+ break;
1866
+ case "shield":
1867
+ case "minecraft:shield":
1868
+ return { model: node.base, special };
1869
+ case "shulker_box":
1870
+ case "minecraft:shulker_box":
1871
+ if (typeof special.texture === "string" && special.texture && (special.openness === void 0 || typeof special.openness === "number" && Number.isFinite(special.openness)) && (special.orientation === void 0 || ["down", "up", "north", "south", "west", "east"].includes(special.orientation))) {
1872
+ return { model: node.base, special };
1873
+ }
1874
+ break;
1783
1875
  case "chest":
1784
1876
  case "minecraft:chest":
1785
1877
  case "bed":
@@ -5519,15 +5611,17 @@ var init_ModelCulling = __esm({
5519
5611
  });
5520
5612
 
5521
5613
  // src/model/SpecialItems.ts
5522
- import { Matrix4 as Matrix48 } from "three";
5614
+ import { Euler as Euler7, Matrix4 as Matrix48 } from "three";
5523
5615
  var SpecialItems;
5524
5616
  var init_SpecialItems = __esm({
5525
5617
  "src/model/SpecialItems.ts"() {
5526
5618
  init_AssetKey();
5527
5619
  init_Entities();
5620
+ init_BannerPatterns();
5621
+ init_ModelTextures();
5528
5622
  SpecialItems = class {
5529
5623
  /** Resolves the static entity parts drawn by a special item renderer, in model units. */
5530
- static async getParts(special, root) {
5624
+ static async getParts(special, root, components = {}) {
5531
5625
  const texture = (id, directory) => {
5532
5626
  const key = AssetKey.parse("textures", id);
5533
5627
  return new AssetKey(
@@ -5540,13 +5634,60 @@ var init_SpecialItems = __esm({
5540
5634
  root
5541
5635
  );
5542
5636
  };
5543
- const load = async (id, textureKey, transform, rotations = {}) => {
5637
+ const load = async (id, textureKey, transform, rotations = {}, layers = ["main"]) => {
5544
5638
  const key = new AssetKey("minecraft", id, void 0, void 0, "entity-models", ".json", root);
5545
- const model = await Entities.getEntity(key, textureKey, { layer: "main" });
5639
+ const model = await Entities.getEntity(key, textureKey, layers.length === 1 ? { layer: layers[0] } : {
5640
+ layers,
5641
+ textures: textureKey ? Object.fromEntries(layers.map((name) => [name, textureKey])) : void 0
5642
+ });
5546
5643
  if (!model) throw new Error(`Missing entity model minecraft:${id} for special item ${special.type}`);
5547
5644
  return { model, transform, rotations };
5548
5645
  };
5549
5646
  switch (special.type) {
5647
+ case "minecraft:banner":
5648
+ case "banner":
5649
+ case "minecraft:shield":
5650
+ case "shield": {
5651
+ const banner = special.type === "banner" || special.type === "minecraft:banner";
5652
+ const color2 = banner ? BannerPatterns.getColor(special.color) : components["minecraft:base_color"] === void 0 ? void 0 : BannerPatterns.getColor(components["minecraft:base_color"]);
5653
+ const patterns = await BannerPatterns.getLayers(components["minecraft:banner_patterns"], banner ? "banner" : "shield", root);
5654
+ const patterned = banner || color2 !== void 0 || patterns.length > 0;
5655
+ const baseTexture = texture(banner ? "banner_base" : patterned ? "shield_base" : "shield_base_nopattern", "");
5656
+ const transform = banner ? new Matrix48().makeTranslation(8, 0, 8).multiply(new Matrix48().makeScale(2 / 3, -2 / 3, -2 / 3)) : new Matrix48().makeScale(1, -1, -1);
5657
+ const part = await load(banner ? "standing_banner" : "shield", baseTexture, transform, {}, banner ? ["main", "flag"] : ["main"]);
5658
+ const layers = Object.fromEntries(Object.entries(part.model.layers ?? { main: part.model }).map(([name, layer]) => [name, { ...layer, render: "solid" }]));
5659
+ let overlay2;
5660
+ if (banner) {
5661
+ const flagLayer = layers.flag;
5662
+ const flag = flagLayer?.layer.root.children.flag;
5663
+ if (!flag) throw new Error("Banner entity model is missing its flag layer");
5664
+ overlay2 = { ...flagLayer.layer, root: { ...flagLayer.layer.root, children: {
5665
+ ...flagLayer.layer.root.children,
5666
+ flag: { ...flag, pose: { ...flag.pose, rotation: [-25e-4 * Math.PI, flag.pose.rotation[1], flag.pose.rotation[2]] } }
5667
+ } } };
5668
+ layers.flag = { ...flagLayer, layer: overlay2 };
5669
+ } else {
5670
+ const main = layers.main.layer;
5671
+ const plate = main.root.children.plate;
5672
+ if (!plate) throw new Error("Shield entity model is missing its plate");
5673
+ overlay2 = { ...main, root: { ...main.root, cubes: [], children: { plate } } };
5674
+ }
5675
+ const tints = {};
5676
+ if (patterned) {
5677
+ const draws = [{ texture: texture(`${banner ? "banner" : "shield"}/base`, ""), color: color2 ?? DYE_COLORS.white }, ...patterns];
5678
+ draws.forEach((draw, index) => {
5679
+ const name = index === 0 ? "pattern_base" : `pattern_${index - 1}`;
5680
+ layers[name] = { key: draw.texture, texture: draw.texture, layer: overlay2, render: "no_outline", tint: name };
5681
+ tints[name] = draw.color;
5682
+ });
5683
+ }
5684
+ await Promise.all([...new Map(Object.values(layers).map((layer) => [layer.texture.serialize(), layer.texture])).values()].map(async (key) => {
5685
+ if (!await ModelTextures.preload(key)) throw new Error(`Missing special item texture ${key.toNamespacedString()}`);
5686
+ }));
5687
+ part.model = { ...part.model, ...layers.main, layers };
5688
+ part.tints = tints;
5689
+ return [part];
5690
+ }
5550
5691
  case "minecraft:chest":
5551
5692
  case "chest": {
5552
5693
  const angle = -(special.openness ?? 0) * Math.PI / 2;
@@ -5557,6 +5698,26 @@ var init_SpecialItems = __esm({
5557
5698
  chest.model = { ...chest.model, render: "solid", layers: void 0 };
5558
5699
  return [chest];
5559
5700
  }
5701
+ case "minecraft:shulker_box":
5702
+ case "shulker_box": {
5703
+ const openness = special.openness === void 0 ? 0 : special.openness;
5704
+ const orientation = special.orientation === void 0 ? "up" : special.orientation;
5705
+ const directions = {
5706
+ down: [Math.PI, 0, 0],
5707
+ up: [0, 0, 0],
5708
+ north: [Math.PI / 2, 0, Math.PI],
5709
+ south: [Math.PI / 2, 0, 0],
5710
+ west: [Math.PI / 2, 0, Math.PI / 2],
5711
+ east: [Math.PI / 2, 0, -Math.PI / 2]
5712
+ };
5713
+ if (!Object.prototype.hasOwnProperty.call(directions, orientation)) throw new Error(`Unsupported shulker-box orientation ${orientation}`);
5714
+ if (typeof openness !== "number" || !Number.isFinite(openness)) throw new Error("Shulker-box openness must be finite");
5715
+ if (typeof special.texture !== "string" || !special.texture) throw new Error("Shulker-box texture is required");
5716
+ const transform = new Matrix48().makeTranslation(8, 8, 8).multiply(new Matrix48().makeScale(0.9995, 0.9995, 0.9995)).multiply(new Matrix48().makeRotationFromEuler(new Euler7(...directions[orientation], "XYZ"))).multiply(new Matrix48().makeScale(1, -1, -1)).multiply(new Matrix48().makeTranslation(0, -16, 0));
5717
+ const box = await load("shulker_box", texture(special.texture, "shulker"), transform, { lid: [0, openness * Math.PI * 1.5, 0] });
5718
+ box.positions = { lid: [0, 24 - openness * 8, 0] };
5719
+ return [box];
5720
+ }
5560
5721
  case "minecraft:bed":
5561
5722
  case "bed": {
5562
5723
  const transform = new Matrix48().makeTranslation(0, 9, 0).multiply(new Matrix48().makeRotationX(Math.PI / 2)).multiply(new Matrix48().makeTranslation(8, 8, 8)).multiply(new Matrix48().makeRotationZ(Math.PI)).multiply(new Matrix48().makeTranslation(-8, -8, -8));
@@ -5758,7 +5919,7 @@ var init_ItemTints = __esm({
5758
5919
  });
5759
5920
 
5760
5921
  // src/model/scene/ModelObject.ts
5761
- import { BoxGeometry as BoxGeometry5, BufferAttribute as BufferAttribute5, Color as Color9, Euler as Euler7, Matrix4 as Matrix49 } from "three";
5922
+ import { BoxGeometry as BoxGeometry5, BufferAttribute as BufferAttribute5, Color as Color9, Euler as Euler8, Matrix4 as Matrix49 } from "three";
5762
5923
  function isModelObject(obj) {
5763
5924
  return obj.isModelObject;
5764
5925
  }
@@ -5824,12 +5985,12 @@ var init_ModelObject = __esm({
5824
5985
  this.options.tints = await ItemTints.get(this.originalModel, this.options.tints);
5825
5986
  const special = this.originalModel.special;
5826
5987
  if (special) {
5827
- const parts2 = await SpecialItems.getParts(special, this.originalModel.key?.root);
5988
+ const parts2 = await SpecialItems.getParts(special, this.originalModel.key?.root, this.originalModel.components);
5828
5989
  const transform = this.options.displayPosition ? DisplayTransforms.getMatrix(this.originalModel.display, this.options.displayPosition) : new Matrix49();
5829
5990
  transform.multiply(new Matrix49().makeTranslation(-8, -8, -8));
5830
5991
  try {
5831
5992
  for (const part of parts2) {
5832
- const object3 = new EntityObject(part.model, { flip: false, wireframe: this.options.wireframe });
5993
+ const object3 = new EntityObject(part.model, { flip: false, wireframe: this.options.wireframe, tints: part.tints });
5833
5994
  object3.matrix.copy(transform).multiply(part.transform);
5834
5995
  object3.matrixWorldNeedsUpdate = true;
5835
5996
  object3.matrixAutoUpdate = false;
@@ -5848,6 +6009,9 @@ var init_ModelObject = __esm({
5848
6009
  for (const [name, rotation] of Object.entries(part.rotations)) {
5849
6010
  object3.getGroupByName(name)?.rotation.set(...rotation, "ZYX");
5850
6011
  }
6012
+ for (const [name, position] of Object.entries(part.positions ?? {})) {
6013
+ object3.getGroupByName(name)?.position.set(...position);
6014
+ }
5851
6015
  }
5852
6016
  } catch (error) {
5853
6017
  this.disposeAndRemoveAllChildren();
@@ -5890,7 +6054,7 @@ var init_ModelObject = __esm({
5890
6054
  elGeo.clearGroups();
5891
6055
  }
5892
6056
  if (this.options.uvLockRotation) {
5893
- UVMapper.lockUvs(elGeo, el.faces, this.atlas, new Euler7(...this.options.uvLockRotation));
6057
+ UVMapper.lockUvs(elGeo, el.faces, this.atlas, new Euler8(...this.options.uvLockRotation));
5894
6058
  }
5895
6059
  UVMapper.setAtlasUvBounds(elGeo, el.faces, this.atlas);
5896
6060
  if (this.options.tints) {
@@ -6410,6 +6574,7 @@ function shutdown() {
6410
6574
  init_AssetKey();
6411
6575
  init_AssetLoader();
6412
6576
  init_Assets();
6577
+ init_BannerPatterns();
6413
6578
 
6414
6579
  // src/assets/BlockEntities.ts
6415
6580
  init_AssetKey();
@@ -10562,7 +10727,7 @@ init_SpecialItems();
10562
10727
  init_BlockStates();
10563
10728
  init_MineRenderError();
10564
10729
  init_util();
10565
- import { Euler as Euler8 } from "three";
10730
+ import { Euler as Euler9 } from "three";
10566
10731
  function matchesCondition(condition, state) {
10567
10732
  return Object.entries(condition).every(([key, value]) => {
10568
10733
  if (Array.isArray(value)) {
@@ -10642,7 +10807,7 @@ var BlockStateResolver = class {
10642
10807
  }
10643
10808
  /** Converts blockstate rotations in degrees into the Euler rotation used by model rendering. */
10644
10809
  static rotation(variant) {
10645
- const rotation = new Euler8();
10810
+ const rotation = new Euler9();
10646
10811
  if (typeof variant.x !== "undefined") {
10647
10812
  rotation.x = toRadians(clampRotationDegrees(variant.x));
10648
10813
  }
@@ -10737,7 +10902,7 @@ var import_ts_deepmerge6 = __toESM(require_dist());
10737
10902
  init_MineRenderError();
10738
10903
  init_InstanceReference();
10739
10904
  init_AssetKey();
10740
- import { Euler as Euler9, Matrix4 as Matrix411, Quaternion as Quaternion5, Vector3 as Vector312 } from "three";
10905
+ import { Euler as Euler10, Matrix4 as Matrix411, Quaternion as Quaternion5, Vector3 as Vector312 } from "three";
10741
10906
  init_ModelCulling();
10742
10907
  init_FluidGeometry();
10743
10908
  init_Entities();
@@ -10884,7 +11049,7 @@ var BlockObject = class _BlockObject extends SceneObject {
10884
11049
  const scale = new Vector312();
10885
11050
  this.getModelMatrix(model).decompose(position, rotation, scale);
10886
11051
  if (position.distanceToSquared(this.position) > 1e-10 || scale.distanceToSquared(new Vector312(1, 1, 1)) > 1e-10) return 0;
10887
- return ModelCulling.toLocalMask(worldMask, new Euler9().setFromQuaternion(rotation));
11052
+ return ModelCulling.toLocalMask(worldMask, new Euler10().setFromQuaternion(rotation));
10888
11053
  }
10889
11054
  async setCullMask(worldMask) {
10890
11055
  worldMask &= 63;
@@ -16825,6 +16990,7 @@ export {
16825
16990
  Axis,
16826
16991
  BUILTIN_ENTITY,
16827
16992
  BUILTIN_GENERATED,
16993
+ BannerPatterns,
16828
16994
  BasicAssetKey,
16829
16995
  BatchedExecutor,
16830
16996
  BlockEntities,
@@ -16847,6 +17013,7 @@ export {
16847
17013
  DEFAULT_ROOT,
16848
17014
  DEFAULT_UV,
16849
17015
  DISPLAY_POSITIONS,
17016
+ DYE_COLORS,
16850
17017
  DefaultBlockStates,
16851
17018
  DisplayPosition,
16852
17019
  DisplayTransforms,