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/node/index.mjs
CHANGED
|
@@ -4719,19 +4719,19 @@ var BlockObject = class _BlockObject extends SceneObject {
|
|
|
4719
4719
|
for (let k in defaultState) {
|
|
4720
4720
|
state[k] = defaultState[k].default;
|
|
4721
4721
|
}
|
|
4722
|
-
|
|
4722
|
+
this._setState(state);
|
|
4723
4723
|
} else {
|
|
4724
4724
|
if (this.blockState.variants) {
|
|
4725
|
-
|
|
4725
|
+
this._setState(Object.keys(this.blockState.variants)[0]);
|
|
4726
4726
|
} else if (this.blockState.multipart) {
|
|
4727
4727
|
const condition = this.blockState.multipart.map((part) => part.when).find((when) => when !== void 0 && Object.values(when).every((value) => typeof value === "string"));
|
|
4728
4728
|
const state = Object.fromEntries(Object.entries(condition ?? {}).map(([key, value]) => [key, value.split("|")[0]]));
|
|
4729
|
-
|
|
4729
|
+
this._setState(state);
|
|
4730
4730
|
}
|
|
4731
4731
|
}
|
|
4732
|
-
} else {
|
|
4733
|
-
await this.recreateModels();
|
|
4734
4732
|
}
|
|
4733
|
+
if (this.options.initialState !== void 0) this._setState(this.options.initialState);
|
|
4734
|
+
await this.recreateModels();
|
|
4735
4735
|
}
|
|
4736
4736
|
dispose() {
|
|
4737
4737
|
this.clearModels();
|
|
@@ -9420,12 +9420,26 @@ var MineRenderWorld = class {
|
|
|
9420
9420
|
if (isTripleArray(posOrX)) {
|
|
9421
9421
|
return this.setBlockAt(new Vector311(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
|
|
9422
9422
|
}
|
|
9423
|
-
this.
|
|
9424
|
-
|
|
9425
|
-
|
|
9426
|
-
|
|
9423
|
+
return this.placeBlock(posOrX, yOrBlock);
|
|
9424
|
+
}
|
|
9425
|
+
async placeBlock(pos, value, onBlocksChanged) {
|
|
9426
|
+
this.validatePosBounds(pos);
|
|
9427
|
+
const chunk = Chunk.isAir(value) ? this.getChunkAt(pos) : this.getOrCreateChunkAt(pos);
|
|
9428
|
+
return chunk?.setBlockInChunkAt(chunk.worldPosToChunkPos(pos), value, pos, onBlocksChanged);
|
|
9427
9429
|
}
|
|
9428
9430
|
async placeMultiBlock(multiblock, useBatches = true, executor) {
|
|
9431
|
+
const changes = /* @__PURE__ */ new Map();
|
|
9432
|
+
try {
|
|
9433
|
+
await this.placeBlocks(multiblock, useBatches, executor, changes);
|
|
9434
|
+
} finally {
|
|
9435
|
+
await this.updateCulling([...changes.values()]);
|
|
9436
|
+
}
|
|
9437
|
+
}
|
|
9438
|
+
async placeBlocks(multiblock, useBatches, executor, changes) {
|
|
9439
|
+
const collect = async (positions2) => {
|
|
9440
|
+
for (const pos of positions2) changes.set(pos.toArray().join(","), pos);
|
|
9441
|
+
};
|
|
9442
|
+
const place = (block) => this.placeBlock(new Vector311(...block.position), block, collect);
|
|
9429
9443
|
const keys = /* @__PURE__ */ new Map();
|
|
9430
9444
|
for (const block of multiblock.blocks) {
|
|
9431
9445
|
if (Chunk.isAir(block)) continue;
|
|
@@ -9434,7 +9448,7 @@ var MineRenderWorld = class {
|
|
|
9434
9448
|
}
|
|
9435
9449
|
await BlockStates.getAll(keys.values());
|
|
9436
9450
|
if (!useBatches) {
|
|
9437
|
-
for (const block of multiblock.blocks) await
|
|
9451
|
+
for (const block of multiblock.blocks) await place(block);
|
|
9438
9452
|
return;
|
|
9439
9453
|
}
|
|
9440
9454
|
const positions = /* @__PURE__ */ new Map();
|
|
@@ -9450,7 +9464,7 @@ var MineRenderWorld = class {
|
|
|
9450
9464
|
for (let i = 0; i < groups.length; i += queue.batch) {
|
|
9451
9465
|
const results = await Promise.allSettled(groups.slice(i, i + queue.batch).map(
|
|
9452
9466
|
(blocks) => queue.submit(async () => {
|
|
9453
|
-
for (const block of blocks) await
|
|
9467
|
+
for (const block of blocks) await place(block);
|
|
9454
9468
|
})
|
|
9455
9469
|
));
|
|
9456
9470
|
const failure = results.find((result) => result.status === "rejected");
|
|
@@ -9462,25 +9476,32 @@ var MineRenderWorld = class {
|
|
|
9462
9476
|
}
|
|
9463
9477
|
/** Replaces one chunk column's blocks. Entity NBT remains available on the parsed chunk. */
|
|
9464
9478
|
async placeChunk(chunk, executor) {
|
|
9465
|
-
const
|
|
9466
|
-
|
|
9467
|
-
this._chunks.
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
9471
|
-
|
|
9472
|
-
for (let index = 0; index < 4096; index++) {
|
|
9473
|
-
const block = section.data.get(index);
|
|
9474
|
-
if (block) blocks.push({
|
|
9475
|
-
...block,
|
|
9476
|
-
position: [
|
|
9477
|
-
chunk.x * 16 + index % 16,
|
|
9478
|
-
section.y * 16 + Math.floor(index / 256),
|
|
9479
|
-
chunk.z * 16 + Math.floor(index / 16) % 16
|
|
9480
|
-
]
|
|
9479
|
+
const changes = /* @__PURE__ */ new Map();
|
|
9480
|
+
try {
|
|
9481
|
+
const previous = [...this._chunks.entries()].filter(([, section]) => section.x === chunk.x && section.z === chunk.z);
|
|
9482
|
+
for (const [key, section] of previous) {
|
|
9483
|
+
this._chunks.delete(key);
|
|
9484
|
+
await section.clear(async (positions) => {
|
|
9485
|
+
for (const pos of positions) changes.set(pos.toArray().join(","), pos);
|
|
9481
9486
|
});
|
|
9482
9487
|
}
|
|
9483
|
-
|
|
9488
|
+
for (const section of chunk.sections) {
|
|
9489
|
+
const blocks = [];
|
|
9490
|
+
for (let index = 0; index < 4096; index++) {
|
|
9491
|
+
const block = section.data.get(index);
|
|
9492
|
+
if (block) blocks.push({
|
|
9493
|
+
...block,
|
|
9494
|
+
position: [
|
|
9495
|
+
chunk.x * 16 + index % 16,
|
|
9496
|
+
section.y * 16 + Math.floor(index / 256),
|
|
9497
|
+
chunk.z * 16 + Math.floor(index / 16) % 16
|
|
9498
|
+
]
|
|
9499
|
+
});
|
|
9500
|
+
}
|
|
9501
|
+
await this.placeBlocks({ size: [16, 16, 16], blocks }, true, executor, changes);
|
|
9502
|
+
}
|
|
9503
|
+
} finally {
|
|
9504
|
+
await this.updateCulling([...changes.values()]);
|
|
9484
9505
|
}
|
|
9485
9506
|
}
|
|
9486
9507
|
async clear() {
|
|
@@ -9603,7 +9624,7 @@ var Chunk = class _Chunk {
|
|
|
9603
9624
|
/**
|
|
9604
9625
|
* Set a block at integer chunk-local coordinates from 0 to 15.
|
|
9605
9626
|
*/
|
|
9606
|
-
async setBlockInChunkAt(pos, block, worldPos) {
|
|
9627
|
+
async setBlockInChunkAt(pos, block, worldPos, onBlocksChanged = this.onBlocksChanged) {
|
|
9607
9628
|
if (typeof worldPos === "undefined") {
|
|
9608
9629
|
worldPos = this.chunkPosToWorldPos(pos);
|
|
9609
9630
|
}
|
|
@@ -9624,9 +9645,9 @@ var Chunk = class _Chunk {
|
|
|
9624
9645
|
object = await this.scene.addBlock(blockState, {
|
|
9625
9646
|
mergeMeshes: true,
|
|
9626
9647
|
instanceMeshes: true,
|
|
9627
|
-
maxInstanceCount: 2e3
|
|
9648
|
+
maxInstanceCount: 2e3,
|
|
9649
|
+
initialState: stored.properties
|
|
9628
9650
|
});
|
|
9629
|
-
if (stored.properties) await object.setState(stored.properties);
|
|
9630
9651
|
object.setPosition(MineRenderWorld.worldToScenePosition(worldPos));
|
|
9631
9652
|
const info = { get block() {
|
|
9632
9653
|
return readBlock();
|
|
@@ -9638,17 +9659,17 @@ var Chunk = class _Chunk {
|
|
|
9638
9659
|
object?.removeFromScene();
|
|
9639
9660
|
throw error;
|
|
9640
9661
|
} finally {
|
|
9641
|
-
await
|
|
9662
|
+
await onBlocksChanged?.([worldPos]);
|
|
9642
9663
|
}
|
|
9643
9664
|
}
|
|
9644
|
-
async clear() {
|
|
9665
|
+
async clear(onBlocksChanged = this.onBlocksChanged) {
|
|
9645
9666
|
const positions = [...this.renderedBlocks.keys()].map((index) => this.chunkPosToWorldPos(
|
|
9646
9667
|
new Vector312(index % 16, Math.floor(index / 256), Math.floor(index / 16) % 16)
|
|
9647
9668
|
));
|
|
9648
9669
|
for (const info of this.renderedBlocks.values()) info.object.removeFromScene();
|
|
9649
9670
|
this.renderedBlocks.clear();
|
|
9650
9671
|
this.data.clear();
|
|
9651
|
-
await
|
|
9672
|
+
await onBlocksChanged?.(positions);
|
|
9652
9673
|
}
|
|
9653
9674
|
async dispose() {
|
|
9654
9675
|
await this.clear();
|