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.
@@ -4136,11 +4136,35 @@ var init_ModelObject = __esm({
4136
4136
  }
4137
4137
  });
4138
4138
 
4139
+ // src/model/fluid/fluidBlocks.json
4140
+ var fluidBlocks_default;
4141
+ var init_fluidBlocks = __esm({
4142
+ "src/model/fluid/fluidBlocks.json"() {
4143
+ fluidBlocks_default = {
4144
+ "minecraft:water": { kind: "water", levelProperty: "level", renderModel: false },
4145
+ "minecraft:lava": { kind: "lava", levelProperty: "level", renderModel: false },
4146
+ "minecraft:kelp": { kind: "water", renderModel: true },
4147
+ "minecraft:kelp_plant": { kind: "water", renderModel: true },
4148
+ "minecraft:seagrass": { kind: "water", renderModel: true },
4149
+ "minecraft:tall_seagrass": { kind: "water", renderModel: true },
4150
+ "minecraft:bubble_column": { kind: "water", renderModel: false }
4151
+ };
4152
+ }
4153
+ });
4154
+
4139
4155
  // src/model/fluid/FluidGeometry.ts
4140
4156
  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;
4157
+ function getBlockFluidState(key, state) {
4158
+ const rule = key && fluidRules[key.toNamespacedString()];
4159
+ if (rule) return {
4160
+ kind: rule.kind,
4161
+ level: rule.levelProperty ? Number(state?.[rule.levelProperty] ?? 0) : 0,
4162
+ renderModel: rule.renderModel
4163
+ };
4164
+ return state?.waterlogged === "true" ? { kind: "water", level: 0, renderModel: true } : void 0;
4165
+ }
4166
+ function getFluidKind(key, state) {
4167
+ return getBlockFluidState(key, state)?.kind;
4144
4168
  }
4145
4169
  function ownHeight(sample) {
4146
4170
  const level = sample.level ?? 0;
@@ -4252,9 +4276,11 @@ function createFluidGeometry(kind, sample) {
4252
4276
  geometry.setIndex(indices);
4253
4277
  return geometry;
4254
4278
  }
4255
- var HORIZONTAL, EPSILON;
4279
+ var fluidRules, HORIZONTAL, EPSILON;
4256
4280
  var init_FluidGeometry = __esm({
4257
4281
  "src/model/fluid/FluidGeometry.ts"() {
4282
+ init_fluidBlocks();
4283
+ fluidRules = fluidBlocks_default;
4258
4284
  HORIZONTAL = [[0, -1], [0, 1], [-1, 0], [1, 0]];
4259
4285
  EPSILON = 1e-3;
4260
4286
  }
@@ -4292,7 +4318,7 @@ var init_FluidModelObject = __esm({
4292
4318
  FluidModelObject = class extends ModelObject {
4293
4319
  constructor(kind, sample, origin, options) {
4294
4320
  super({
4295
- key: new AssetKey("minecraft", kind, "models", "fluid", "assets", ".json", origin.root),
4321
+ key: new AssetKey("minecraft", kind, "models", "fluid", "assets", ".json", origin?.root),
4296
4322
  textures: { still: `minecraft:block/${kind}_still`, flow: `minecraft:block/${kind}_flow` },
4297
4323
  elements: []
4298
4324
  }, options);
@@ -5510,6 +5536,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
5510
5536
  clearModels() {
5511
5537
  this.removeModels(this._models.splice(0));
5512
5538
  this._fluidKey = void 0;
5539
+ this._fluidModel = void 0;
5513
5540
  this._isInstanced = false;
5514
5541
  this._instanceCounter = 0;
5515
5542
  }
@@ -5541,11 +5568,14 @@ var _BlockObject = class _BlockObject extends SceneObject {
5541
5568
  return ModelCulling.toLocalMask(worldMask, new Euler7().setFromQuaternion(rotation));
5542
5569
  }
5543
5570
  async setCullMask(worldMask) {
5544
- if (this.fluidKind) return;
5545
5571
  worldMask &= 63;
5546
5572
  const replacements = [];
5547
5573
  try {
5548
5574
  for (const model of this._models) {
5575
+ if (model === this._fluidModel) {
5576
+ replacements.push(model);
5577
+ continue;
5578
+ }
5549
5579
  const object = isInstanceReference(model) ? model.instanceable : model;
5550
5580
  const cullMask = this.getModelCullMask(model, worldMask);
5551
5581
  if (cullMask === (object.options.cullMask ?? 0)) {
@@ -5578,7 +5608,10 @@ var _BlockObject = class _BlockObject extends SceneObject {
5578
5608
  return this._state;
5579
5609
  }
5580
5610
  get fluidKind() {
5581
- return getFluidKind(this.blockState.key);
5611
+ return getFluidKind(this.blockState.key, this.state);
5612
+ }
5613
+ get fluidLevel() {
5614
+ return getBlockFluidState(this.blockState.key, this.state)?.level ?? 0;
5582
5615
  }
5583
5616
  /** Refreshes fluid surfaces from relative neighbors; standalone previews use air around the block. */
5584
5617
  async updateFluid(sample) {
@@ -5586,22 +5619,24 @@ var _BlockObject = class _BlockObject extends SceneObject {
5586
5619
  if (!kind) return;
5587
5620
  const { FluidModelObject: FluidModelObject2, sampleFluid: sampleFluid2 } = await Promise.resolve().then(() => (init_FluidModelObject(), FluidModelObject_exports));
5588
5621
  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) ?? {});
5622
+ const surface = sampleFluid2(kind, (x, y, z) => x === 0 && y === 0 && z === 0 ? { fluid: kind, level: this.fluidLevel } : sample?.(x, y, z) ?? {});
5590
5623
  if (this._fluidKey === surface.key) return;
5591
- const key = new AssetKey("minecraft", `${kind}/${surface.key}`, "models", "fluid", "assets", ".json", this.blockState.key.root);
5624
+ const key = new AssetKey("minecraft", `${kind}/${surface.key}`, "models", "fluid", "assets", ".json", this.blockState.key?.root);
5592
5625
  const replacement = await this.scene.addSceneObject(
5593
5626
  { key },
5594
5627
  () => new FluidModelObject2(kind, surface.sample, this.blockState.key, this.options)
5595
5628
  );
5596
- const previous = this._models;
5597
- const matrix = previous.length ? this.getModelMatrix(previous[0]) : new Matrix45().makeTranslation(...this.position.toArray());
5629
+ const previous = this._fluidModel;
5630
+ const matrix = previous ? this.getModelMatrix(previous) : new Matrix45().makeTranslation(...this.position.toArray());
5598
5631
  if (isInstanceReference(replacement)) replacement.setMatrix(matrix);
5599
5632
  else matrix.decompose(replacement.position, replacement.quaternion, replacement.scale);
5600
- this._models = [replacement];
5633
+ this._models = this._models.filter((model) => model !== previous);
5634
+ this._models.push(replacement);
5635
+ this._fluidModel = replacement;
5601
5636
  this._fluidKey = surface.key;
5602
- this._isInstanced = isInstanceReference(replacement);
5637
+ this._isInstanced || (this._isInstanced = isInstanceReference(replacement));
5603
5638
  this._instanceCounter = this._isInstanced ? 1 : 0;
5604
- this.removeModels(previous);
5639
+ if (previous) this.removeModels([previous]);
5605
5640
  this.notifyDirty();
5606
5641
  }
5607
5642
  nextInstance() {
@@ -5618,7 +5653,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
5618
5653
  }
5619
5654
  async recreateModels() {
5620
5655
  this.clearModels();
5621
- if (this.fluidKind) {
5656
+ if (getBlockFluidState(this.blockState.key, this.state)?.renderModel === false) {
5622
5657
  await this.updateFluid(this._fluidSampler);
5623
5658
  return;
5624
5659
  }
@@ -5627,6 +5662,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
5627
5662
  for (let blockStateVariant of variantsToCreate) {
5628
5663
  this._models.push(await this.createVariant(blockStateVariant));
5629
5664
  }
5665
+ await this.updateFluid(this._fluidSampler);
5630
5666
  }
5631
5667
  getSingleVariant(variants) {
5632
5668
  return BlockStateResolver.choose(variants);
@@ -10454,11 +10490,10 @@ var MineRenderWorld = class {
10454
10490
  const object = section?.getBlockAt(neighbor)?.object;
10455
10491
  return {
10456
10492
  fluid: object?.fluidKind,
10457
- level: Number(object?.state.level ?? 0),
10493
+ level: object?.fluidLevel,
10458
10494
  solid: section?.isOccludingAt(neighbor) ?? false
10459
10495
  };
10460
10496
  });
10461
- continue;
10462
10497
  }
10463
10498
  let mask = 0;
10464
10499
  for (const [face, offset] of CUBE_FACE_OFFSETS.entries()) {
@@ -10687,7 +10722,7 @@ var Chunk = class _Chunk {
10687
10722
  this.data.set(index, void 0);
10688
10723
  return void 0;
10689
10724
  }
10690
- const template = getFluidKind(blockState.key) ? void 0 : await this.sectionModels?.get(blockState, stored.properties);
10725
+ const template = getFluidKind(blockState.key, stored.properties) ? void 0 : await this.sectionModels?.get(blockState, stored.properties);
10691
10726
  if (template) {
10692
10727
  this.sectionBlocks.set(index, { index, template, cullMask: 0 });
10693
10728
  this.meshDirty = true;
@@ -10892,6 +10927,7 @@ export {
10892
10927
  createFluidGeometry,
10893
10928
  createImage,
10894
10929
  estimateBytesUsed,
10930
+ getBlockFluidState,
10895
10931
  getFluidKind,
10896
10932
  interleaveAttributes,
10897
10933
  isAssetKey,