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.
package/dist/bundle.js CHANGED
@@ -79707,9 +79707,9 @@ ${key}` : key;
79707
79707
  });
79708
79708
 
79709
79709
  // src/model/fluid/FluidGeometry.ts
79710
- function getFluidKind(key) {
79711
- if (key?.namespace !== "minecraft" || key.type) return void 0;
79712
- return key.path === "water" || key.path === "lava" ? key.path : void 0;
79710
+ function getFluidKind(key, state) {
79711
+ if (key?.namespace === "minecraft" && !key.type && (key.path === "water" || key.path === "lava")) return key.path;
79712
+ return state?.waterlogged === "true" ? "water" : void 0;
79713
79713
  }
79714
79714
  function ownHeight(sample) {
79715
79715
  const level = sample.level ?? 0;
@@ -79868,7 +79868,7 @@ ${key}` : key;
79868
79868
  FluidModelObject = class extends ModelObject {
79869
79869
  constructor(kind, sample, origin, options) {
79870
79870
  super({
79871
- key: new AssetKey("minecraft", kind, "models", "fluid", "assets", ".json", origin.root),
79871
+ key: new AssetKey("minecraft", kind, "models", "fluid", "assets", ".json", origin?.root),
79872
79872
  textures: { still: `minecraft:block/${kind}_still`, flow: `minecraft:block/${kind}_flow` },
79873
79873
  elements: []
79874
79874
  }, options);
@@ -84283,6 +84283,7 @@ ${key}` : key;
84283
84283
  clearModels() {
84284
84284
  this.removeModels(this._models.splice(0));
84285
84285
  this._fluidKey = void 0;
84286
+ this._fluidModel = void 0;
84286
84287
  this._isInstanced = false;
84287
84288
  this._instanceCounter = 0;
84288
84289
  }
@@ -84314,11 +84315,14 @@ ${key}` : key;
84314
84315
  return ModelCulling.toLocalMask(worldMask, new Euler().setFromQuaternion(rotation));
84315
84316
  }
84316
84317
  async setCullMask(worldMask) {
84317
- if (this.fluidKind) return;
84318
84318
  worldMask &= 63;
84319
84319
  const replacements = [];
84320
84320
  try {
84321
84321
  for (const model of this._models) {
84322
+ if (model === this._fluidModel) {
84323
+ replacements.push(model);
84324
+ continue;
84325
+ }
84322
84326
  const object = isInstanceReference(model) ? model.instanceable : model;
84323
84327
  const cullMask = this.getModelCullMask(model, worldMask);
84324
84328
  if (cullMask === (object.options.cullMask ?? 0)) {
@@ -84351,7 +84355,10 @@ ${key}` : key;
84351
84355
  return this._state;
84352
84356
  }
84353
84357
  get fluidKind() {
84354
- return getFluidKind(this.blockState.key);
84358
+ return getFluidKind(this.blockState.key, this.state);
84359
+ }
84360
+ get fluidLevel() {
84361
+ return getFluidKind(this.blockState.key) ? Number(this.state.level ?? 0) : 0;
84355
84362
  }
84356
84363
  /** Refreshes fluid surfaces from relative neighbors; standalone previews use air around the block. */
84357
84364
  async updateFluid(sample) {
@@ -84359,22 +84366,24 @@ ${key}` : key;
84359
84366
  if (!kind) return;
84360
84367
  const { FluidModelObject: FluidModelObject2, sampleFluid: sampleFluid2 } = await Promise.resolve().then(() => (init_FluidModelObject(), FluidModelObject_exports));
84361
84368
  this._fluidSampler = sample;
84362
- const surface = sampleFluid2(kind, (x4, y5, z4) => x4 === 0 && y5 === 0 && z4 === 0 ? { fluid: kind, level: Number(this.state.level ?? 0) } : sample?.(x4, y5, z4) ?? {});
84369
+ const surface = sampleFluid2(kind, (x4, y5, z4) => x4 === 0 && y5 === 0 && z4 === 0 ? { fluid: kind, level: this.fluidLevel } : sample?.(x4, y5, z4) ?? {});
84363
84370
  if (this._fluidKey === surface.key) return;
84364
- const key = new AssetKey("minecraft", `${kind}/${surface.key}`, "models", "fluid", "assets", ".json", this.blockState.key.root);
84371
+ const key = new AssetKey("minecraft", `${kind}/${surface.key}`, "models", "fluid", "assets", ".json", this.blockState.key?.root);
84365
84372
  const replacement = await this.scene.addSceneObject(
84366
84373
  { key },
84367
84374
  () => new FluidModelObject2(kind, surface.sample, this.blockState.key, this.options)
84368
84375
  );
84369
- const previous = this._models;
84370
- const matrix = previous.length ? this.getModelMatrix(previous[0]) : new Matrix4().makeTranslation(...this.position.toArray());
84376
+ const previous = this._fluidModel;
84377
+ const matrix = previous ? this.getModelMatrix(previous) : new Matrix4().makeTranslation(...this.position.toArray());
84371
84378
  if (isInstanceReference(replacement)) replacement.setMatrix(matrix);
84372
84379
  else matrix.decompose(replacement.position, replacement.quaternion, replacement.scale);
84373
- this._models = [replacement];
84380
+ this._models = this._models.filter((model) => model !== previous);
84381
+ this._models.push(replacement);
84382
+ this._fluidModel = replacement;
84374
84383
  this._fluidKey = surface.key;
84375
- this._isInstanced = isInstanceReference(replacement);
84384
+ this._isInstanced || (this._isInstanced = isInstanceReference(replacement));
84376
84385
  this._instanceCounter = this._isInstanced ? 1 : 0;
84377
- this.removeModels(previous);
84386
+ if (previous) this.removeModels([previous]);
84378
84387
  this.notifyDirty();
84379
84388
  }
84380
84389
  nextInstance() {
@@ -84391,7 +84400,7 @@ ${key}` : key;
84391
84400
  }
84392
84401
  async recreateModels() {
84393
84402
  this.clearModels();
84394
- if (this.fluidKind) {
84403
+ if (getFluidKind(this.blockState.key)) {
84395
84404
  await this.updateFluid(this._fluidSampler);
84396
84405
  return;
84397
84406
  }
@@ -84400,6 +84409,7 @@ ${key}` : key;
84400
84409
  for (let blockStateVariant of variantsToCreate) {
84401
84410
  this._models.push(await this.createVariant(blockStateVariant));
84402
84411
  }
84412
+ await this.updateFluid(this._fluidSampler);
84403
84413
  }
84404
84414
  getSingleVariant(variants) {
84405
84415
  return BlockStateResolver.choose(variants);
@@ -91096,11 +91106,10 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
91096
91106
  const object = section?.getBlockAt(neighbor)?.object;
91097
91107
  return {
91098
91108
  fluid: object?.fluidKind,
91099
- level: Number(object?.state.level ?? 0),
91109
+ level: object?.fluidLevel,
91100
91110
  solid: section?.isOccludingAt(neighbor) ?? false
91101
91111
  };
91102
91112
  });
91103
- continue;
91104
91113
  }
91105
91114
  let mask = 0;
91106
91115
  for (const [face, offset] of CUBE_FACE_OFFSETS.entries()) {
@@ -91332,7 +91341,7 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
91332
91341
  this.data.set(index, void 0);
91333
91342
  return void 0;
91334
91343
  }
91335
- const template = getFluidKind(blockState.key) ? void 0 : await this.sectionModels?.get(blockState, stored.properties);
91344
+ const template = getFluidKind(blockState.key, stored.properties) ? void 0 : await this.sectionModels?.get(blockState, stored.properties);
91336
91345
  if (template) {
91337
91346
  this.sectionBlocks.set(index, { index, template, cullMask: 0 });
91338
91347
  this.meshDirty = true;