minerender 2.1.0-alpha.82 → 2.1.0-alpha.84

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,17 @@ 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
+ case "trident":
1869
+ case "minecraft:trident":
1870
+ case "conduit":
1871
+ case "minecraft:conduit":
1872
+ return { model: node.base, special };
1783
1873
  case "shulker_box":
1784
1874
  case "minecraft:shulker_box":
1785
1875
  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))) {
@@ -5531,9 +5621,11 @@ var init_SpecialItems = __esm({
5531
5621
  "src/model/SpecialItems.ts"() {
5532
5622
  init_AssetKey();
5533
5623
  init_Entities();
5624
+ init_BannerPatterns();
5625
+ init_ModelTextures();
5534
5626
  SpecialItems = class {
5535
5627
  /** Resolves the static entity parts drawn by a special item renderer, in model units. */
5536
- static async getParts(special, root) {
5628
+ static async getParts(special, root, components = {}) {
5537
5629
  const texture = (id, directory) => {
5538
5630
  const key = AssetKey.parse("textures", id);
5539
5631
  return new AssetKey(
@@ -5546,13 +5638,77 @@ var init_SpecialItems = __esm({
5546
5638
  root
5547
5639
  );
5548
5640
  };
5549
- const load = async (id, textureKey, transform, rotations = {}) => {
5641
+ const load = async (id, textureKey, transform, rotations = {}, layers = ["main"]) => {
5550
5642
  const key = new AssetKey("minecraft", id, void 0, void 0, "entity-models", ".json", root);
5551
- const model = await Entities.getEntity(key, textureKey, { layer: "main" });
5643
+ const model = await Entities.getEntity(key, textureKey, layers.length === 1 ? { layer: layers[0] } : {
5644
+ layers,
5645
+ textures: textureKey ? Object.fromEntries(layers.map((name) => [name, textureKey])) : void 0
5646
+ });
5552
5647
  if (!model) throw new Error(`Missing entity model minecraft:${id} for special item ${special.type}`);
5553
5648
  return { model, transform, rotations };
5554
5649
  };
5555
5650
  switch (special.type) {
5651
+ case "minecraft:trident":
5652
+ case "trident":
5653
+ case "minecraft:conduit":
5654
+ case "conduit": {
5655
+ const trident = special.type === "trident" || special.type === "minecraft:trident";
5656
+ const part = await load(
5657
+ trident ? "trident" : "conduit",
5658
+ texture(trident ? "trident" : "conduit/base", ""),
5659
+ trident ? new Matrix48().makeScale(1, -1, -1) : new Matrix48().makeTranslation(8, 8, 8),
5660
+ {},
5661
+ trident ? ["main"] : ["shell"]
5662
+ );
5663
+ part.model = { ...part.model, render: "solid", layers: part.model.layers && Object.fromEntries(
5664
+ Object.entries(part.model.layers).map(([name, layer]) => [name, { ...layer, render: "solid" }])
5665
+ ) };
5666
+ return [part];
5667
+ }
5668
+ case "minecraft:banner":
5669
+ case "banner":
5670
+ case "minecraft:shield":
5671
+ case "shield": {
5672
+ const banner = special.type === "banner" || special.type === "minecraft:banner";
5673
+ const color2 = banner ? BannerPatterns.getColor(special.color) : components["minecraft:base_color"] === void 0 ? void 0 : BannerPatterns.getColor(components["minecraft:base_color"]);
5674
+ const patterns = await BannerPatterns.getLayers(components["minecraft:banner_patterns"], banner ? "banner" : "shield", root);
5675
+ const patterned = banner || color2 !== void 0 || patterns.length > 0;
5676
+ const baseTexture = texture(banner ? "banner_base" : patterned ? "shield_base" : "shield_base_nopattern", "");
5677
+ 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);
5678
+ const part = await load(banner ? "standing_banner" : "shield", baseTexture, transform, {}, banner ? ["main", "flag"] : ["main"]);
5679
+ const layers = Object.fromEntries(Object.entries(part.model.layers ?? { main: part.model }).map(([name, layer]) => [name, { ...layer, render: "solid" }]));
5680
+ let overlay2;
5681
+ if (banner) {
5682
+ const flagLayer = layers.flag;
5683
+ const flag = flagLayer?.layer.root.children.flag;
5684
+ if (!flag) throw new Error("Banner entity model is missing its flag layer");
5685
+ overlay2 = { ...flagLayer.layer, root: { ...flagLayer.layer.root, children: {
5686
+ ...flagLayer.layer.root.children,
5687
+ flag: { ...flag, pose: { ...flag.pose, rotation: [-25e-4 * Math.PI, flag.pose.rotation[1], flag.pose.rotation[2]] } }
5688
+ } } };
5689
+ layers.flag = { ...flagLayer, layer: overlay2 };
5690
+ } else {
5691
+ const main = layers.main.layer;
5692
+ const plate = main.root.children.plate;
5693
+ if (!plate) throw new Error("Shield entity model is missing its plate");
5694
+ overlay2 = { ...main, root: { ...main.root, cubes: [], children: { plate } } };
5695
+ }
5696
+ const tints = {};
5697
+ if (patterned) {
5698
+ const draws = [{ texture: texture(`${banner ? "banner" : "shield"}/base`, ""), color: color2 ?? DYE_COLORS.white }, ...patterns];
5699
+ draws.forEach((draw, index) => {
5700
+ const name = index === 0 ? "pattern_base" : `pattern_${index - 1}`;
5701
+ layers[name] = { key: draw.texture, texture: draw.texture, layer: overlay2, render: "no_outline", tint: name };
5702
+ tints[name] = draw.color;
5703
+ });
5704
+ }
5705
+ await Promise.all([...new Map(Object.values(layers).map((layer) => [layer.texture.serialize(), layer.texture])).values()].map(async (key) => {
5706
+ if (!await ModelTextures.preload(key)) throw new Error(`Missing special item texture ${key.toNamespacedString()}`);
5707
+ }));
5708
+ part.model = { ...part.model, ...layers.main, layers };
5709
+ part.tints = tints;
5710
+ return [part];
5711
+ }
5556
5712
  case "minecraft:chest":
5557
5713
  case "chest": {
5558
5714
  const angle = -(special.openness ?? 0) * Math.PI / 2;
@@ -5850,12 +6006,12 @@ var init_ModelObject = __esm({
5850
6006
  this.options.tints = await ItemTints.get(this.originalModel, this.options.tints);
5851
6007
  const special = this.originalModel.special;
5852
6008
  if (special) {
5853
- const parts2 = await SpecialItems.getParts(special, this.originalModel.key?.root);
6009
+ const parts2 = await SpecialItems.getParts(special, this.originalModel.key?.root, this.originalModel.components);
5854
6010
  const transform = this.options.displayPosition ? DisplayTransforms.getMatrix(this.originalModel.display, this.options.displayPosition) : new Matrix49();
5855
6011
  transform.multiply(new Matrix49().makeTranslation(-8, -8, -8));
5856
6012
  try {
5857
6013
  for (const part of parts2) {
5858
- const object3 = new EntityObject(part.model, { flip: false, wireframe: this.options.wireframe });
6014
+ const object3 = new EntityObject(part.model, { flip: false, wireframe: this.options.wireframe, tints: part.tints });
5859
6015
  object3.matrix.copy(transform).multiply(part.transform);
5860
6016
  object3.matrixWorldNeedsUpdate = true;
5861
6017
  object3.matrixAutoUpdate = false;
@@ -6439,6 +6595,7 @@ function shutdown() {
6439
6595
  init_AssetKey();
6440
6596
  init_AssetLoader();
6441
6597
  init_Assets();
6598
+ init_BannerPatterns();
6442
6599
 
6443
6600
  // src/assets/BlockEntities.ts
6444
6601
  init_AssetKey();
@@ -16854,6 +17011,7 @@ export {
16854
17011
  Axis,
16855
17012
  BUILTIN_ENTITY,
16856
17013
  BUILTIN_GENERATED,
17014
+ BannerPatterns,
16857
17015
  BasicAssetKey,
16858
17016
  BatchedExecutor,
16859
17017
  BlockEntities,
@@ -16876,6 +17034,7 @@ export {
16876
17034
  DEFAULT_ROOT,
16877
17035
  DEFAULT_UV,
16878
17036
  DISPLAY_POSITIONS,
17037
+ DYE_COLORS,
16879
17038
  DefaultBlockStates,
16880
17039
  DisplayPosition,
16881
17040
  DisplayTransforms,