minerender 2.1.0-alpha.53 → 2.1.0-alpha.54

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.
@@ -799,7 +799,7 @@ var init_Textures = __esm({
799
799
  });
800
800
 
801
801
  // src/Materials.ts
802
- import { Color, DoubleSide, FrontSide, MeshBasicMaterial, MeshStandardMaterial, ShaderChunk, ShaderMaterial } from "three";
802
+ import { Color, CustomBlending, DoubleSide, OneFactor, RepeatWrapping, FrontSide, MeshBasicMaterial, MeshStandardMaterial, ShaderChunk, ShaderMaterial, ZeroFactor } from "three";
803
803
  var _Materials, Materials;
804
804
  var init_Materials = __esm({
805
805
  "src/Materials.ts"() {
@@ -838,6 +838,71 @@ var init_Materials = __esm({
838
838
  alphaTest: 0.5
839
839
  });
840
840
  }
841
+ /** Whether vanilla's render type for the mode culls back faces. */
842
+ static entityModeCulls(mode = "cutout") {
843
+ return mode === "cutout_cull" || mode === "solid" || mode === "eyes" || mode === "water_mask";
844
+ }
845
+ /** UV offset per tick of entity age for the scrolling modes, as vanilla's texture matrix applies it. */
846
+ static entityModeScroll(mode = "cutout") {
847
+ if (mode === "energy_swirl") return [0.01, 0.01];
848
+ if (mode === "breeze_wind") return [0.02, 0];
849
+ return void 0;
850
+ }
851
+ /**
852
+ * Entity material for one of vanilla's render types. Entities are unlit here, so the lit and full-bright modes
853
+ * differ only in blending and depth state. Culling is not a material property: {@link entityModeCulls} decides
854
+ * whether the geometry gets inward faces.
855
+ */
856
+ static createEntityCanvasMaterial(canvas, mode = "cutout", tint) {
857
+ const material = _Materials.createBasicCanvasMaterial(canvas);
858
+ switch (mode) {
859
+ case "cutout":
860
+ case "cutout_cull":
861
+ break;
862
+ case "cutout_z_offset":
863
+ material.polygonOffset = true;
864
+ material.polygonOffsetFactor = -1;
865
+ material.polygonOffsetUnits = -10;
866
+ break;
867
+ case "solid":
868
+ material.alphaTest = 0;
869
+ break;
870
+ case "translucent":
871
+ case "breeze_wind":
872
+ material.transparent = true;
873
+ material.alphaTest = 0.1;
874
+ break;
875
+ case "translucent_emissive":
876
+ material.transparent = true;
877
+ material.alphaTest = 0.1;
878
+ material.depthWrite = false;
879
+ break;
880
+ case "eyes":
881
+ material.transparent = true;
882
+ material.alphaTest = 0;
883
+ material.depthWrite = false;
884
+ break;
885
+ case "energy_swirl":
886
+ material.transparent = true;
887
+ material.alphaTest = 0.1;
888
+ material.blending = CustomBlending;
889
+ material.blendSrc = OneFactor;
890
+ material.blendDst = OneFactor;
891
+ material.blendSrcAlpha = ZeroFactor;
892
+ material.blendDstAlpha = OneFactor;
893
+ material.color.set(8421504);
894
+ break;
895
+ case "water_mask":
896
+ material.alphaTest = 0;
897
+ material.colorWrite = false;
898
+ break;
899
+ }
900
+ if (_Materials.entityModeScroll(mode)) {
901
+ material.map.wrapS = material.map.wrapT = RepeatWrapping;
902
+ }
903
+ if (tint !== void 0) material.color.multiply(new Color(tint));
904
+ return material;
905
+ }
841
906
  static createGuiCanvasMaterial(canvas) {
842
907
  const material = new MeshBasicMaterial({
843
908
  map: Textures.createCanvasTexture(canvas),
@@ -4039,7 +4104,7 @@ var init_ModelCulling = __esm({
4039
4104
  });
4040
4105
 
4041
4106
  // src/model/scene/ModelObject.ts
4042
- import { BoxGeometry as BoxGeometry5, BufferAttribute as BufferAttribute5, Color as Color7, Euler as Euler5, Matrix4 as Matrix46 } from "three";
4107
+ import { BoxGeometry as BoxGeometry5, BufferAttribute as BufferAttribute5, Color as Color8, Euler as Euler6, Matrix4 as Matrix47 } from "three";
4043
4108
  function isModelObject(obj) {
4044
4109
  return obj.isModelObject;
4045
4110
  }
@@ -4102,7 +4167,7 @@ var init_ModelObject = __esm({
4102
4167
  elGeo.clearGroups();
4103
4168
  }
4104
4169
  if (this.options.uvLockRotation) {
4105
- UVMapper.lockUvs(elGeo, el.faces, this.atlas, new Euler5(...this.options.uvLockRotation));
4170
+ UVMapper.lockUvs(elGeo, el.faces, this.atlas, new Euler6(...this.options.uvLockRotation));
4106
4171
  }
4107
4172
  if (this.options.tints) {
4108
4173
  const colors = new Float32Array(elGeo.getAttribute("position").count * 3).fill(1);
@@ -4111,19 +4176,19 @@ var init_ModelObject = __esm({
4111
4176
  if (tintIndex === void 0 || tintIndex < 0) continue;
4112
4177
  const tint = this.options.tints[tintIndex];
4113
4178
  if (tint === void 0) continue;
4114
- const color = new Color7(tint);
4179
+ const color = new Color8(tint);
4115
4180
  for (let vertex = 0; vertex < 4; vertex++) {
4116
4181
  color.toArray(colors, (faceIndex * 4 + vertex) * 3);
4117
4182
  }
4118
4183
  }
4119
4184
  elGeo.setAttribute("color", new BufferAttribute5(colors, 3));
4120
4185
  }
4121
- elGeo.applyMatrix4(new Matrix46().makeTranslation((el.to[0] - el.from[0]) / 2, (el.to[1] - el.from[1]) / 2, (el.to[2] - el.from[2]) / 2));
4122
- elGeo.applyMatrix4(new Matrix46().makeTranslation(el.from[0], el.from[1], el.from[2]));
4186
+ elGeo.applyMatrix4(new Matrix47().makeTranslation((el.to[0] - el.from[0]) / 2, (el.to[1] - el.from[1]) / 2, (el.to[2] - el.from[2]) / 2));
4187
+ elGeo.applyMatrix4(new Matrix47().makeTranslation(el.from[0], el.from[1], el.from[2]));
4123
4188
  if (el.rotation) {
4124
4189
  applyElementRotation(el.rotation, elGeo);
4125
4190
  }
4126
- elGeo.applyMatrix4(new Matrix46().makeTranslation(-8, -8, -8));
4191
+ elGeo.applyMatrix4(new Matrix47().makeTranslation(-8, -8, -8));
4127
4192
  if (displayTransform) DisplayTransforms.apply(elGeo, displayTransform);
4128
4193
  if (this.options.mergeMeshes) {
4129
4194
  allGeos.push(elGeo);
@@ -4377,7 +4442,7 @@ __export(FluidModelObject_exports, {
4377
4442
  FluidModelObject: () => FluidModelObject,
4378
4443
  sampleFluid: () => sampleFluid
4379
4444
  });
4380
- import { BufferAttribute as BufferAttribute6, Color as Color8, DoubleSide as DoubleSide3 } from "three";
4445
+ import { BufferAttribute as BufferAttribute6, Color as Color9, DoubleSide as DoubleSide3 } from "three";
4381
4446
  function sampleFluid(kind, sample) {
4382
4447
  const cells = [];
4383
4448
  const key = [];
@@ -4428,7 +4493,7 @@ var init_FluidModelObject = __esm({
4428
4493
  }
4429
4494
  }
4430
4495
  geometry.clearGroups();
4431
- const color = new Color8(this.options.tints?.[0] ?? (this.kind === "water" ? 4159204 : 16777215));
4496
+ const color = new Color9(this.options.tints?.[0] ?? (this.kind === "water" ? 4159204 : 16777215));
4432
4497
  const colors = new Float32Array(geometry.getAttribute("position").count * 3);
4433
4498
  for (let i = 0; i < colors.length; i += 3) color.toArray(colors, i);
4434
4499
  geometry.setAttribute("color", new BufferAttribute6(colors, 3));
@@ -4763,32 +4828,44 @@ var Entities = class {
4763
4828
  static async getLayerList(modelKey) {
4764
4829
  return Object.keys((await this.getModelFile(modelKey))?.layers ?? {});
4765
4830
  }
4831
+ /** The dataset's extra draws on top of `main`; their `when` labels are the states `EntityModelOptions.when` can enable. */
4832
+ static async getPassList(modelKey) {
4833
+ return (await this.getModelFile(modelKey))?.passes ?? [];
4834
+ }
4766
4835
  static async getEntity(modelKey, textureKey, options) {
4767
4836
  const model = await this.getModelFile(modelKey);
4768
4837
  if (!model) return void 0;
4769
- const names = [...new Set(options?.layers ?? [options?.layer ?? "main"])];
4770
- if (names.length === 0) throw new MineRenderError(`Entity ${model.id} requires at least one layer`);
4771
- const selected = names.map((name) => {
4772
- const layer = model.layers[name];
4838
+ const passes = options?.layers || options?.layer !== void 0 ? [] : (model.passes ?? []).filter((pass) => pass.when === void 0 || options?.when?.includes(pass.when));
4839
+ const draws = [...new Set(options?.layers ?? [options?.layer ?? "main"])].map((layer) => ({ layer }));
4840
+ if (draws.length === 0) throw new MineRenderError(`Entity ${model.id} requires at least one layer`);
4841
+ draws.push(...passes);
4842
+ const names = [];
4843
+ const selected = draws.map((pass) => {
4844
+ const layer = model.layers[pass.layer];
4773
4845
  if (!layer) {
4774
- throw new MineRenderError(`Entity ${model.id} has no layer "${name}". Available layers: ${Object.keys(model.layers).join(", ")}`);
4846
+ throw new MineRenderError(`Entity ${model.id} has no layer "${pass.layer}". Available layers: ${Object.keys(model.layers).join(", ")}`);
4775
4847
  }
4776
- return { name, layer };
4848
+ let name = pass.layer;
4849
+ for (let n = 2; names.includes(name); n++) name = `${pass.layer}#${n}`;
4850
+ names.push(name);
4851
+ return { name, layer, pass };
4777
4852
  });
4778
- const layers = Object.fromEntries(await Promise.all(selected.map(async ({ name, layer }, index) => {
4853
+ const layers = Object.fromEntries(await Promise.all(selected.map(async ({ name, layer, pass }, index) => {
4779
4854
  const override = options?.textures?.[name] ?? (index === 0 ? textureKey : void 0);
4855
+ const textureLocation = pass.textureLocation ?? layer.textureLocation;
4780
4856
  let texture;
4781
4857
  if (override) {
4782
4858
  const path = isAssetKey(override) ? override.getFullPath() : override.path;
4783
4859
  texture = isAssetKey(override) && override.assetType === "textures" && path.startsWith("entity/") ? override : new AssetKey(override.namespace, path, "textures", "entity", "assets", ".png", isAssetKey(override) ? override.root : void 0);
4784
- } else if (layer.textureLocation !== void 0) {
4785
- texture = AssetKey.parse("textures", layer.textureLocation.replace(/^([^:]+:)?textures\//, "$1"));
4860
+ } else if (textureLocation !== void 0) {
4861
+ texture = AssetKey.parse("textures", textureLocation.replace(/^([^:]+:)?textures\//, "$1"));
4786
4862
  } else {
4787
4863
  texture = await this.resolveTexture(modelKey);
4788
4864
  }
4789
- return [name, { key: override ?? modelKey, texture, layer }];
4865
+ const render = pass.render ?? layer.render;
4866
+ return [name, { key: override ?? modelKey, texture, layer, ...render && { render }, ...pass.tint && { tint: pass.tint } }];
4790
4867
  })));
4791
- return { ...layers[names[0]], id: model.id, layers };
4868
+ return { ...layers[names[0]], id: model.id, layers, ...model.transform && { transform: model.transform } };
4792
4869
  }
4793
4870
  static async resolveTexture(modelKey) {
4794
4871
  const path = isAssetKey(modelKey) ? modelKey.getFullPath() : modelKey.path;
@@ -4870,11 +4947,12 @@ function trimCanvas(source) {
4870
4947
  init_SceneObject();
4871
4948
  init_Caching();
4872
4949
  var import_ts_deepmerge4 = __toESM(require_dist());
4950
+ init_Ticker();
4873
4951
  init_model();
4874
4952
  init_ModelTextures();
4875
4953
  init_AssetKey();
4876
4954
  init_Materials();
4877
- import { Object3D as Object3D3 } from "three";
4955
+ import { Color as Color3, Euler as Euler4, Matrix4 as Matrix44, Object3D as Object3D3 } from "three";
4878
4956
  init_three();
4879
4957
  var _EntityObject = class _EntityObject extends SceneObject {
4880
4958
  constructor(entity, options) {
@@ -4882,6 +4960,10 @@ var _EntityObject = class _EntityObject extends SceneObject {
4882
4960
  this.entity = entity;
4883
4961
  this.isEntityObject = true;
4884
4962
  this.meshesCreated = false;
4963
+ /** Scrolling materials are owned: their texture offset follows this entity's age. */
4964
+ this.scrollMaterials = [];
4965
+ /** Entity age in ticks, as vanilla's `ageInTicks`; drives the scrolling render modes. */
4966
+ this.age = 0;
4885
4967
  this.options = (0, import_ts_deepmerge4.default)({}, _EntityObject.DEFAULT_OPTIONS, options ?? {});
4886
4968
  }
4887
4969
  async init() {
@@ -4891,6 +4973,25 @@ var _EntityObject = class _EntityObject extends SceneObject {
4891
4973
  dispose() {
4892
4974
  super.dispose();
4893
4975
  }
4976
+ disposeAndRemoveAllChildren() {
4977
+ this.clearScrollMaterials();
4978
+ super.disposeAndRemoveAllChildren();
4979
+ }
4980
+ clearScrollMaterials() {
4981
+ Ticker.remove(this.scrollTicker);
4982
+ this.scrollTicker = void 0;
4983
+ for (const { material } of this.scrollMaterials.splice(0)) {
4984
+ material.map?.dispose();
4985
+ material.dispose();
4986
+ }
4987
+ }
4988
+ /** Applies the entity age to the scrolling materials; the ticker calls this 20 times per second. */
4989
+ updateScroll() {
4990
+ for (const { offset, speed } of this.scrollMaterials) {
4991
+ offset.set(this.age * speed[0] % 1, 0 - this.age * speed[1] % 1);
4992
+ }
4993
+ this.notifyDirty();
4994
+ }
4894
4995
  getLayerGroup(name) {
4895
4996
  return super.getGroupByName(`layer:${name}`);
4896
4997
  }
@@ -4921,16 +5022,29 @@ var _EntityObject = class _EntityObject extends SceneObject {
4921
5022
  createMeshes(force = false) {
4922
5023
  if (this.meshesCreated && !force) return;
4923
5024
  const modelRoot = new Object3D3();
4924
- if (this.options.flip) modelRoot.scale.set(-1, -1, 1);
5025
+ const transform = this.options.flip === void 0 ? this.entity.transform : void 0;
5026
+ if (transform) {
5027
+ for (const op of transform) {
5028
+ const matrix = new Matrix44();
5029
+ if ("scale" in op) matrix.makeScale(...op.scale);
5030
+ else if ("translate" in op) matrix.makeTranslation(...op.translate);
5031
+ else matrix.makeRotationFromEuler(new Euler4(...op.rotate, "ZYX"));
5032
+ modelRoot.matrix.multiply(matrix);
5033
+ }
5034
+ modelRoot.matrixAutoUpdate = false;
5035
+ } else if (this.options.flip ?? true) {
5036
+ modelRoot.scale.set(-1, -1, 1);
5037
+ }
4925
5038
  this.add(modelRoot);
4926
5039
  Object.entries(this.entityLayers).forEach(([name, layer], index) => {
4927
5040
  const group = this.createGroup(`layer:${name}`);
4928
5041
  modelRoot.add(group);
4929
- this.createPart("root", layer.layer.root, group, layer.layer.texture, Materials.MISSING_TEXTURE, index);
5042
+ const inward = !Materials.entityModeCulls(layer.render ?? layer.layer.render);
5043
+ this.createPart("root", layer.layer.root, group, layer.layer.texture, Materials.MISSING_TEXTURE, index, inward);
4930
5044
  });
4931
5045
  this.meshesCreated = true;
4932
5046
  }
4933
- createPart(name, part, parent, textureSize, material, renderOrder) {
5047
+ createPart(name, part, parent, textureSize, material, renderOrder, inward = true) {
4934
5048
  const anchor = this.createGroup(name);
4935
5049
  anchor.position.fromArray(part.pose.offset);
4936
5050
  anchor.rotation.set(...part.pose.rotation, "ZYX");
@@ -4949,7 +5063,7 @@ var _EntityObject = class _EntityObject extends SceneObject {
4949
5063
  uv
4950
5064
  ).clone();
4951
5065
  geometry.translate(cube.origin[0] + width / 2, cube.origin[1] + height / 2, cube.origin[2] + depth / 2);
4952
- if (Math.min(width + growX * 2, height + growY * 2, depth + growZ * 2) > 0) {
5066
+ if (inward && Math.min(width + growX * 2, height + growY * 2, depth + growZ * 2) > 0) {
4953
5067
  const index = Array.from(geometry.getIndex().array);
4954
5068
  geometry.setIndex(index.concat(index.slice().reverse()));
4955
5069
  }
@@ -4959,30 +5073,46 @@ var _EntityObject = class _EntityObject extends SceneObject {
4959
5073
  if (this.options.wireframe) addWireframeToMesh(geometry, mesh);
4960
5074
  }
4961
5075
  for (const [childName, child] of Object.entries(part.children)) {
4962
- this.createPart(childName, child, anchor, size, material, renderOrder);
5076
+ this.createPart(childName, child, anchor, size, material, renderOrder, inward);
4963
5077
  }
4964
5078
  }
4965
5079
  async applyTextures() {
5080
+ this.clearScrollMaterials();
4966
5081
  await Promise.all(Object.entries(this.entityLayers).map(async ([name, layer]) => {
5082
+ const mode = layer.render ?? layer.layer.render ?? "cutout";
5083
+ const tint = layer.tint === void 0 ? void 0 : this.options.tints?.[layer.tint];
5084
+ const scroll = Materials.entityModeScroll(mode);
4967
5085
  const assetKeyStr = this.getTextureKey(layer).serialize();
4968
- const keyStr = `entity:${assetKeyStr}`;
4969
- let mat = Caching.materialCache.getIfPresent(keyStr);
5086
+ const keyStr = `entity:${mode}:${tint === void 0 ? "" : new Color3(tint).getHexString()}:${assetKeyStr}`;
5087
+ let mat = scroll ? void 0 : Caching.materialCache.getIfPresent(keyStr);
4970
5088
  if (!mat) {
4971
5089
  const cachedAsset = Caching.textureAssetCache.getIfPresent(assetKeyStr);
4972
5090
  const imageData = await this.loadTextures(layer);
4973
5091
  if (!imageData) return;
4974
5092
  const canvas = imageData.data.canvas;
4975
- const createMaterial = () => Materials.createBasicCanvasMaterial(canvas);
4976
- mat = cachedAsset && Caching.textureAssetCache.getIfPresent(assetKeyStr) === cachedAsset ? Caching.materialCache.get(keyStr, createMaterial) : createMaterial();
5093
+ const createMaterial = () => Materials.createEntityCanvasMaterial(canvas, mode, tint);
5094
+ mat = !scroll && cachedAsset && Caching.textureAssetCache.getIfPresent(assetKeyStr) === cachedAsset ? Caching.materialCache.get(keyStr, createMaterial) : createMaterial();
5095
+ if (scroll) {
5096
+ this.scrollMaterials.push({ material: mat, offset: mat.map.offset, speed: scroll });
5097
+ }
4977
5098
  }
4978
5099
  this.getLayerGroup(name)?.traverse((object) => {
4979
5100
  if (isMesh(object)) object.material = mat;
4980
5101
  });
4981
5102
  }));
5103
+ if (!this.children.length) {
5104
+ this.clearScrollMaterials();
5105
+ } else if (this.scrollMaterials.length) {
5106
+ this.updateScroll();
5107
+ this.scrollTicker = Ticker.add(() => {
5108
+ this.age++;
5109
+ this.updateScroll();
5110
+ });
5111
+ }
4982
5112
  this.notifyDirty();
4983
5113
  }
4984
5114
  };
4985
- _EntityObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge4.default)({}, SceneObject.DEFAULT_OPTIONS, { flip: true });
5115
+ _EntityObject.DEFAULT_OPTIONS = (0, import_ts_deepmerge4.default)({}, SceneObject.DEFAULT_OPTIONS);
4986
5116
  var EntityObject = _EntityObject;
4987
5117
  function isEntityObject(obj) {
4988
5118
  return obj.isEntityObject;
@@ -4992,11 +5122,11 @@ function isEntityObject(obj) {
4992
5122
  init_MineRenderError();
4993
5123
 
4994
5124
  // src/export/SceneExporter.ts
4995
- import { ClampToEdgeWrapping as ClampToEdgeWrapping2, Color as Color6, Float32BufferAttribute as Float32BufferAttribute3, Matrix4 as Matrix45, Mesh as Mesh5, MeshBasicMaterial as MeshBasicMaterial2, NearestFilter as NearestFilter3, RGBAFormat as RGBAFormat3, Scene as Scene4, Source as Source2, Texture as Texture4, UnsignedByteType } from "three";
5125
+ import { ClampToEdgeWrapping as ClampToEdgeWrapping2, Color as Color7, Float32BufferAttribute as Float32BufferAttribute3, Matrix4 as Matrix46, Mesh as Mesh5, MeshBasicMaterial as MeshBasicMaterial2, NearestFilter as NearestFilter3, RGBAFormat as RGBAFormat3, Scene as Scene4, Source as Source2, Texture as Texture4, UnsignedByteType } from "three";
4996
5126
 
4997
5127
  // ../../node_modules/three/examples/jsm/exporters/OBJExporter.js
4998
5128
  import {
4999
- Color as Color3,
5129
+ Color as Color4,
5000
5130
  Matrix3,
5001
5131
  Vector2 as Vector22,
5002
5132
  Vector3 as Vector36
@@ -5008,7 +5138,7 @@ var OBJExporter = class {
5008
5138
  let indexVertexUvs = 0;
5009
5139
  let indexNormals = 0;
5010
5140
  const vertex = new Vector36();
5011
- const color = new Color3();
5141
+ const color = new Color4();
5012
5142
  const normal = new Vector36();
5013
5143
  const uv = new Vector22();
5014
5144
  const face = [];
@@ -5139,7 +5269,7 @@ var OBJExporter = class {
5139
5269
  import {
5140
5270
  Matrix3 as Matrix32,
5141
5271
  Vector3 as Vector37,
5142
- Color as Color4
5272
+ Color as Color5
5143
5273
  } from "three";
5144
5274
  var PLYExporter = class {
5145
5275
  parse(object, onDone, options = {}) {
@@ -5197,7 +5327,7 @@ var PLYExporter = class {
5197
5327
  includeIndices = false;
5198
5328
  }
5199
5329
  });
5200
- const tempColor = new Color4();
5330
+ const tempColor = new Color5();
5201
5331
  includeIndices = includeIndices && excludeAttributes.indexOf("index") === -1;
5202
5332
  includeNormals = includeNormals && excludeAttributes.indexOf("normal") === -1;
5203
5333
  includeColors = includeColors && excludeAttributes.indexOf("color") === -1;
@@ -5409,7 +5539,7 @@ property list uchar int vertex_index
5409
5539
  import {
5410
5540
  BufferAttribute as BufferAttribute3,
5411
5541
  ClampToEdgeWrapping,
5412
- Color as Color5,
5542
+ Color as Color6,
5413
5543
  DoubleSide as DoubleSide2,
5414
5544
  InterpolateDiscrete,
5415
5545
  InterpolateLinear,
@@ -5418,14 +5548,14 @@ import {
5418
5548
  LinearMipmapLinearFilter,
5419
5549
  LinearMipmapNearestFilter,
5420
5550
  MathUtils as MathUtils2,
5421
- Matrix4 as Matrix44,
5551
+ Matrix4 as Matrix45,
5422
5552
  MirroredRepeatWrapping,
5423
5553
  NearestFilter as NearestFilter2,
5424
5554
  NearestMipmapLinearFilter,
5425
5555
  NearestMipmapNearestFilter,
5426
5556
  PropertyBinding,
5427
5557
  RGBAFormat as RGBAFormat2,
5428
- RepeatWrapping,
5558
+ RepeatWrapping as RepeatWrapping2,
5429
5559
  Scene as Scene3,
5430
5560
  Source,
5431
5561
  SRGBColorSpace as SRGBColorSpace4,
@@ -5643,7 +5773,7 @@ THREE_TO_WEBGL[LinearFilter] = WEBGL_CONSTANTS.LINEAR;
5643
5773
  THREE_TO_WEBGL[LinearMipmapNearestFilter] = WEBGL_CONSTANTS.LINEAR_MIPMAP_NEAREST;
5644
5774
  THREE_TO_WEBGL[LinearMipmapLinearFilter] = WEBGL_CONSTANTS.LINEAR_MIPMAP_LINEAR;
5645
5775
  THREE_TO_WEBGL[ClampToEdgeWrapping] = WEBGL_CONSTANTS.CLAMP_TO_EDGE;
5646
- THREE_TO_WEBGL[RepeatWrapping] = WEBGL_CONSTANTS.REPEAT;
5776
+ THREE_TO_WEBGL[RepeatWrapping2] = WEBGL_CONSTANTS.REPEAT;
5647
5777
  THREE_TO_WEBGL[MirroredRepeatWrapping] = WEBGL_CONSTANTS.MIRRORED_REPEAT;
5648
5778
  var PATH_PROPERTIES = {
5649
5779
  scale: "scale",
@@ -5651,7 +5781,7 @@ var PATH_PROPERTIES = {
5651
5781
  quaternion: "rotation",
5652
5782
  morphTargetInfluences: "weights"
5653
5783
  };
5654
- var DEFAULT_SPECULAR_COLOR = new Color5();
5784
+ var DEFAULT_SPECULAR_COLOR = new Color6();
5655
5785
  var GLB_HEADER_BYTES = 12;
5656
5786
  var GLB_HEADER_MAGIC = 1179937895;
5657
5787
  var GLB_VERSION = 2;
@@ -6708,7 +6838,7 @@ var GLTFWriter = class {
6708
6838
  if (rootJoint === void 0) return null;
6709
6839
  const joints = [];
6710
6840
  const inverseBindMatrices = new Float32Array(skeleton.bones.length * 16);
6711
- const temporaryBoneInverse = new Matrix44();
6841
+ const temporaryBoneInverse = new Matrix45();
6712
6842
  for (let i = 0; i < skeleton.bones.length; ++i) {
6713
6843
  joints.push(nodeMap.get(skeleton.bones[i]));
6714
6844
  temporaryBoneInverse.copy(skeleton.boneInverses[i]);
@@ -7174,7 +7304,7 @@ var GLTFMeshGpuInstancing = class {
7174
7304
  const translationAttr = new Float32Array(mesh.count * 3);
7175
7305
  const rotationAttr = new Float32Array(mesh.count * 4);
7176
7306
  const scaleAttr = new Float32Array(mesh.count * 3);
7177
- const matrix = new Matrix44();
7307
+ const matrix = new Matrix45();
7178
7308
  const position = new Vector38();
7179
7309
  const quaternion = new Quaternion4();
7180
7310
  const scale = new Vector38();
@@ -7348,7 +7478,7 @@ var SceneExporter = class {
7348
7478
  }
7349
7479
  };
7350
7480
  function localMatrix(object) {
7351
- return object.matrixAutoUpdate ? new Matrix45().compose(object.position, object.quaternion, object.scale) : object.matrix.clone();
7481
+ return object.matrixAutoUpdate ? new Matrix46().compose(object.position, object.quaternion, object.scale) : object.matrix.clone();
7352
7482
  }
7353
7483
  function createSnapshot(root, gltf, bakeColors = false) {
7354
7484
  const scene = new Scene4();
@@ -7433,7 +7563,7 @@ function createSnapshot(root, gltf, bakeColors = false) {
7433
7563
  const material = copyMaterial(sourceMaterial, geometry);
7434
7564
  if (!sourceMaterial.vertexColors) geometry.deleteAttribute("color");
7435
7565
  if (bakeColors || instanceColor) {
7436
- const tint = (material.color ?? new Color6()).clone();
7566
+ const tint = (material.color ?? new Color7()).clone();
7437
7567
  if (instanceColor) tint.multiply(instanceColor);
7438
7568
  if (bakeColors) {
7439
7569
  const original = geometry.getAttribute("color");
@@ -7460,9 +7590,9 @@ function createSnapshot(root, gltf, bakeColors = false) {
7460
7590
  const instanced = mesh;
7461
7591
  if (instanced.isInstancedMesh) {
7462
7592
  for (let i = 0; i < instanced.count; i++) {
7463
- const matrix = new Matrix45();
7593
+ const matrix = new Matrix46();
7464
7594
  instanced.getMatrixAt(i, matrix);
7465
- const color = instanced.instanceColor ? new Color6().fromBufferAttribute(instanced.instanceColor, i) : void 0;
7595
+ const color = instanced.instanceColor ? new Color7().fromBufferAttribute(instanced.instanceColor, i) : void 0;
7466
7596
  addMesh(mesh, world.clone().multiply(matrix), color);
7467
7597
  }
7468
7598
  } else {
@@ -7474,7 +7604,7 @@ function createSnapshot(root, gltf, bakeColors = false) {
7474
7604
  try {
7475
7605
  const ancestors = [];
7476
7606
  for (let parent = root.parent; parent; parent = parent.parent) ancestors.unshift(parent);
7477
- const world = new Matrix45();
7607
+ const world = new Matrix46();
7478
7608
  for (const ancestor of ancestors) {
7479
7609
  if (!ancestor.visible) return { scene, dispose };
7480
7610
  world.multiply(localMatrix(ancestor));
@@ -7541,11 +7671,69 @@ function copyDataTexture(source) {
7541
7671
  }
7542
7672
 
7543
7673
  // src/gui/GuiHelper.ts
7674
+ init_AssetKey();
7544
7675
  var GuiHelper = class {
7545
7676
  static inventorySlot(slot, origin = [0, 0], offset = [18, 18], rowSize = 9) {
7546
7677
  const [column, row] = typeof slot === "number" ? [slot % rowSize, Math.floor(slot / rowSize)] : slot;
7547
7678
  return [origin[0] + column * offset[0], origin[1] + row * offset[1]];
7548
7679
  }
7680
+ /** Creates crafting-table layers for ingredients and the result; stack counts are not drawn. */
7681
+ static recipe(recipe, options = {}) {
7682
+ const layers = [
7683
+ { name: "background", texture: "minecraft:gui/container/crafting_table", crop: [0, 0, 176, 166] }
7684
+ ];
7685
+ const itemKey = (ingredient) => {
7686
+ const item = typeof ingredient === "string" && !ingredient.startsWith("#") ? ingredient : typeof ingredient === "object" && "item" in ingredient ? ingredient.item : options.resolveIngredient?.(ingredient);
7687
+ if (isAssetKey(item)) return item;
7688
+ if (!item || item.startsWith("#")) {
7689
+ throw new Error(`Select a concrete item for recipe ingredient ${JSON.stringify(ingredient)}`);
7690
+ }
7691
+ const key = AssetKey.parse("models", item);
7692
+ return new AssetKey(key.namespace, key.getFullPath(), "models", "item");
7693
+ };
7694
+ const addIngredient = (ingredient, slot) => {
7695
+ layers.push({
7696
+ name: `ingredient-${slot}`,
7697
+ item: itemKey(ingredient),
7698
+ position: this.inventorySlot(slot, [30, 17], [18, 18], 3)
7699
+ });
7700
+ };
7701
+ switch (recipe.type) {
7702
+ case "minecraft:crafting_shaped":
7703
+ case "crafting_shaped": {
7704
+ const pattern = recipe.pattern;
7705
+ if (!pattern.length || pattern.length > 3 || !pattern[0].length || pattern[0].length > 3 || pattern.some((row) => row.length !== pattern[0].length)) {
7706
+ throw new Error("Crafting patterns must be rectangular, with 1\u20133 rows and columns");
7707
+ }
7708
+ const cells = pattern.flatMap((row, y) => row.split("").map((symbol, x) => ({ symbol, x, y }))).filter((cell) => cell.symbol !== " ");
7709
+ if (!cells.length) throw new Error("Crafting patterns must contain an ingredient");
7710
+ const minX = Math.min(...cells.map((cell) => cell.x)), maxX = Math.max(...cells.map((cell) => cell.x));
7711
+ const minY = Math.min(...cells.map((cell) => cell.y)), maxY = Math.max(...cells.map((cell) => cell.y));
7712
+ const offsetX = minX === maxX ? 1 : 0, offsetY = minY === maxY ? 1 : 0;
7713
+ for (const { symbol, x, y } of cells) {
7714
+ const ingredient = recipe.key[symbol];
7715
+ if (!ingredient) throw new Error(`Missing recipe ingredient for symbol ${JSON.stringify(symbol)}`);
7716
+ addIngredient(ingredient, (y - minY + offsetY) * 3 + x - minX + offsetX);
7717
+ }
7718
+ break;
7719
+ }
7720
+ case "minecraft:crafting_shapeless":
7721
+ case "crafting_shapeless":
7722
+ if (!recipe.ingredients.length || recipe.ingredients.length > 9) {
7723
+ throw new Error("Shapeless crafting recipes require 1\u20139 ingredients");
7724
+ }
7725
+ recipe.ingredients.forEach(addIngredient);
7726
+ break;
7727
+ default:
7728
+ throw new Error(`Unsupported crafting recipe type: ${recipe.type}`);
7729
+ }
7730
+ layers.push({
7731
+ name: "result",
7732
+ item: itemKey("id" in recipe.result ? recipe.result.id : recipe.result.item),
7733
+ position: [124, 35]
7734
+ });
7735
+ return layers;
7736
+ }
7549
7737
  };
7550
7738
 
7551
7739
  // src/gui/scene/GuiObject.ts
@@ -8133,7 +8321,7 @@ init_ModelMerger();
8133
8321
  init_BlockStates();
8134
8322
  init_MineRenderError();
8135
8323
  init_util();
8136
- import { Euler as Euler6 } from "three";
8324
+ import { Euler as Euler7 } from "three";
8137
8325
  function matchesCondition(condition, state) {
8138
8326
  return Object.entries(condition).every(([key, value]) => {
8139
8327
  if (Array.isArray(value)) {
@@ -8208,7 +8396,7 @@ var BlockStateResolver = class {
8208
8396
  return variants[variants.length - 1];
8209
8397
  }
8210
8398
  static rotation(variant) {
8211
- const rotation = new Euler6();
8399
+ const rotation = new Euler7();
8212
8400
  if (typeof variant.x !== "undefined") {
8213
8401
  rotation.x = toRadians(clampRotationDegrees(variant.x));
8214
8402
  }
@@ -8318,7 +8506,7 @@ var import_ts_deepmerge6 = __toESM(require_dist());
8318
8506
  init_MineRenderError();
8319
8507
  init_InstanceReference();
8320
8508
  init_AssetKey();
8321
- import { Euler as Euler7, Matrix4 as Matrix47, Quaternion as Quaternion5, Vector3 as Vector311 } from "three";
8509
+ import { Euler as Euler8, Matrix4 as Matrix48, Quaternion as Quaternion5, Vector3 as Vector311 } from "three";
8322
8510
  init_ModelCulling();
8323
8511
  init_FluidGeometry();
8324
8512
  var _BlockObject = class _BlockObject extends SceneObject {
@@ -8384,7 +8572,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
8384
8572
  const scale = new Vector311();
8385
8573
  this.getModelMatrix(model).decompose(position, rotation, scale);
8386
8574
  if (position.distanceToSquared(this.position) > 1e-10 || scale.distanceToSquared(new Vector311(1, 1, 1)) > 1e-10) return 0;
8387
- return ModelCulling.toLocalMask(worldMask, new Euler7().setFromQuaternion(rotation));
8575
+ return ModelCulling.toLocalMask(worldMask, new Euler8().setFromQuaternion(rotation));
8388
8576
  }
8389
8577
  async setCullMask(worldMask) {
8390
8578
  worldMask &= 63;
@@ -8446,7 +8634,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
8446
8634
  () => new FluidModelObject2(kind, surface.sample, this.blockState.key, this.options)
8447
8635
  );
8448
8636
  const previous = this._fluidModel;
8449
- const matrix = previous ? this.getModelMatrix(previous) : new Matrix47().makeTranslation(...this.position.toArray());
8637
+ const matrix = previous ? this.getModelMatrix(previous) : new Matrix48().makeTranslation(...this.position.toArray());
8450
8638
  if (isInstanceReference(replacement)) replacement.setMatrix(matrix);
8451
8639
  else matrix.decompose(replacement.position, replacement.quaternion, replacement.scale);
8452
8640
  this._models = this._models.filter((model) => model !== previous);
@@ -8577,7 +8765,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
8577
8765
  setPositionRotationScaleAt(index, position, rotation, scale) {
8578
8766
  super.setPositionRotationScaleAt(index, position, rotation, scale);
8579
8767
  }
8580
- getMatrixAt(index, matrix = new Matrix47()) {
8768
+ getMatrixAt(index, matrix = new Matrix48()) {
8581
8769
  if (!this.isInstanced) throw new MineRenderError("Object is not instanced");
8582
8770
  const child = this._models[0];
8583
8771
  if (child && isModelObject(child)) {
@@ -13141,7 +13329,7 @@ init_CubeFace();
13141
13329
  init_AssetKey();
13142
13330
  init_Models();
13143
13331
  init_CubeFace();
13144
- import { Matrix4 as Matrix48, Vector3 as Vector314 } from "three";
13332
+ import { Matrix4 as Matrix49, Vector3 as Vector314 } from "three";
13145
13333
  init_ModelCulling();
13146
13334
  init_ModelObject();
13147
13335
  init_UVMapper();
@@ -13204,7 +13392,7 @@ var SectionModels = class {
13204
13392
  });
13205
13393
  await object.init();
13206
13394
  const geometry = object.children[0].geometry;
13207
- geometry.applyMatrix4(new Matrix48().makeRotationFromEuler(rotation));
13395
+ geometry.applyMatrix4(new Matrix49().makeRotationFromEuler(rotation));
13208
13396
  object.clear();
13209
13397
  const cullFaces = CUBE_FACES.map((face) => {
13210
13398
  const local = CUBE_FACES.findIndex((name) => name === atlas.model.elements[0].faces[face]?.cullface);