Biome as data
This commit is contained in:
@@ -1,107 +1,22 @@
|
||||
// what color each biome tints grass, leaves and water, as 0xRRGGBB, minecraft's grass, foliage and water colors.
|
||||
// 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:snowy_slopes": 0x80b497,
|
||||
"bworld:stony_peaks": 0x9abe4b,
|
||||
"bworld:jagged_peaks": 0x80b497,
|
||||
"bworld:frozen_peaks": 0x80b497,
|
||||
};
|
||||
// what color each biome tints grass, leaves and water, as 0xRRGGBB, from its "colors" (see biomes.ts). blocks pick
|
||||
// them with "tint"
|
||||
import { get_biome } from "./biomes.ts";
|
||||
|
||||
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:snowy_slopes": 0x60a17b,
|
||||
"bworld:stony_peaks": 0x82ac1e,
|
||||
"bworld:jagged_peaks": 0x60a17b,
|
||||
"bworld:frozen_peaks": 0x60a17b,
|
||||
};
|
||||
|
||||
export const BIOME_WATER_COLORS: Record<string, number> = {
|
||||
"bworld:deep_ocean": 0x3f76e4,
|
||||
"bworld:deep_frozen_ocean": 0x3938c9,
|
||||
"bworld:deep_lukewarm_ocean": 0x45adf2,
|
||||
"bworld:ocean": 0x3f76e4,
|
||||
"bworld:frozen_ocean": 0x3938c9,
|
||||
"bworld:warm_ocean": 0x43d5ee,
|
||||
"bworld:river": 0x3f76e4,
|
||||
"bworld:frozen_river": 0x3938c9,
|
||||
"bworld:beach": 0x3f76e4,
|
||||
"bworld:snowy_beach": 0x3d57d6,
|
||||
"bworld:stony_shore": 0x3f76e4,
|
||||
"bworld:plains": 0x3f76e4,
|
||||
"bworld:meadow": 0x0e4ecf,
|
||||
"bworld:forest": 0x3f76e4,
|
||||
"bworld:dark_forest": 0x3f76e4,
|
||||
"bworld:swamp": 0x617b64,
|
||||
"bworld:taiga": 0x3f76e4,
|
||||
"bworld:snowy_plains": 0x3f76e4,
|
||||
"bworld:snowy_taiga": 0x3d57d6,
|
||||
"bworld:savanna": 0x3f76e4,
|
||||
"bworld:jungle": 0x3f76e4,
|
||||
"bworld:desert": 0x3f76e4,
|
||||
"bworld:snowy_slopes": 0x3f76e4,
|
||||
"bworld:stony_peaks": 0x3f76e4,
|
||||
"bworld:jagged_peaks": 0x3f76e4,
|
||||
"bworld:frozen_peaks": 0x3f76e4,
|
||||
};
|
||||
|
||||
// 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 const DEFAULT_WATER_COLOR = BIOME_WATER_COLORS["bworld:plains"];
|
||||
// biomes without a color, and items, which aren't in any biome: plains' colors
|
||||
export const DEFAULT_GRASS_COLOR = 0x91bd59;
|
||||
export const DEFAULT_FOLIAGE_COLOR = 0x77ab2f;
|
||||
export const DEFAULT_WATER_COLOR = 0x3f76e4;
|
||||
|
||||
export function grass_color(biome: string | undefined) {
|
||||
return (biome !== undefined ? BIOME_GRASS_COLORS[biome] : undefined) ?? DEFAULT_GRASS_COLOR;
|
||||
return (biome !== undefined ? get_biome(biome)?.colors.grass : undefined) ?? DEFAULT_GRASS_COLOR;
|
||||
}
|
||||
|
||||
export function foliage_color(biome: string | undefined) {
|
||||
return (biome !== undefined ? BIOME_FOLIAGE_COLORS[biome] : undefined) ?? DEFAULT_FOLIAGE_COLOR;
|
||||
return (biome !== undefined ? get_biome(biome)?.colors.foliage : undefined) ?? DEFAULT_FOLIAGE_COLOR;
|
||||
}
|
||||
|
||||
export function water_color(biome: string | undefined) {
|
||||
return (biome !== undefined ? BIOME_WATER_COLORS[biome] : undefined) ?? DEFAULT_WATER_COLOR;
|
||||
return (biome !== undefined ? get_biome(biome)?.colors.water : undefined) ?? DEFAULT_WATER_COLOR;
|
||||
}
|
||||
|
||||
// a block's "tint" color: the biome's grass, foliage or water color, or a fixed one like "#80a755"
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
// biomes as data: worldgen/biomes/<name>.json in a mod, see docs/modding/worldgen/biomes.md. which biome a column
|
||||
// gets is still code (pick_biome in overworld.ts), these say what a biome looks like once it's picked
|
||||
import { EverythingRegistry } from "../everything_registry.ts";
|
||||
import { ID_PATTERN } from "../mod_data.ts";
|
||||
import { TREE_KINDS, type TreeKind, type Wood, WOODS } from "./trees.ts";
|
||||
|
||||
export const SEASONS = ["spring", "summer", "autumn", "winter"] as const;
|
||||
export type Season = typeof SEASONS[number];
|
||||
export const DEFAULT_SEASON: Season = "spring";
|
||||
|
||||
// how a biome covers its ground, like minecraft's surface rules. blocks are ids
|
||||
export interface SurfaceJson {
|
||||
top: string;
|
||||
filler: string;
|
||||
filler_depth: number;
|
||||
// the ground's cover under water, filler when not set
|
||||
underwater_top?: string;
|
||||
underwater_filler?: string;
|
||||
// cliffs show bare stone instead of top
|
||||
bare_cliffs?: boolean;
|
||||
}
|
||||
|
||||
export interface BiomeJson {
|
||||
id: string;
|
||||
// spring when not set
|
||||
season?: Season;
|
||||
surface: SurfaceJson;
|
||||
// "#rrggbb", minecraft's grass, foliage and water colors, which blocks pick with "tint". plains' when not set
|
||||
colors?: { grass?: string; foliage?: string; water?: string };
|
||||
// how likely each tree cell is to have a tree, and which kinds grow, picked evenly (list one twice to make it
|
||||
// twice as likely). wood is the logs and leaves a kind grows here when it isn't its own, like big oaks being dark
|
||||
// oak in the dark forest
|
||||
trees?: { chance: number; kinds: TreeKind[]; wood?: Partial<Record<TreeKind, Wood>> };
|
||||
}
|
||||
|
||||
// what's registered in "biomes", with the defaults filled in
|
||||
export interface Biome {
|
||||
id: string;
|
||||
season: Season;
|
||||
surface: Required<SurfaceJson>;
|
||||
// 0xRRGGBB
|
||||
colors: { grass?: number; foliage?: number; water?: number };
|
||||
trees?: { chance: number; kinds: TreeKind[]; wood: Partial<Record<TreeKind, Wood>> };
|
||||
}
|
||||
|
||||
export function biome_from_json(json: BiomeJson): Biome {
|
||||
const { surface, colors = {}, trees } = json;
|
||||
const color = (value: string | undefined) => value === undefined ? undefined : parseInt(value.slice(1), 16);
|
||||
return {
|
||||
id: json.id,
|
||||
season: json.season ?? DEFAULT_SEASON,
|
||||
surface: {
|
||||
top: surface.top,
|
||||
filler: surface.filler,
|
||||
filler_depth: surface.filler_depth,
|
||||
underwater_top: surface.underwater_top ?? surface.filler,
|
||||
underwater_filler: surface.underwater_filler ?? surface.filler,
|
||||
bare_cliffs: surface.bare_cliffs ?? false,
|
||||
},
|
||||
colors: { grass: color(colors.grass), foliage: color(colors.foliage), water: color(colors.water) },
|
||||
trees: trees && { chance: trees.chance, kinds: trees.kinds, wood: trees.wood ?? {} },
|
||||
};
|
||||
}
|
||||
|
||||
export function register_biome(json: BiomeJson) {
|
||||
EverythingRegistry.register<Biome>("biomes", json.id, biome_from_json(json));
|
||||
}
|
||||
|
||||
export function get_biome(id: string): Biome | undefined {
|
||||
return EverythingRegistry.get<Biome>("biomes", id);
|
||||
}
|
||||
|
||||
export function biome_ids(): string[] {
|
||||
return EverythingRegistry.entries<Biome>("biomes").map(([id]) => id);
|
||||
}
|
||||
|
||||
// the logs and leaves a kind of tree grows in a biome
|
||||
export function tree_wood(kind: TreeKind, biome: Biome): Wood {
|
||||
const wood = biome.trees?.wood[kind];
|
||||
if (wood) return wood;
|
||||
return kind === "big_oak" ? "oak" : kind;
|
||||
}
|
||||
|
||||
// the block ids a biome's json uses, for checking they exist
|
||||
export function biome_blocks(json: BiomeJson): string[] {
|
||||
const { top, filler, underwater_top, underwater_filler } = json.surface;
|
||||
return [top, filler, underwater_top, underwater_filler].filter((id) => id !== undefined);
|
||||
}
|
||||
|
||||
export function validate_biome(json: unknown): string[] {
|
||||
if (!is_object(json)) return ["biome must be an object"];
|
||||
const problems: string[] = [];
|
||||
const id = (value: unknown, field: string) => {
|
||||
if (!(typeof value === "string" && ID_PATTERN.test(value))) {
|
||||
problems.push(`${field} must be an id like "my_mod:thing"`);
|
||||
}
|
||||
};
|
||||
id(json.id, "id");
|
||||
if (json.season !== undefined && !SEASONS.includes(json.season as Season)) {
|
||||
problems.push(`season must be one of ${SEASONS.join(", ")}`);
|
||||
}
|
||||
|
||||
const surface = json.surface;
|
||||
if (!is_object(surface)) {
|
||||
problems.push("surface must be { top, filler, filler_depth }");
|
||||
} else {
|
||||
id(surface.top, "surface.top");
|
||||
id(surface.filler, "surface.filler");
|
||||
if (surface.underwater_top !== undefined) id(surface.underwater_top, "surface.underwater_top");
|
||||
if (surface.underwater_filler !== undefined) id(surface.underwater_filler, "surface.underwater_filler");
|
||||
const depth = surface.filler_depth;
|
||||
if (!Number.isInteger(depth) || (depth as number) < 0 || (depth as number) > 32) {
|
||||
problems.push("surface.filler_depth must be a whole number from 0 to 32");
|
||||
}
|
||||
if (surface.bare_cliffs !== undefined && typeof surface.bare_cliffs !== "boolean") {
|
||||
problems.push("surface.bare_cliffs must be true or false");
|
||||
}
|
||||
}
|
||||
|
||||
if (json.colors !== undefined) {
|
||||
if (!is_object(json.colors)) {
|
||||
problems.push("colors must be { grass, foliage, water }");
|
||||
} else {
|
||||
for (const [key, value] of Object.entries(json.colors)) {
|
||||
if (!["grass", "foliage", "water"].includes(key)) problems.push(`colors.${key} isn't a biome color`);
|
||||
else if (!(typeof value === "string" && /^#[0-9a-fA-F]{6}$/.test(value))) {
|
||||
problems.push(`colors.${key} must be a color like "#79c05a"`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const trees = json.trees;
|
||||
if (trees !== undefined) {
|
||||
if (!is_object(trees)) {
|
||||
problems.push("trees must be { chance, kinds }");
|
||||
} else {
|
||||
if (typeof trees.chance !== "number" || trees.chance < 0 || trees.chance > 1) {
|
||||
problems.push("trees.chance must be a number from 0 to 1");
|
||||
}
|
||||
if (!Array.isArray(trees.kinds) || trees.kinds.length === 0) {
|
||||
problems.push("trees.kinds must list at least one kind of tree");
|
||||
} else {
|
||||
for (const kind of trees.kinds) {
|
||||
if (!TREE_KINDS.includes(kind)) {
|
||||
problems.push(`trees.kinds: ${kind} isn't one of ${TREE_KINDS.join(", ")}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (trees.wood !== undefined) {
|
||||
if (!is_object(trees.wood)) {
|
||||
problems.push("trees.wood must be { <kind>: <wood> }");
|
||||
} else {
|
||||
for (const [kind, wood] of Object.entries(trees.wood)) {
|
||||
if (!TREE_KINDS.includes(kind as TreeKind)) {
|
||||
problems.push(`trees.wood: ${kind} isn't a kind of tree`);
|
||||
}
|
||||
if (!WOODS.includes(wood as Wood)) {
|
||||
problems.push(`trees.wood.${kind} must be one of ${WOODS.join(", ")}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return problems;
|
||||
}
|
||||
|
||||
function is_object(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
@@ -3,7 +3,8 @@
|
||||
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, tree_wood, type Wood } from "./trees.ts";
|
||||
import { grow_tree, tree_sites, type Wood } from "./trees.ts";
|
||||
import { type Biome, get_biome, tree_wood } from "./biomes.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
|
||||
@@ -26,83 +27,24 @@ export interface OverworldBlocks {
|
||||
stone: number;
|
||||
dirt: number;
|
||||
grass: number;
|
||||
sand: number;
|
||||
snow: number;
|
||||
water: number;
|
||||
logs: Record<Wood, number>;
|
||||
leaves: Record<Wood, number>;
|
||||
// any other block, for biomes' surfaces
|
||||
block(id: string): number;
|
||||
}
|
||||
|
||||
type Palette = "stone" | "dirt" | "grass" | "sand" | "snow";
|
||||
|
||||
// how a biome covers its ground, like minecraft's surface rules
|
||||
// a biome's surface, as numeric ids
|
||||
interface Surface {
|
||||
top: Palette;
|
||||
filler: Palette;
|
||||
top: number;
|
||||
filler: number;
|
||||
filler_depth: number;
|
||||
// the ground's cover under water
|
||||
underwater_top: Palette;
|
||||
underwater_filler: Palette;
|
||||
// cliffs show bare stone instead of top
|
||||
underwater_top: number;
|
||||
underwater_filler: number;
|
||||
bare_cliffs: boolean;
|
||||
}
|
||||
|
||||
const GRASSY: Surface = {
|
||||
top: "grass",
|
||||
filler: "dirt",
|
||||
filler_depth: 3,
|
||||
underwater_top: "dirt",
|
||||
underwater_filler: "dirt",
|
||||
bare_cliffs: true,
|
||||
};
|
||||
const SANDY: Surface = {
|
||||
top: "sand",
|
||||
filler: "sand",
|
||||
filler_depth: 4,
|
||||
underwater_top: "sand",
|
||||
underwater_filler: "sand",
|
||||
bare_cliffs: false,
|
||||
};
|
||||
const SNOWY: Surface = { ...GRASSY, top: "snow" };
|
||||
const STONY: Surface = {
|
||||
...GRASSY,
|
||||
top: "stone",
|
||||
filler: "stone",
|
||||
underwater_top: "stone",
|
||||
underwater_filler: "stone",
|
||||
};
|
||||
const SEA_FLOOR: Surface = { ...SANDY, filler_depth: 3 };
|
||||
|
||||
// every biome the overworld has, and its surface. names follow minecraft's
|
||||
export const BIOMES: Record<string, Surface> = {
|
||||
"bworld:deep_ocean": SEA_FLOOR,
|
||||
"bworld:deep_frozen_ocean": SEA_FLOOR,
|
||||
"bworld:deep_lukewarm_ocean": SEA_FLOOR,
|
||||
"bworld:ocean": SEA_FLOOR,
|
||||
"bworld:frozen_ocean": SEA_FLOOR,
|
||||
"bworld:warm_ocean": SEA_FLOOR,
|
||||
"bworld:river": { ...GRASSY, underwater_top: "sand", underwater_filler: "sand" },
|
||||
"bworld:frozen_river": { ...SNOWY, underwater_top: "sand", underwater_filler: "sand" },
|
||||
"bworld:beach": SANDY,
|
||||
"bworld:snowy_beach": { ...SANDY, top: "snow" },
|
||||
"bworld:stony_shore": STONY,
|
||||
"bworld:plains": GRASSY,
|
||||
"bworld:meadow": GRASSY,
|
||||
"bworld:forest": GRASSY,
|
||||
"bworld:dark_forest": GRASSY,
|
||||
"bworld:swamp": { ...GRASSY, bare_cliffs: false },
|
||||
"bworld:taiga": GRASSY,
|
||||
"bworld:snowy_plains": SNOWY,
|
||||
"bworld:snowy_taiga": SNOWY,
|
||||
"bworld:savanna": GRASSY,
|
||||
"bworld:jungle": GRASSY,
|
||||
"bworld:desert": SANDY,
|
||||
"bworld:snowy_slopes": SNOWY,
|
||||
"bworld:stony_peaks": STONY,
|
||||
"bworld:jagged_peaks": { ...STONY, top: "snow" },
|
||||
"bworld:frozen_peaks": { ...SNOWY, filler: "stone" },
|
||||
};
|
||||
|
||||
// picks a column's biome from its climate and shape, like minecraft's multi noise biome source
|
||||
export function pick_biome(column: TerrainColumn, surface_y: number, steep: boolean): string {
|
||||
const { continentalness: c, erosion, ridges, temperature: t, humidity: h } = column.climate;
|
||||
@@ -230,6 +172,31 @@ export function generate_overworld(
|
||||
}
|
||||
const column_at = (x: number, z: number) => columns[(z + 1) * ring + x + 1];
|
||||
|
||||
// biomes are registered by mods (bworld's are in mods/bworld/worldgen/biomes), with their surfaces' ids looked up
|
||||
// once per chunk
|
||||
const found = new Map<string, { biome: Biome; surface: Surface }>();
|
||||
const biome_info = (id: string) => {
|
||||
let info = found.get(id);
|
||||
if (!info) {
|
||||
const biome = get_biome(id);
|
||||
if (!biome) throw new Error(`biome ${id} isn't registered, is the bworld mod loaded?`);
|
||||
const { surface } = biome;
|
||||
info = {
|
||||
biome,
|
||||
surface: {
|
||||
top: ids.block(surface.top),
|
||||
filler: ids.block(surface.filler),
|
||||
filler_depth: surface.filler_depth,
|
||||
underwater_top: ids.block(surface.underwater_top),
|
||||
underwater_filler: ids.block(surface.underwater_filler),
|
||||
bare_cliffs: surface.bare_cliffs,
|
||||
},
|
||||
};
|
||||
found.set(id, info);
|
||||
}
|
||||
return info;
|
||||
};
|
||||
|
||||
for (let z = 0; z < CHUNK_SIZE; z++) {
|
||||
for (let x = 0; x < CHUNK_SIZE; x++) {
|
||||
fill_column(x, z);
|
||||
@@ -259,7 +226,8 @@ export function generate_overworld(
|
||||
|
||||
for (const site of tree_sites(seed, chunk_x, chunk_z)) {
|
||||
const column = (site.z - z0) * CHUNK_SIZE + (site.x - x0);
|
||||
const trees = BIOME_TREES[biomes[column]];
|
||||
const { biome } = biome_info(biomes[column]);
|
||||
const trees = biome.trees;
|
||||
if (!trees || site.rng.next() >= trees.chance) continue;
|
||||
|
||||
// on soil with air above it, so never under water or on bare rock
|
||||
@@ -269,7 +237,7 @@ 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)];
|
||||
const wood = tree_wood(kind, biomes[column]);
|
||||
const wood = tree_wood(kind, biome);
|
||||
grow_tree(kind, site.x, ground_y + 1, site.z, site.rng, (x, y, z, block) => place(x, y, z, block, wood));
|
||||
}
|
||||
}
|
||||
@@ -315,7 +283,7 @@ export function generate_overworld(
|
||||
const neighbors = [column_at(x - 1, z), column_at(x + 1, z), column_at(x, z - 1), column_at(x, z + 1)];
|
||||
const steep = neighbors.some((neighbor) => Math.abs(neighbor.height - ground) >= STEEP);
|
||||
const biome = pick_biome(column, surface_y, steep);
|
||||
const surface = BIOMES[biome];
|
||||
const { surface } = biome_info(biome);
|
||||
const snow_y = SNOW_LINE + snow_line.sample(x0 + x, z0 + z) * 10;
|
||||
|
||||
heights[z * CHUNK_SIZE + x] = surface_y;
|
||||
@@ -344,17 +312,17 @@ export function generate_overworld(
|
||||
}
|
||||
|
||||
// surface rules reach the ground and anything above it, not cave floors
|
||||
let block: Palette = "stone";
|
||||
let block = ids.stone;
|
||||
if (y >= ground - SURFACE_REACH) {
|
||||
if (depth === 0) {
|
||||
if (underwater) block = surface.underwater_top;
|
||||
else if (y >= snow_y) block = steep ? "stone" : "snow";
|
||||
else block = steep && surface.bare_cliffs ? "stone" : surface.top;
|
||||
else if (y >= snow_y) block = steep ? ids.stone : ids.snow;
|
||||
else block = steep && surface.bare_cliffs ? ids.stone : surface.top;
|
||||
} else if (depth <= surface.filler_depth) {
|
||||
block = underwater ? surface.underwater_filler : surface.filler;
|
||||
}
|
||||
}
|
||||
blocks[index(y)] = ids[block];
|
||||
blocks[index(y)] = block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,42 +15,11 @@ const REACH = Math.ceil(MIN_DISTANCE / CELL);
|
||||
// the widest a canopy layer gets
|
||||
const MAX_CANOPY = 3;
|
||||
|
||||
export type TreeKind = "oak" | "big_oak" | "birch" | "spruce" | "jungle" | "acacia" | "cherry";
|
||||
export const TREE_KINDS = ["oak", "big_oak", "birch", "spruce", "jungle", "acacia", "cherry"] as const;
|
||||
export type TreeKind = typeof TREE_KINDS[number];
|
||||
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", "birch"] },
|
||||
"bworld:dark_forest": { chance: 1, kinds: ["big_oak", "big_oak", "oak"] },
|
||||
"bworld:plains": { chance: 0.05, 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"] },
|
||||
"bworld:snowy_taiga": { chance: 0.6, kinds: ["spruce"] },
|
||||
"bworld:snowy_plains": { chance: 0.03, kinds: ["spruce"] },
|
||||
"bworld:snowy_slopes": { chance: 0.06, kinds: ["spruce"] },
|
||||
"bworld:savanna": { chance: 0.15, kinds: ["acacia", "acacia", "oak"] },
|
||||
"bworld:jungle": { chance: 1, kinds: ["jungle", "jungle", "big_oak"] },
|
||||
};
|
||||
|
||||
export interface TreeSite {
|
||||
x: number;
|
||||
z: number;
|
||||
|
||||
Reference in New Issue
Block a user