minerender 2.1.0-alpha.44 → 2.1.0-alpha.46

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
@@ -79706,10 +79706,34 @@ ${key}` : key;
79706
79706
  }
79707
79707
  });
79708
79708
 
79709
+ // src/model/fluid/fluidBlocks.json
79710
+ var fluidBlocks_default;
79711
+ var init_fluidBlocks = __esm({
79712
+ "src/model/fluid/fluidBlocks.json"() {
79713
+ fluidBlocks_default = {
79714
+ "minecraft:water": { kind: "water", levelProperty: "level", renderModel: false },
79715
+ "minecraft:lava": { kind: "lava", levelProperty: "level", renderModel: false },
79716
+ "minecraft:kelp": { kind: "water", renderModel: true },
79717
+ "minecraft:kelp_plant": { kind: "water", renderModel: true },
79718
+ "minecraft:seagrass": { kind: "water", renderModel: true },
79719
+ "minecraft:tall_seagrass": { kind: "water", renderModel: true },
79720
+ "minecraft:bubble_column": { kind: "water", renderModel: false }
79721
+ };
79722
+ }
79723
+ });
79724
+
79709
79725
  // 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;
79726
+ function getBlockFluidState(key, state) {
79727
+ const rule = key && fluidRules[key.toNamespacedString()];
79728
+ if (rule) return {
79729
+ kind: rule.kind,
79730
+ level: rule.levelProperty ? Number(state?.[rule.levelProperty] ?? 0) : 0,
79731
+ renderModel: rule.renderModel
79732
+ };
79733
+ return state?.waterlogged === "true" ? { kind: "water", level: 0, renderModel: true } : void 0;
79734
+ }
79735
+ function getFluidKind(key, state) {
79736
+ return getBlockFluidState(key, state)?.kind;
79713
79737
  }
79714
79738
  function ownHeight(sample) {
79715
79739
  const level = sample.level ?? 0;
@@ -79821,13 +79845,15 @@ ${key}` : key;
79821
79845
  geometry.setIndex(indices);
79822
79846
  return geometry;
79823
79847
  }
79824
- var HORIZONTAL, EPSILON;
79848
+ var fluidRules, HORIZONTAL, EPSILON;
79825
79849
  var init_FluidGeometry = __esm({
79826
79850
  "src/model/fluid/FluidGeometry.ts"() {
79827
79851
  init_dirname();
79828
79852
  init_buffer2();
79829
79853
  init_process2();
79830
79854
  init_three_module();
79855
+ init_fluidBlocks();
79856
+ fluidRules = fluidBlocks_default;
79831
79857
  HORIZONTAL = [[0, -1], [0, 1], [-1, 0], [1, 0]];
79832
79858
  EPSILON = 1e-3;
79833
79859
  }
@@ -79868,7 +79894,7 @@ ${key}` : key;
79868
79894
  FluidModelObject = class extends ModelObject {
79869
79895
  constructor(kind, sample, origin, options) {
79870
79896
  super({
79871
- key: new AssetKey("minecraft", kind, "models", "fluid", "assets", ".json", origin.root),
79897
+ key: new AssetKey("minecraft", kind, "models", "fluid", "assets", ".json", origin?.root),
79872
79898
  textures: { still: `minecraft:block/${kind}_still`, flow: `minecraft:block/${kind}_flow` },
79873
79899
  elements: []
79874
79900
  }, options);
@@ -82849,6 +82875,7 @@ ${key}` : key;
82849
82875
  createFluidGeometry: () => createFluidGeometry,
82850
82876
  createImage: () => createImage,
82851
82877
  estimateBytesUsed: () => estimateBytesUsed,
82878
+ getBlockFluidState: () => getBlockFluidState,
82852
82879
  getFluidKind: () => getFluidKind,
82853
82880
  interleaveAttributes: () => interleaveAttributes,
82854
82881
  isAssetKey: () => isAssetKey,
@@ -84283,6 +84310,7 @@ ${key}` : key;
84283
84310
  clearModels() {
84284
84311
  this.removeModels(this._models.splice(0));
84285
84312
  this._fluidKey = void 0;
84313
+ this._fluidModel = void 0;
84286
84314
  this._isInstanced = false;
84287
84315
  this._instanceCounter = 0;
84288
84316
  }
@@ -84314,11 +84342,14 @@ ${key}` : key;
84314
84342
  return ModelCulling.toLocalMask(worldMask, new Euler().setFromQuaternion(rotation));
84315
84343
  }
84316
84344
  async setCullMask(worldMask) {
84317
- if (this.fluidKind) return;
84318
84345
  worldMask &= 63;
84319
84346
  const replacements = [];
84320
84347
  try {
84321
84348
  for (const model of this._models) {
84349
+ if (model === this._fluidModel) {
84350
+ replacements.push(model);
84351
+ continue;
84352
+ }
84322
84353
  const object = isInstanceReference(model) ? model.instanceable : model;
84323
84354
  const cullMask = this.getModelCullMask(model, worldMask);
84324
84355
  if (cullMask === (object.options.cullMask ?? 0)) {
@@ -84351,7 +84382,10 @@ ${key}` : key;
84351
84382
  return this._state;
84352
84383
  }
84353
84384
  get fluidKind() {
84354
- return getFluidKind(this.blockState.key);
84385
+ return getFluidKind(this.blockState.key, this.state);
84386
+ }
84387
+ get fluidLevel() {
84388
+ return getBlockFluidState(this.blockState.key, this.state)?.level ?? 0;
84355
84389
  }
84356
84390
  /** Refreshes fluid surfaces from relative neighbors; standalone previews use air around the block. */
84357
84391
  async updateFluid(sample) {
@@ -84359,22 +84393,24 @@ ${key}` : key;
84359
84393
  if (!kind) return;
84360
84394
  const { FluidModelObject: FluidModelObject2, sampleFluid: sampleFluid2 } = await Promise.resolve().then(() => (init_FluidModelObject(), FluidModelObject_exports));
84361
84395
  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) ?? {});
84396
+ const surface = sampleFluid2(kind, (x4, y5, z4) => x4 === 0 && y5 === 0 && z4 === 0 ? { fluid: kind, level: this.fluidLevel } : sample?.(x4, y5, z4) ?? {});
84363
84397
  if (this._fluidKey === surface.key) return;
84364
- const key = new AssetKey("minecraft", `${kind}/${surface.key}`, "models", "fluid", "assets", ".json", this.blockState.key.root);
84398
+ const key = new AssetKey("minecraft", `${kind}/${surface.key}`, "models", "fluid", "assets", ".json", this.blockState.key?.root);
84365
84399
  const replacement = await this.scene.addSceneObject(
84366
84400
  { key },
84367
84401
  () => new FluidModelObject2(kind, surface.sample, this.blockState.key, this.options)
84368
84402
  );
84369
- const previous = this._models;
84370
- const matrix = previous.length ? this.getModelMatrix(previous[0]) : new Matrix4().makeTranslation(...this.position.toArray());
84403
+ const previous = this._fluidModel;
84404
+ const matrix = previous ? this.getModelMatrix(previous) : new Matrix4().makeTranslation(...this.position.toArray());
84371
84405
  if (isInstanceReference(replacement)) replacement.setMatrix(matrix);
84372
84406
  else matrix.decompose(replacement.position, replacement.quaternion, replacement.scale);
84373
- this._models = [replacement];
84407
+ this._models = this._models.filter((model) => model !== previous);
84408
+ this._models.push(replacement);
84409
+ this._fluidModel = replacement;
84374
84410
  this._fluidKey = surface.key;
84375
- this._isInstanced = isInstanceReference(replacement);
84411
+ this._isInstanced || (this._isInstanced = isInstanceReference(replacement));
84376
84412
  this._instanceCounter = this._isInstanced ? 1 : 0;
84377
- this.removeModels(previous);
84413
+ if (previous) this.removeModels([previous]);
84378
84414
  this.notifyDirty();
84379
84415
  }
84380
84416
  nextInstance() {
@@ -84391,7 +84427,7 @@ ${key}` : key;
84391
84427
  }
84392
84428
  async recreateModels() {
84393
84429
  this.clearModels();
84394
- if (this.fluidKind) {
84430
+ if (getBlockFluidState(this.blockState.key, this.state)?.renderModel === false) {
84395
84431
  await this.updateFluid(this._fluidSampler);
84396
84432
  return;
84397
84433
  }
@@ -84400,6 +84436,7 @@ ${key}` : key;
84400
84436
  for (let blockStateVariant of variantsToCreate) {
84401
84437
  this._models.push(await this.createVariant(blockStateVariant));
84402
84438
  }
84439
+ await this.updateFluid(this._fluidSampler);
84403
84440
  }
84404
84441
  getSingleVariant(variants) {
84405
84442
  return BlockStateResolver.choose(variants);
@@ -91096,11 +91133,10 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
91096
91133
  const object = section?.getBlockAt(neighbor)?.object;
91097
91134
  return {
91098
91135
  fluid: object?.fluidKind,
91099
- level: Number(object?.state.level ?? 0),
91136
+ level: object?.fluidLevel,
91100
91137
  solid: section?.isOccludingAt(neighbor) ?? false
91101
91138
  };
91102
91139
  });
91103
- continue;
91104
91140
  }
91105
91141
  let mask = 0;
91106
91142
  for (const [face, offset] of CUBE_FACE_OFFSETS.entries()) {
@@ -91332,7 +91368,7 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
91332
91368
  this.data.set(index, void 0);
91333
91369
  return void 0;
91334
91370
  }
91335
- const template = getFluidKind(blockState.key) ? void 0 : await this.sectionModels?.get(blockState, stored.properties);
91371
+ const template = getFluidKind(blockState.key, stored.properties) ? void 0 : await this.sectionModels?.get(blockState, stored.properties);
91336
91372
  if (template) {
91337
91373
  this.sectionBlocks.set(index, { index, template, cullMask: 0 });
91338
91374
  this.meshDirty = true;