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.mjs
CHANGED
|
@@ -7193,15 +7193,12 @@ var Skins = class {
|
|
|
7193
7193
|
};
|
|
7194
7194
|
|
|
7195
7195
|
// src/world/Chunk.ts
|
|
7196
|
-
import {
|
|
7196
|
+
import { Vector3 as Vector311 } from "three";
|
|
7197
7197
|
|
|
7198
7198
|
// src/world/MineRenderWorld.ts
|
|
7199
7199
|
import { Vector3 as Vector310 } from "three";
|
|
7200
7200
|
var MineRenderWorld = class {
|
|
7201
7201
|
constructor(scene) {
|
|
7202
|
-
this._size = 4;
|
|
7203
|
-
//TODO: expandable
|
|
7204
|
-
this._blockSize = this._size * 16;
|
|
7205
7202
|
this._chunks = /* @__PURE__ */ new Map();
|
|
7206
7203
|
this.scene = scene;
|
|
7207
7204
|
}
|
|
@@ -7212,12 +7209,8 @@ var MineRenderWorld = class {
|
|
|
7212
7209
|
if (isTripleArray(posOrX)) {
|
|
7213
7210
|
return this.getBlockAt(new Vector310(posOrX[0], posOrX[1], posOrX[2]));
|
|
7214
7211
|
}
|
|
7215
|
-
const chunk = this.getChunkAt(posOrX);
|
|
7216
|
-
if (typeof chunk === "undefined") {
|
|
7217
|
-
return void 0;
|
|
7218
|
-
}
|
|
7219
7212
|
this.validatePosBounds(posOrX);
|
|
7220
|
-
return
|
|
7213
|
+
return this.getChunkAt(posOrX)?.getBlockAt(posOrX);
|
|
7221
7214
|
}
|
|
7222
7215
|
async setBlockAt(posOrX, yOrBlock, z, block) {
|
|
7223
7216
|
if (typeof posOrX == "number") {
|
|
@@ -7227,8 +7220,9 @@ var MineRenderWorld = class {
|
|
|
7227
7220
|
return this.setBlockAt(new Vector310(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
|
|
7228
7221
|
}
|
|
7229
7222
|
this.validatePosBounds(posOrX);
|
|
7230
|
-
const
|
|
7231
|
-
|
|
7223
|
+
const value = yOrBlock;
|
|
7224
|
+
const chunk = Chunk.isAir(value) ? this.getChunkAt(posOrX) : this.getOrCreateChunkAt(posOrX);
|
|
7225
|
+
return chunk?.setBlockAt(posOrX, value);
|
|
7232
7226
|
}
|
|
7233
7227
|
async placeMultiBlock(multiblock, useBatches = true, executor = new BatchedExecutor()) {
|
|
7234
7228
|
const keys = new Set(multiblock.blocks.map((block) => AssetKey.parse("blockstates", block.type)));
|
|
@@ -7249,10 +7243,8 @@ var MineRenderWorld = class {
|
|
|
7249
7243
|
}
|
|
7250
7244
|
}
|
|
7251
7245
|
async clear() {
|
|
7252
|
-
|
|
7253
|
-
|
|
7254
|
-
console.log("dispose chunk", chunk);
|
|
7255
|
-
await chunk?.dispose();
|
|
7246
|
+
for (const chunk of this._chunks.values()) {
|
|
7247
|
+
await chunk.dispose();
|
|
7256
7248
|
}
|
|
7257
7249
|
this._chunks.clear();
|
|
7258
7250
|
}
|
|
@@ -7266,8 +7258,7 @@ var MineRenderWorld = class {
|
|
|
7266
7258
|
return chunk;
|
|
7267
7259
|
}
|
|
7268
7260
|
getChunkAt(pos) {
|
|
7269
|
-
|
|
7270
|
-
return this._chunks[index];
|
|
7261
|
+
return this._chunks.get(this.worldPosToChunkKey(pos));
|
|
7271
7262
|
}
|
|
7272
7263
|
static worldToScenePosition(pos) {
|
|
7273
7264
|
return new Vector310(
|
|
@@ -7283,12 +7274,6 @@ var MineRenderWorld = class {
|
|
|
7283
7274
|
pos.z / 16
|
|
7284
7275
|
);
|
|
7285
7276
|
}
|
|
7286
|
-
worldPosToChunkIndex(pos) {
|
|
7287
|
-
const chunkX = Math.floor(pos.x / 16);
|
|
7288
|
-
const chunkY = Math.floor(pos.y / 16);
|
|
7289
|
-
const chunkZ = Math.floor(pos.z / 16);
|
|
7290
|
-
return chunkZ * this._size * this._size + chunkY * this._size + chunkX;
|
|
7291
|
-
}
|
|
7292
7277
|
worldPosToChunkKey(pos) {
|
|
7293
7278
|
const chunkX = Math.floor(pos.x / 16);
|
|
7294
7279
|
const chunkY = Math.floor(pos.y / 16);
|
|
@@ -7296,12 +7281,9 @@ var MineRenderWorld = class {
|
|
|
7296
7281
|
return `${chunkX}_${chunkY}_${chunkZ}`;
|
|
7297
7282
|
}
|
|
7298
7283
|
validatePosBounds(pos) {
|
|
7299
|
-
if (pos.x
|
|
7300
|
-
|
|
7301
|
-
|
|
7302
|
-
if (pos.x > this._blockSize) throw new Error("x>" + this._blockSize);
|
|
7303
|
-
if (pos.y > this._blockSize) throw new Error("y>" + this._blockSize);
|
|
7304
|
-
if (pos.z > this._blockSize) throw new Error("z>" + this._blockSize);
|
|
7284
|
+
if (![pos.x, pos.y, pos.z].every(Number.isInteger)) {
|
|
7285
|
+
throw new RangeError("Block coordinates must be integers");
|
|
7286
|
+
}
|
|
7305
7287
|
}
|
|
7306
7288
|
};
|
|
7307
7289
|
|
|
@@ -7314,16 +7296,6 @@ var Chunk = class _Chunk {
|
|
|
7314
7296
|
this.x = x;
|
|
7315
7297
|
this.y = y;
|
|
7316
7298
|
this.z = z;
|
|
7317
|
-
let anchor = new Object3D6();
|
|
7318
|
-
this._anchor = anchor;
|
|
7319
|
-
scene.add(anchor);
|
|
7320
|
-
anchor.position.set(this.x * 256 + 128 - 8, this.y * 256 + 128 - 8, this.z * 256 + 128 - 8);
|
|
7321
|
-
addBox3WireframeToObject(
|
|
7322
|
-
new Box32(new Vector311(0, 0, 0), new Vector311(256, 256, 256)),
|
|
7323
|
-
anchor,
|
|
7324
|
-
16776960,
|
|
7325
|
-
4
|
|
7326
|
-
);
|
|
7327
7299
|
}
|
|
7328
7300
|
getBlockAt(posOrX, y, z) {
|
|
7329
7301
|
if (typeof posOrX == "number") {
|
|
@@ -7349,7 +7321,7 @@ var Chunk = class _Chunk {
|
|
|
7349
7321
|
return this.setBlockInChunkAt(pos, block, worldPos);
|
|
7350
7322
|
}
|
|
7351
7323
|
/**
|
|
7352
|
-
* Set block at
|
|
7324
|
+
* Set a block at integer chunk-local coordinates from 0 to 15.
|
|
7353
7325
|
*/
|
|
7354
7326
|
async setBlockInChunkAt(pos, block, worldPos) {
|
|
7355
7327
|
if (typeof worldPos === "undefined") {
|
|
@@ -7362,15 +7334,13 @@ var Chunk = class _Chunk {
|
|
|
7362
7334
|
current.object.removeFromScene();
|
|
7363
7335
|
delete this._blocks[index];
|
|
7364
7336
|
}
|
|
7365
|
-
if (
|
|
7337
|
+
if (!block || _Chunk.isAir(block)) return void 0;
|
|
7366
7338
|
const blockState = await BlockStates.get(AssetKey.parse("blockstates", block.type));
|
|
7367
7339
|
if (blockState) {
|
|
7368
7340
|
const blockObject = await this.scene.addBlock(blockState, {
|
|
7369
7341
|
mergeMeshes: true,
|
|
7370
7342
|
instanceMeshes: true,
|
|
7371
|
-
wireframe: true,
|
|
7372
7343
|
maxInstanceCount: 2e3
|
|
7373
|
-
//TODO: setting this to high kills FPS; increase on demand somehow?
|
|
7374
7344
|
});
|
|
7375
7345
|
if (block.properties) {
|
|
7376
7346
|
await blockObject.setState(block.properties);
|
|
@@ -7386,23 +7356,21 @@ var Chunk = class _Chunk {
|
|
|
7386
7356
|
return void 0;
|
|
7387
7357
|
}
|
|
7388
7358
|
async clear() {
|
|
7389
|
-
|
|
7390
|
-
|
|
7391
|
-
for (let x = 0; x < 16; x++) {
|
|
7392
|
-
for (let z = 0; z < 16; z++) {
|
|
7393
|
-
for (let y = 0; y < 16; y++) {
|
|
7394
|
-
promises.push(this.setBlockInChunkAt(pos.set(x, y, z), void 0));
|
|
7395
|
-
}
|
|
7396
|
-
}
|
|
7397
|
-
}
|
|
7398
|
-
return Promise.all(promises).then((ignored) => {
|
|
7399
|
-
});
|
|
7359
|
+
this._blocks.forEach((block) => block.object.removeFromScene());
|
|
7360
|
+
this._blocks.length = 0;
|
|
7400
7361
|
}
|
|
7401
7362
|
async dispose() {
|
|
7402
7363
|
await this.clear();
|
|
7403
|
-
|
|
7364
|
+
}
|
|
7365
|
+
static isAir(block) {
|
|
7366
|
+
if (typeof block === "undefined" || typeof block.type === "undefined") return true;
|
|
7367
|
+
const key = AssetKey.parse("blockstates", block.type);
|
|
7368
|
+
return key.namespace === "minecraft" && !key.type && ["air", "cave_air", "void_air"].includes(key.path);
|
|
7404
7369
|
}
|
|
7405
7370
|
static chunkPosToBlockIndex(pos) {
|
|
7371
|
+
if ([pos.x, pos.y, pos.z].some((value) => !Number.isInteger(value) || value < 0 || value >= 16)) {
|
|
7372
|
+
throw new RangeError("Block coordinates must be integers from 0 to 15 within a chunk");
|
|
7373
|
+
}
|
|
7406
7374
|
return pos.y * 16 * 16 + pos.z * 16 + pos.x;
|
|
7407
7375
|
}
|
|
7408
7376
|
worldPosToChunkPos(pos) {
|