minerender 2.1.0-alpha.44 → 2.1.0-alpha.45

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.
@@ -4138,9 +4138,9 @@ var init_ModelObject = __esm({
4138
4138
 
4139
4139
  // src/model/fluid/FluidGeometry.ts
4140
4140
  import { BufferGeometry as BufferGeometry2, Float32BufferAttribute as Float32BufferAttribute4 } from "three";
4141
- function getFluidKind(key) {
4142
- if (key?.namespace !== "minecraft" || key.type) return void 0;
4143
- return key.path === "water" || key.path === "lava" ? key.path : void 0;
4141
+ function getFluidKind(key, state) {
4142
+ if (key?.namespace === "minecraft" && !key.type && (key.path === "water" || key.path === "lava")) return key.path;
4143
+ return state?.waterlogged === "true" ? "water" : void 0;
4144
4144
  }
4145
4145
  function ownHeight(sample) {
4146
4146
  const level = sample.level ?? 0;
@@ -4292,7 +4292,7 @@ var init_FluidModelObject = __esm({
4292
4292
  FluidModelObject = class extends ModelObject {
4293
4293
  constructor(kind, sample, origin, options) {
4294
4294
  super({
4295
- key: new AssetKey("minecraft", kind, "models", "fluid", "assets", ".json", origin.root),
4295
+ key: new AssetKey("minecraft", kind, "models", "fluid", "assets", ".json", origin?.root),
4296
4296
  textures: { still: `minecraft:block/${kind}_still`, flow: `minecraft:block/${kind}_flow` },
4297
4297
  elements: []
4298
4298
  }, options);
@@ -5510,6 +5510,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
5510
5510
  clearModels() {
5511
5511
  this.removeModels(this._models.splice(0));
5512
5512
  this._fluidKey = void 0;
5513
+ this._fluidModel = void 0;
5513
5514
  this._isInstanced = false;
5514
5515
  this._instanceCounter = 0;
5515
5516
  }
@@ -5541,11 +5542,14 @@ var _BlockObject = class _BlockObject extends SceneObject {
5541
5542
  return ModelCulling.toLocalMask(worldMask, new Euler7().setFromQuaternion(rotation));
5542
5543
  }
5543
5544
  async setCullMask(worldMask) {
5544
- if (this.fluidKind) return;
5545
5545
  worldMask &= 63;
5546
5546
  const replacements = [];
5547
5547
  try {
5548
5548
  for (const model of this._models) {
5549
+ if (model === this._fluidModel) {
5550
+ replacements.push(model);
5551
+ continue;
5552
+ }
5549
5553
  const object = isInstanceReference(model) ? model.instanceable : model;
5550
5554
  const cullMask = this.getModelCullMask(model, worldMask);
5551
5555
  if (cullMask === (object.options.cullMask ?? 0)) {
@@ -5578,7 +5582,10 @@ var _BlockObject = class _BlockObject extends SceneObject {
5578
5582
  return this._state;
5579
5583
  }
5580
5584
  get fluidKind() {
5581
- return getFluidKind(this.blockState.key);
5585
+ return getFluidKind(this.blockState.key, this.state);
5586
+ }
5587
+ get fluidLevel() {
5588
+ return getFluidKind(this.blockState.key) ? Number(this.state.level ?? 0) : 0;
5582
5589
  }
5583
5590
  /** Refreshes fluid surfaces from relative neighbors; standalone previews use air around the block. */
5584
5591
  async updateFluid(sample) {
@@ -5586,22 +5593,24 @@ var _BlockObject = class _BlockObject extends SceneObject {
5586
5593
  if (!kind) return;
5587
5594
  const { FluidModelObject: FluidModelObject2, sampleFluid: sampleFluid2 } = await Promise.resolve().then(() => (init_FluidModelObject(), FluidModelObject_exports));
5588
5595
  this._fluidSampler = sample;
5589
- const surface = sampleFluid2(kind, (x, y, z) => x === 0 && y === 0 && z === 0 ? { fluid: kind, level: Number(this.state.level ?? 0) } : sample?.(x, y, z) ?? {});
5596
+ const surface = sampleFluid2(kind, (x, y, z) => x === 0 && y === 0 && z === 0 ? { fluid: kind, level: this.fluidLevel } : sample?.(x, y, z) ?? {});
5590
5597
  if (this._fluidKey === surface.key) return;
5591
- const key = new AssetKey("minecraft", `${kind}/${surface.key}`, "models", "fluid", "assets", ".json", this.blockState.key.root);
5598
+ const key = new AssetKey("minecraft", `${kind}/${surface.key}`, "models", "fluid", "assets", ".json", this.blockState.key?.root);
5592
5599
  const replacement = await this.scene.addSceneObject(
5593
5600
  { key },
5594
5601
  () => new FluidModelObject2(kind, surface.sample, this.blockState.key, this.options)
5595
5602
  );
5596
- const previous = this._models;
5597
- const matrix = previous.length ? this.getModelMatrix(previous[0]) : new Matrix45().makeTranslation(...this.position.toArray());
5603
+ const previous = this._fluidModel;
5604
+ const matrix = previous ? this.getModelMatrix(previous) : new Matrix45().makeTranslation(...this.position.toArray());
5598
5605
  if (isInstanceReference(replacement)) replacement.setMatrix(matrix);
5599
5606
  else matrix.decompose(replacement.position, replacement.quaternion, replacement.scale);
5600
- this._models = [replacement];
5607
+ this._models = this._models.filter((model) => model !== previous);
5608
+ this._models.push(replacement);
5609
+ this._fluidModel = replacement;
5601
5610
  this._fluidKey = surface.key;
5602
- this._isInstanced = isInstanceReference(replacement);
5611
+ this._isInstanced || (this._isInstanced = isInstanceReference(replacement));
5603
5612
  this._instanceCounter = this._isInstanced ? 1 : 0;
5604
- this.removeModels(previous);
5613
+ if (previous) this.removeModels([previous]);
5605
5614
  this.notifyDirty();
5606
5615
  }
5607
5616
  nextInstance() {
@@ -5618,7 +5627,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
5618
5627
  }
5619
5628
  async recreateModels() {
5620
5629
  this.clearModels();
5621
- if (this.fluidKind) {
5630
+ if (getFluidKind(this.blockState.key)) {
5622
5631
  await this.updateFluid(this._fluidSampler);
5623
5632
  return;
5624
5633
  }
@@ -5627,6 +5636,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
5627
5636
  for (let blockStateVariant of variantsToCreate) {
5628
5637
  this._models.push(await this.createVariant(blockStateVariant));
5629
5638
  }
5639
+ await this.updateFluid(this._fluidSampler);
5630
5640
  }
5631
5641
  getSingleVariant(variants) {
5632
5642
  return BlockStateResolver.choose(variants);
@@ -10454,11 +10464,10 @@ var MineRenderWorld = class {
10454
10464
  const object = section?.getBlockAt(neighbor)?.object;
10455
10465
  return {
10456
10466
  fluid: object?.fluidKind,
10457
- level: Number(object?.state.level ?? 0),
10467
+ level: object?.fluidLevel,
10458
10468
  solid: section?.isOccludingAt(neighbor) ?? false
10459
10469
  };
10460
10470
  });
10461
- continue;
10462
10471
  }
10463
10472
  let mask = 0;
10464
10473
  for (const [face, offset] of CUBE_FACE_OFFSETS.entries()) {
@@ -10687,7 +10696,7 @@ var Chunk = class _Chunk {
10687
10696
  this.data.set(index, void 0);
10688
10697
  return void 0;
10689
10698
  }
10690
- const template = getFluidKind(blockState.key) ? void 0 : await this.sectionModels?.get(blockState, stored.properties);
10699
+ const template = getFluidKind(blockState.key, stored.properties) ? void 0 : await this.sectionModels?.get(blockState, stored.properties);
10691
10700
  if (template) {
10692
10701
  this.sectionBlocks.set(index, { index, template, cullMask: 0 });
10693
10702
  this.meshDirty = true;