minerender 2.1.0-alpha.34 → 2.1.0-alpha.35
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 +5 -8
- package/dist/browser/index.d.ts +5 -8
- package/dist/browser/index.js +22 -54
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +23 -55
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +22 -54
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +5 -8
- package/dist/node/index.d.ts +5 -8
- package/dist/node/index.js +22 -54
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +23 -55
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.d.mts
CHANGED
|
@@ -1691,7 +1691,6 @@ declare class Chunk {
|
|
|
1691
1691
|
readonly y: number;
|
|
1692
1692
|
readonly z: number;
|
|
1693
1693
|
private readonly _blocks;
|
|
1694
|
-
private readonly _anchor;
|
|
1695
1694
|
constructor(scene: MineRenderScene, x: number, y: number, z: number);
|
|
1696
1695
|
getBlockAt(x: number, y: number, z: number): Maybe<BlockInfo>;
|
|
1697
1696
|
getBlockAt(pos: Vector3): Maybe<BlockInfo>;
|
|
@@ -1703,11 +1702,12 @@ declare class Chunk {
|
|
|
1703
1702
|
setBlockAt(pos: Vector3, block: Maybe<Block>): Promise<Maybe<BlockInfo>>;
|
|
1704
1703
|
setBlockAt(pos: TripleArray, block: Maybe<Block>): Promise<Maybe<BlockInfo>>;
|
|
1705
1704
|
/**
|
|
1706
|
-
* Set block at
|
|
1705
|
+
* Set a block at integer chunk-local coordinates from 0 to 15.
|
|
1707
1706
|
*/
|
|
1708
1707
|
setBlockInChunkAt(pos: Vector3, block?: Block, worldPos?: Vector3): Promise<Maybe<BlockInfo>>;
|
|
1709
1708
|
clear(): Promise<void>;
|
|
1710
1709
|
dispose(): Promise<void>;
|
|
1710
|
+
static isAir(block: Maybe<Block>): boolean;
|
|
1711
1711
|
static chunkPosToBlockIndex(pos: Vector3): number;
|
|
1712
1712
|
worldPosToChunkPos(pos: Vector3): Vector3;
|
|
1713
1713
|
chunkPosToWorldPos(pos: Vector3): Vector3;
|
|
@@ -1715,23 +1715,20 @@ declare class Chunk {
|
|
|
1715
1715
|
|
|
1716
1716
|
declare class MineRenderWorld {
|
|
1717
1717
|
readonly scene: MineRenderScene;
|
|
1718
|
-
private _size;
|
|
1719
|
-
private _blockSize;
|
|
1720
1718
|
private readonly _chunks;
|
|
1721
1719
|
constructor(scene: MineRenderScene);
|
|
1722
1720
|
getBlockAt(x: number, y: number, z: number): Maybe<BlockInfo>;
|
|
1723
1721
|
getBlockAt(pos: Vector3): Maybe<BlockInfo>;
|
|
1724
1722
|
getBlockAt(pos: TripleArray): Maybe<BlockInfo>;
|
|
1725
|
-
setBlockAt(x: number, y: number, z: number, block: Block): Promise<Maybe<BlockInfo>>;
|
|
1726
|
-
setBlockAt(pos: Vector3, block: Block): Promise<Maybe<BlockInfo>>;
|
|
1727
|
-
setBlockAt(pos: TripleArray, block: Block): Promise<Maybe<BlockInfo>>;
|
|
1723
|
+
setBlockAt(x: number, y: number, z: number, block: Maybe<Block>): Promise<Maybe<BlockInfo>>;
|
|
1724
|
+
setBlockAt(pos: Vector3, block: Maybe<Block>): Promise<Maybe<BlockInfo>>;
|
|
1725
|
+
setBlockAt(pos: TripleArray, block: Maybe<Block>): Promise<Maybe<BlockInfo>>;
|
|
1728
1726
|
placeMultiBlock(multiblock: MultiBlockStructure, useBatches?: boolean, executor?: BatchedExecutor): Promise<void>;
|
|
1729
1727
|
clear(): Promise<void>;
|
|
1730
1728
|
private getOrCreateChunkAt;
|
|
1731
1729
|
getChunkAt(pos: Vector3): Maybe<Chunk>;
|
|
1732
1730
|
static worldToScenePosition(pos: Vector3): Vector3;
|
|
1733
1731
|
static sceneToWorldPosition(pos: Vector3): Vector3;
|
|
1734
|
-
worldPosToChunkIndex(pos: Vector3): number;
|
|
1735
1732
|
worldPosToChunkKey(pos: Vector3): string;
|
|
1736
1733
|
validatePosBounds(pos: Vector3): void;
|
|
1737
1734
|
}
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -1691,7 +1691,6 @@ declare class Chunk {
|
|
|
1691
1691
|
readonly y: number;
|
|
1692
1692
|
readonly z: number;
|
|
1693
1693
|
private readonly _blocks;
|
|
1694
|
-
private readonly _anchor;
|
|
1695
1694
|
constructor(scene: MineRenderScene, x: number, y: number, z: number);
|
|
1696
1695
|
getBlockAt(x: number, y: number, z: number): Maybe<BlockInfo>;
|
|
1697
1696
|
getBlockAt(pos: Vector3): Maybe<BlockInfo>;
|
|
@@ -1703,11 +1702,12 @@ declare class Chunk {
|
|
|
1703
1702
|
setBlockAt(pos: Vector3, block: Maybe<Block>): Promise<Maybe<BlockInfo>>;
|
|
1704
1703
|
setBlockAt(pos: TripleArray, block: Maybe<Block>): Promise<Maybe<BlockInfo>>;
|
|
1705
1704
|
/**
|
|
1706
|
-
* Set block at
|
|
1705
|
+
* Set a block at integer chunk-local coordinates from 0 to 15.
|
|
1707
1706
|
*/
|
|
1708
1707
|
setBlockInChunkAt(pos: Vector3, block?: Block, worldPos?: Vector3): Promise<Maybe<BlockInfo>>;
|
|
1709
1708
|
clear(): Promise<void>;
|
|
1710
1709
|
dispose(): Promise<void>;
|
|
1710
|
+
static isAir(block: Maybe<Block>): boolean;
|
|
1711
1711
|
static chunkPosToBlockIndex(pos: Vector3): number;
|
|
1712
1712
|
worldPosToChunkPos(pos: Vector3): Vector3;
|
|
1713
1713
|
chunkPosToWorldPos(pos: Vector3): Vector3;
|
|
@@ -1715,23 +1715,20 @@ declare class Chunk {
|
|
|
1715
1715
|
|
|
1716
1716
|
declare class MineRenderWorld {
|
|
1717
1717
|
readonly scene: MineRenderScene;
|
|
1718
|
-
private _size;
|
|
1719
|
-
private _blockSize;
|
|
1720
1718
|
private readonly _chunks;
|
|
1721
1719
|
constructor(scene: MineRenderScene);
|
|
1722
1720
|
getBlockAt(x: number, y: number, z: number): Maybe<BlockInfo>;
|
|
1723
1721
|
getBlockAt(pos: Vector3): Maybe<BlockInfo>;
|
|
1724
1722
|
getBlockAt(pos: TripleArray): Maybe<BlockInfo>;
|
|
1725
|
-
setBlockAt(x: number, y: number, z: number, block: Block): Promise<Maybe<BlockInfo>>;
|
|
1726
|
-
setBlockAt(pos: Vector3, block: Block): Promise<Maybe<BlockInfo>>;
|
|
1727
|
-
setBlockAt(pos: TripleArray, block: Block): Promise<Maybe<BlockInfo>>;
|
|
1723
|
+
setBlockAt(x: number, y: number, z: number, block: Maybe<Block>): Promise<Maybe<BlockInfo>>;
|
|
1724
|
+
setBlockAt(pos: Vector3, block: Maybe<Block>): Promise<Maybe<BlockInfo>>;
|
|
1725
|
+
setBlockAt(pos: TripleArray, block: Maybe<Block>): Promise<Maybe<BlockInfo>>;
|
|
1728
1726
|
placeMultiBlock(multiblock: MultiBlockStructure, useBatches?: boolean, executor?: BatchedExecutor): Promise<void>;
|
|
1729
1727
|
clear(): Promise<void>;
|
|
1730
1728
|
private getOrCreateChunkAt;
|
|
1731
1729
|
getChunkAt(pos: Vector3): Maybe<Chunk>;
|
|
1732
1730
|
static worldToScenePosition(pos: Vector3): Vector3;
|
|
1733
1731
|
static sceneToWorldPosition(pos: Vector3): Vector3;
|
|
1734
|
-
worldPosToChunkIndex(pos: Vector3): number;
|
|
1735
1732
|
worldPosToChunkKey(pos: Vector3): string;
|
|
1736
1733
|
validatePosBounds(pos: Vector3): void;
|
|
1737
1734
|
}
|
package/dist/browser/index.js
CHANGED
|
@@ -7339,9 +7339,6 @@ var import_three25 = require("three");
|
|
|
7339
7339
|
var import_three24 = require("three");
|
|
7340
7340
|
var MineRenderWorld = class {
|
|
7341
7341
|
constructor(scene) {
|
|
7342
|
-
this._size = 4;
|
|
7343
|
-
//TODO: expandable
|
|
7344
|
-
this._blockSize = this._size * 16;
|
|
7345
7342
|
this._chunks = /* @__PURE__ */ new Map();
|
|
7346
7343
|
this.scene = scene;
|
|
7347
7344
|
}
|
|
@@ -7352,12 +7349,8 @@ var MineRenderWorld = class {
|
|
|
7352
7349
|
if (isTripleArray(posOrX)) {
|
|
7353
7350
|
return this.getBlockAt(new import_three24.Vector3(posOrX[0], posOrX[1], posOrX[2]));
|
|
7354
7351
|
}
|
|
7355
|
-
const chunk = this.getChunkAt(posOrX);
|
|
7356
|
-
if (typeof chunk === "undefined") {
|
|
7357
|
-
return void 0;
|
|
7358
|
-
}
|
|
7359
7352
|
this.validatePosBounds(posOrX);
|
|
7360
|
-
return
|
|
7353
|
+
return this.getChunkAt(posOrX)?.getBlockAt(posOrX);
|
|
7361
7354
|
}
|
|
7362
7355
|
async setBlockAt(posOrX, yOrBlock, z, block) {
|
|
7363
7356
|
if (typeof posOrX == "number") {
|
|
@@ -7367,8 +7360,9 @@ var MineRenderWorld = class {
|
|
|
7367
7360
|
return this.setBlockAt(new import_three24.Vector3(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
|
|
7368
7361
|
}
|
|
7369
7362
|
this.validatePosBounds(posOrX);
|
|
7370
|
-
const
|
|
7371
|
-
|
|
7363
|
+
const value = yOrBlock;
|
|
7364
|
+
const chunk = Chunk.isAir(value) ? this.getChunkAt(posOrX) : this.getOrCreateChunkAt(posOrX);
|
|
7365
|
+
return chunk?.setBlockAt(posOrX, value);
|
|
7372
7366
|
}
|
|
7373
7367
|
async placeMultiBlock(multiblock, useBatches = true, executor = new BatchedExecutor()) {
|
|
7374
7368
|
const keys = new Set(multiblock.blocks.map((block) => AssetKey.parse("blockstates", block.type)));
|
|
@@ -7389,10 +7383,8 @@ var MineRenderWorld = class {
|
|
|
7389
7383
|
}
|
|
7390
7384
|
}
|
|
7391
7385
|
async clear() {
|
|
7392
|
-
|
|
7393
|
-
|
|
7394
|
-
console.log("dispose chunk", chunk);
|
|
7395
|
-
await chunk?.dispose();
|
|
7386
|
+
for (const chunk of this._chunks.values()) {
|
|
7387
|
+
await chunk.dispose();
|
|
7396
7388
|
}
|
|
7397
7389
|
this._chunks.clear();
|
|
7398
7390
|
}
|
|
@@ -7406,8 +7398,7 @@ var MineRenderWorld = class {
|
|
|
7406
7398
|
return chunk;
|
|
7407
7399
|
}
|
|
7408
7400
|
getChunkAt(pos) {
|
|
7409
|
-
|
|
7410
|
-
return this._chunks[index];
|
|
7401
|
+
return this._chunks.get(this.worldPosToChunkKey(pos));
|
|
7411
7402
|
}
|
|
7412
7403
|
static worldToScenePosition(pos) {
|
|
7413
7404
|
return new import_three24.Vector3(
|
|
@@ -7423,12 +7414,6 @@ var MineRenderWorld = class {
|
|
|
7423
7414
|
pos.z / 16
|
|
7424
7415
|
);
|
|
7425
7416
|
}
|
|
7426
|
-
worldPosToChunkIndex(pos) {
|
|
7427
|
-
const chunkX = Math.floor(pos.x / 16);
|
|
7428
|
-
const chunkY = Math.floor(pos.y / 16);
|
|
7429
|
-
const chunkZ = Math.floor(pos.z / 16);
|
|
7430
|
-
return chunkZ * this._size * this._size + chunkY * this._size + chunkX;
|
|
7431
|
-
}
|
|
7432
7417
|
worldPosToChunkKey(pos) {
|
|
7433
7418
|
const chunkX = Math.floor(pos.x / 16);
|
|
7434
7419
|
const chunkY = Math.floor(pos.y / 16);
|
|
@@ -7436,12 +7421,9 @@ var MineRenderWorld = class {
|
|
|
7436
7421
|
return `${chunkX}_${chunkY}_${chunkZ}`;
|
|
7437
7422
|
}
|
|
7438
7423
|
validatePosBounds(pos) {
|
|
7439
|
-
if (pos.x
|
|
7440
|
-
|
|
7441
|
-
|
|
7442
|
-
if (pos.x > this._blockSize) throw new Error("x>" + this._blockSize);
|
|
7443
|
-
if (pos.y > this._blockSize) throw new Error("y>" + this._blockSize);
|
|
7444
|
-
if (pos.z > this._blockSize) throw new Error("z>" + this._blockSize);
|
|
7424
|
+
if (![pos.x, pos.y, pos.z].every(Number.isInteger)) {
|
|
7425
|
+
throw new RangeError("Block coordinates must be integers");
|
|
7426
|
+
}
|
|
7445
7427
|
}
|
|
7446
7428
|
};
|
|
7447
7429
|
|
|
@@ -7454,16 +7436,6 @@ var Chunk = class _Chunk {
|
|
|
7454
7436
|
this.x = x;
|
|
7455
7437
|
this.y = y;
|
|
7456
7438
|
this.z = z;
|
|
7457
|
-
let anchor = new import_three25.Object3D();
|
|
7458
|
-
this._anchor = anchor;
|
|
7459
|
-
scene.add(anchor);
|
|
7460
|
-
anchor.position.set(this.x * 256 + 128 - 8, this.y * 256 + 128 - 8, this.z * 256 + 128 - 8);
|
|
7461
|
-
addBox3WireframeToObject(
|
|
7462
|
-
new import_three25.Box3(new import_three25.Vector3(0, 0, 0), new import_three25.Vector3(256, 256, 256)),
|
|
7463
|
-
anchor,
|
|
7464
|
-
16776960,
|
|
7465
|
-
4
|
|
7466
|
-
);
|
|
7467
7439
|
}
|
|
7468
7440
|
getBlockAt(posOrX, y, z) {
|
|
7469
7441
|
if (typeof posOrX == "number") {
|
|
@@ -7489,7 +7461,7 @@ var Chunk = class _Chunk {
|
|
|
7489
7461
|
return this.setBlockInChunkAt(pos, block, worldPos);
|
|
7490
7462
|
}
|
|
7491
7463
|
/**
|
|
7492
|
-
* Set block at
|
|
7464
|
+
* Set a block at integer chunk-local coordinates from 0 to 15.
|
|
7493
7465
|
*/
|
|
7494
7466
|
async setBlockInChunkAt(pos, block, worldPos) {
|
|
7495
7467
|
if (typeof worldPos === "undefined") {
|
|
@@ -7502,15 +7474,13 @@ var Chunk = class _Chunk {
|
|
|
7502
7474
|
current.object.removeFromScene();
|
|
7503
7475
|
delete this._blocks[index];
|
|
7504
7476
|
}
|
|
7505
|
-
if (
|
|
7477
|
+
if (!block || _Chunk.isAir(block)) return void 0;
|
|
7506
7478
|
const blockState = await BlockStates.get(AssetKey.parse("blockstates", block.type));
|
|
7507
7479
|
if (blockState) {
|
|
7508
7480
|
const blockObject = await this.scene.addBlock(blockState, {
|
|
7509
7481
|
mergeMeshes: true,
|
|
7510
7482
|
instanceMeshes: true,
|
|
7511
|
-
wireframe: true,
|
|
7512
7483
|
maxInstanceCount: 2e3
|
|
7513
|
-
//TODO: setting this to high kills FPS; increase on demand somehow?
|
|
7514
7484
|
});
|
|
7515
7485
|
if (block.properties) {
|
|
7516
7486
|
await blockObject.setState(block.properties);
|
|
@@ -7526,23 +7496,21 @@ var Chunk = class _Chunk {
|
|
|
7526
7496
|
return void 0;
|
|
7527
7497
|
}
|
|
7528
7498
|
async clear() {
|
|
7529
|
-
|
|
7530
|
-
|
|
7531
|
-
for (let x = 0; x < 16; x++) {
|
|
7532
|
-
for (let z = 0; z < 16; z++) {
|
|
7533
|
-
for (let y = 0; y < 16; y++) {
|
|
7534
|
-
promises.push(this.setBlockInChunkAt(pos.set(x, y, z), void 0));
|
|
7535
|
-
}
|
|
7536
|
-
}
|
|
7537
|
-
}
|
|
7538
|
-
return Promise.all(promises).then((ignored) => {
|
|
7539
|
-
});
|
|
7499
|
+
this._blocks.forEach((block) => block.object.removeFromScene());
|
|
7500
|
+
this._blocks.length = 0;
|
|
7540
7501
|
}
|
|
7541
7502
|
async dispose() {
|
|
7542
7503
|
await this.clear();
|
|
7543
|
-
|
|
7504
|
+
}
|
|
7505
|
+
static isAir(block) {
|
|
7506
|
+
if (typeof block === "undefined" || typeof block.type === "undefined") return true;
|
|
7507
|
+
const key = AssetKey.parse("blockstates", block.type);
|
|
7508
|
+
return key.namespace === "minecraft" && !key.type && ["air", "cave_air", "void_air"].includes(key.path);
|
|
7544
7509
|
}
|
|
7545
7510
|
static chunkPosToBlockIndex(pos) {
|
|
7511
|
+
if ([pos.x, pos.y, pos.z].some((value) => !Number.isInteger(value) || value < 0 || value >= 16)) {
|
|
7512
|
+
throw new RangeError("Block coordinates must be integers from 0 to 15 within a chunk");
|
|
7513
|
+
}
|
|
7546
7514
|
return pos.y * 16 * 16 + pos.z * 16 + pos.x;
|
|
7547
7515
|
}
|
|
7548
7516
|
worldPosToChunkPos(pos) {
|