Client side chunk sections
This commit is contained in:
+11
-3
@@ -11,7 +11,8 @@ import { start_game } from "@/server/game/load_mods.ts";
|
||||
import { apply_config } from "@/server/load_mods.ts";
|
||||
import { AIR_ID, PROTOCOL_VERSION } from "@/common/protocol.ts";
|
||||
import { decode_level_chunk } from "@/common/chunk_streaming.ts";
|
||||
import { CHUNK_AREA, CHUNK_SIZE, ID_MASK } from "@/common/constants.ts";
|
||||
import { CHUNK_SIZE, ID_MASK } from "@/common/constants.ts";
|
||||
import { Section, section_index, SECTION_VOLUME, type SectionData } from "@/common/section.ts";
|
||||
import type { SavedChunk, SavedChunks, WorldSave } from "@/server/game/saves.ts";
|
||||
import { FluidRules } from "@/common/fluids.ts";
|
||||
import { BlockRules } from "@/common/block_rules.ts";
|
||||
@@ -161,11 +162,18 @@ export function sent_block(
|
||||
const chunk_z = Math.floor(z / CHUNK_SIZE);
|
||||
const chunk = messages.findLast((m) => m.type === "level_chunk" && m.x === chunk_x && m.z === chunk_z);
|
||||
if (!chunk) return undefined;
|
||||
const ly = y - join.shape.min_y;
|
||||
const value = chunk.blocks[ly * CHUNK_AREA + (z - chunk_z * CHUNK_SIZE) * CHUNK_SIZE + (x - chunk_x * CHUNK_SIZE)];
|
||||
const value = chunk.sections[(y - join.shape.min_y) >> 4].get(section_index(x, y, z));
|
||||
return [join.blocks[value & ID_MASK], value >>> 16];
|
||||
}
|
||||
|
||||
// a chunk's blocks in one array, y from the bottom of the world then z then x, as the sections a mesh request sends
|
||||
export function section_data(blocks: Uint32Array): SectionData[] {
|
||||
return Array.from(
|
||||
{ length: blocks.length / SECTION_VOLUME },
|
||||
(_, i) => Section.of(blocks.subarray(i * SECTION_VOLUME, (i + 1) * SECTION_VOLUME)).data,
|
||||
);
|
||||
}
|
||||
|
||||
// a stone floor at y 99 from -radius to radius on x and z, high above the terrain, for players to stand on at y 100
|
||||
export function stone_floor(game: GameServer, radius = 3) {
|
||||
for (let x = -radius; x <= radius; x++) {
|
||||
|
||||
Reference in New Issue
Block a user