Files
GameStarter/src/js/net/minecraft/client/world/ChunkSection.js
T
2022-01-31 20:24:53 +01:00

64 lines
1.7 KiB
JavaScript

window.ChunkSection = class {
static get SIZE() {
return 16;
}
constructor(world, x, y, z) {
this.world = world;
this.x = x;
this.y = y;
this.z = z;
this.group = new THREE.Object3D();
this.dirty = true;
this.blocks = [];
for (let x = 0; x < ChunkSection.SIZE; x++) {
for (let y = 0; y < ChunkSection.SIZE; y++) {
for (let z = 0; z < ChunkSection.SIZE; z++) {
this.setBlockAt(x, y, z, 0);
}
}
}
}
rebuild(renderer) {
this.dirty = false;
this.group.clear();
renderer.blockRenderer.tessellator.startDrawing();
for (let x = 0; x < ChunkSection.SIZE; x++) {
for (let y = 0; y < ChunkSection.SIZE; y++) {
for (let z = 0; z < ChunkSection.SIZE; z++) {
let typeId = this.getBlockAt(x, y, z);
if (typeId !== 0) {
let absoluteX = this.x * ChunkSection.SIZE + x;
let absoluteY = this.y * ChunkSection.SIZE + y;
let absoluteZ = this.z * ChunkSection.SIZE + z;
renderer.blockRenderer.renderBlock(this.world, this.group, typeId, absoluteX, absoluteY, absoluteZ);
}
}
}
}
renderer.blockRenderer.tessellator.draw(this.group);
}
getBlockAt(x, y, z) {
let index = y << 8 | z << 4 | x;
return this.blocks[index];
}
setBlockAt(x, y, z, typeId) {
let index = y << 8 | z << 4 | x;
this.blocks[index] = typeId;
}
queueForRebuild() {
this.dirty = true;
}
}