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.
@@ -1112,7 +1112,7 @@ declare class SceneObject extends Object3D<Object3DEventMap & {
1112
1112
  declare function isSceneObject(obj: any): obj is SceneObject;
1113
1113
 
1114
1114
  type FluidKind = "water" | "lava";
1115
- declare function getFluidKind(key?: AssetKey): FluidKind | undefined;
1115
+ declare function getFluidKind(key?: AssetKey, state?: BlockStateProperties): FluidKind | undefined;
1116
1116
  interface FluidSample {
1117
1117
  fluid?: FluidKind;
1118
1118
  level?: number;
@@ -1138,6 +1138,7 @@ declare class BlockObject extends SceneObject {
1138
1138
  private _cullMask;
1139
1139
  private _fluidKey?;
1140
1140
  private _fluidSampler?;
1141
+ private _fluidModel?;
1141
1142
  constructor(blockState: BlockState, options?: Partial<BlockObjectOptions>);
1142
1143
  init(): Promise<void>;
1143
1144
  dispose(): void;
@@ -1152,6 +1153,7 @@ declare class BlockObject extends SceneObject {
1152
1153
  [key: string]: string;
1153
1154
  };
1154
1155
  get fluidKind(): FluidKind | undefined;
1156
+ get fluidLevel(): number;
1155
1157
  /** Refreshes fluid surfaces from relative neighbors; standalone previews use air around the block. */
1156
1158
  updateFluid(sample?: FluidSampler): Promise<void>;
1157
1159
  nextInstance(): InstanceReference<SceneObject>;
@@ -1186,7 +1188,7 @@ declare class FluidModelObject extends ModelObject {
1186
1188
  readonly kind: FluidKind;
1187
1189
  private readonly sample;
1188
1190
  private geometry?;
1189
- constructor(kind: FluidKind, sample: FluidSampler, origin: AssetKey, options?: Partial<ModelObjectOptions>);
1191
+ constructor(kind: FluidKind, sample: FluidSampler, origin?: AssetKey, options?: Partial<ModelObjectOptions>);
1190
1192
  protected createMeshes(): void;
1191
1193
  protected applyTextures(): void;
1192
1194
  disposeAndRemoveAllChildren(): void;
@@ -1112,7 +1112,7 @@ declare class SceneObject extends Object3D<Object3DEventMap & {
1112
1112
  declare function isSceneObject(obj: any): obj is SceneObject;
1113
1113
 
1114
1114
  type FluidKind = "water" | "lava";
1115
- declare function getFluidKind(key?: AssetKey): FluidKind | undefined;
1115
+ declare function getFluidKind(key?: AssetKey, state?: BlockStateProperties): FluidKind | undefined;
1116
1116
  interface FluidSample {
1117
1117
  fluid?: FluidKind;
1118
1118
  level?: number;
@@ -1138,6 +1138,7 @@ declare class BlockObject extends SceneObject {
1138
1138
  private _cullMask;
1139
1139
  private _fluidKey?;
1140
1140
  private _fluidSampler?;
1141
+ private _fluidModel?;
1141
1142
  constructor(blockState: BlockState, options?: Partial<BlockObjectOptions>);
1142
1143
  init(): Promise<void>;
1143
1144
  dispose(): void;
@@ -1152,6 +1153,7 @@ declare class BlockObject extends SceneObject {
1152
1153
  [key: string]: string;
1153
1154
  };
1154
1155
  get fluidKind(): FluidKind | undefined;
1156
+ get fluidLevel(): number;
1155
1157
  /** Refreshes fluid surfaces from relative neighbors; standalone previews use air around the block. */
1156
1158
  updateFluid(sample?: FluidSampler): Promise<void>;
1157
1159
  nextInstance(): InstanceReference<SceneObject>;
@@ -1186,7 +1188,7 @@ declare class FluidModelObject extends ModelObject {
1186
1188
  readonly kind: FluidKind;
1187
1189
  private readonly sample;
1188
1190
  private geometry?;
1189
- constructor(kind: FluidKind, sample: FluidSampler, origin: AssetKey, options?: Partial<ModelObjectOptions>);
1191
+ constructor(kind: FluidKind, sample: FluidSampler, origin?: AssetKey, options?: Partial<ModelObjectOptions>);
1190
1192
  protected createMeshes(): void;
1191
1193
  protected applyTextures(): void;
1192
1194
  disposeAndRemoveAllChildren(): void;
@@ -4130,9 +4130,9 @@ var init_ModelObject = __esm({
4130
4130
  });
4131
4131
 
4132
4132
  // src/model/fluid/FluidGeometry.ts
4133
- function getFluidKind(key) {
4134
- if (key?.namespace !== "minecraft" || key.type) return void 0;
4135
- return key.path === "water" || key.path === "lava" ? key.path : void 0;
4133
+ function getFluidKind(key, state) {
4134
+ if (key?.namespace === "minecraft" && !key.type && (key.path === "water" || key.path === "lava")) return key.path;
4135
+ return state?.waterlogged === "true" ? "water" : void 0;
4136
4136
  }
4137
4137
  function ownHeight(sample) {
4138
4138
  const level = sample.level ?? 0;
@@ -4285,7 +4285,7 @@ var init_FluidModelObject = __esm({
4285
4285
  FluidModelObject = class extends ModelObject {
4286
4286
  constructor(kind, sample, origin, options) {
4287
4287
  super({
4288
- key: new AssetKey("minecraft", kind, "models", "fluid", "assets", ".json", origin.root),
4288
+ key: new AssetKey("minecraft", kind, "models", "fluid", "assets", ".json", origin?.root),
4289
4289
  textures: { still: `minecraft:block/${kind}_still`, flow: `minecraft:block/${kind}_flow` },
4290
4290
  elements: []
4291
4291
  }, options);
@@ -5667,6 +5667,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
5667
5667
  clearModels() {
5668
5668
  this.removeModels(this._models.splice(0));
5669
5669
  this._fluidKey = void 0;
5670
+ this._fluidModel = void 0;
5670
5671
  this._isInstanced = false;
5671
5672
  this._instanceCounter = 0;
5672
5673
  }
@@ -5698,11 +5699,14 @@ var _BlockObject = class _BlockObject extends SceneObject {
5698
5699
  return ModelCulling.toLocalMask(worldMask, new import_three22.Euler().setFromQuaternion(rotation));
5699
5700
  }
5700
5701
  async setCullMask(worldMask) {
5701
- if (this.fluidKind) return;
5702
5702
  worldMask &= 63;
5703
5703
  const replacements = [];
5704
5704
  try {
5705
5705
  for (const model of this._models) {
5706
+ if (model === this._fluidModel) {
5707
+ replacements.push(model);
5708
+ continue;
5709
+ }
5706
5710
  const object = isInstanceReference(model) ? model.instanceable : model;
5707
5711
  const cullMask = this.getModelCullMask(model, worldMask);
5708
5712
  if (cullMask === (object.options.cullMask ?? 0)) {
@@ -5735,7 +5739,10 @@ var _BlockObject = class _BlockObject extends SceneObject {
5735
5739
  return this._state;
5736
5740
  }
5737
5741
  get fluidKind() {
5738
- return getFluidKind(this.blockState.key);
5742
+ return getFluidKind(this.blockState.key, this.state);
5743
+ }
5744
+ get fluidLevel() {
5745
+ return getFluidKind(this.blockState.key) ? Number(this.state.level ?? 0) : 0;
5739
5746
  }
5740
5747
  /** Refreshes fluid surfaces from relative neighbors; standalone previews use air around the block. */
5741
5748
  async updateFluid(sample) {
@@ -5743,22 +5750,24 @@ var _BlockObject = class _BlockObject extends SceneObject {
5743
5750
  if (!kind) return;
5744
5751
  const { FluidModelObject: FluidModelObject2, sampleFluid: sampleFluid2 } = await Promise.resolve().then(() => (init_FluidModelObject(), FluidModelObject_exports));
5745
5752
  this._fluidSampler = sample;
5746
- 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) ?? {});
5753
+ const surface = sampleFluid2(kind, (x, y, z) => x === 0 && y === 0 && z === 0 ? { fluid: kind, level: this.fluidLevel } : sample?.(x, y, z) ?? {});
5747
5754
  if (this._fluidKey === surface.key) return;
5748
- const key = new AssetKey("minecraft", `${kind}/${surface.key}`, "models", "fluid", "assets", ".json", this.blockState.key.root);
5755
+ const key = new AssetKey("minecraft", `${kind}/${surface.key}`, "models", "fluid", "assets", ".json", this.blockState.key?.root);
5749
5756
  const replacement = await this.scene.addSceneObject(
5750
5757
  { key },
5751
5758
  () => new FluidModelObject2(kind, surface.sample, this.blockState.key, this.options)
5752
5759
  );
5753
- const previous = this._models;
5754
- const matrix = previous.length ? this.getModelMatrix(previous[0]) : new import_three22.Matrix4().makeTranslation(...this.position.toArray());
5760
+ const previous = this._fluidModel;
5761
+ const matrix = previous ? this.getModelMatrix(previous) : new import_three22.Matrix4().makeTranslation(...this.position.toArray());
5755
5762
  if (isInstanceReference(replacement)) replacement.setMatrix(matrix);
5756
5763
  else matrix.decompose(replacement.position, replacement.quaternion, replacement.scale);
5757
- this._models = [replacement];
5764
+ this._models = this._models.filter((model) => model !== previous);
5765
+ this._models.push(replacement);
5766
+ this._fluidModel = replacement;
5758
5767
  this._fluidKey = surface.key;
5759
- this._isInstanced = isInstanceReference(replacement);
5768
+ this._isInstanced || (this._isInstanced = isInstanceReference(replacement));
5760
5769
  this._instanceCounter = this._isInstanced ? 1 : 0;
5761
- this.removeModels(previous);
5770
+ if (previous) this.removeModels([previous]);
5762
5771
  this.notifyDirty();
5763
5772
  }
5764
5773
  nextInstance() {
@@ -5775,7 +5784,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
5775
5784
  }
5776
5785
  async recreateModels() {
5777
5786
  this.clearModels();
5778
- if (this.fluidKind) {
5787
+ if (getFluidKind(this.blockState.key)) {
5779
5788
  await this.updateFluid(this._fluidSampler);
5780
5789
  return;
5781
5790
  }
@@ -5784,6 +5793,7 @@ var _BlockObject = class _BlockObject extends SceneObject {
5784
5793
  for (let blockStateVariant of variantsToCreate) {
5785
5794
  this._models.push(await this.createVariant(blockStateVariant));
5786
5795
  }
5796
+ await this.updateFluid(this._fluidSampler);
5787
5797
  }
5788
5798
  getSingleVariant(variants) {
5789
5799
  return BlockStateResolver.choose(variants);
@@ -10603,11 +10613,10 @@ var MineRenderWorld = class {
10603
10613
  const object = section?.getBlockAt(neighbor)?.object;
10604
10614
  return {
10605
10615
  fluid: object?.fluidKind,
10606
- level: Number(object?.state.level ?? 0),
10616
+ level: object?.fluidLevel,
10607
10617
  solid: section?.isOccludingAt(neighbor) ?? false
10608
10618
  };
10609
10619
  });
10610
- continue;
10611
10620
  }
10612
10621
  let mask = 0;
10613
10622
  for (const [face, offset] of CUBE_FACE_OFFSETS.entries()) {
@@ -10836,7 +10845,7 @@ var Chunk = class _Chunk {
10836
10845
  this.data.set(index, void 0);
10837
10846
  return void 0;
10838
10847
  }
10839
- const template = getFluidKind(blockState.key) ? void 0 : await this.sectionModels?.get(blockState, stored.properties);
10848
+ const template = getFluidKind(blockState.key, stored.properties) ? void 0 : await this.sectionModels?.get(blockState, stored.properties);
10840
10849
  if (template) {
10841
10850
  this.sectionBlocks.set(index, { index, template, cullMask: 0 });
10842
10851
  this.meshDirty = true;