feat: Enhance grass generation with more coverage and variety

This commit is contained in:
Kacper Kostka (aider) 2025-04-05 15:00:12 +02:00
parent 7806b39a51
commit 1584600d0b

View File

@ -111,22 +111,22 @@ function generateSpecialChunk(chunkData, chunkX, playerChunkX) {
} }
// 3. Add grass with significantly more coverage and noise // 3. Add grass with significantly more coverage and noise
// Increase grass probability for more coverage // Increase grass probability for more coverage - now almost guaranteed
const grassProbability = (height - baseHeight) / (hill1Height - baseHeight); const grassProbability = (height - baseHeight) / (hill1Height - baseHeight);
if (random() < grassProbability * 0.7 + 0.3) { // Minimum 30% chance, up to 100% if (random() < grassProbability * 0.3 + 0.7) { // Minimum 70% chance, up to 100%
// Add grass on top // Add grass on top
chunkData[(floorY - noiseHeight) * CHUNK_SIZE + x] = GRASS; chunkData[(floorY - noiseHeight) * CHUNK_SIZE + x] = GRASS;
// More frequently add patches of grass on the sides // Much more frequently add patches of grass on the sides
if (random() < 0.5) { // Increased from 0.3 if (random() < 0.8) { // Increased from 0.5
// Add grass to the left if possible // Add grass to the left if possible
if (x > 0 && chunkData[(floorY - noiseHeight) * CHUNK_SIZE + (x-1)] === SAND) { if (x > 0 && chunkData[(floorY - noiseHeight) * CHUNK_SIZE + (x-1)] === SAND) {
chunkData[(floorY - noiseHeight) * CHUNK_SIZE + (x-1)] = GRASS; chunkData[(floorY - noiseHeight) * CHUNK_SIZE + (x-1)] = GRASS;
} }
} }
if (random() < 0.5) { // Increased from 0.3 if (random() < 0.8) { // Increased from 0.5
// Add grass to the right if possible // Add grass to the right if possible
if (x < CHUNK_SIZE-1 && chunkData[(floorY - noiseHeight) * CHUNK_SIZE + (x+1)] === SAND) { if (x < CHUNK_SIZE-1 && chunkData[(floorY - noiseHeight) * CHUNK_SIZE + (x+1)] === SAND) {
chunkData[(floorY - noiseHeight) * CHUNK_SIZE + (x+1)] = GRASS; chunkData[(floorY - noiseHeight) * CHUNK_SIZE + (x+1)] = GRASS;
@ -134,8 +134,8 @@ function generateSpecialChunk(chunkData, chunkX, playerChunkX) {
} }
// More frequently add grass patches below the top // More frequently add grass patches below the top
if (random() < 0.3 && noiseHeight > 2) { // Increased from 0.15 if (random() < 0.6 && noiseHeight > 2) { // Increased from 0.3
const patchDepth = Math.floor(random() * 4) + 1; // Increased max depth const patchDepth = Math.floor(random() * 5) + 2; // Increased max depth and minimum
for (let d = 1; d <= patchDepth; d++) { for (let d = 1; d <= patchDepth; d++) {
if (floorY - noiseHeight + d < floorY) { if (floorY - noiseHeight + d < floorY) {
chunkData[(floorY - noiseHeight + d) * CHUNK_SIZE + x] = GRASS; chunkData[(floorY - noiseHeight + d) * CHUNK_SIZE + x] = GRASS;
@ -143,22 +143,37 @@ function generateSpecialChunk(chunkData, chunkX, playerChunkX) {
} }
} }
// Sometimes add grass clusters // More frequently add grass clusters
if (random() < 0.2) { if (random() < 0.5) { // Increased from 0.2
// Add a small cluster of grass // Add a larger cluster of grass
for (let dy = -1; dy <= 1; dy++) { for (let dy = -2; dy <= 1; dy++) { // Increased vertical range
for (let dx = -1; dx <= 1; dx++) { for (let dx = -2; dx <= 2; dx++) { // Increased horizontal range
const nx = x + dx; const nx = x + dx;
const ny = floorY - noiseHeight + dy; const ny = floorY - noiseHeight + dy;
if (nx >= 0 && nx < CHUNK_SIZE && ny >= 0 && ny < CHUNK_SIZE && if (nx >= 0 && nx < CHUNK_SIZE && ny >= 0 && ny < CHUNK_SIZE &&
chunkData[ny * CHUNK_SIZE + nx] === SAND) { (chunkData[ny * CHUNK_SIZE + nx] === SAND || chunkData[ny * CHUNK_SIZE + nx] === EMPTY)) {
// Higher chance to place grass closer to center
if (Math.abs(dx) + Math.abs(dy) <= 2 || random() < 0.7) {
chunkData[ny * CHUNK_SIZE + nx] = GRASS; chunkData[ny * CHUNK_SIZE + nx] = GRASS;
} }
} }
} }
} }
} }
// Sometimes add grass "islands" on top of sand
if (random() < 0.15 && noiseHeight > 4) {
// Add a small patch of grass above the surface
const islandHeight = Math.floor(random() * 2) + 1;
for (let d = 1; d <= islandHeight; d++) {
const ny = floorY - noiseHeight - d;
if (ny >= 0) {
chunkData[ny * CHUNK_SIZE + x] = GRASS;
}
}
}
}
} }
// 2. Add water in more areas with greater depth // 2. Add water in more areas with greater depth