minerender 2.1.0-alpha.36 → 2.1.0-alpha.37
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 +20 -3
- package/dist/browser/index.d.ts +20 -3
- package/dist/browser/index.js +121 -36
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +121 -36
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +562 -474
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +20 -3
- package/dist/node/index.d.ts +20 -3
- package/dist/node/index.js +122 -36
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +121 -36
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.mjs
CHANGED
|
@@ -32,8 +32,8 @@ var require_dist = __commonJS({
|
|
|
32
32
|
__assign = Object.assign || function(t) {
|
|
33
33
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
34
34
|
s = arguments[i];
|
|
35
|
-
for (var
|
|
36
|
-
t[
|
|
35
|
+
for (var p11 in s) if (Object.prototype.hasOwnProperty.call(s, p11))
|
|
36
|
+
t[p11] = s[p11];
|
|
37
37
|
}
|
|
38
38
|
return t;
|
|
39
39
|
};
|
|
@@ -1172,12 +1172,12 @@ var AssetKey = class _AssetKey extends BasicAssetKey {
|
|
|
1172
1172
|
return a.join("/");
|
|
1173
1173
|
}
|
|
1174
1174
|
getFullPath() {
|
|
1175
|
-
let
|
|
1175
|
+
let p11 = [];
|
|
1176
1176
|
if (this.type) {
|
|
1177
|
-
|
|
1177
|
+
p11.push(this.type);
|
|
1178
1178
|
}
|
|
1179
|
-
|
|
1180
|
-
return
|
|
1179
|
+
p11.push(this.path);
|
|
1180
|
+
return p11.join("/");
|
|
1181
1181
|
}
|
|
1182
1182
|
toNamespacedString() {
|
|
1183
1183
|
return this.namespace + ":" + this.getFullPath();
|
|
@@ -1264,7 +1264,7 @@ var ModelMerger = class {
|
|
|
1264
1264
|
merged.display = { ...inheritedDisplay, ...DisplayTransforms.withHandFallbacks(source.display) };
|
|
1265
1265
|
}
|
|
1266
1266
|
}
|
|
1267
|
-
merged.hierarchy = models.map((m) => m.parent).filter((
|
|
1267
|
+
merged.hierarchy = models.map((m) => m.parent).filter((p11) => `${p11}`);
|
|
1268
1268
|
merged.hierarchy.push(`${merged.parent}`);
|
|
1269
1269
|
return merged;
|
|
1270
1270
|
}
|
|
@@ -7241,6 +7241,87 @@ var Skins = class {
|
|
|
7241
7241
|
// src/world/Chunk.ts
|
|
7242
7242
|
import { Vector3 as Vector311 } from "three";
|
|
7243
7243
|
|
|
7244
|
+
// src/world/ChunkData.ts
|
|
7245
|
+
var ChunkData = class _ChunkData {
|
|
7246
|
+
constructor() {
|
|
7247
|
+
this.indices = new Uint16Array(4096);
|
|
7248
|
+
this.palette = [void 0];
|
|
7249
|
+
this.paletteIds = /* @__PURE__ */ new Map();
|
|
7250
|
+
this.freeIds = [];
|
|
7251
|
+
this.nbt = /* @__PURE__ */ new Map();
|
|
7252
|
+
}
|
|
7253
|
+
get(index) {
|
|
7254
|
+
_ChunkData.validateIndex(index);
|
|
7255
|
+
const entry = this.palette[this.indices[index]];
|
|
7256
|
+
return entry ? _ChunkData.copyBlock(entry.state, this.nbt.get(index)) : void 0;
|
|
7257
|
+
}
|
|
7258
|
+
snapshot(index) {
|
|
7259
|
+
_ChunkData.validateIndex(index);
|
|
7260
|
+
const entry = this.palette[this.indices[index]];
|
|
7261
|
+
return entry ? _ChunkData.copyBlock.bind(void 0, entry.state, this.nbt.get(index)) : void 0;
|
|
7262
|
+
}
|
|
7263
|
+
set(index, block) {
|
|
7264
|
+
_ChunkData.validateIndex(index);
|
|
7265
|
+
let state;
|
|
7266
|
+
let key;
|
|
7267
|
+
let nbt;
|
|
7268
|
+
if (block && !_ChunkData.isAir(block)) {
|
|
7269
|
+
const type = AssetKey.parse("blockstates", block.type).toNamespacedString();
|
|
7270
|
+
const properties = Object.fromEntries(Object.keys(block.properties ?? {}).sort().map((name) => [name, block.properties[name]]));
|
|
7271
|
+
state = Object.freeze(Object.keys(properties).length ? { type, properties: Object.freeze(properties) } : { type });
|
|
7272
|
+
key = JSON.stringify([type, properties]);
|
|
7273
|
+
if (block.nbt !== void 0) nbt = structuredClone(block.nbt);
|
|
7274
|
+
}
|
|
7275
|
+
const previousId = this.indices[index];
|
|
7276
|
+
if (previousId !== 0) {
|
|
7277
|
+
const previous = this.palette[previousId];
|
|
7278
|
+
if (--previous.references === 0) {
|
|
7279
|
+
this.paletteIds.delete(previous.key);
|
|
7280
|
+
this.palette[previousId] = void 0;
|
|
7281
|
+
this.freeIds.push(previousId);
|
|
7282
|
+
}
|
|
7283
|
+
}
|
|
7284
|
+
let id = 0;
|
|
7285
|
+
if (state && key !== void 0) {
|
|
7286
|
+
const existingId = this.paletteIds.get(key);
|
|
7287
|
+
if (existingId !== void 0) {
|
|
7288
|
+
id = existingId;
|
|
7289
|
+
this.palette[id].references++;
|
|
7290
|
+
} else {
|
|
7291
|
+
id = this.freeIds.pop() ?? this.palette.length;
|
|
7292
|
+
this.palette[id] = { key, state, references: 1 };
|
|
7293
|
+
this.paletteIds.set(key, id);
|
|
7294
|
+
}
|
|
7295
|
+
}
|
|
7296
|
+
this.indices[index] = id;
|
|
7297
|
+
if (nbt !== void 0) this.nbt.set(index, nbt);
|
|
7298
|
+
else this.nbt.delete(index);
|
|
7299
|
+
}
|
|
7300
|
+
clear() {
|
|
7301
|
+
this.indices.fill(0);
|
|
7302
|
+
this.palette.length = 1;
|
|
7303
|
+
this.paletteIds.clear();
|
|
7304
|
+
this.freeIds.length = 0;
|
|
7305
|
+
this.nbt.clear();
|
|
7306
|
+
}
|
|
7307
|
+
static isAir(block) {
|
|
7308
|
+
if (typeof block === "undefined" || typeof block.type === "undefined") return true;
|
|
7309
|
+
const key = AssetKey.parse("blockstates", block.type);
|
|
7310
|
+
return key.namespace === "minecraft" && !key.type && ["air", "cave_air", "void_air"].includes(key.path);
|
|
7311
|
+
}
|
|
7312
|
+
static copyBlock(state, nbt) {
|
|
7313
|
+
const block = { type: state.type };
|
|
7314
|
+
if (state.properties) block.properties = { ...state.properties };
|
|
7315
|
+
if (nbt !== void 0) block.nbt = structuredClone(nbt);
|
|
7316
|
+
return block;
|
|
7317
|
+
}
|
|
7318
|
+
static validateIndex(index) {
|
|
7319
|
+
if (!Number.isInteger(index) || index < 0 || index >= 4096) {
|
|
7320
|
+
throw new RangeError("Block index must be an integer from 0 to 4095");
|
|
7321
|
+
}
|
|
7322
|
+
}
|
|
7323
|
+
};
|
|
7324
|
+
|
|
7244
7325
|
// src/world/MineRenderWorld.ts
|
|
7245
7326
|
import { Vector3 as Vector310 } from "three";
|
|
7246
7327
|
var MineRenderWorld = class {
|
|
@@ -7351,10 +7432,10 @@ var MineRenderWorld = class {
|
|
|
7351
7432
|
};
|
|
7352
7433
|
|
|
7353
7434
|
// src/world/Chunk.ts
|
|
7354
|
-
var p11 = prefix("Chunk");
|
|
7355
7435
|
var Chunk = class _Chunk {
|
|
7356
7436
|
constructor(scene, x, y, z) {
|
|
7357
|
-
this.
|
|
7437
|
+
this.data = new ChunkData();
|
|
7438
|
+
this.renderedBlocks = /* @__PURE__ */ new Map();
|
|
7358
7439
|
this.scene = scene;
|
|
7359
7440
|
this.x = x;
|
|
7360
7441
|
this.y = y;
|
|
@@ -7369,7 +7450,7 @@ var Chunk = class _Chunk {
|
|
|
7369
7450
|
}
|
|
7370
7451
|
const pos = this.worldPosToChunkPos(posOrX);
|
|
7371
7452
|
const index = _Chunk.chunkPosToBlockIndex(pos);
|
|
7372
|
-
return this.
|
|
7453
|
+
return this.renderedBlocks.get(index);
|
|
7373
7454
|
}
|
|
7374
7455
|
async setBlockAt(posOrX, yOrBlock, z, block) {
|
|
7375
7456
|
if (typeof posOrX == "number") {
|
|
@@ -7391,44 +7472,47 @@ var Chunk = class _Chunk {
|
|
|
7391
7472
|
worldPos = this.chunkPosToWorldPos(pos);
|
|
7392
7473
|
}
|
|
7393
7474
|
const index = _Chunk.chunkPosToBlockIndex(pos);
|
|
7394
|
-
|
|
7395
|
-
|
|
7396
|
-
|
|
7397
|
-
|
|
7398
|
-
|
|
7399
|
-
|
|
7400
|
-
|
|
7401
|
-
|
|
7402
|
-
|
|
7403
|
-
|
|
7475
|
+
this.data.set(index, block);
|
|
7476
|
+
const readBlock = this.data.snapshot(index);
|
|
7477
|
+
this.renderedBlocks.get(index)?.object.removeFromScene();
|
|
7478
|
+
this.renderedBlocks.delete(index);
|
|
7479
|
+
if (!readBlock) return void 0;
|
|
7480
|
+
const stored = readBlock();
|
|
7481
|
+
let object;
|
|
7482
|
+
try {
|
|
7483
|
+
const blockState = await BlockStates.get(AssetKey.parse("blockstates", stored.type));
|
|
7484
|
+
if (!blockState) {
|
|
7485
|
+
this.data.set(index, void 0);
|
|
7486
|
+
return void 0;
|
|
7487
|
+
}
|
|
7488
|
+
object = await this.scene.addBlock(blockState, {
|
|
7404
7489
|
mergeMeshes: true,
|
|
7405
7490
|
instanceMeshes: true,
|
|
7406
7491
|
maxInstanceCount: 2e3
|
|
7407
7492
|
});
|
|
7408
|
-
if (
|
|
7409
|
-
|
|
7410
|
-
|
|
7411
|
-
|
|
7412
|
-
|
|
7413
|
-
this.
|
|
7414
|
-
|
|
7415
|
-
|
|
7416
|
-
|
|
7417
|
-
|
|
7493
|
+
if (stored.properties) await object.setState(stored.properties);
|
|
7494
|
+
object.setPosition(MineRenderWorld.worldToScenePosition(worldPos));
|
|
7495
|
+
const info = { get block() {
|
|
7496
|
+
return readBlock();
|
|
7497
|
+
}, object };
|
|
7498
|
+
this.renderedBlocks.set(index, info);
|
|
7499
|
+
return info;
|
|
7500
|
+
} catch (error) {
|
|
7501
|
+
this.data.set(index, void 0);
|
|
7502
|
+
object?.removeFromScene();
|
|
7503
|
+
throw error;
|
|
7418
7504
|
}
|
|
7419
|
-
return void 0;
|
|
7420
7505
|
}
|
|
7421
7506
|
async clear() {
|
|
7422
|
-
this.
|
|
7423
|
-
this.
|
|
7507
|
+
for (const info of this.renderedBlocks.values()) info.object.removeFromScene();
|
|
7508
|
+
this.renderedBlocks.clear();
|
|
7509
|
+
this.data.clear();
|
|
7424
7510
|
}
|
|
7425
7511
|
async dispose() {
|
|
7426
7512
|
await this.clear();
|
|
7427
7513
|
}
|
|
7428
7514
|
static isAir(block) {
|
|
7429
|
-
|
|
7430
|
-
const key = AssetKey.parse("blockstates", block.type);
|
|
7431
|
-
return key.namespace === "minecraft" && !key.type && ["air", "cave_air", "void_air"].includes(key.path);
|
|
7515
|
+
return ChunkData.isAir(block);
|
|
7432
7516
|
}
|
|
7433
7517
|
static chunkPosToBlockIndex(pos) {
|
|
7434
7518
|
if ([pos.x, pos.y, pos.z].some((value) => !Number.isInteger(value) || value < 0 || value >= 16)) {
|
|
@@ -7473,6 +7557,7 @@ export {
|
|
|
7473
7557
|
Caching,
|
|
7474
7558
|
CanvasImage,
|
|
7475
7559
|
Chunk,
|
|
7560
|
+
ChunkData,
|
|
7476
7561
|
CubeFace,
|
|
7477
7562
|
CubeFaceIndex,
|
|
7478
7563
|
DEFAULT_ELEMENTS,
|