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.
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,17 @@ 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
+ case "trident":
43402
+ case "minecraft:trident":
43403
+ case "conduit":
43404
+ case "minecraft:conduit":
43405
+ return { model: node.base, special };
43315
43406
  case "shulker_box":
43316
43407
  case "minecraft:shulker_box":
43317
43408
  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 +90481,11 @@ ${key}` : key;
90390
90481
  init_three_module();
90391
90482
  init_AssetKey();
90392
90483
  init_Entities();
90484
+ init_BannerPatterns();
90485
+ init_ModelTextures();
90393
90486
  SpecialItems = class {
90394
90487
  /** Resolves the static entity parts drawn by a special item renderer, in model units. */
90395
- static async getParts(special, root) {
90488
+ static async getParts(special, root, components = {}) {
90396
90489
  const texture = (id, directory) => {
90397
90490
  const key = AssetKey.parse("textures", id);
90398
90491
  return new AssetKey(
@@ -90405,13 +90498,77 @@ ${key}` : key;
90405
90498
  root
90406
90499
  );
90407
90500
  };
90408
- const load = async (id, textureKey, transform, rotations = {}) => {
90501
+ const load = async (id, textureKey, transform, rotations = {}, layers = ["main"]) => {
90409
90502
  const key = new AssetKey("minecraft", id, void 0, void 0, "entity-models", ".json", root);
90410
- const model = await Entities.getEntity(key, textureKey, { layer: "main" });
90503
+ const model = await Entities.getEntity(key, textureKey, layers.length === 1 ? { layer: layers[0] } : {
90504
+ layers,
90505
+ textures: textureKey ? Object.fromEntries(layers.map((name2) => [name2, textureKey])) : void 0
90506
+ });
90411
90507
  if (!model) throw new Error(`Missing entity model minecraft:${id} for special item ${special.type}`);
90412
90508
  return { model, transform, rotations };
90413
90509
  };
90414
90510
  switch (special.type) {
90511
+ case "minecraft:trident":
90512
+ case "trident":
90513
+ case "minecraft:conduit":
90514
+ case "conduit": {
90515
+ const trident = special.type === "trident" || special.type === "minecraft:trident";
90516
+ const part = await load(
90517
+ trident ? "trident" : "conduit",
90518
+ texture(trident ? "trident" : "conduit/base", ""),
90519
+ trident ? new Matrix4().makeScale(1, -1, -1) : new Matrix4().makeTranslation(8, 8, 8),
90520
+ {},
90521
+ trident ? ["main"] : ["shell"]
90522
+ );
90523
+ part.model = { ...part.model, render: "solid", layers: part.model.layers && Object.fromEntries(
90524
+ Object.entries(part.model.layers).map(([name2, layer]) => [name2, { ...layer, render: "solid" }])
90525
+ ) };
90526
+ return [part];
90527
+ }
90528
+ case "minecraft:banner":
90529
+ case "banner":
90530
+ case "minecraft:shield":
90531
+ case "shield": {
90532
+ const banner = special.type === "banner" || special.type === "minecraft:banner";
90533
+ const color3 = banner ? BannerPatterns.getColor(special.color) : components["minecraft:base_color"] === void 0 ? void 0 : BannerPatterns.getColor(components["minecraft:base_color"]);
90534
+ const patterns = await BannerPatterns.getLayers(components["minecraft:banner_patterns"], banner ? "banner" : "shield", root);
90535
+ const patterned = banner || color3 !== void 0 || patterns.length > 0;
90536
+ const baseTexture = texture(banner ? "banner_base" : patterned ? "shield_base" : "shield_base_nopattern", "");
90537
+ 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);
90538
+ const part = await load(banner ? "standing_banner" : "shield", baseTexture, transform, {}, banner ? ["main", "flag"] : ["main"]);
90539
+ const layers = Object.fromEntries(Object.entries(part.model.layers ?? { main: part.model }).map(([name2, layer]) => [name2, { ...layer, render: "solid" }]));
90540
+ let overlay2;
90541
+ if (banner) {
90542
+ const flagLayer = layers.flag;
90543
+ const flag = flagLayer?.layer.root.children.flag;
90544
+ if (!flag) throw new Error("Banner entity model is missing its flag layer");
90545
+ overlay2 = { ...flagLayer.layer, root: { ...flagLayer.layer.root, children: {
90546
+ ...flagLayer.layer.root.children,
90547
+ flag: { ...flag, pose: { ...flag.pose, rotation: [-25e-4 * Math.PI, flag.pose.rotation[1], flag.pose.rotation[2]] } }
90548
+ } } };
90549
+ layers.flag = { ...flagLayer, layer: overlay2 };
90550
+ } else {
90551
+ const main = layers.main.layer;
90552
+ const plate = main.root.children.plate;
90553
+ if (!plate) throw new Error("Shield entity model is missing its plate");
90554
+ overlay2 = { ...main, root: { ...main.root, cubes: [], children: { plate } } };
90555
+ }
90556
+ const tints = {};
90557
+ if (patterned) {
90558
+ const draws = [{ texture: texture(`${banner ? "banner" : "shield"}/base`, ""), color: color3 ?? DYE_COLORS.white }, ...patterns];
90559
+ draws.forEach((draw, index) => {
90560
+ const name2 = index === 0 ? "pattern_base" : `pattern_${index - 1}`;
90561
+ layers[name2] = { key: draw.texture, texture: draw.texture, layer: overlay2, render: "no_outline", tint: name2 };
90562
+ tints[name2] = draw.color;
90563
+ });
90564
+ }
90565
+ await Promise.all([...new Map(Object.values(layers).map((layer) => [layer.texture.serialize(), layer.texture])).values()].map(async (key) => {
90566
+ if (!await ModelTextures.preload(key)) throw new Error(`Missing special item texture ${key.toNamespacedString()}`);
90567
+ }));
90568
+ part.model = { ...part.model, ...layers.main, layers };
90569
+ part.tints = tints;
90570
+ return [part];
90571
+ }
90415
90572
  case "minecraft:chest":
90416
90573
  case "chest": {
90417
90574
  const angle = -(special.openness ?? 0) * Math.PI / 2;
@@ -90718,12 +90875,12 @@ ${shader.fragmentShader}`.replace(
90718
90875
  this.options.tints = await ItemTints.get(this.originalModel, this.options.tints);
90719
90876
  const special = this.originalModel.special;
90720
90877
  if (special) {
90721
- const parts2 = await SpecialItems.getParts(special, this.originalModel.key?.root);
90878
+ const parts2 = await SpecialItems.getParts(special, this.originalModel.key?.root, this.originalModel.components);
90722
90879
  const transform = this.options.displayPosition ? DisplayTransforms.getMatrix(this.originalModel.display, this.options.displayPosition) : new Matrix4();
90723
90880
  transform.multiply(new Matrix4().makeTranslation(-8, -8, -8));
90724
90881
  try {
90725
90882
  for (const part of parts2) {
90726
- const object3 = new EntityObject(part.model, { flip: false, wireframe: this.options.wireframe });
90883
+ const object3 = new EntityObject(part.model, { flip: false, wireframe: this.options.wireframe, tints: part.tints });
90727
90884
  object3.matrix.copy(transform).multiply(part.transform);
90728
90885
  object3.matrixWorldNeedsUpdate = true;
90729
90886
  object3.matrixAutoUpdate = false;
@@ -93994,6 +94151,7 @@ ${shader.fragmentShader}`.replace(
93994
94151
  Axis: () => Axis,
93995
94152
  BUILTIN_ENTITY: () => BUILTIN_ENTITY,
93996
94153
  BUILTIN_GENERATED: () => BUILTIN_GENERATED,
94154
+ BannerPatterns: () => BannerPatterns,
93997
94155
  BasicAssetKey: () => BasicAssetKey,
93998
94156
  BatchedExecutor: () => BatchedExecutor,
93999
94157
  BlockEntities: () => BlockEntities,
@@ -94018,6 +94176,7 @@ ${shader.fragmentShader}`.replace(
94018
94176
  DEFAULT_ROOT: () => DEFAULT_ROOT,
94019
94177
  DEFAULT_UV: () => DEFAULT_UV,
94020
94178
  DISPLAY_POSITIONS: () => DISPLAY_POSITIONS,
94179
+ DYE_COLORS: () => DYE_COLORS,
94021
94180
  DefaultBlockStates: () => DefaultBlockStates,
94022
94181
  DisplayPosition: () => DisplayPosition,
94023
94182
  DisplayTransforms: () => DisplayTransforms,
@@ -94425,6 +94584,7 @@ ${shader.fragmentShader}`.replace(
94425
94584
  init_AssetKey();
94426
94585
  init_AssetLoader();
94427
94586
  init_Assets();
94587
+ init_BannerPatterns();
94428
94588
 
94429
94589
  // src/assets/BlockEntities.ts
94430
94590
  init_dirname();