Biome as data
This commit is contained in:
@@ -66,6 +66,7 @@ deno task build && deno task server # packs the mods and starts a se
|
||||
**Everything else**
|
||||
|
||||
- [World Generation](docs/modding/worldgen/index.md): ores and features
|
||||
- [Biomes](docs/modding/worldgen/biomes.md): surfaces, colors, trees and seasons
|
||||
- [Screens](docs/modding/gui/index.md): plain screens, inventory overlays and drawing with `Graphics`
|
||||
- [Networking](docs/modding/networking/index.md): how players get mods and the world
|
||||
- [Saving Data](docs/modding/datastorage/index.md): where a mod keeps what should last
|
||||
|
||||
+2
-2
@@ -23,8 +23,8 @@ What world generation has today (see [World Generation](docs/modding/worldgen/in
|
||||
The biome is exact away from coasts and cliffs. The height is the height before 3D noise, so it isn't the real
|
||||
surface.
|
||||
- **Blocks:** numeric states (up to 16 bits), `variants`, `parts`, shapes, tile data, containers, components and shared
|
||||
rules. Tags exist for blocks, items and entities. Biomes are engine constants (`BIOMES` in
|
||||
`common/worldgen/overworld.ts`), not a registry.
|
||||
rules. Tags exist for blocks, items and entities. Biomes are a registry of data (`worldgen/biomes/` in a mod), but
|
||||
which one a column gets is still engine code (`pick_biome`).
|
||||
- **Loot:** a block's `drops` is one item id. There are no loot tables.
|
||||
|
||||
What's missing for structures:
|
||||
|
||||
+5
-2
@@ -29,6 +29,7 @@ import {
|
||||
} from "./mod_data.ts";
|
||||
import type { ModData } from "./mod_loader.ts";
|
||||
import { type LootTableJson, validate_loot_table } from "./loot.ts";
|
||||
import { type BiomeJson, validate_biome } from "./worldgen/biomes.ts";
|
||||
import { texture_animation, type TextureJson, validate_texture_json } from "./texture_animation.ts";
|
||||
import { ENGINE_GLOBAL } from "./hooks.ts";
|
||||
|
||||
@@ -64,7 +65,8 @@ export class BmodError extends Error {
|
||||
|
||||
// the zip's layout:
|
||||
// manifest.json the mod's manifest, with "scripts" and "credits" pointing into the zip
|
||||
// data.json every block, model, item, recipe, ore, entity, entity model, effect, tag and loot table
|
||||
// data.json every block, model, item, recipe, ore, entity, entity model, effect, tag, loot table and
|
||||
// biome
|
||||
// scripts/<side>.js
|
||||
// textures/<name>.png the texture <mod id>:<name>
|
||||
// textures/<name>.json its animation, if it has one
|
||||
@@ -163,10 +165,11 @@ export function read_bmod(bytes: Uint8Array, file: string): Bmod {
|
||||
effects: checked(raw_data.effects, "effects", validate_effect, problems) as EffectJson[],
|
||||
tags: checked(raw_data.tags, "tags", validate_tag, problems) as TagJson[],
|
||||
loot_tables: checked(raw_data.loot_tables, "loot_tables", validate_loot_table, problems) as LootTableJson[],
|
||||
biomes: checked(raw_data.biomes, "biomes", validate_biome, problems) as BiomeJson[],
|
||||
};
|
||||
// a mod only registers ids in its own namespace
|
||||
const registered = [...data.blocks, ...data.models, ...data.items, ...data.entities, ...data.entity_models];
|
||||
for (const { id } of [...registered, ...data.effects, ...data.loot_tables!]) {
|
||||
for (const { id } of [...registered, ...data.effects, ...data.loot_tables!, ...data.biomes!]) {
|
||||
if (typeof id === "string" && id.split(":")[0] !== mod) problems.push(`${id} isn't in this mod's namespace`);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import { BlockRules } from "./block_rules.ts";
|
||||
import { Tags } from "./tags.ts";
|
||||
import { CommandDispatcher } from "./commands.ts";
|
||||
import { OverworldTerrain } from "./worldgen/terrain.ts";
|
||||
import { BIOMES } from "./worldgen/overworld.ts";
|
||||
import { physics } from "./physics.ts";
|
||||
|
||||
// built when it's exposed, not when this module loads, so import cycles can't leave anything undefined
|
||||
@@ -19,7 +18,6 @@ export function common_engine() {
|
||||
Tags,
|
||||
CommandDispatcher,
|
||||
OverworldTerrain,
|
||||
BIOMES,
|
||||
physics,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -80,11 +80,11 @@ export function generate_raw_chunk(
|
||||
stone: id("bworld:stone"),
|
||||
dirt: id("bworld:dirt"),
|
||||
grass: id("bworld:grass"),
|
||||
sand: id("bworld:sand"),
|
||||
snow: id("bworld:snow_block"),
|
||||
water: id("bworld:water"),
|
||||
logs: wood_ids("log"),
|
||||
leaves: wood_ids("leaves"),
|
||||
block: id,
|
||||
}, (x, y, z, block) => spills.push(x, y, z, block));
|
||||
generate_ores(blocks, chunk_x, chunk_z, seed, block_ids, BASE_ORES, default_values);
|
||||
|
||||
|
||||
+12
-3
@@ -19,7 +19,7 @@ import { BUILTIN_MODELS, type ModelJson } from "./block_models.ts";
|
||||
import { resolve_tags } from "./tags.ts";
|
||||
import type { TextureJson } from "./texture_animation.ts";
|
||||
import { loot_references, type LootTableJson } from "./loot.ts";
|
||||
import { BIOMES } from "./worldgen/overworld.ts";
|
||||
import { biome_blocks, type BiomeJson } from "./worldgen/biomes.ts";
|
||||
|
||||
export interface ModReport {
|
||||
id: string;
|
||||
@@ -43,6 +43,7 @@ export interface LoadedMod {
|
||||
effects: { file: string; json: EffectJson }[];
|
||||
tags: { file: string; json: TagJson }[];
|
||||
loot_tables: { file: string; json: LootTableJson }[];
|
||||
biomes: { file: string; json: BiomeJson }[];
|
||||
textures: string[];
|
||||
// absolute paths by texture id
|
||||
texture_files: Map<string, string>;
|
||||
@@ -90,6 +91,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
const tag_owners = new Map<TagRegistry, Set<string>>();
|
||||
const liquids = new Set<string>();
|
||||
const loot_tables = new Set<string>();
|
||||
const biome_owners = new Map<string, string[]>();
|
||||
const add = (map: Map<string, string[]>, id: string, mod: string) => map.set(id, [...(map.get(id) ?? []), mod]);
|
||||
|
||||
const textures = new Set<string>(engine_textures);
|
||||
@@ -113,6 +115,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
}
|
||||
for (const { json } of mod.effects) add(effect_owners, json.id, mod.id);
|
||||
for (const { json } of mod.loot_tables ?? []) loot_tables.add(json.id);
|
||||
for (const { json } of mod.biomes ?? []) add(biome_owners, json.id, mod.id);
|
||||
for (const { json } of mod.tags) {
|
||||
if (!tag_owners.has(json.registry)) tag_owners.set(json.registry, new Set());
|
||||
tag_owners.get(json.registry)!.add(json.id);
|
||||
@@ -272,6 +275,12 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
// mods' conditions and functions are registered by scripts, the server checks them when it starts
|
||||
for (const id of refs.custom) check_namespace(file, id);
|
||||
}
|
||||
for (const { file, json } of mod.biomes ?? []) {
|
||||
if ((biome_owners.get(json.id)?.length ?? 0) > 1) {
|
||||
errors.push(`${file}: biome ${json.id} is also defined by ${biome_owners.get(json.id)!.join(", ")}`);
|
||||
}
|
||||
for (const id of biome_blocks(json)) uses(file, id, "block");
|
||||
}
|
||||
for (const { file, json } of mod.effects) {
|
||||
if ((effect_owners.get(json.id)?.length ?? 0) > 1) {
|
||||
errors.push(`${file}: effect ${json.id} is also defined by ${effect_owners.get(json.id)!.join(", ")}`);
|
||||
@@ -285,9 +294,9 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
else if (entity.behavior !== "monster") {
|
||||
errors.push(`${file}: ${json.entity} isn't a monster, only monsters spawn on their own for now`);
|
||||
}
|
||||
// biomes are the engine's, whatever their namespace
|
||||
for (const biome of json.biomes ?? []) {
|
||||
if (!(biome in BIOMES)) errors.push(`${file}: biome ${biome} doesn't exist`);
|
||||
check_namespace(file, biome);
|
||||
if (!biome_owners.has(biome)) errors.push(`${file}: biome ${biome} doesn't exist`);
|
||||
}
|
||||
}
|
||||
for (const { file, json } of mod.entity_models) {
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
} from "./mod_data.ts";
|
||||
import { resolve_tags, Tags } from "./tags.ts";
|
||||
import type { LootTableJson } from "./loot.ts";
|
||||
import { type BiomeJson, register_biome } from "./worldgen/biomes.ts";
|
||||
import { register_block_item } from "./utils.ts";
|
||||
import type { ModelJson } from "./block_models.ts";
|
||||
|
||||
@@ -43,6 +44,8 @@ export interface ModData {
|
||||
tags: TagJson[];
|
||||
// see common/loot.ts. missing from mods packed before there were loot tables
|
||||
loot_tables?: LootTableJson[];
|
||||
// see common/worldgen/biomes.ts. missing from mods packed before biomes were data
|
||||
biomes?: BiomeJson[];
|
||||
}
|
||||
|
||||
// a mod as the server lists it to clients, in load order: the .bmod players download, without its server script
|
||||
@@ -123,6 +126,9 @@ export function register_mod_data(mods: { id: string; data: ModData }[]): Recipe
|
||||
for (const json of data.loot_tables ?? []) {
|
||||
EverythingRegistry.register<LootTableJson>("loot_tables", json.id, json);
|
||||
}
|
||||
for (const json of data.biomes ?? []) {
|
||||
register_biome(json);
|
||||
}
|
||||
} catch (e) {
|
||||
throw new ModLoadError(id, (e as Error).message);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -21,6 +21,7 @@ mods/
|
||||
tags/<registry>/<namespace>/*.json # tags, see resources/tags.md
|
||||
loot_tables/**/*.json # loot tables, see resources/loot_tables.md
|
||||
worldgen/ores.json
|
||||
worldgen/biomes/*.json # one biome per file, see worldgen/biomes.md
|
||||
worldgen/spawns.json # monsters that spawn on their own, see entities/index.md
|
||||
textures/*.png
|
||||
textures/*.json # animations, see resources/textures.md
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
# Biomes
|
||||
|
||||
A biome says what the ground looks like where it's picked: the blocks on top, the colors grass, leaves and water are
|
||||
tinted, which trees grow, and its season. Biomes are data, one file each in a mod's `worldgen/biomes/` folder. The base
|
||||
game's are in `mods/bworld/worldgen/biomes/`.
|
||||
|
||||
> [!NOTE]
|
||||
> Which biome a column gets is still decided by the engine (`pick_biome` in `common/worldgen/overworld.ts`), from the
|
||||
> column's climate and height. It only picks the base game's biomes, so a biome a mod adds doesn't generate anywhere
|
||||
> yet. Mods can still list it in their spawns.
|
||||
|
||||
## A Biome
|
||||
|
||||
`worldgen/biomes/dark_forest.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:dark_forest",
|
||||
"surface": {
|
||||
"top": "bworld:grass",
|
||||
"filler": "bworld:dirt",
|
||||
"filler_depth": 3,
|
||||
"bare_cliffs": true
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#507a32",
|
||||
"foliage": "#59ae30",
|
||||
"water": "#3f76e4"
|
||||
},
|
||||
"trees": {
|
||||
"chance": 1,
|
||||
"kinds": ["big_oak", "big_oak", "oak"],
|
||||
"wood": { "big_oak": "dark_oak" }
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
| Field | What it does | When not set |
|
||||
| --------------------------- | ---------------------------------------------------------------------------------------- | ------------ |
|
||||
| `id` | in your mod's namespace | required |
|
||||
| `season` | `spring`, `summer`, `autumn` or `winter`. Nothing uses it yet | `spring` |
|
||||
| `surface.top` | the block on top of the ground | required |
|
||||
| `surface.filler` | the blocks under it | required |
|
||||
| `surface.filler_depth` | how many blocks of filler, 0 to 32. Stone is below | required |
|
||||
| `surface.underwater_top` | the top block where the ground is under water | `filler` |
|
||||
| `surface.underwater_filler` | the filler under water | `filler` |
|
||||
| `surface.bare_cliffs` | steep ground shows stone instead of `top` | `false` |
|
||||
| `colors.grass` | what blocks with `"tint": { "color": "grass" }` are drawn in, as `#rrggbb` | plains' |
|
||||
| `colors.foliage` | the same for `"foliage"`, like leaves | plains' |
|
||||
| `colors.water` | the same for `"water"` | plains' |
|
||||
| `trees.chance` | how likely each tree spot is to get a tree, 0 to 1. Spots are at least 4 blocks apart | no trees |
|
||||
| `trees.kinds` | which trees grow, picked evenly: list one twice to make it twice as likely | |
|
||||
| `trees.wood` | the logs and leaves a kind grows here when it isn't its own, like dark oak for `big_oak` | |
|
||||
|
||||
Tree kinds are `oak`, `big_oak`, `birch`, `spruce`, `jungle`, `acacia` and `cherry`. Woods are `oak`, `spruce`, `birch`,
|
||||
`jungle`, `acacia`, `dark_oak` and `cherry`. Trees only grow on grass, dirt or snow with air above.
|
||||
|
||||
Above the snow line, around y 176, the top block is snow whatever the biome says.
|
||||
|
||||
## Biome Ids
|
||||
|
||||
Biome ids are what features' `biome_at` gives and what spawns list. The base game has `bworld:deep_ocean`,
|
||||
`bworld:deep_frozen_ocean`, `bworld:deep_lukewarm_ocean`, `bworld:ocean`, `bworld:frozen_ocean`, `bworld:warm_ocean`,
|
||||
`bworld:river`, `bworld:frozen_river`, `bworld:beach`, `bworld:snowy_beach`, `bworld:stony_shore`, `bworld:plains`,
|
||||
`bworld:meadow`, `bworld:forest`, `bworld:dark_forest`, `bworld:swamp`, `bworld:taiga`, `bworld:snowy_plains`,
|
||||
`bworld:snowy_taiga`, `bworld:savanna`, `bworld:jungle`, `bworld:desert`, `bworld:snowy_slopes`, `bworld:stony_peaks`,
|
||||
`bworld:jagged_peaks` and `bworld:frozen_peaks`.
|
||||
|
||||
`/locatebiome <id>` finds the nearest one.
|
||||
@@ -101,7 +101,7 @@ sea. Mountain ranges rise where erosion is low, and rivers run along the valleys
|
||||
they reach mountains. The flatter land is split into regions with their own shapes: valleys and plateaus (with badlands
|
||||
ridges where it's hot), tiered mesas, rolling hills and jungle pillars, and wetlands and desert dunes.
|
||||
|
||||
Biome ids are the keys of `BIOMES` in `common/worldgen/overworld.ts`, like `bworld:plains` or `bworld:jagged_peaks`.
|
||||
Which biome each column gets is part of the terrain, but what a biome looks like is data: see [Biomes](biomes.md).
|
||||
|
||||
`deno run -A tools/worldgen_preview.ts [seed] [out dir] [x z]` renders it to PNG files, around chunk `x z`.
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:beach",
|
||||
"surface": {
|
||||
"top": "bworld:sand",
|
||||
"filler": "bworld:sand",
|
||||
"filler_depth": 4
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#91bd59",
|
||||
"foliage": "#77ab2f",
|
||||
"water": "#3f76e4"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:dark_forest",
|
||||
"surface": {
|
||||
"top": "bworld:grass",
|
||||
"filler": "bworld:dirt",
|
||||
"filler_depth": 3,
|
||||
"bare_cliffs": true
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#507a32",
|
||||
"foliage": "#59ae30",
|
||||
"water": "#3f76e4"
|
||||
},
|
||||
"trees": {
|
||||
"chance": 1,
|
||||
"kinds": [
|
||||
"big_oak",
|
||||
"big_oak",
|
||||
"oak"
|
||||
],
|
||||
"wood": {
|
||||
"big_oak": "dark_oak"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:deep_frozen_ocean",
|
||||
"surface": {
|
||||
"top": "bworld:sand",
|
||||
"filler": "bworld:sand",
|
||||
"filler_depth": 3
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#80b497",
|
||||
"foliage": "#60a17b",
|
||||
"water": "#3938c9"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:deep_lukewarm_ocean",
|
||||
"surface": {
|
||||
"top": "bworld:sand",
|
||||
"filler": "bworld:sand",
|
||||
"filler_depth": 3
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#8eb971",
|
||||
"foliage": "#71a74d",
|
||||
"water": "#45adf2"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:deep_ocean",
|
||||
"surface": {
|
||||
"top": "bworld:sand",
|
||||
"filler": "bworld:sand",
|
||||
"filler_depth": 3
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#8eb971",
|
||||
"foliage": "#71a74d",
|
||||
"water": "#3f76e4"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:desert",
|
||||
"surface": {
|
||||
"top": "bworld:sand",
|
||||
"filler": "bworld:sand",
|
||||
"filler_depth": 4
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#bfb755",
|
||||
"foliage": "#aea42a",
|
||||
"water": "#3f76e4"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:forest",
|
||||
"surface": {
|
||||
"top": "bworld:grass",
|
||||
"filler": "bworld:dirt",
|
||||
"filler_depth": 3,
|
||||
"bare_cliffs": true
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#79c05a",
|
||||
"foliage": "#59ae30",
|
||||
"water": "#3f76e4"
|
||||
},
|
||||
"trees": {
|
||||
"chance": 0.85,
|
||||
"kinds": [
|
||||
"oak",
|
||||
"oak",
|
||||
"big_oak",
|
||||
"birch"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:frozen_ocean",
|
||||
"surface": {
|
||||
"top": "bworld:sand",
|
||||
"filler": "bworld:sand",
|
||||
"filler_depth": 3
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#80b497",
|
||||
"foliage": "#60a17b",
|
||||
"water": "#3938c9"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:frozen_peaks",
|
||||
"surface": {
|
||||
"top": "bworld:snow_block",
|
||||
"filler": "bworld:stone",
|
||||
"filler_depth": 3,
|
||||
"underwater_top": "bworld:dirt",
|
||||
"underwater_filler": "bworld:dirt",
|
||||
"bare_cliffs": true
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#80b497",
|
||||
"foliage": "#60a17b",
|
||||
"water": "#3f76e4"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:frozen_river",
|
||||
"surface": {
|
||||
"top": "bworld:snow_block",
|
||||
"filler": "bworld:dirt",
|
||||
"filler_depth": 3,
|
||||
"underwater_top": "bworld:sand",
|
||||
"underwater_filler": "bworld:sand",
|
||||
"bare_cliffs": true
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#80b497",
|
||||
"foliage": "#60a17b",
|
||||
"water": "#3938c9"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:jagged_peaks",
|
||||
"surface": {
|
||||
"top": "bworld:snow_block",
|
||||
"filler": "bworld:stone",
|
||||
"filler_depth": 3,
|
||||
"bare_cliffs": true
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#80b497",
|
||||
"foliage": "#60a17b",
|
||||
"water": "#3f76e4"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:jungle",
|
||||
"surface": {
|
||||
"top": "bworld:grass",
|
||||
"filler": "bworld:dirt",
|
||||
"filler_depth": 3,
|
||||
"bare_cliffs": true
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#59c93c",
|
||||
"foliage": "#30bb0b",
|
||||
"water": "#3f76e4"
|
||||
},
|
||||
"trees": {
|
||||
"chance": 1,
|
||||
"kinds": [
|
||||
"jungle",
|
||||
"jungle",
|
||||
"big_oak"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:meadow",
|
||||
"surface": {
|
||||
"top": "bworld:grass",
|
||||
"filler": "bworld:dirt",
|
||||
"filler_depth": 3,
|
||||
"bare_cliffs": true
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#83bb6d",
|
||||
"foliage": "#63a948",
|
||||
"water": "#0e4ecf"
|
||||
},
|
||||
"trees": {
|
||||
"chance": 0.06,
|
||||
"kinds": [
|
||||
"oak",
|
||||
"birch",
|
||||
"cherry",
|
||||
"cherry"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:ocean",
|
||||
"surface": {
|
||||
"top": "bworld:sand",
|
||||
"filler": "bworld:sand",
|
||||
"filler_depth": 3
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#8eb971",
|
||||
"foliage": "#71a74d",
|
||||
"water": "#3f76e4"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:plains",
|
||||
"surface": {
|
||||
"top": "bworld:grass",
|
||||
"filler": "bworld:dirt",
|
||||
"filler_depth": 3,
|
||||
"bare_cliffs": true
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#91bd59",
|
||||
"foliage": "#77ab2f",
|
||||
"water": "#3f76e4"
|
||||
},
|
||||
"trees": {
|
||||
"chance": 0.05,
|
||||
"kinds": [
|
||||
"oak"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:river",
|
||||
"surface": {
|
||||
"top": "bworld:grass",
|
||||
"filler": "bworld:dirt",
|
||||
"filler_depth": 3,
|
||||
"underwater_top": "bworld:sand",
|
||||
"underwater_filler": "bworld:sand",
|
||||
"bare_cliffs": true
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#8eb971",
|
||||
"foliage": "#71a74d",
|
||||
"water": "#3f76e4"
|
||||
},
|
||||
"trees": {
|
||||
"chance": 0.05,
|
||||
"kinds": [
|
||||
"oak"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:savanna",
|
||||
"surface": {
|
||||
"top": "bworld:grass",
|
||||
"filler": "bworld:dirt",
|
||||
"filler_depth": 3,
|
||||
"bare_cliffs": true
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#bfb755",
|
||||
"foliage": "#aea42a",
|
||||
"water": "#3f76e4"
|
||||
},
|
||||
"trees": {
|
||||
"chance": 0.15,
|
||||
"kinds": [
|
||||
"acacia",
|
||||
"acacia",
|
||||
"oak"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:snowy_beach",
|
||||
"surface": {
|
||||
"top": "bworld:snow_block",
|
||||
"filler": "bworld:sand",
|
||||
"filler_depth": 4
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#83b593",
|
||||
"foliage": "#64a278",
|
||||
"water": "#3d57d6"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:snowy_plains",
|
||||
"surface": {
|
||||
"top": "bworld:snow_block",
|
||||
"filler": "bworld:dirt",
|
||||
"filler_depth": 3,
|
||||
"bare_cliffs": true
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#80b497",
|
||||
"foliage": "#60a17b",
|
||||
"water": "#3f76e4"
|
||||
},
|
||||
"trees": {
|
||||
"chance": 0.03,
|
||||
"kinds": [
|
||||
"spruce"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:snowy_slopes",
|
||||
"surface": {
|
||||
"top": "bworld:snow_block",
|
||||
"filler": "bworld:dirt",
|
||||
"filler_depth": 3,
|
||||
"bare_cliffs": true
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#80b497",
|
||||
"foliage": "#60a17b",
|
||||
"water": "#3f76e4"
|
||||
},
|
||||
"trees": {
|
||||
"chance": 0.06,
|
||||
"kinds": [
|
||||
"spruce"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:snowy_taiga",
|
||||
"surface": {
|
||||
"top": "bworld:snow_block",
|
||||
"filler": "bworld:dirt",
|
||||
"filler_depth": 3,
|
||||
"bare_cliffs": true
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#80b497",
|
||||
"foliage": "#60a17b",
|
||||
"water": "#3d57d6"
|
||||
},
|
||||
"trees": {
|
||||
"chance": 0.6,
|
||||
"kinds": [
|
||||
"spruce"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:stony_peaks",
|
||||
"surface": {
|
||||
"top": "bworld:stone",
|
||||
"filler": "bworld:stone",
|
||||
"filler_depth": 3,
|
||||
"bare_cliffs": true
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#9abe4b",
|
||||
"foliage": "#82ac1e",
|
||||
"water": "#3f76e4"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:stony_shore",
|
||||
"surface": {
|
||||
"top": "bworld:stone",
|
||||
"filler": "bworld:stone",
|
||||
"filler_depth": 3,
|
||||
"bare_cliffs": true
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#8ab689",
|
||||
"foliage": "#6da36b",
|
||||
"water": "#3f76e4"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:swamp",
|
||||
"surface": {
|
||||
"top": "bworld:grass",
|
||||
"filler": "bworld:dirt",
|
||||
"filler_depth": 3
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#6a7039",
|
||||
"foliage": "#6a7039",
|
||||
"water": "#617b64"
|
||||
},
|
||||
"trees": {
|
||||
"chance": 0.4,
|
||||
"kinds": [
|
||||
"big_oak"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:taiga",
|
||||
"surface": {
|
||||
"top": "bworld:grass",
|
||||
"filler": "bworld:dirt",
|
||||
"filler_depth": 3,
|
||||
"bare_cliffs": true
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#86b783",
|
||||
"foliage": "#68a464",
|
||||
"water": "#3f76e4"
|
||||
},
|
||||
"trees": {
|
||||
"chance": 0.75,
|
||||
"kinds": [
|
||||
"spruce"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"biome": {
|
||||
"id": "bworld:warm_ocean",
|
||||
"surface": {
|
||||
"top": "bworld:sand",
|
||||
"filler": "bworld:sand",
|
||||
"filler_depth": 3
|
||||
},
|
||||
"colors": {
|
||||
"grass": "#8eb971",
|
||||
"foliage": "#71a74d",
|
||||
"water": "#43d5ee"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,8 @@ import {
|
||||
number,
|
||||
word,
|
||||
} from "$/common/commands.ts";
|
||||
import { BIOMES, estimate_biome } from "$/common/worldgen/overworld.ts";
|
||||
import { estimate_biome } from "$/common/worldgen/overworld.ts";
|
||||
import { biome_ids, get_biome } from "$/common/worldgen/biomes.ts";
|
||||
import type { GameLoop } from "./game_loop.ts";
|
||||
import { update_crafting_result } from "./crafting.ts";
|
||||
import type { Menu } from "./menu.ts";
|
||||
@@ -1401,12 +1402,10 @@ export class GameServer {
|
||||
register(
|
||||
literal<ServerCommandSource>("locatebiome").describe("Finds the nearest biome of a kind").then(
|
||||
argument<string, ServerCommandSource>("biome", word())
|
||||
.suggests((partial) =>
|
||||
Object.keys(BIOMES).filter((id) => id.startsWith(partial)).map((text) => ({ text }))
|
||||
)
|
||||
.suggests((partial) => biome_ids().filter((id) => id.startsWith(partial)).map((text) => ({ text })))
|
||||
.executes((context) => {
|
||||
const id = context.get<string>("biome");
|
||||
if (!BIOMES[id]) throw new CommandError(`There's no biome ${id}`);
|
||||
if (!get_biome(id)) throw new CommandError(`There's no biome ${id}`);
|
||||
const player = context.source.server_player;
|
||||
const found = this.#locate_biome(id, Math.floor(player.x), Math.floor(player.z));
|
||||
if (!found) {
|
||||
|
||||
@@ -107,6 +107,7 @@ function as_loaded_mod(file: string, bmod: Bmod): LoadedMod {
|
||||
effects: entries(bmod.data.effects),
|
||||
tags: entries(bmod.data.tags),
|
||||
loot_tables: entries(bmod.data.loot_tables ?? []),
|
||||
biomes: entries(bmod.data.biomes ?? []),
|
||||
textures: [...bmod.textures.keys()],
|
||||
texture_files: new Map(),
|
||||
texture_json: new Map(bmod.texture_json),
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// biomes are data, worldgen/biomes/<name>.json in a mod. see common/worldgen/biomes.ts
|
||||
import { assert, assertEquals } from "@std/assert";
|
||||
import { biome_from_json, biome_ids, get_biome, validate_biome } from "$/common/worldgen/biomes.ts";
|
||||
import { test_game } from "./helpers.ts";
|
||||
|
||||
const PLAIN = { id: "my_mod:flat", surface: { top: "bworld:grass", filler: "bworld:dirt", filler_depth: 3 } };
|
||||
|
||||
Deno.test("the bworld mod registers every biome the overworld picks", async () => {
|
||||
await test_game("mods");
|
||||
assertEquals(biome_ids().length, 26);
|
||||
assertEquals(get_biome("bworld:dark_forest")?.trees?.wood.big_oak, "dark_oak");
|
||||
assertEquals(get_biome("bworld:river")?.surface.underwater_top, "bworld:sand");
|
||||
});
|
||||
|
||||
Deno.test("a biome is in spring unless it says otherwise", async () => {
|
||||
await test_game("mods");
|
||||
assertEquals(get_biome("bworld:plains")?.season, "spring");
|
||||
assertEquals(biome_from_json(PLAIN).season, "spring");
|
||||
assertEquals(biome_from_json({ ...PLAIN, season: "winter" }).season, "winter");
|
||||
});
|
||||
|
||||
Deno.test("a biome's surface defaults: underwater is its filler, cliffs aren't bare", () => {
|
||||
const { surface, colors, trees } = biome_from_json(PLAIN);
|
||||
assertEquals(surface.underwater_top, "bworld:dirt");
|
||||
assertEquals(surface.underwater_filler, "bworld:dirt");
|
||||
assertEquals(surface.bare_cliffs, false);
|
||||
assertEquals(colors, { grass: undefined, foliage: undefined, water: undefined });
|
||||
assertEquals(trees, undefined);
|
||||
});
|
||||
|
||||
Deno.test("bad biome json is reported", () => {
|
||||
assertEquals(validate_biome(PLAIN), []);
|
||||
assert(validate_biome({ ...PLAIN, season: "monsoon" }).some((p) => p.startsWith("season")));
|
||||
assert(validate_biome({ ...PLAIN, colors: { grass: "green" } }).some((p) => p.startsWith("colors.grass")));
|
||||
assert(validate_biome({ ...PLAIN, trees: { chance: 2, kinds: ["palm"] } }).length === 2);
|
||||
assert(validate_biome({ id: "my_mod:flat" }).some((p) => p.startsWith("surface")));
|
||||
});
|
||||
@@ -39,6 +39,7 @@ export function mod_sources(mods_dir: string): ServerModSource[] {
|
||||
effects: mod.effects.map((e) => e.json),
|
||||
tags: mod.tags.map((t) => t.json),
|
||||
loot_tables: mod.loot_tables.map((t) => t.json),
|
||||
biomes: mod.biomes.map((b) => b.json),
|
||||
},
|
||||
server_url: url(scripts.server),
|
||||
worldgen_url: url(scripts.worldgen),
|
||||
|
||||
+5
-4
@@ -3,7 +3,7 @@ import { assert, assertEquals } from "@std/assert";
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { CHUNK_AREA, CHUNK_HEIGHT, CHUNK_SIZE } from "$/common/constants.ts";
|
||||
import { generate_raw_chunk } from "$/common/generation.ts";
|
||||
import { BIOME_FOLIAGE_COLORS, BIOME_GRASS_COLORS, BIOME_WATER_COLORS } from "$/common/worldgen/biome_colors.ts";
|
||||
import { get_biome } from "$/common/worldgen/biomes.ts";
|
||||
import { type LayerMesh, TERRAIN_VERTEX_BYTES } from "$/client/workers/chunk_messages.ts";
|
||||
import { test_game } from "./helpers.ts";
|
||||
|
||||
@@ -121,9 +121,10 @@ Deno.test("every column the overworld generates has a biome with grass, foliage
|
||||
const { biomes } = generate_raw_chunk(x, z, game.world.seed, block_ids);
|
||||
assertEquals(biomes.length, CHUNK_AREA);
|
||||
for (const biome of biomes) {
|
||||
assert(biome in BIOME_GRASS_COLORS, `${biome} has no grass color`);
|
||||
assert(biome in BIOME_FOLIAGE_COLORS, `${biome} has no foliage color`);
|
||||
assert(biome in BIOME_WATER_COLORS, `${biome} has no water color`);
|
||||
const { colors } = get_biome(biome)!;
|
||||
assert(colors.grass !== undefined, `${biome} has no grass color`);
|
||||
assert(colors.foliage !== undefined, `${biome} has no foliage color`);
|
||||
assert(colors.water !== undefined, `${biome} has no water color`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+3
-2
@@ -3,7 +3,7 @@ import { CHUNK_AREA, CHUNK_SIZE } from "$/common/constants.ts";
|
||||
import { Container, ItemStack } from "$/common/inventory.ts";
|
||||
import { CRAFTING_RESULT_SLOT } from "$/common/protocol.ts";
|
||||
import { generate_raw_chunk } from "$/common/generation.ts";
|
||||
import { BIOME_TREES, tree_wood } from "$/common/worldgen/trees.ts";
|
||||
import { get_biome, tree_wood } from "$/common/worldgen/biomes.ts";
|
||||
import { update_crafting_result } from "$/server/game/crafting.ts";
|
||||
import { test_game } from "./helpers.ts";
|
||||
|
||||
@@ -63,7 +63,8 @@ Deno.test("trees grow the wood of their kind and biome", async () => {
|
||||
if (!wood || !ground.has(blocks[i - CHUNK_AREA])) return;
|
||||
const column = i % CHUNK_AREA;
|
||||
const biome = biomes[column];
|
||||
const allowed = BIOME_TREES[biome].kinds.map((kind) => tree_wood(kind, biome));
|
||||
const info = get_biome(biome)!;
|
||||
const allowed = info.trees!.kinds.map((kind) => tree_wood(kind, info));
|
||||
assert(
|
||||
allowed.includes(wood as never),
|
||||
`${wood} in ${biome} at ${cx * CHUNK_SIZE}, ${cz * CHUNK_SIZE}`,
|
||||
|
||||
@@ -21,6 +21,7 @@ import { check_references, load_order, type LoadedMod, type ModReport } from "$/
|
||||
import { png_size, texture_size_problem } from "$/common/bmod.ts";
|
||||
import { type TextureJson, validate_texture_json } from "$/common/texture_animation.ts";
|
||||
import { type LootTableJson, validate_loot_table } from "$/common/loot.ts";
|
||||
import { validate_biome } from "$/common/worldgen/biomes.ts";
|
||||
import { dirname } from "@std/path";
|
||||
|
||||
export { load_order, type LoadedMod, type ModReport };
|
||||
@@ -82,6 +83,7 @@ function load_mod(mods_dir: string, id: string): LoadedMod {
|
||||
effects: [],
|
||||
tags: [],
|
||||
loot_tables: [],
|
||||
biomes: [],
|
||||
textures: [],
|
||||
texture_files: new Map(),
|
||||
texture_json: new Map(),
|
||||
@@ -147,6 +149,7 @@ function load_mod(mods_dir: string, id: string): LoadedMod {
|
||||
load_data("recipes", "recipe", validate_recipe, mod.recipes);
|
||||
load_data("entities", "entity", validate_entity, mod.entities);
|
||||
load_data("effects", "effect", validate_effect, mod.effects);
|
||||
load_data("worldgen/biomes", "biome", validate_biome, mod.biomes);
|
||||
|
||||
for (const file of walk(`${dir}/models`, ".geo.json")) {
|
||||
const path = `models/${file}`;
|
||||
|
||||
@@ -43,6 +43,7 @@ export async function pack_mod(mod: LoadedMod): Promise<Uint8Array<ArrayBuffer>>
|
||||
effects: mod.effects.map((e) => e.json),
|
||||
tags: mod.tags.map((t) => t.json),
|
||||
loot_tables: mod.loot_tables.map((t) => t.json),
|
||||
biomes: mod.biomes.map((b) => b.json),
|
||||
},
|
||||
scripts,
|
||||
textures,
|
||||
|
||||
@@ -7,11 +7,18 @@ import { CHUNK_AREA, CHUNK_HEIGHT, CHUNK_SIZE, SEA_LEVEL } from "$/common/consta
|
||||
import { generate_raw_chunk } from "$/common/generation.ts";
|
||||
import { OverworldTerrain } from "$/common/worldgen/terrain.ts";
|
||||
import { pick_biome } from "$/common/worldgen/overworld.ts";
|
||||
import { register_biome } from "$/common/worldgen/biomes.ts";
|
||||
import { load_and_check } from "./check_mods.ts";
|
||||
|
||||
const seed = Deno.args[0] ?? "preview";
|
||||
const out = Deno.args[1] ?? ".";
|
||||
const [center_x, center_z] = [Number(Deno.args[2] ?? 0), Number(Deno.args[3] ?? 0)];
|
||||
|
||||
// the base game's biomes, from mods/bworld
|
||||
for (const mod of load_and_check()) {
|
||||
if (mod.id === "bworld") { for (const { json } of mod.biomes) register_biome(json); }
|
||||
}
|
||||
|
||||
const NAMES = [
|
||||
"bworld:stone",
|
||||
"bworld:dirt",
|
||||
|
||||
Reference in New Issue
Block a user