feat: Add generateChunksAroundPlayer function to world.js

This commit is contained in:
Kacper Kostka (aider) 2025-04-05 15:14:35 +02:00
parent b85ae017b8
commit 7aa0c1785b

View File

@ -447,3 +447,25 @@ function getVisibleChunks() {
return visibleChunks;
}
function generateChunksAroundPlayer() {
const centerChunkX = Math.floor(worldOffsetX / CHUNK_SIZE);
const centerChunkY = Math.floor(worldOffsetY / CHUNK_SIZE);
const radius = 3; // Generate chunks within 3 chunks of the player
// Always generate the stone layer at y = 1 instead of below the floor
for (let dx = -radius; dx <= radius; dx++) {
const chunkX = centerChunkX + dx;
const chunkY = 1; // The chunk at y = 1 (moved from y = -1)
getOrCreateChunk(chunkX, chunkY);
}
// Generate chunks in a square around the player
for (let dy = -radius; dy <= radius; dy++) {
for (let dx = -radius; dx <= radius; dx++) {
const chunkX = centerChunkX + dx;
const chunkY = centerChunkY + dy;
getOrCreateChunk(chunkX, chunkY);
}
}
}