minerender 2.1.0-alpha.122 → 2.1.0-alpha.123
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 +23 -1
- package/dist/browser/index.d.ts +23 -1
- package/dist/browser/index.js +126 -75
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.mjs +113 -62
- package/dist/browser/index.mjs.map +1 -1
- package/dist/bundle.js +85 -26
- package/dist/bundle.js.map +1 -1
- package/dist/node/index.d.mts +23 -1
- package/dist/node/index.d.ts +23 -1
- package/dist/node/index.js +126 -75
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +113 -62
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.mjs
CHANGED
|
@@ -17228,14 +17228,14 @@ var AnvilWorldSource = class {
|
|
|
17228
17228
|
};
|
|
17229
17229
|
|
|
17230
17230
|
// src/world/Chunk.ts
|
|
17231
|
-
import { Color as Color13,
|
|
17231
|
+
import { Color as Color13, Vector3 as Vector320 } from "three";
|
|
17232
17232
|
init_BlockStates();
|
|
17233
17233
|
init_AssetKey();
|
|
17234
17234
|
|
|
17235
17235
|
// src/world/MineRenderWorld.ts
|
|
17236
17236
|
init_Model();
|
|
17237
17237
|
init_util();
|
|
17238
|
-
import { Vector3 as
|
|
17238
|
+
import { Vector3 as Vector319 } from "three";
|
|
17239
17239
|
init_AssetKey();
|
|
17240
17240
|
init_BlockStates();
|
|
17241
17241
|
init_CubeFace();
|
|
@@ -17498,11 +17498,74 @@ function resolveSavedEntity(entity) {
|
|
|
17498
17498
|
|
|
17499
17499
|
// src/world/_entities/WorldEntities.ts
|
|
17500
17500
|
init_BannerPatterns();
|
|
17501
|
+
import { Vector3 as Vector318 } from "three";
|
|
17502
|
+
|
|
17503
|
+
// src/world/_picking/Picking.ts
|
|
17504
|
+
init_three();
|
|
17505
|
+
import { Matrix3 as Matrix33, Matrix4 as Matrix413 } from "three";
|
|
17506
|
+
function pickableMeshes(root, scene, raycaster) {
|
|
17507
|
+
const result = [];
|
|
17508
|
+
let attached = false;
|
|
17509
|
+
for (let parent = root; parent; parent = parent.parent) {
|
|
17510
|
+
if (!parent.visible) return result;
|
|
17511
|
+
if (parent === scene) attached = true;
|
|
17512
|
+
}
|
|
17513
|
+
if (!attached) return result;
|
|
17514
|
+
root.updateWorldMatrix(true, true);
|
|
17515
|
+
root.traverseVisible((object4) => {
|
|
17516
|
+
if (isMesh(object4) && raycaster.layers.test(object4.layers)) result.push(object4);
|
|
17517
|
+
});
|
|
17518
|
+
return result;
|
|
17519
|
+
}
|
|
17520
|
+
function visibleHits(raycaster, meshes) {
|
|
17521
|
+
return raycaster.intersectObjects(meshes, false).filter((hit) => {
|
|
17522
|
+
if (!hit.face) return false;
|
|
17523
|
+
const mesh = hit.object;
|
|
17524
|
+
const material = Array.isArray(mesh.material) ? mesh.material[hit.face.materialIndex] : mesh.material;
|
|
17525
|
+
return material?.visible;
|
|
17526
|
+
});
|
|
17527
|
+
}
|
|
17528
|
+
function hitNormal(hit) {
|
|
17529
|
+
const mesh = hit.object;
|
|
17530
|
+
const matrix = mesh.matrixWorld.clone();
|
|
17531
|
+
if (isInstancedMesh(mesh) && hit.instanceId !== void 0) {
|
|
17532
|
+
const instance = new Matrix413();
|
|
17533
|
+
mesh.getMatrixAt(hit.instanceId, instance);
|
|
17534
|
+
matrix.multiply(instance);
|
|
17535
|
+
}
|
|
17536
|
+
return hit.face.normal.clone().applyNormalMatrix(new Matrix33().getNormalMatrix(matrix));
|
|
17537
|
+
}
|
|
17538
|
+
|
|
17539
|
+
// src/world/_entities/WorldEntities.ts
|
|
17501
17540
|
var WorldEntities = class {
|
|
17502
17541
|
constructor(scene) {
|
|
17503
17542
|
this.scene = scene;
|
|
17504
17543
|
this.columns = /* @__PURE__ */ new Map();
|
|
17505
17544
|
}
|
|
17545
|
+
/** Finds the nearest visible triangle belonging to an entity owned by this world. */
|
|
17546
|
+
raycast(raycaster) {
|
|
17547
|
+
const owners = /* @__PURE__ */ new Map();
|
|
17548
|
+
for (const column of this.columns.values()) {
|
|
17549
|
+
for (const [object4, placement] of column) {
|
|
17550
|
+
for (const mesh of pickableMeshes(object4, this.scene, raycaster)) {
|
|
17551
|
+
owners.set(mesh, { object: object4, ...placement });
|
|
17552
|
+
}
|
|
17553
|
+
}
|
|
17554
|
+
}
|
|
17555
|
+
for (const hit of visibleHits(raycaster, [...owners.keys()])) {
|
|
17556
|
+
const mesh = hit.object;
|
|
17557
|
+
const owner = owners.get(mesh);
|
|
17558
|
+
return {
|
|
17559
|
+
type: owner.type,
|
|
17560
|
+
position: new Vector318(...owner.position),
|
|
17561
|
+
object: owner.object,
|
|
17562
|
+
point: hit.point.clone(),
|
|
17563
|
+
normal: hitNormal(hit),
|
|
17564
|
+
distance: hit.distance
|
|
17565
|
+
};
|
|
17566
|
+
}
|
|
17567
|
+
return void 0;
|
|
17568
|
+
}
|
|
17506
17569
|
/** Captures column ownership before asynchronous block or asset loading starts. */
|
|
17507
17570
|
prepare(entities = [], column) {
|
|
17508
17571
|
const placements = entities.flatMap((entity) => {
|
|
@@ -17511,7 +17574,7 @@ var WorldEntities = class {
|
|
|
17511
17574
|
const position = [...entity.position];
|
|
17512
17575
|
const key = column?.join(",") ?? `${Math.floor(position[0] / 16)},${Math.floor(position[2] / 16)}`;
|
|
17513
17576
|
let owner = this.columns.get(key);
|
|
17514
|
-
if (!owner) this.columns.set(key, owner = /* @__PURE__ */ new
|
|
17577
|
+
if (!owner) this.columns.set(key, owner = /* @__PURE__ */ new Map());
|
|
17515
17578
|
return [{ ...resolved, position, column: key, owner }];
|
|
17516
17579
|
});
|
|
17517
17580
|
return async () => {
|
|
@@ -17537,7 +17600,7 @@ var WorldEntities = class {
|
|
|
17537
17600
|
object4.rotation.y = placement.yaw;
|
|
17538
17601
|
await object4.init();
|
|
17539
17602
|
if (!current()) return;
|
|
17540
|
-
placement.owner.
|
|
17603
|
+
placement.owner.set(object4, { type: placement.key.toNamespacedString(), position: placement.position });
|
|
17541
17604
|
this.scene.add(object4);
|
|
17542
17605
|
} catch (error) {
|
|
17543
17606
|
console.warn(`Could not draw saved entity ${placement.key.toNamespacedString()}, skipping it`, error);
|
|
@@ -17552,7 +17615,7 @@ var WorldEntities = class {
|
|
|
17552
17615
|
const objects = this.columns.get(key);
|
|
17553
17616
|
this.columns.delete(key);
|
|
17554
17617
|
if (!objects) return;
|
|
17555
|
-
for (const object4 of objects) {
|
|
17618
|
+
for (const object4 of objects.keys()) {
|
|
17556
17619
|
object4.removeFromScene();
|
|
17557
17620
|
object4.dispose();
|
|
17558
17621
|
}
|
|
@@ -17620,6 +17683,14 @@ var MineRenderWorld = class {
|
|
|
17620
17683
|
raycast(raycaster) {
|
|
17621
17684
|
return Chunk.raycast(this._chunks.values(), raycaster);
|
|
17622
17685
|
}
|
|
17686
|
+
/**
|
|
17687
|
+
* Returns the nearest visible mob geometry hit when renderEntities is enabled.
|
|
17688
|
+
* Respects layers and near/far; compare its distance with raycast() to account for blocks.
|
|
17689
|
+
* Texture alpha does not change triangle intersections.
|
|
17690
|
+
*/
|
|
17691
|
+
raycastEntities(raycaster) {
|
|
17692
|
+
return this.entities?.raycast(raycaster);
|
|
17693
|
+
}
|
|
17623
17694
|
/** Whether neighboring opaque cubes shade block-face corners. Defaults to false. */
|
|
17624
17695
|
get ambientOcclusion() {
|
|
17625
17696
|
return this._ambientOcclusion;
|
|
@@ -17640,25 +17711,25 @@ var MineRenderWorld = class {
|
|
|
17640
17711
|
}
|
|
17641
17712
|
getBlockAt(posOrX, y, z) {
|
|
17642
17713
|
if (typeof posOrX == "number") {
|
|
17643
|
-
return this.getBlockAt(new
|
|
17714
|
+
return this.getBlockAt(new Vector319(posOrX, y, z));
|
|
17644
17715
|
}
|
|
17645
17716
|
if (isTripleArray(posOrX)) {
|
|
17646
|
-
return this.getBlockAt(new
|
|
17717
|
+
return this.getBlockAt(new Vector319(posOrX[0], posOrX[1], posOrX[2]));
|
|
17647
17718
|
}
|
|
17648
17719
|
this.validatePosBounds(posOrX);
|
|
17649
17720
|
return this.getChunkAt(posOrX)?.getBlockAt(posOrX);
|
|
17650
17721
|
}
|
|
17651
17722
|
getBiomeAt(posOrX, y, z) {
|
|
17652
|
-
if (typeof posOrX === "number") return this.getBiomeAt(new
|
|
17653
|
-
if (isTripleArray(posOrX)) return this.getBiomeAt(new
|
|
17723
|
+
if (typeof posOrX === "number") return this.getBiomeAt(new Vector319(posOrX, y, z));
|
|
17724
|
+
if (isTripleArray(posOrX)) return this.getBiomeAt(new Vector319(...posOrX));
|
|
17654
17725
|
this.validatePosBounds(posOrX);
|
|
17655
17726
|
const cx = Math.floor(posOrX.x / 16), cy = Math.floor(posOrX.y / 16), cz = Math.floor(posOrX.z / 16);
|
|
17656
17727
|
const lx = posOrX.x - cx * 16, ly = posOrX.y - cy * 16, lz = posOrX.z - cz * 16;
|
|
17657
17728
|
return this.biomes.get(`${cx}_${cz}`)?.get(cy)?.[Math.floor(lx / 4) + Math.floor(lz / 4) * 4 + Math.floor(ly / 4) * 16];
|
|
17658
17729
|
}
|
|
17659
17730
|
getLightAt(posOrX, y, z) {
|
|
17660
|
-
if (typeof posOrX === "number") return this.getLightAt(new
|
|
17661
|
-
if (isTripleArray(posOrX)) return this.getLightAt(new
|
|
17731
|
+
if (typeof posOrX === "number") return this.getLightAt(new Vector319(posOrX, y, z));
|
|
17732
|
+
if (isTripleArray(posOrX)) return this.getLightAt(new Vector319(...posOrX));
|
|
17662
17733
|
this.validatePosBounds(posOrX);
|
|
17663
17734
|
const { x, y: py, z: pz } = posOrX;
|
|
17664
17735
|
const cx = Math.floor(x / 16), cy = Math.floor(py / 16), cz = Math.floor(pz / 16);
|
|
@@ -17676,10 +17747,10 @@ var MineRenderWorld = class {
|
|
|
17676
17747
|
}
|
|
17677
17748
|
async setBlockAt(posOrX, yOrBlock, z, block) {
|
|
17678
17749
|
if (typeof posOrX == "number") {
|
|
17679
|
-
return this.setBlockAt(new
|
|
17750
|
+
return this.setBlockAt(new Vector319(posOrX, yOrBlock, z), block);
|
|
17680
17751
|
}
|
|
17681
17752
|
if (isTripleArray(posOrX)) {
|
|
17682
|
-
return this.setBlockAt(new
|
|
17753
|
+
return this.setBlockAt(new Vector319(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
|
|
17683
17754
|
}
|
|
17684
17755
|
return this.placeBlock(posOrX, yOrBlock);
|
|
17685
17756
|
}
|
|
@@ -17690,10 +17761,10 @@ var MineRenderWorld = class {
|
|
|
17690
17761
|
}
|
|
17691
17762
|
async setBlockVisibleAt(posOrX, yOrVisible, z, visible) {
|
|
17692
17763
|
if (typeof posOrX === "number") {
|
|
17693
|
-
return this.setBlockVisibleAt(new
|
|
17764
|
+
return this.setBlockVisibleAt(new Vector319(posOrX, yOrVisible, z), visible);
|
|
17694
17765
|
}
|
|
17695
17766
|
if (isTripleArray(posOrX)) {
|
|
17696
|
-
return this.setBlockVisibleAt(new
|
|
17767
|
+
return this.setBlockVisibleAt(new Vector319(...posOrX), yOrVisible);
|
|
17697
17768
|
}
|
|
17698
17769
|
this.validatePosBounds(posOrX);
|
|
17699
17770
|
await this.getChunkAt(posOrX)?.setBlockVisibleAt(posOrX, yOrVisible);
|
|
@@ -17719,7 +17790,7 @@ var MineRenderWorld = class {
|
|
|
17719
17790
|
const collect = async (positions2) => {
|
|
17720
17791
|
for (const pos of positions2) changes.set(pos.toArray().join(","), pos);
|
|
17721
17792
|
};
|
|
17722
|
-
const place = (block) => this.placeBlock(new
|
|
17793
|
+
const place = (block) => this.placeBlock(new Vector319(...block.position), block, collect);
|
|
17723
17794
|
const keys = /* @__PURE__ */ new Map();
|
|
17724
17795
|
const types = /* @__PURE__ */ new Set();
|
|
17725
17796
|
for (const block of multiblock.blocks) {
|
|
@@ -17735,7 +17806,7 @@ var MineRenderWorld = class {
|
|
|
17735
17806
|
}
|
|
17736
17807
|
if (!executor) {
|
|
17737
17808
|
const groups2 = /* @__PURE__ */ new Map();
|
|
17738
|
-
const position = new
|
|
17809
|
+
const position = new Vector319();
|
|
17739
17810
|
for (const block of multiblock.blocks) {
|
|
17740
17811
|
const [x, y, z] = block.position;
|
|
17741
17812
|
this.validatePosBounds(position.set(x, y, z));
|
|
@@ -17775,7 +17846,7 @@ var MineRenderWorld = class {
|
|
|
17775
17846
|
try {
|
|
17776
17847
|
positions = await chunk.placeBlocks(blocks);
|
|
17777
17848
|
} finally {
|
|
17778
|
-
positions ??= blocks.map(({ index }) => new
|
|
17849
|
+
positions ??= blocks.map(({ index }) => new Vector319(
|
|
17779
17850
|
chunk.x * 16 + index % 16,
|
|
17780
17851
|
chunk.y * 16 + Math.floor(index / 256),
|
|
17781
17852
|
chunk.z * 16 + Math.floor(index / 16) % 16
|
|
@@ -17827,7 +17898,7 @@ var MineRenderWorld = class {
|
|
|
17827
17898
|
}
|
|
17828
17899
|
for (const section of chunk.sections) {
|
|
17829
17900
|
if (section.biomes) {
|
|
17830
|
-
const position = new
|
|
17901
|
+
const position = new Vector319(chunk.x * 16, section.y * 16, chunk.z * 16);
|
|
17831
17902
|
this.validatePosBounds(position);
|
|
17832
17903
|
const copy = [...section.biomes];
|
|
17833
17904
|
if (copy.length !== 64 || !copy.every((id) => typeof id === "string" && id.length > 0)) {
|
|
@@ -17843,7 +17914,7 @@ var MineRenderWorld = class {
|
|
|
17843
17914
|
for (const section of chunk.sections) {
|
|
17844
17915
|
if (!executor) {
|
|
17845
17916
|
if (!occupiedSections.has(section.y)) continue;
|
|
17846
|
-
const position = new
|
|
17917
|
+
const position = new Vector319(chunk.x * 16, section.y * 16, chunk.z * 16);
|
|
17847
17918
|
this.validatePosBounds(position);
|
|
17848
17919
|
const target = this.getOrCreateChunkAt(position);
|
|
17849
17920
|
try {
|
|
@@ -17947,7 +18018,7 @@ var MineRenderWorld = class {
|
|
|
17947
18018
|
this.sectionModels?.clear();
|
|
17948
18019
|
}
|
|
17949
18020
|
updateCulling(positions) {
|
|
17950
|
-
const neighbor = new
|
|
18021
|
+
const neighbor = new Vector319();
|
|
17951
18022
|
for (const pos of positions) {
|
|
17952
18023
|
const cx = Math.floor(pos.x / 16), cy = Math.floor(pos.y / 16), cz = Math.floor(pos.z / 16);
|
|
17953
18024
|
const chunk = this._chunks.get(`${cx}_${cy}_${cz}`);
|
|
@@ -18078,7 +18149,7 @@ var MineRenderWorld = class {
|
|
|
18078
18149
|
}
|
|
18079
18150
|
/** Converts block coordinates to scene units by multiplying each component by 16. */
|
|
18080
18151
|
static worldToScenePosition(pos) {
|
|
18081
|
-
return new
|
|
18152
|
+
return new Vector319(
|
|
18082
18153
|
pos.x * 16,
|
|
18083
18154
|
pos.y * 16,
|
|
18084
18155
|
pos.z * 16
|
|
@@ -18086,7 +18157,7 @@ var MineRenderWorld = class {
|
|
|
18086
18157
|
}
|
|
18087
18158
|
/** Converts scene units to block coordinates without rounding to an integer block. */
|
|
18088
18159
|
static sceneToWorldPosition(pos) {
|
|
18089
|
-
return new
|
|
18160
|
+
return new Vector319(
|
|
18090
18161
|
pos.x / 16,
|
|
18091
18162
|
pos.y / 16,
|
|
18092
18163
|
pos.z / 16
|
|
@@ -18111,7 +18182,7 @@ init_Model();
|
|
|
18111
18182
|
// src/world/SectionMesh.ts
|
|
18112
18183
|
init_CanvasCompat();
|
|
18113
18184
|
init_Materials();
|
|
18114
|
-
import { BufferGeometry as BufferGeometry9, Color as Color12, DoubleSide as DoubleSide8, Float32BufferAttribute as Float32BufferAttribute10, FrontSide as FrontSide4, Group as Group3, Mesh as
|
|
18185
|
+
import { BufferGeometry as BufferGeometry9, Color as Color12, DoubleSide as DoubleSide8, Float32BufferAttribute as Float32BufferAttribute10, FrontSide as FrontSide4, Group as Group3, Mesh as Mesh12, Uint32BufferAttribute } from "three";
|
|
18115
18186
|
|
|
18116
18187
|
// src/world/SectionGeometry.ts
|
|
18117
18188
|
init_FluidQuads();
|
|
@@ -18582,7 +18653,7 @@ var SectionMesh = class _SectionMesh extends Group3 {
|
|
|
18582
18653
|
}
|
|
18583
18654
|
material.vertexColors = true;
|
|
18584
18655
|
const texture = material.uniforms?.map?.value ?? material.map;
|
|
18585
|
-
const mesh = new
|
|
18656
|
+
const mesh = new Mesh12(geometry, material);
|
|
18586
18657
|
section.add(mesh);
|
|
18587
18658
|
section.blockIndices.set(mesh, page.blockIndices);
|
|
18588
18659
|
const unsubscribe = [];
|
|
@@ -18621,7 +18692,6 @@ init_FluidGeometry();
|
|
|
18621
18692
|
init_FluidQuads();
|
|
18622
18693
|
init_CubeFace();
|
|
18623
18694
|
init_InstanceReference();
|
|
18624
|
-
init_three();
|
|
18625
18695
|
var WATER_TINT2 = new Color13(4159204).toArray();
|
|
18626
18696
|
var Chunk = class _Chunk {
|
|
18627
18697
|
constructor(scene, x, y, z, onBlocksChanged, sectionModels, neighborCell, biomeAt, onBiomesChanged, lightAt, onLightCleared, ambientLight = 0) {
|
|
@@ -18639,7 +18709,7 @@ var Chunk = class _Chunk {
|
|
|
18639
18709
|
this.sectionBlocks = /* @__PURE__ */ new Map();
|
|
18640
18710
|
this.hiddenBlocks = /* @__PURE__ */ new Set();
|
|
18641
18711
|
this.fluidCells = new Uint8Array(4096);
|
|
18642
|
-
this.blockPosition = new
|
|
18712
|
+
this.blockPosition = new Vector320();
|
|
18643
18713
|
this.meshDirty = false;
|
|
18644
18714
|
this.meshGeneration = 0;
|
|
18645
18715
|
this.scene = scene;
|
|
@@ -18654,18 +18724,8 @@ var Chunk = class _Chunk {
|
|
|
18654
18724
|
const meshes = (root, scene) => {
|
|
18655
18725
|
const cached2 = roots.get(root);
|
|
18656
18726
|
if (cached2) return cached2;
|
|
18657
|
-
const result =
|
|
18727
|
+
const result = pickableMeshes(root, scene, raycaster);
|
|
18658
18728
|
roots.set(root, result);
|
|
18659
|
-
let attached = false;
|
|
18660
|
-
for (let parent = root; parent; parent = parent.parent) {
|
|
18661
|
-
if (!parent.visible) return result;
|
|
18662
|
-
if (parent === scene) attached = true;
|
|
18663
|
-
}
|
|
18664
|
-
if (!attached) return result;
|
|
18665
|
-
root.updateWorldMatrix(true, true);
|
|
18666
|
-
root.traverseVisible((object4) => {
|
|
18667
|
-
if (isMesh(object4) && raycaster.layers.test(object4.layers)) result.push(object4);
|
|
18668
|
-
});
|
|
18669
18729
|
return result;
|
|
18670
18730
|
};
|
|
18671
18731
|
const add = (root, owner, reference) => {
|
|
@@ -18696,11 +18756,8 @@ var Chunk = class _Chunk {
|
|
|
18696
18756
|
}
|
|
18697
18757
|
}
|
|
18698
18758
|
}
|
|
18699
|
-
for (const hit of raycaster
|
|
18700
|
-
if (!hit.face) continue;
|
|
18759
|
+
for (const hit of visibleHits(raycaster, [...targets.keys()])) {
|
|
18701
18760
|
const mesh = hit.object;
|
|
18702
|
-
const material = Array.isArray(mesh.material) ? mesh.material[hit.face.materialIndex] : mesh.material;
|
|
18703
|
-
if (!material?.visible) continue;
|
|
18704
18761
|
const entry = targets.get(mesh);
|
|
18705
18762
|
let owner = entry.owners.get(hit.instanceId) ?? entry.owners.get(void 0);
|
|
18706
18763
|
if (entry.section) {
|
|
@@ -18710,21 +18767,15 @@ var Chunk = class _Chunk {
|
|
|
18710
18767
|
if (!owner || owner.chunk.hiddenBlocks.has(owner.index)) continue;
|
|
18711
18768
|
const info = owner.chunk.renderedBlocks.get(owner.index);
|
|
18712
18769
|
if (!info) continue;
|
|
18713
|
-
const matrix = mesh.matrixWorld.clone();
|
|
18714
|
-
if (isInstancedMesh(mesh) && hit.instanceId !== void 0) {
|
|
18715
|
-
const instance = new Matrix413();
|
|
18716
|
-
mesh.getMatrixAt(hit.instanceId, instance);
|
|
18717
|
-
matrix.multiply(instance);
|
|
18718
|
-
}
|
|
18719
18770
|
return {
|
|
18720
|
-
position: new
|
|
18771
|
+
position: new Vector320(
|
|
18721
18772
|
owner.chunk.x * 16 + owner.index % 16,
|
|
18722
18773
|
owner.chunk.y * 16 + Math.floor(owner.index / 256),
|
|
18723
18774
|
owner.chunk.z * 16 + Math.floor(owner.index / 16) % 16
|
|
18724
18775
|
),
|
|
18725
18776
|
block: info.block,
|
|
18726
18777
|
point: hit.point.clone(),
|
|
18727
|
-
normal: hit
|
|
18778
|
+
normal: hitNormal(hit),
|
|
18728
18779
|
distance: hit.distance
|
|
18729
18780
|
};
|
|
18730
18781
|
}
|
|
@@ -18732,18 +18783,18 @@ var Chunk = class _Chunk {
|
|
|
18732
18783
|
}
|
|
18733
18784
|
getBlockAt(posOrX, y, z) {
|
|
18734
18785
|
if (typeof posOrX == "number") {
|
|
18735
|
-
return this.getBlockAt(new
|
|
18786
|
+
return this.getBlockAt(new Vector320(posOrX, y, z));
|
|
18736
18787
|
}
|
|
18737
18788
|
if (isTripleArray(posOrX)) {
|
|
18738
|
-
return this.getBlockAt(new
|
|
18789
|
+
return this.getBlockAt(new Vector320(posOrX[0], posOrX[1], posOrX[2]));
|
|
18739
18790
|
}
|
|
18740
18791
|
const pos = this.blockPosition.set(posOrX.x - this.x * 16, posOrX.y - this.y * 16, posOrX.z - this.z * 16);
|
|
18741
18792
|
const index = _Chunk.chunkPosToBlockIndex(pos);
|
|
18742
18793
|
return this.renderedBlocks.get(index);
|
|
18743
18794
|
}
|
|
18744
18795
|
getBiomeAt(posOrX, y, z) {
|
|
18745
|
-
if (typeof posOrX === "number") return this.getBiomeAt(new
|
|
18746
|
-
if (isTripleArray(posOrX)) return this.getBiomeAt(new
|
|
18796
|
+
if (typeof posOrX === "number") return this.getBiomeAt(new Vector320(posOrX, y, z));
|
|
18797
|
+
if (isTripleArray(posOrX)) return this.getBiomeAt(new Vector320(...posOrX));
|
|
18747
18798
|
const pos = this.worldPosToChunkPos(posOrX);
|
|
18748
18799
|
_Chunk.chunkPosToBlockIndex(pos);
|
|
18749
18800
|
return this.biomeAt ? this.biomeAt(posOrX.x, posOrX.y, posOrX.z) : this.biomes?.[Math.floor(pos.x / 4) + Math.floor(pos.z / 4) * 4 + Math.floor(pos.y / 4) * 16];
|
|
@@ -18786,17 +18837,17 @@ var Chunk = class _Chunk {
|
|
|
18786
18837
|
this.hiddenBlocks.add(index);
|
|
18787
18838
|
this.renderedBlocks.get(index)?.object?.setVisible(false);
|
|
18788
18839
|
}
|
|
18789
|
-
const positions = blocks.map(({ index }) => new
|
|
18840
|
+
const positions = blocks.map(({ index }) => new Vector320(...this.positionAt(index)));
|
|
18790
18841
|
if (this.onBlocksChanged) await this.onBlocksChanged(positions);
|
|
18791
18842
|
else await this.rebuildSectionMesh();
|
|
18792
18843
|
}
|
|
18793
18844
|
}
|
|
18794
18845
|
async setBlockAt(posOrX, yOrBlock, z, block) {
|
|
18795
18846
|
if (typeof posOrX == "number") {
|
|
18796
|
-
return this.setBlockAt(new
|
|
18847
|
+
return this.setBlockAt(new Vector320(posOrX, yOrBlock, z), block);
|
|
18797
18848
|
}
|
|
18798
18849
|
if (isTripleArray(posOrX)) {
|
|
18799
|
-
return this.setBlockAt(new
|
|
18850
|
+
return this.setBlockAt(new Vector320(posOrX[0], posOrX[1], posOrX[2]), yOrBlock);
|
|
18800
18851
|
}
|
|
18801
18852
|
const worldPos = posOrX;
|
|
18802
18853
|
const pos = this.worldPosToChunkPos(worldPos);
|
|
@@ -18851,7 +18902,7 @@ var Chunk = class _Chunk {
|
|
|
18851
18902
|
this.fluidCells[index] = 0;
|
|
18852
18903
|
this.renderedBlocks.delete(index);
|
|
18853
18904
|
this.objectBlocks.delete(index);
|
|
18854
|
-
const worldPos = new
|
|
18905
|
+
const worldPos = new Vector320(
|
|
18855
18906
|
this.x * 16 + index % 16,
|
|
18856
18907
|
this.y * 16 + Math.floor(index / 256),
|
|
18857
18908
|
this.z * 16 + Math.floor(index / 16) % 16
|
|
@@ -18982,7 +19033,7 @@ var Chunk = class _Chunk {
|
|
|
18982
19033
|
biome,
|
|
18983
19034
|
biomePosition: this.biomePosition(index, blockState3, this.data.stateAt(this.data.idAt(index)))
|
|
18984
19035
|
});
|
|
18985
|
-
object4.setPosition(new
|
|
19036
|
+
object4.setPosition(new Vector320(
|
|
18986
19037
|
this.x * 256 + index % 16 * 16,
|
|
18987
19038
|
this.y * 256 + Math.floor(index / 256) * 16,
|
|
18988
19039
|
this.z * 256 + Math.floor(index / 16) % 16 * 16
|
|
@@ -19245,7 +19296,7 @@ var Chunk = class _Chunk {
|
|
|
19245
19296
|
/** Removes stored blocks and render objects. Set `notify` to false to skip the owning world's update. */
|
|
19246
19297
|
async clear(notify = true) {
|
|
19247
19298
|
const positions = notify && this.onBlocksChanged ? [...this.renderedBlocks.keys()].map((index) => this.chunkPosToWorldPos(
|
|
19248
|
-
new
|
|
19299
|
+
new Vector320(index % 16, Math.floor(index / 256), Math.floor(index / 16) % 16)
|
|
19249
19300
|
)) : [];
|
|
19250
19301
|
for (const info of this.renderedBlocks.values()) info.object?.removeFromScene();
|
|
19251
19302
|
this.sectionBlocks.clear();
|
|
@@ -19281,14 +19332,14 @@ var Chunk = class _Chunk {
|
|
|
19281
19332
|
return pos.y * 16 * 16 + pos.z * 16 + pos.x;
|
|
19282
19333
|
}
|
|
19283
19334
|
worldPosToChunkPos(pos) {
|
|
19284
|
-
return new
|
|
19335
|
+
return new Vector320(
|
|
19285
19336
|
pos.x - this.x * 16,
|
|
19286
19337
|
pos.y - this.y * 16,
|
|
19287
19338
|
pos.z - this.z * 16
|
|
19288
19339
|
);
|
|
19289
19340
|
}
|
|
19290
19341
|
chunkPosToWorldPos(pos) {
|
|
19291
|
-
return new
|
|
19342
|
+
return new Vector320(
|
|
19292
19343
|
this.x * 16 + pos.x,
|
|
19293
19344
|
this.y * 16 + pos.y,
|
|
19294
19345
|
this.z * 16 + pos.z
|