Improve a buuuunch of textures and some reworks
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
// what color each biome tints grass and leaves, as 0xRRGGBB. minecraft's grass and foliage colors, with the terralith
|
||||
// style biomes given the ones of the vanilla biome closest to them. blocks pick them with "tint"
|
||||
export const BIOME_GRASS_COLORS: Record<string, number> = {
|
||||
"bworld:deep_ocean": 0x8eb971,
|
||||
"bworld:deep_frozen_ocean": 0x80b497,
|
||||
"bworld:deep_lukewarm_ocean": 0x8eb971,
|
||||
"bworld:ocean": 0x8eb971,
|
||||
"bworld:frozen_ocean": 0x80b497,
|
||||
"bworld:warm_ocean": 0x8eb971,
|
||||
"bworld:river": 0x8eb971,
|
||||
"bworld:frozen_river": 0x80b497,
|
||||
"bworld:beach": 0x91bd59,
|
||||
"bworld:snowy_beach": 0x83b593,
|
||||
"bworld:stony_shore": 0x8ab689,
|
||||
"bworld:plains": 0x91bd59,
|
||||
"bworld:meadow": 0x83bb6d,
|
||||
"bworld:forest": 0x79c05a,
|
||||
"bworld:dark_forest": 0x507a32,
|
||||
"bworld:swamp": 0x6a7039,
|
||||
"bworld:taiga": 0x86b783,
|
||||
"bworld:snowy_plains": 0x80b497,
|
||||
"bworld:snowy_taiga": 0x80b497,
|
||||
"bworld:savanna": 0xbfb755,
|
||||
"bworld:jungle": 0x59c93c,
|
||||
"bworld:desert": 0xbfb755,
|
||||
"bworld:alpine_highlands": 0x8ab689,
|
||||
"bworld:snowy_slopes": 0x80b497,
|
||||
"bworld:stony_peaks": 0x9abe4b,
|
||||
"bworld:jagged_peaks": 0x80b497,
|
||||
"bworld:frozen_peaks": 0x80b497,
|
||||
"bworld:yosemite_cliffs": 0x86b783,
|
||||
"bworld:snowy_cliffs": 0x80b497,
|
||||
"bworld:painted_mountains": 0x90814d,
|
||||
"bworld:stony_spires": 0x8ab689,
|
||||
"bworld:shattered_savanna": 0xbfb755,
|
||||
"bworld:skylands": 0x79c05a,
|
||||
};
|
||||
|
||||
export const BIOME_FOLIAGE_COLORS: Record<string, number> = {
|
||||
"bworld:deep_ocean": 0x71a74d,
|
||||
"bworld:deep_frozen_ocean": 0x60a17b,
|
||||
"bworld:deep_lukewarm_ocean": 0x71a74d,
|
||||
"bworld:ocean": 0x71a74d,
|
||||
"bworld:frozen_ocean": 0x60a17b,
|
||||
"bworld:warm_ocean": 0x71a74d,
|
||||
"bworld:river": 0x71a74d,
|
||||
"bworld:frozen_river": 0x60a17b,
|
||||
"bworld:beach": 0x77ab2f,
|
||||
"bworld:snowy_beach": 0x64a278,
|
||||
"bworld:stony_shore": 0x6da36b,
|
||||
"bworld:plains": 0x77ab2f,
|
||||
"bworld:meadow": 0x63a948,
|
||||
"bworld:forest": 0x59ae30,
|
||||
"bworld:dark_forest": 0x59ae30,
|
||||
"bworld:swamp": 0x6a7039,
|
||||
"bworld:taiga": 0x68a464,
|
||||
"bworld:snowy_plains": 0x60a17b,
|
||||
"bworld:snowy_taiga": 0x60a17b,
|
||||
"bworld:savanna": 0xaea42a,
|
||||
"bworld:jungle": 0x30bb0b,
|
||||
"bworld:desert": 0xaea42a,
|
||||
"bworld:alpine_highlands": 0x6da36b,
|
||||
"bworld:snowy_slopes": 0x60a17b,
|
||||
"bworld:stony_peaks": 0x82ac1e,
|
||||
"bworld:jagged_peaks": 0x60a17b,
|
||||
"bworld:frozen_peaks": 0x60a17b,
|
||||
"bworld:yosemite_cliffs": 0x68a464,
|
||||
"bworld:snowy_cliffs": 0x60a17b,
|
||||
"bworld:painted_mountains": 0x9e814d,
|
||||
"bworld:stony_spires": 0x6da36b,
|
||||
"bworld:shattered_savanna": 0xaea42a,
|
||||
"bworld:skylands": 0x59ae30,
|
||||
};
|
||||
|
||||
// biomes mods add without a color, and items, which aren't in any biome
|
||||
export const DEFAULT_GRASS_COLOR = BIOME_GRASS_COLORS["bworld:plains"];
|
||||
export const DEFAULT_FOLIAGE_COLOR = BIOME_FOLIAGE_COLORS["bworld:plains"];
|
||||
|
||||
export function grass_color(biome: string | undefined) {
|
||||
return (biome !== undefined ? BIOME_GRASS_COLORS[biome] : undefined) ?? DEFAULT_GRASS_COLOR;
|
||||
}
|
||||
|
||||
export function foliage_color(biome: string | undefined) {
|
||||
return (biome !== undefined ? BIOME_FOLIAGE_COLORS[biome] : undefined) ?? DEFAULT_FOLIAGE_COLOR;
|
||||
}
|
||||
|
||||
// a block's "tint" color: the biome's grass or foliage color, or a fixed one like "#80a755"
|
||||
export type TintColor = "grass" | "foliage" | `#${string}`;
|
||||
|
||||
export function is_tint_color(value: unknown): value is TintColor {
|
||||
return value === "grass" || value === "foliage" || (typeof value === "string" && /^#[0-9a-fA-F]{6}$/.test(value));
|
||||
}
|
||||
|
||||
// the color outside any biome, for items: the default grass or foliage color, or the fixed one
|
||||
export function tint_without_biome(color: TintColor) {
|
||||
if (color === "grass") return DEFAULT_GRASS_COLOR;
|
||||
if (color === "foliage") return DEFAULT_FOLIAGE_COLOR;
|
||||
return parseInt(color.slice(1), 16);
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,14 +15,32 @@ const REACH = Math.ceil(MIN_DISTANCE / CELL);
|
||||
// the widest a canopy layer gets
|
||||
const MAX_CANOPY = 3;
|
||||
|
||||
export type TreeKind = "oak" | "big_oak" | "spruce" | "jungle" | "acacia";
|
||||
export type TreeKind = "oak" | "big_oak" | "birch" | "spruce" | "jungle" | "acacia" | "cherry";
|
||||
export const WOODS = ["oak", "spruce", "birch", "jungle", "acacia", "dark_oak", "cherry"] as const;
|
||||
export type Wood = typeof WOODS[number];
|
||||
|
||||
// the logs and leaves a tree grows, big oaks are dark oak in the dark forest like minecraft's
|
||||
export function tree_wood(kind: TreeKind, biome: string): Wood {
|
||||
switch (kind) {
|
||||
case "big_oak":
|
||||
return biome === "bworld:dark_forest" ? "dark_oak" : "oak";
|
||||
case "birch":
|
||||
case "spruce":
|
||||
case "jungle":
|
||||
case "acacia":
|
||||
case "cherry":
|
||||
return kind;
|
||||
default:
|
||||
return "oak";
|
||||
}
|
||||
}
|
||||
|
||||
// how likely each biome's cells are to have a tree, and which kinds grow there
|
||||
export const BIOME_TREES: Record<string, { chance: number; kinds: TreeKind[] }> = {
|
||||
"bworld:forest": { chance: 0.85, kinds: ["oak", "oak", "big_oak"] },
|
||||
"bworld:forest": { chance: 0.85, kinds: ["oak", "oak", "big_oak", "birch"] },
|
||||
"bworld:dark_forest": { chance: 1, kinds: ["big_oak", "big_oak", "oak"] },
|
||||
"bworld:plains": { chance: 0.05, kinds: ["oak"] },
|
||||
"bworld:meadow": { chance: 0.04, kinds: ["oak"] },
|
||||
"bworld:meadow": { chance: 0.06, kinds: ["oak", "birch", "cherry", "cherry"] },
|
||||
"bworld:swamp": { chance: 0.4, kinds: ["big_oak"] },
|
||||
"bworld:river": { chance: 0.05, kinds: ["oak"] },
|
||||
"bworld:taiga": { chance: 0.75, kinds: ["spruce"] },
|
||||
@@ -126,6 +144,30 @@ export function grow_tree(kind: TreeKind, x: number, y: number, z: number, rng:
|
||||
layer(y + height + 1, 1, false);
|
||||
break;
|
||||
}
|
||||
case "birch": {
|
||||
// oak's canopy on a taller, straight trunk
|
||||
const height = random(5, 7);
|
||||
top = y + height + 1;
|
||||
if (top >= CHUNK_HEIGHT - 1) return false;
|
||||
trunk(height);
|
||||
layer(y + height - 2, 2, true);
|
||||
layer(y + height - 1, 2, true);
|
||||
layer(y + height, 1, true);
|
||||
layer(y + height + 1, 1, false);
|
||||
break;
|
||||
}
|
||||
case "cherry": {
|
||||
// a short trunk under a wide, rounded canopy
|
||||
const height = random(4, 6);
|
||||
top = y + height + 1;
|
||||
if (top >= CHUNK_HEIGHT - 1) return false;
|
||||
trunk(height);
|
||||
layer(y + height - 2, 2, false);
|
||||
layer(y + height - 1, MAX_CANOPY, false);
|
||||
layer(y + height, MAX_CANOPY, false);
|
||||
layer(y + height + 1, 2, false);
|
||||
break;
|
||||
}
|
||||
case "big_oak": {
|
||||
const height = random(6, 8);
|
||||
top = y + height + 1;
|
||||
|
||||
Reference in New Issue
Block a user