Change how ticking works a little
This commit is contained in:
@@ -190,6 +190,25 @@ export class ServerWorld {
|
||||
return this.#chunks.get(chunk_key(chunk_x, chunk_z)) !== undefined;
|
||||
}
|
||||
|
||||
// where in a kept chunk (see has_chunk) the blocks are whose numeric id is set in wanted, as x, y, z. nothing when
|
||||
// the chunk isn't kept
|
||||
find_blocks(chunk_x: number, chunk_z: number, wanted: Uint8Array): [number, number, number][] {
|
||||
const blocks = this.#chunks.get(chunk_key(chunk_x, chunk_z));
|
||||
if (!blocks) return [];
|
||||
const found: [number, number, number][] = [];
|
||||
for (let i = 0; i < blocks.length; i++) {
|
||||
if (!wanted[blocks[i] & ID_MASK]) continue;
|
||||
const y = Math.floor(i / CHUNK_AREA);
|
||||
const rest = i % CHUNK_AREA;
|
||||
found.push([
|
||||
chunk_x * CHUNK_SIZE + rest % CHUNK_SIZE,
|
||||
y,
|
||||
chunk_z * CHUNK_SIZE + Math.floor(rest / CHUNK_SIZE),
|
||||
]);
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
// whether every chunk within radius blocks of x, z is, see has_chunk
|
||||
has_chunks_around(x: number, z: number, radius: number) {
|
||||
for (let cx = Math.floor((x - radius) / CHUNK_SIZE); cx <= Math.floor((x + radius) / CHUNK_SIZE); cx++) {
|
||||
|
||||
Reference in New Issue
Block a user