minerender 2.1.0-alpha.39 → 2.1.0-alpha.40
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/browser/index.d.mts +6 -2
- package/dist/browser/index.d.ts +6 -2
- package/dist/browser/index.js +55 -34
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +55 -34
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +55 -34
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +6 -2
- package/dist/node/index.d.ts +6 -2
- package/dist/node/index.js +55 -34
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +55 -34
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -83177,19 +83177,19 @@ ${key}` : key;
|
|
|
83177
83177
|
for (let k4 in defaultState) {
|
|
83178
83178
|
state[k4] = defaultState[k4].default;
|
|
83179
83179
|
}
|
|
83180
|
-
|
|
83180
|
+
this._setState(state);
|
|
83181
83181
|
} else {
|
|
83182
83182
|
if (this.blockState.variants) {
|
|
83183
|
-
|
|
83183
|
+
this._setState(Object.keys(this.blockState.variants)[0]);
|
|
83184
83184
|
} else if (this.blockState.multipart) {
|
|
83185
83185
|
const condition = this.blockState.multipart.map((part) => part.when).find((when) => when !== void 0 && Object.values(when).every((value) => typeof value === "string"));
|
|
83186
83186
|
const state = Object.fromEntries(Object.entries(condition ?? {}).map(([key, value]) => [key, value.split("|")[0]]));
|
|
83187
|
-
|
|
83187
|
+
this._setState(state);
|
|
83188
83188
|
}
|
|
83189
83189
|
}
|
|
83190
|
-
} else {
|
|
83191
|
-
await this.recreateModels();
|
|
83192
83190
|
}
|
|
83191
|
+
if (this.options.initialState !== void 0) this._setState(this.options.initialState);
|
|
83192
|
+
await this.recreateModels();
|
|
83193
83193
|
}
|
|
83194
83194
|
dispose() {
|
|
83195
83195
|
this.clearModels();
|
|
@@ -89740,12 +89740,26 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
89740
89740
|
if (isTripleArray(posOrX)) {
|
|
89741
89741
|
return this.setBlockAt(new Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
|
|
89742
89742
|
}
|
|
89743
|
-
this.
|
|
89744
|
-
|
|
89745
|
-
|
|
89746
|
-
|
|
89743
|
+
return this.placeBlock(posOrX, yOrBlock);
|
|
89744
|
+
}
|
|
89745
|
+
async placeBlock(pos, value, onBlocksChanged) {
|
|
89746
|
+
this.validatePosBounds(pos);
|
|
89747
|
+
const chunk = Chunk.isAir(value) ? this.getChunkAt(pos) : this.getOrCreateChunkAt(pos);
|
|
89748
|
+
return chunk?.setBlockInChunkAt(chunk.worldPosToChunkPos(pos), value, pos, onBlocksChanged);
|
|
89747
89749
|
}
|
|
89748
89750
|
async placeMultiBlock(multiblock, useBatches = true, executor) {
|
|
89751
|
+
const changes = /* @__PURE__ */ new Map();
|
|
89752
|
+
try {
|
|
89753
|
+
await this.placeBlocks(multiblock, useBatches, executor, changes);
|
|
89754
|
+
} finally {
|
|
89755
|
+
await this.updateCulling([...changes.values()]);
|
|
89756
|
+
}
|
|
89757
|
+
}
|
|
89758
|
+
async placeBlocks(multiblock, useBatches, executor, changes) {
|
|
89759
|
+
const collect = async (positions2) => {
|
|
89760
|
+
for (const pos of positions2) changes.set(pos.toArray().join(","), pos);
|
|
89761
|
+
};
|
|
89762
|
+
const place = (block) => this.placeBlock(new Vector3(...block.position), block, collect);
|
|
89749
89763
|
const keys = /* @__PURE__ */ new Map();
|
|
89750
89764
|
for (const block of multiblock.blocks) {
|
|
89751
89765
|
if (Chunk.isAir(block)) continue;
|
|
@@ -89754,7 +89768,7 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
89754
89768
|
}
|
|
89755
89769
|
await BlockStates.getAll(keys.values());
|
|
89756
89770
|
if (!useBatches) {
|
|
89757
|
-
for (const block of multiblock.blocks) await
|
|
89771
|
+
for (const block of multiblock.blocks) await place(block);
|
|
89758
89772
|
return;
|
|
89759
89773
|
}
|
|
89760
89774
|
const positions = /* @__PURE__ */ new Map();
|
|
@@ -89770,7 +89784,7 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
89770
89784
|
for (let i4 = 0; i4 < groups.length; i4 += queue2.batch) {
|
|
89771
89785
|
const results = await Promise.allSettled(groups.slice(i4, i4 + queue2.batch).map(
|
|
89772
89786
|
(blocks) => queue2.submit(async () => {
|
|
89773
|
-
for (const block of blocks) await
|
|
89787
|
+
for (const block of blocks) await place(block);
|
|
89774
89788
|
})
|
|
89775
89789
|
));
|
|
89776
89790
|
const failure = results.find((result) => result.status === "rejected");
|
|
@@ -89782,25 +89796,32 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
89782
89796
|
}
|
|
89783
89797
|
/** Replaces one chunk column's blocks. Entity NBT remains available on the parsed chunk. */
|
|
89784
89798
|
async placeChunk(chunk, executor) {
|
|
89785
|
-
const
|
|
89786
|
-
|
|
89787
|
-
this._chunks.
|
|
89788
|
-
|
|
89789
|
-
|
|
89790
|
-
|
|
89791
|
-
|
|
89792
|
-
for (let index = 0; index < 4096; index++) {
|
|
89793
|
-
const block = section.data.get(index);
|
|
89794
|
-
if (block) blocks.push({
|
|
89795
|
-
...block,
|
|
89796
|
-
position: [
|
|
89797
|
-
chunk.x * 16 + index % 16,
|
|
89798
|
-
section.y * 16 + Math.floor(index / 256),
|
|
89799
|
-
chunk.z * 16 + Math.floor(index / 16) % 16
|
|
89800
|
-
]
|
|
89799
|
+
const changes = /* @__PURE__ */ new Map();
|
|
89800
|
+
try {
|
|
89801
|
+
const previous = [...this._chunks.entries()].filter(([, section]) => section.x === chunk.x && section.z === chunk.z);
|
|
89802
|
+
for (const [key, section] of previous) {
|
|
89803
|
+
this._chunks.delete(key);
|
|
89804
|
+
await section.clear(async (positions) => {
|
|
89805
|
+
for (const pos of positions) changes.set(pos.toArray().join(","), pos);
|
|
89801
89806
|
});
|
|
89802
89807
|
}
|
|
89803
|
-
|
|
89808
|
+
for (const section of chunk.sections) {
|
|
89809
|
+
const blocks = [];
|
|
89810
|
+
for (let index = 0; index < 4096; index++) {
|
|
89811
|
+
const block = section.data.get(index);
|
|
89812
|
+
if (block) blocks.push({
|
|
89813
|
+
...block,
|
|
89814
|
+
position: [
|
|
89815
|
+
chunk.x * 16 + index % 16,
|
|
89816
|
+
section.y * 16 + Math.floor(index / 256),
|
|
89817
|
+
chunk.z * 16 + Math.floor(index / 16) % 16
|
|
89818
|
+
]
|
|
89819
|
+
});
|
|
89820
|
+
}
|
|
89821
|
+
await this.placeBlocks({ size: [16, 16, 16], blocks }, true, executor, changes);
|
|
89822
|
+
}
|
|
89823
|
+
} finally {
|
|
89824
|
+
await this.updateCulling([...changes.values()]);
|
|
89804
89825
|
}
|
|
89805
89826
|
}
|
|
89806
89827
|
async clear() {
|
|
@@ -89923,7 +89944,7 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
89923
89944
|
/**
|
|
89924
89945
|
* Set a block at integer chunk-local coordinates from 0 to 15.
|
|
89925
89946
|
*/
|
|
89926
|
-
async setBlockInChunkAt(pos, block, worldPos) {
|
|
89947
|
+
async setBlockInChunkAt(pos, block, worldPos, onBlocksChanged = this.onBlocksChanged) {
|
|
89927
89948
|
if (typeof worldPos === "undefined") {
|
|
89928
89949
|
worldPos = this.chunkPosToWorldPos(pos);
|
|
89929
89950
|
}
|
|
@@ -89944,9 +89965,9 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
89944
89965
|
object = await this.scene.addBlock(blockState, {
|
|
89945
89966
|
mergeMeshes: true,
|
|
89946
89967
|
instanceMeshes: true,
|
|
89947
|
-
maxInstanceCount: 2e3
|
|
89968
|
+
maxInstanceCount: 2e3,
|
|
89969
|
+
initialState: stored.properties
|
|
89948
89970
|
});
|
|
89949
|
-
if (stored.properties) await object.setState(stored.properties);
|
|
89950
89971
|
object.setPosition(MineRenderWorld.worldToScenePosition(worldPos));
|
|
89951
89972
|
const info = { get block() {
|
|
89952
89973
|
return readBlock();
|
|
@@ -89958,17 +89979,17 @@ uniform float opacity;varying vec2 vUv;void main(){vec4 texel=texture2D(inputBuf
|
|
|
89958
89979
|
object?.removeFromScene();
|
|
89959
89980
|
throw error;
|
|
89960
89981
|
} finally {
|
|
89961
|
-
await
|
|
89982
|
+
await onBlocksChanged?.([worldPos]);
|
|
89962
89983
|
}
|
|
89963
89984
|
}
|
|
89964
|
-
async clear() {
|
|
89985
|
+
async clear(onBlocksChanged = this.onBlocksChanged) {
|
|
89965
89986
|
const positions = [...this.renderedBlocks.keys()].map((index) => this.chunkPosToWorldPos(
|
|
89966
89987
|
new Vector3(index % 16, Math.floor(index / 256), Math.floor(index / 16) % 16)
|
|
89967
89988
|
));
|
|
89968
89989
|
for (const info of this.renderedBlocks.values()) info.object.removeFromScene();
|
|
89969
89990
|
this.renderedBlocks.clear();
|
|
89970
89991
|
this.data.clear();
|
|
89971
|
-
await
|
|
89992
|
+
await onBlocksChanged?.(positions);
|
|
89972
89993
|
}
|
|
89973
89994
|
async dispose() {
|
|
89974
89995
|
await this.clear();
|