Improve a buuuunch of textures and some reworks

This commit is contained in:
2026-09-27 18:05:20 -03:00
parent 9f47c709f1
commit b7ded817d9
186 changed files with 1486 additions and 124 deletions
+12 -8
View File
@@ -3,7 +3,7 @@
import { CHUNK_AREA, CHUNK_HEIGHT, CHUNK_SIZE, SEA_LEVEL } from "$/common/constants.ts";
import { OctaveNoise2D } from "./noise.ts";
import { OverworldTerrain, TerrainColumn } from "./terrain.ts";
import { BIOME_TREES, grow_tree, tree_sites } from "./trees.ts";
import { BIOME_TREES, grow_tree, tree_sites, tree_wood, type Wood } from "./trees.ts";
// density is sampled every CELL_WIDTH blocks across and CELL_HEIGHT up, caves every CAVE_CELL_HEIGHT up since
// tunnels are thinner than terrain features
@@ -29,8 +29,8 @@ export interface OverworldBlocks {
sand: number;
snow: number;
water: number;
log: number;
leaves: number;
logs: Record<Wood, number>;
leaves: Record<Wood, number>;
}
type Palette = "stone" | "dirt" | "grass" | "sand" | "snow";
@@ -244,19 +244,22 @@ export function generate_overworld(
grow_trees();
function grow_trees() {
const place = (x: number, y: number, z: number, block: "log" | "leaves") => {
// logs replace any tree's leaves
const all_leaves = new Set(Object.values(ids.leaves));
const place = (x: number, y: number, z: number, block: "log" | "leaves", wood: Wood) => {
if (y < 0 || y >= CHUNK_HEIGHT) return;
const id = block === "log" ? ids.logs[wood] : ids.leaves[wood];
const lx = x - x0;
const lz = z - z0;
if (lx < 0 || lx >= CHUNK_SIZE || lz < 0 || lz >= CHUNK_SIZE) {
// the other chunk only takes it where it has air
spill(x, y, z, ids[block]);
spill(x, y, z, id);
return;
}
const i = y * CHUNK_AREA + lz * CHUNK_SIZE + lx;
const current = blocks[i];
if (current === 0 || (block === "log" && current === ids.leaves)) {
blocks[i] = ids[block];
if (current === 0 || (block === "log" && all_leaves.has(current))) {
blocks[i] = id;
}
};
@@ -272,7 +275,8 @@ export function generate_overworld(
if ((ground !== ids.grass && ground !== ids.dirt && ground !== ids.snow) || above !== 0) continue;
const kind = trees.kinds[Math.floor(site.rng.next() * trees.kinds.length)];
grow_tree(kind, site.x, ground_y + 1, site.z, site.rng, place);
const wood = tree_wood(kind, biomes[column]);
grow_tree(kind, site.x, ground_y + 1, site.z, site.rng, (x, y, z, block) => place(x, y, z, block, wood));
}
}