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.
@@ -260,7 +260,8 @@ var init_Caching = __esm({
260
260
  this.entityTextureCache,
261
261
  this.entityAnimationCache,
262
262
  this.blockEntityIndexCache,
263
- this.fontCache
263
+ this.fontCache,
264
+ this.bannerPatternCache
264
265
  ];
265
266
  }
266
267
  /** Invalidates in-memory entries so later lookups reload them. Persisted entries are retained. */
@@ -309,6 +310,7 @@ var init_Caching = __esm({
309
310
  _Caching.entityAnimationCache = _Caching.createAssetCache();
310
311
  _Caching.blockEntityIndexCache = _Caching.createAssetCache();
311
312
  _Caching.fontCache = _Caching.createAssetCache();
313
+ _Caching.bannerPatternCache = _Caching.createAssetCache();
312
314
  Caching = _Caching;
313
315
  }
314
316
  });
@@ -941,6 +943,7 @@ var init_Materials = __esm({
941
943
  material.depthWrite = false;
942
944
  break;
943
945
  case "eyes":
946
+ case "no_outline":
944
947
  material.transparent = true;
945
948
  material.alphaTest = 0;
946
949
  material.depthWrite = false;
@@ -1529,6 +1532,79 @@ var init_AssetParsers = __esm({
1529
1532
  }
1530
1533
  });
1531
1534
 
1535
+ // src/assets/BannerPatterns.ts
1536
+ var DYE_COLORS, BannerPatterns;
1537
+ var init_BannerPatterns = __esm({
1538
+ "src/assets/BannerPatterns.ts"() {
1539
+ init_AssetKey();
1540
+ init_AssetLoader();
1541
+ init_AssetParsers();
1542
+ init_Caching();
1543
+ DYE_COLORS = Object.freeze({
1544
+ white: 16383998,
1545
+ orange: 16351261,
1546
+ magenta: 13061821,
1547
+ light_blue: 3847130,
1548
+ yellow: 16701501,
1549
+ lime: 8439583,
1550
+ pink: 15961002,
1551
+ gray: 4673362,
1552
+ light_gray: 10329495,
1553
+ cyan: 1481884,
1554
+ purple: 8991416,
1555
+ blue: 3949738,
1556
+ brown: 8606770,
1557
+ green: 6192150,
1558
+ red: 11546150,
1559
+ black: 1908001
1560
+ });
1561
+ BannerPatterns = class {
1562
+ /** Lists namespaced pattern IDs from the selected namespace's data directory. */
1563
+ static async getList(namespace = "minecraft", root) {
1564
+ const collect = async (path) => {
1565
+ const prefix2 = path ? `${path}/` : "";
1566
+ const key = new AssetKey(namespace, `${prefix2}_list`, "banner_pattern", void 0, "data", ".json", root);
1567
+ const list2 = await Caching.listAssetCache.get(key.serialize(), () => AssetLoader.get(key, "list" /* LIST */));
1568
+ if (!list2) return [];
1569
+ const files = list2.files.filter((file) => file.endsWith(".json") && file !== "_list.json").map((file) => `${namespace}:${prefix2}${file.slice(0, -5)}`);
1570
+ const children = await Promise.all(list2.directories.map((directory) => collect(`${prefix2}${directory}`)));
1571
+ return [...files, ...children.flat()];
1572
+ };
1573
+ return collect("");
1574
+ }
1575
+ /** Returns the named dye's sRGB value, rejecting unknown colors. */
1576
+ static getColor(color2) {
1577
+ if (typeof color2 !== "string" || !Object.prototype.hasOwnProperty.call(DYE_COLORS, color2)) throw new Error(`Unsupported dye color ${color2}`);
1578
+ return DYE_COLORS[color2];
1579
+ }
1580
+ /** Resolves the first 16 layers of a `banner_patterns` component, preserving their order. */
1581
+ static async getLayers(value, target, root) {
1582
+ if (value === void 0) return [];
1583
+ if (!Array.isArray(value)) throw new Error("banner_patterns must be an array");
1584
+ return Promise.all(value.slice(0, 16).map(async (layer) => {
1585
+ if (!layer || typeof layer !== "object" || Array.isArray(layer)) throw new Error("Each banner pattern requires a pattern and dye color");
1586
+ const color2 = this.getColor(layer.color);
1587
+ let pattern2 = layer.pattern;
1588
+ if (typeof pattern2 === "string") {
1589
+ const id = this.identifier(pattern2);
1590
+ const key = new AssetKey(id.namespace, id.getFullPath(), "banner_pattern", void 0, "data", ".json", root);
1591
+ pattern2 = await Caching.bannerPatternCache.get(key.serialize(), () => AssetLoader.get(key, "json" /* JSON */));
1592
+ if (!pattern2) throw new Error(`Missing banner pattern ${layer.pattern}`);
1593
+ }
1594
+ if (!pattern2 || typeof pattern2 !== "object" || Array.isArray(pattern2) || typeof pattern2.translation_key !== "string") throw new Error("Banner patterns require asset_id and translation_key");
1595
+ const asset2 = this.identifier(pattern2.asset_id);
1596
+ return { color: color2, texture: new AssetKey(asset2.namespace, `${target}/${asset2.getFullPath()}`, "textures", "entity", "assets", ".png", root) };
1597
+ }));
1598
+ }
1599
+ static identifier(value) {
1600
+ if (typeof value !== "string" || !/^(?:[a-z0-9_.-]+:)?[a-z0-9_./-]+$/.test(value)) throw new Error(`Invalid banner-pattern identifier ${value}`);
1601
+ const [namespace, path] = value.includes(":") ? value.split(":") : ["minecraft", value];
1602
+ return new AssetKey(namespace, path);
1603
+ }
1604
+ };
1605
+ }
1606
+ });
1607
+
1532
1608
  // src/assets/Models.ts
1533
1609
  var Models;
1534
1610
  var init_Models = __esm({
@@ -1541,6 +1617,7 @@ var init_Models = __esm({
1541
1617
  init_AssetKey();
1542
1618
  init_AssetParsers();
1543
1619
  init_DisplayPosition();
1620
+ init_BannerPatterns();
1544
1621
  Models = class _Models {
1545
1622
  // opened lazily: touching the store at import time would hit IndexedDB/disk just for loading
1546
1623
  // the library, and would require an EnvProvider before any entry has had a chance to register
@@ -1730,6 +1807,19 @@ var init_Models = __esm({
1730
1807
  if (!node.base || !node.model || typeof node.model !== "object") break;
1731
1808
  const special = node.model;
1732
1809
  switch (special.type) {
1810
+ case "banner":
1811
+ case "minecraft:banner":
1812
+ if (typeof special.color === "string" && Object.prototype.hasOwnProperty.call(DYE_COLORS, special.color)) return { model: node.base, special };
1813
+ break;
1814
+ case "shield":
1815
+ case "minecraft:shield":
1816
+ return { model: node.base, special };
1817
+ case "shulker_box":
1818
+ case "minecraft:shulker_box":
1819
+ 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))) {
1820
+ return { model: node.base, special };
1821
+ }
1822
+ break;
1733
1823
  case "chest":
1734
1824
  case "minecraft:chest":
1735
1825
  case "bed":
@@ -5428,15 +5518,17 @@ var init_ModelCulling = __esm({
5428
5518
  });
5429
5519
 
5430
5520
  // src/model/SpecialItems.ts
5431
- import { Matrix4 as Matrix48 } from "three";
5521
+ import { Euler as Euler7, Matrix4 as Matrix48 } from "three";
5432
5522
  var SpecialItems;
5433
5523
  var init_SpecialItems = __esm({
5434
5524
  "src/model/SpecialItems.ts"() {
5435
5525
  init_AssetKey();
5436
5526
  init_Entities();
5527
+ init_BannerPatterns();
5528
+ init_ModelTextures();
5437
5529
  SpecialItems = class {
5438
5530
  /** Resolves the static entity parts drawn by a special item renderer, in model units. */
5439
- static async getParts(special, root) {
5531
+ static async getParts(special, root, components = {}) {
5440
5532
  const texture = (id, directory) => {
5441
5533
  const key = AssetKey.parse("textures", id);
5442
5534
  return new AssetKey(
@@ -5449,13 +5541,60 @@ var init_SpecialItems = __esm({
5449
5541
  root
5450
5542
  );
5451
5543
  };
5452
- const load = async (id, textureKey, transform, rotations = {}) => {
5544
+ const load = async (id, textureKey, transform, rotations = {}, layers = ["main"]) => {
5453
5545
  const key = new AssetKey("minecraft", id, void 0, void 0, "entity-models", ".json", root);
5454
- const model = await Entities.getEntity(key, textureKey, { layer: "main" });
5546
+ const model = await Entities.getEntity(key, textureKey, layers.length === 1 ? { layer: layers[0] } : {
5547
+ layers,
5548
+ textures: textureKey ? Object.fromEntries(layers.map((name) => [name, textureKey])) : void 0
5549
+ });
5455
5550
  if (!model) throw new Error(`Missing entity model minecraft:${id} for special item ${special.type}`);
5456
5551
  return { model, transform, rotations };
5457
5552
  };
5458
5553
  switch (special.type) {
5554
+ case "minecraft:banner":
5555
+ case "banner":
5556
+ case "minecraft:shield":
5557
+ case "shield": {
5558
+ const banner = special.type === "banner" || special.type === "minecraft:banner";
5559
+ const color2 = banner ? BannerPatterns.getColor(special.color) : components["minecraft:base_color"] === void 0 ? void 0 : BannerPatterns.getColor(components["minecraft:base_color"]);
5560
+ const patterns = await BannerPatterns.getLayers(components["minecraft:banner_patterns"], banner ? "banner" : "shield", root);
5561
+ const patterned = banner || color2 !== void 0 || patterns.length > 0;
5562
+ const baseTexture = texture(banner ? "banner_base" : patterned ? "shield_base" : "shield_base_nopattern", "");
5563
+ 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);
5564
+ const part = await load(banner ? "standing_banner" : "shield", baseTexture, transform, {}, banner ? ["main", "flag"] : ["main"]);
5565
+ const layers = Object.fromEntries(Object.entries(part.model.layers ?? { main: part.model }).map(([name, layer]) => [name, { ...layer, render: "solid" }]));
5566
+ let overlay2;
5567
+ if (banner) {
5568
+ const flagLayer = layers.flag;
5569
+ const flag = flagLayer?.layer.root.children.flag;
5570
+ if (!flag) throw new Error("Banner entity model is missing its flag layer");
5571
+ overlay2 = { ...flagLayer.layer, root: { ...flagLayer.layer.root, children: {
5572
+ ...flagLayer.layer.root.children,
5573
+ flag: { ...flag, pose: { ...flag.pose, rotation: [-25e-4 * Math.PI, flag.pose.rotation[1], flag.pose.rotation[2]] } }
5574
+ } } };
5575
+ layers.flag = { ...flagLayer, layer: overlay2 };
5576
+ } else {
5577
+ const main = layers.main.layer;
5578
+ const plate = main.root.children.plate;
5579
+ if (!plate) throw new Error("Shield entity model is missing its plate");
5580
+ overlay2 = { ...main, root: { ...main.root, cubes: [], children: { plate } } };
5581
+ }
5582
+ const tints = {};
5583
+ if (patterned) {
5584
+ const draws = [{ texture: texture(`${banner ? "banner" : "shield"}/base`, ""), color: color2 ?? DYE_COLORS.white }, ...patterns];
5585
+ draws.forEach((draw, index) => {
5586
+ const name = index === 0 ? "pattern_base" : `pattern_${index - 1}`;
5587
+ layers[name] = { key: draw.texture, texture: draw.texture, layer: overlay2, render: "no_outline", tint: name };
5588
+ tints[name] = draw.color;
5589
+ });
5590
+ }
5591
+ await Promise.all([...new Map(Object.values(layers).map((layer) => [layer.texture.serialize(), layer.texture])).values()].map(async (key) => {
5592
+ if (!await ModelTextures.preload(key)) throw new Error(`Missing special item texture ${key.toNamespacedString()}`);
5593
+ }));
5594
+ part.model = { ...part.model, ...layers.main, layers };
5595
+ part.tints = tints;
5596
+ return [part];
5597
+ }
5459
5598
  case "minecraft:chest":
5460
5599
  case "chest": {
5461
5600
  const angle = -(special.openness ?? 0) * Math.PI / 2;
@@ -5466,6 +5605,26 @@ var init_SpecialItems = __esm({
5466
5605
  chest.model = { ...chest.model, render: "solid", layers: void 0 };
5467
5606
  return [chest];
5468
5607
  }
5608
+ case "minecraft:shulker_box":
5609
+ case "shulker_box": {
5610
+ const openness = special.openness === void 0 ? 0 : special.openness;
5611
+ const orientation = special.orientation === void 0 ? "up" : special.orientation;
5612
+ const directions = {
5613
+ down: [Math.PI, 0, 0],
5614
+ up: [0, 0, 0],
5615
+ north: [Math.PI / 2, 0, Math.PI],
5616
+ south: [Math.PI / 2, 0, 0],
5617
+ west: [Math.PI / 2, 0, Math.PI / 2],
5618
+ east: [Math.PI / 2, 0, -Math.PI / 2]
5619
+ };
5620
+ if (!Object.prototype.hasOwnProperty.call(directions, orientation)) throw new Error(`Unsupported shulker-box orientation ${orientation}`);
5621
+ if (typeof openness !== "number" || !Number.isFinite(openness)) throw new Error("Shulker-box openness must be finite");
5622
+ if (typeof special.texture !== "string" || !special.texture) throw new Error("Shulker-box texture is required");
5623
+ 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));
5624
+ const box = await load("shulker_box", texture(special.texture, "shulker"), transform, { lid: [0, openness * Math.PI * 1.5, 0] });
5625
+ box.positions = { lid: [0, 24 - openness * 8, 0] };
5626
+ return [box];
5627
+ }
5469
5628
  case "minecraft:bed":
5470
5629
  case "bed": {
5471
5630
  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));
@@ -5667,7 +5826,7 @@ var init_ItemTints = __esm({
5667
5826
  });
5668
5827
 
5669
5828
  // src/model/scene/ModelObject.ts
5670
- import { BoxGeometry as BoxGeometry5, BufferAttribute as BufferAttribute5, Color as Color9, Euler as Euler7, Matrix4 as Matrix49 } from "three";
5829
+ import { BoxGeometry as BoxGeometry5, BufferAttribute as BufferAttribute5, Color as Color9, Euler as Euler8, Matrix4 as Matrix49 } from "three";
5671
5830
  function isModelObject(obj) {
5672
5831
  return obj.isModelObject;
5673
5832
  }
@@ -5730,12 +5889,12 @@ var init_ModelObject = __esm({
5730
5889
  this.options.tints = await ItemTints.get(this.originalModel, this.options.tints);
5731
5890
  const special = this.originalModel.special;
5732
5891
  if (special) {
5733
- const parts2 = await SpecialItems.getParts(special, this.originalModel.key?.root);
5892
+ const parts2 = await SpecialItems.getParts(special, this.originalModel.key?.root, this.originalModel.components);
5734
5893
  const transform = this.options.displayPosition ? DisplayTransforms.getMatrix(this.originalModel.display, this.options.displayPosition) : new Matrix49();
5735
5894
  transform.multiply(new Matrix49().makeTranslation(-8, -8, -8));
5736
5895
  try {
5737
5896
  for (const part of parts2) {
5738
- const object3 = new EntityObject(part.model, { flip: false, wireframe: this.options.wireframe });
5897
+ const object3 = new EntityObject(part.model, { flip: false, wireframe: this.options.wireframe, tints: part.tints });
5739
5898
  object3.matrix.copy(transform).multiply(part.transform);
5740
5899
  object3.matrixWorldNeedsUpdate = true;
5741
5900
  object3.matrixAutoUpdate = false;
@@ -5754,6 +5913,9 @@ var init_ModelObject = __esm({
5754
5913
  for (const [name, rotation] of Object.entries(part.rotations)) {
5755
5914
  object3.getGroupByName(name)?.rotation.set(...rotation, "ZYX");
5756
5915
  }
5916
+ for (const [name, position] of Object.entries(part.positions ?? {})) {
5917
+ object3.getGroupByName(name)?.position.set(...position);
5918
+ }
5757
5919
  }
5758
5920
  } catch (error) {
5759
5921
  this.disposeAndRemoveAllChildren();
@@ -5796,7 +5958,7 @@ var init_ModelObject = __esm({
5796
5958
  elGeo.clearGroups();
5797
5959
  }
5798
5960
  if (this.options.uvLockRotation) {
5799
- UVMapper.lockUvs(elGeo, el.faces, this.atlas, new Euler7(...this.options.uvLockRotation));
5961
+ UVMapper.lockUvs(elGeo, el.faces, this.atlas, new Euler8(...this.options.uvLockRotation));
5800
5962
  }
5801
5963
  UVMapper.setAtlasUvBounds(elGeo, el.faces, this.atlas);
5802
5964
  if (this.options.tints) {
@@ -6356,6 +6518,7 @@ function shutdown() {
6356
6518
  init_AssetKey();
6357
6519
  init_AssetLoader();
6358
6520
  init_Assets();
6521
+ init_BannerPatterns();
6359
6522
 
6360
6523
  // src/assets/BlockEntities.ts
6361
6524
  init_AssetKey();
@@ -10508,7 +10671,7 @@ init_SpecialItems();
10508
10671
  init_BlockStates();
10509
10672
  init_MineRenderError();
10510
10673
  init_util();
10511
- import { Euler as Euler8 } from "three";
10674
+ import { Euler as Euler9 } from "three";
10512
10675
  function matchesCondition(condition, state) {
10513
10676
  return Object.entries(condition).every(([key, value]) => {
10514
10677
  if (Array.isArray(value)) {
@@ -10588,7 +10751,7 @@ var BlockStateResolver = class {
10588
10751
  }
10589
10752
  /** Converts blockstate rotations in degrees into the Euler rotation used by model rendering. */
10590
10753
  static rotation(variant) {
10591
- const rotation = new Euler8();
10754
+ const rotation = new Euler9();
10592
10755
  if (typeof variant.x !== "undefined") {
10593
10756
  rotation.x = toRadians(clampRotationDegrees(variant.x));
10594
10757
  }
@@ -10683,7 +10846,7 @@ var import_ts_deepmerge6 = __toESM(require_dist());
10683
10846
  init_MineRenderError();
10684
10847
  init_InstanceReference();
10685
10848
  init_AssetKey();
10686
- import { Euler as Euler9, Matrix4 as Matrix411, Quaternion as Quaternion5, Vector3 as Vector312 } from "three";
10849
+ import { Euler as Euler10, Matrix4 as Matrix411, Quaternion as Quaternion5, Vector3 as Vector312 } from "three";
10687
10850
  init_ModelCulling();
10688
10851
  init_FluidGeometry();
10689
10852
  init_Entities();
@@ -10825,7 +10988,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
10825
10988
  const scale = new Vector312();
10826
10989
  this.getModelMatrix(model).decompose(position, rotation, scale);
10827
10990
  if (position.distanceToSquared(this.position) > 1e-10 || scale.distanceToSquared(new Vector312(1, 1, 1)) > 1e-10) return 0;
10828
- return ModelCulling.toLocalMask(worldMask, new Euler9().setFromQuaternion(rotation));
10991
+ return ModelCulling.toLocalMask(worldMask, new Euler10().setFromQuaternion(rotation));
10829
10992
  }
10830
10993
  async setCullMask(worldMask) {
10831
10994
  worldMask &= 63;
@@ -16768,6 +16931,7 @@ export {
16768
16931
  Axis,
16769
16932
  BUILTIN_ENTITY,
16770
16933
  BUILTIN_GENERATED,
16934
+ BannerPatterns,
16771
16935
  BasicAssetKey,
16772
16936
  BatchedExecutor,
16773
16937
  BlockEntities,
@@ -16792,6 +16956,7 @@ export {
16792
16956
  DEFAULT_ROOT,
16793
16957
  DEFAULT_UV,
16794
16958
  DISPLAY_POSITIONS,
16959
+ DYE_COLORS,
16795
16960
  DefaultBlockStates,
16796
16961
  DisplayPosition,
16797
16962
  DisplayTransforms,