minerender 2.1.0-alpha.82 → 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.
package/dist/bundle.js CHANGED
@@ -41423,7 +41423,8 @@ void main() {
41423
41423
  this.entityTextureCache,
41424
41424
  this.entityAnimationCache,
41425
41425
  this.blockEntityIndexCache,
41426
- this.fontCache
41426
+ this.fontCache,
41427
+ this.bannerPatternCache
41427
41428
  ];
41428
41429
  }
41429
41430
  /** Invalidates in-memory entries so later lookups reload them. Persisted entries are retained. */
@@ -41472,6 +41473,7 @@ void main() {
41472
41473
  _Caching.entityAnimationCache = _Caching.createAssetCache();
41473
41474
  _Caching.blockEntityIndexCache = _Caching.createAssetCache();
41474
41475
  _Caching.fontCache = _Caching.createAssetCache();
41476
+ _Caching.bannerPatternCache = _Caching.createAssetCache();
41475
41477
  Caching = _Caching;
41476
41478
  }
41477
41479
  });
@@ -42499,6 +42501,7 @@ void main() {
42499
42501
  material.depthWrite = false;
42500
42502
  break;
42501
42503
  case "eyes":
42504
+ case "no_outline":
42502
42505
  material.transparent = true;
42503
42506
  material.alphaTest = 0;
42504
42507
  material.depthWrite = false;
@@ -43108,6 +43111,82 @@ void main() {
43108
43111
  }
43109
43112
  });
43110
43113
 
43114
+ // src/assets/BannerPatterns.ts
43115
+ var DYE_COLORS, BannerPatterns;
43116
+ var init_BannerPatterns = __esm({
43117
+ "src/assets/BannerPatterns.ts"() {
43118
+ init_dirname();
43119
+ init_buffer2();
43120
+ init_process2();
43121
+ init_AssetKey();
43122
+ init_AssetLoader();
43123
+ init_AssetParsers();
43124
+ init_Caching();
43125
+ DYE_COLORS = Object.freeze({
43126
+ white: 16383998,
43127
+ orange: 16351261,
43128
+ magenta: 13061821,
43129
+ light_blue: 3847130,
43130
+ yellow: 16701501,
43131
+ lime: 8439583,
43132
+ pink: 15961002,
43133
+ gray: 4673362,
43134
+ light_gray: 10329495,
43135
+ cyan: 1481884,
43136
+ purple: 8991416,
43137
+ blue: 3949738,
43138
+ brown: 8606770,
43139
+ green: 6192150,
43140
+ red: 11546150,
43141
+ black: 1908001
43142
+ });
43143
+ BannerPatterns = class {
43144
+ /** Lists namespaced pattern IDs from the selected namespace's data directory. */
43145
+ static async getList(namespace = "minecraft", root) {
43146
+ const collect = async (path) => {
43147
+ const prefix2 = path ? `${path}/` : "";
43148
+ const key = new AssetKey(namespace, `${prefix2}_list`, "banner_pattern", void 0, "data", ".json", root);
43149
+ const list2 = await Caching.listAssetCache.get(key.serialize(), () => AssetLoader.get(key, "list" /* LIST */));
43150
+ if (!list2) return [];
43151
+ const files = list2.files.filter((file) => file.endsWith(".json") && file !== "_list.json").map((file) => `${namespace}:${prefix2}${file.slice(0, -5)}`);
43152
+ const children = await Promise.all(list2.directories.map((directory) => collect(`${prefix2}${directory}`)));
43153
+ return [...files, ...children.flat()];
43154
+ };
43155
+ return collect("");
43156
+ }
43157
+ /** Returns the named dye's sRGB value, rejecting unknown colors. */
43158
+ static getColor(color3) {
43159
+ if (typeof color3 !== "string" || !Object.prototype.hasOwnProperty.call(DYE_COLORS, color3)) throw new Error(`Unsupported dye color ${color3}`);
43160
+ return DYE_COLORS[color3];
43161
+ }
43162
+ /** Resolves the first 16 layers of a `banner_patterns` component, preserving their order. */
43163
+ static async getLayers(value, target, root) {
43164
+ if (value === void 0) return [];
43165
+ if (!Array.isArray(value)) throw new Error("banner_patterns must be an array");
43166
+ return Promise.all(value.slice(0, 16).map(async (layer) => {
43167
+ if (!layer || typeof layer !== "object" || Array.isArray(layer)) throw new Error("Each banner pattern requires a pattern and dye color");
43168
+ const color3 = this.getColor(layer.color);
43169
+ let pattern2 = layer.pattern;
43170
+ if (typeof pattern2 === "string") {
43171
+ const id = this.identifier(pattern2);
43172
+ const key = new AssetKey(id.namespace, id.getFullPath(), "banner_pattern", void 0, "data", ".json", root);
43173
+ pattern2 = await Caching.bannerPatternCache.get(key.serialize(), () => AssetLoader.get(key, "json" /* JSON */));
43174
+ if (!pattern2) throw new Error(`Missing banner pattern ${layer.pattern}`);
43175
+ }
43176
+ if (!pattern2 || typeof pattern2 !== "object" || Array.isArray(pattern2) || typeof pattern2.translation_key !== "string") throw new Error("Banner patterns require asset_id and translation_key");
43177
+ const asset2 = this.identifier(pattern2.asset_id);
43178
+ return { color: color3, texture: new AssetKey(asset2.namespace, `${target}/${asset2.getFullPath()}`, "textures", "entity", "assets", ".png", root) };
43179
+ }));
43180
+ }
43181
+ static identifier(value) {
43182
+ if (typeof value !== "string" || !/^(?:[a-z0-9_.-]+:)?[a-z0-9_./-]+$/.test(value)) throw new Error(`Invalid banner-pattern identifier ${value}`);
43183
+ const [namespace, path] = value.includes(":") ? value.split(":") : ["minecraft", value];
43184
+ return new AssetKey(namespace, path);
43185
+ }
43186
+ };
43187
+ }
43188
+ });
43189
+
43111
43190
  // src/assets/Models.ts
43112
43191
  var Models;
43113
43192
  var init_Models = __esm({
@@ -43123,6 +43202,7 @@ void main() {
43123
43202
  init_AssetKey();
43124
43203
  init_AssetParsers();
43125
43204
  init_DisplayPosition();
43205
+ init_BannerPatterns();
43126
43206
  Models = class _Models {
43127
43207
  // opened lazily: touching the store at import time would hit IndexedDB/disk just for loading
43128
43208
  // the library, and would require an EnvProvider before any entry has had a chance to register
@@ -43312,6 +43392,13 @@ void main() {
43312
43392
  if (!node.base || !node.model || typeof node.model !== "object") break;
43313
43393
  const special = node.model;
43314
43394
  switch (special.type) {
43395
+ case "banner":
43396
+ case "minecraft:banner":
43397
+ if (typeof special.color === "string" && Object.prototype.hasOwnProperty.call(DYE_COLORS, special.color)) return { model: node.base, special };
43398
+ break;
43399
+ case "shield":
43400
+ case "minecraft:shield":
43401
+ return { model: node.base, special };
43315
43402
  case "shulker_box":
43316
43403
  case "minecraft:shulker_box":
43317
43404
  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))) {
@@ -90390,9 +90477,11 @@ ${key}` : key;
90390
90477
  init_three_module();
90391
90478
  init_AssetKey();
90392
90479
  init_Entities();
90480
+ init_BannerPatterns();
90481
+ init_ModelTextures();
90393
90482
  SpecialItems = class {
90394
90483
  /** Resolves the static entity parts drawn by a special item renderer, in model units. */
90395
- static async getParts(special, root) {
90484
+ static async getParts(special, root, components = {}) {
90396
90485
  const texture = (id, directory) => {
90397
90486
  const key = AssetKey.parse("textures", id);
90398
90487
  return new AssetKey(
@@ -90405,13 +90494,60 @@ ${key}` : key;
90405
90494
  root
90406
90495
  );
90407
90496
  };
90408
- const load = async (id, textureKey, transform, rotations = {}) => {
90497
+ const load = async (id, textureKey, transform, rotations = {}, layers = ["main"]) => {
90409
90498
  const key = new AssetKey("minecraft", id, void 0, void 0, "entity-models", ".json", root);
90410
- const model = await Entities.getEntity(key, textureKey, { layer: "main" });
90499
+ const model = await Entities.getEntity(key, textureKey, layers.length === 1 ? { layer: layers[0] } : {
90500
+ layers,
90501
+ textures: textureKey ? Object.fromEntries(layers.map((name2) => [name2, textureKey])) : void 0
90502
+ });
90411
90503
  if (!model) throw new Error(`Missing entity model minecraft:${id} for special item ${special.type}`);
90412
90504
  return { model, transform, rotations };
90413
90505
  };
90414
90506
  switch (special.type) {
90507
+ case "minecraft:banner":
90508
+ case "banner":
90509
+ case "minecraft:shield":
90510
+ case "shield": {
90511
+ const banner = special.type === "banner" || special.type === "minecraft:banner";
90512
+ const color3 = banner ? BannerPatterns.getColor(special.color) : components["minecraft:base_color"] === void 0 ? void 0 : BannerPatterns.getColor(components["minecraft:base_color"]);
90513
+ const patterns = await BannerPatterns.getLayers(components["minecraft:banner_patterns"], banner ? "banner" : "shield", root);
90514
+ const patterned = banner || color3 !== void 0 || patterns.length > 0;
90515
+ const baseTexture = texture(banner ? "banner_base" : patterned ? "shield_base" : "shield_base_nopattern", "");
90516
+ const transform = banner ? new Matrix4().makeTranslation(8, 0, 8).multiply(new Matrix4().makeScale(2 / 3, -2 / 3, -2 / 3)) : new Matrix4().makeScale(1, -1, -1);
90517
+ const part = await load(banner ? "standing_banner" : "shield", baseTexture, transform, {}, banner ? ["main", "flag"] : ["main"]);
90518
+ const layers = Object.fromEntries(Object.entries(part.model.layers ?? { main: part.model }).map(([name2, layer]) => [name2, { ...layer, render: "solid" }]));
90519
+ let overlay2;
90520
+ if (banner) {
90521
+ const flagLayer = layers.flag;
90522
+ const flag = flagLayer?.layer.root.children.flag;
90523
+ if (!flag) throw new Error("Banner entity model is missing its flag layer");
90524
+ overlay2 = { ...flagLayer.layer, root: { ...flagLayer.layer.root, children: {
90525
+ ...flagLayer.layer.root.children,
90526
+ flag: { ...flag, pose: { ...flag.pose, rotation: [-25e-4 * Math.PI, flag.pose.rotation[1], flag.pose.rotation[2]] } }
90527
+ } } };
90528
+ layers.flag = { ...flagLayer, layer: overlay2 };
90529
+ } else {
90530
+ const main = layers.main.layer;
90531
+ const plate = main.root.children.plate;
90532
+ if (!plate) throw new Error("Shield entity model is missing its plate");
90533
+ overlay2 = { ...main, root: { ...main.root, cubes: [], children: { plate } } };
90534
+ }
90535
+ const tints = {};
90536
+ if (patterned) {
90537
+ const draws = [{ texture: texture(`${banner ? "banner" : "shield"}/base`, ""), color: color3 ?? DYE_COLORS.white }, ...patterns];
90538
+ draws.forEach((draw, index) => {
90539
+ const name2 = index === 0 ? "pattern_base" : `pattern_${index - 1}`;
90540
+ layers[name2] = { key: draw.texture, texture: draw.texture, layer: overlay2, render: "no_outline", tint: name2 };
90541
+ tints[name2] = draw.color;
90542
+ });
90543
+ }
90544
+ await Promise.all([...new Map(Object.values(layers).map((layer) => [layer.texture.serialize(), layer.texture])).values()].map(async (key) => {
90545
+ if (!await ModelTextures.preload(key)) throw new Error(`Missing special item texture ${key.toNamespacedString()}`);
90546
+ }));
90547
+ part.model = { ...part.model, ...layers.main, layers };
90548
+ part.tints = tints;
90549
+ return [part];
90550
+ }
90415
90551
  case "minecraft:chest":
90416
90552
  case "chest": {
90417
90553
  const angle = -(special.openness ?? 0) * Math.PI / 2;
@@ -90718,12 +90854,12 @@ ${shader.fragmentShader}`.replace(
90718
90854
  this.options.tints = await ItemTints.get(this.originalModel, this.options.tints);
90719
90855
  const special = this.originalModel.special;
90720
90856
  if (special) {
90721
- const parts2 = await SpecialItems.getParts(special, this.originalModel.key?.root);
90857
+ const parts2 = await SpecialItems.getParts(special, this.originalModel.key?.root, this.originalModel.components);
90722
90858
  const transform = this.options.displayPosition ? DisplayTransforms.getMatrix(this.originalModel.display, this.options.displayPosition) : new Matrix4();
90723
90859
  transform.multiply(new Matrix4().makeTranslation(-8, -8, -8));
90724
90860
  try {
90725
90861
  for (const part of parts2) {
90726
- const object3 = new EntityObject(part.model, { flip: false, wireframe: this.options.wireframe });
90862
+ const object3 = new EntityObject(part.model, { flip: false, wireframe: this.options.wireframe, tints: part.tints });
90727
90863
  object3.matrix.copy(transform).multiply(part.transform);
90728
90864
  object3.matrixWorldNeedsUpdate = true;
90729
90865
  object3.matrixAutoUpdate = false;
@@ -93994,6 +94130,7 @@ ${shader.fragmentShader}`.replace(
93994
94130
  Axis: () => Axis,
93995
94131
  BUILTIN_ENTITY: () => BUILTIN_ENTITY,
93996
94132
  BUILTIN_GENERATED: () => BUILTIN_GENERATED,
94133
+ BannerPatterns: () => BannerPatterns,
93997
94134
  BasicAssetKey: () => BasicAssetKey,
93998
94135
  BatchedExecutor: () => BatchedExecutor,
93999
94136
  BlockEntities: () => BlockEntities,
@@ -94018,6 +94155,7 @@ ${shader.fragmentShader}`.replace(
94018
94155
  DEFAULT_ROOT: () => DEFAULT_ROOT,
94019
94156
  DEFAULT_UV: () => DEFAULT_UV,
94020
94157
  DISPLAY_POSITIONS: () => DISPLAY_POSITIONS,
94158
+ DYE_COLORS: () => DYE_COLORS,
94021
94159
  DefaultBlockStates: () => DefaultBlockStates,
94022
94160
  DisplayPosition: () => DisplayPosition,
94023
94161
  DisplayTransforms: () => DisplayTransforms,
@@ -94425,6 +94563,7 @@ ${shader.fragmentShader}`.replace(
94425
94563
  init_AssetKey();
94426
94564
  init_AssetLoader();
94427
94565
  init_Assets();
94566
+ init_BannerPatterns();
94428
94567
 
94429
94568
  // src/assets/BlockEntities.ts
94430
94569
  init_dirname();