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
+33
View File
@@ -2,6 +2,7 @@
// a block picks one with "model" and fills in its texture variables with "textures". baking turns a model
// into quads in block space (0 to 1) that the chunk mesher and the item renderers draw
import type { BlockRegistry, BlockTextures } from "./everything_registry.ts";
import { tint_without_biome } from "./worldgen/biome_colors.ts";
export type ModelFace = "top" | "bottom" | "north" | "south" | "west" | "east";
export const MODEL_FACES: ModelFace[] = ["top", "bottom", "north", "south", "west", "east"];
@@ -126,6 +127,20 @@ export function resolve_texture(reference: string, textures: BlockTextures | und
return reference.startsWith("#") ? "engine:missing" : reference;
}
// the variables a texture reference goes through before it's a texture id, "#front" on a cube is front then side
export function texture_variables(reference: string, textures: BlockTextures | undefined, model?: ModelJson) {
const variables: string[] = [];
for (let depth = 0; depth < 8 && reference.startsWith("#"); depth++) {
const name = reference.slice(1);
variables.push(name);
if (typeof textures === "string") break;
const next = (textures as Record<string, string> | undefined)?.[name] ?? model?.textures?.[name];
if (next === undefined) break;
reference = next;
}
return variables;
}
// the block's model and textures for a value with state bits, from the first variant whose conditions match
export function block_variant(block: BlockRegistry, states?: Record<string, number>): Required<BlockVariant> {
const variant: Required<BlockVariant> = {
@@ -168,6 +183,21 @@ export function cube_face_texture(block: BlockRegistry, face: "top" | "bottom" |
return resolve_texture(`#${face}`, block.textures, BUILTIN_MODELS[DEFAULT_MODEL]);
}
// the color to draw a face of a block's item in, as r g b from 0 to 1. items aren't in a biome, so a biome "tint"
// gets the default grass or foliage color, like minecraft's grass block item
export function cube_face_tint(block: BlockRegistry, face: "top" | "bottom" | "front" | "side"): number[] {
const variables = texture_variables(`#${face}`, block.textures, BUILTIN_MODELS[DEFAULT_MODEL]);
if (!is_tinted(block, variables)) return [1, 1, 1];
const color = tint_without_biome(block.tint!.color);
return [color >> 16, (color >> 8) & 0xff, color & 0xff].map((c) => c / 255);
}
// whether a face that got its texture through these variables is drawn in the block's tint
export function is_tinted(block: BlockRegistry, variables: string[]) {
if (!block.tint) return false;
return !block.tint.textures || block.tint.textures.some((name) => variables.includes(name));
}
// baking
export interface BakedQuad {
@@ -176,6 +206,8 @@ export interface BakedQuad {
// u v per corner, in pixels of the texture (0-16)
uvs: number[];
texture: string;
// the texture variables it went through to get there, like ["front", "side"], for "tint"
variables: string[];
// the side it faces most, as the mesher's face index (see FACE_INDEX)
face: number;
// the side whose neighbor can hide it, or -1
@@ -257,6 +289,7 @@ export function bake_model(model: ModelJson, textures: BlockTextures | undefined
positions,
uvs,
texture: resolve_texture(face_json.texture, textures, model),
variables: texture_variables(face_json.texture, textures, model),
face: facing,
cull,
flush,
+4
View File
@@ -1,3 +1,4 @@
import type { TintColor } from "./worldgen/biome_colors.ts";
import type { ItemStack } from "./inventory.ts";
import type { BlockVariant } from "./block_models.ts";
@@ -108,6 +109,9 @@ export interface BlockRegistry {
render_layer?: RenderLayer;
// hide faces between two of this block, like glass and water. defaults to true for translucent blocks
cull_same?: boolean;
// drawn in a color: the biome's grass or foliage color, like minecraft's grass block and leaves, or a fixed one
// like "#80a755". only the texture variables listed (like "top"), or all of them
tint?: { color: TintColor; textures?: string[] };
// light level 0-15 it gives off
light_emission?: number;
// how much light going through it loses, 0-15. see block_light_opacity for the default
+11 -3
View File
@@ -5,6 +5,7 @@ import { AIR, CHUNK_AREA, CHUNK_HEIGHT, CHUNK_SIZE, ID_MASK } from "$/common/con
import type { FeatureChunk } from "$/common/mod_api/worldgen.ts";
import type { OreJson } from "$/common/mod_data.ts";
import { generate_overworld } from "./worldgen/overworld.ts";
import { type Wood, WOODS } from "./worldgen/trees.ts";
import { named_noise_2d, named_noise_3d } from "./worldgen/noise.ts";
export { named_noise_2d, named_noise_3d };
@@ -29,6 +30,8 @@ export interface RawChunk {
blocks: Uint32Array;
// blocks it generated in other chunks (from features like a mod's trees), flattened as x, y, z, numeric id
spills: Int32Array;
// each column's biome id, x then z
biomes: string[];
}
// features that threw, so each is only reported once
@@ -70,6 +73,11 @@ export function generate_raw_chunk(
const nid = block_ids[name];
return nid === undefined ? AIR : default_values?.[nid] ?? nid;
};
// oak's are the plain bworld:log and bworld:leaves, the others are named after their wood
const wood_ids = (part: "log" | "leaves") =>
Object.fromEntries(
WOODS.map((wood) => [wood, id(wood === "oak" ? `bworld:${part}` : `bworld:${wood}_${part}`)]),
) as Record<Wood, number>;
generate_overworld(blocks, heights, biomes, chunk_x, chunk_z, seed, {
stone: id("bworld:stone"),
dirt: id("bworld:dirt"),
@@ -77,8 +85,8 @@ export function generate_raw_chunk(
sand: id("bworld:sand"),
snow: id("bworld:snow"),
water: id("bworld:water"),
log: id("bworld:log"),
leaves: id("bworld:leaves"),
logs: wood_ids("log"),
leaves: wood_ids("leaves"),
}, (x, y, z, block) => spills.push(x, y, z, block));
generate_ores(blocks, chunk_x, chunk_z, seed, block_ids, BASE_ORES, default_values);
@@ -87,7 +95,7 @@ export function generate_raw_chunk(
generate_features(blocks, heights, biomes, set, chunk_x, chunk_z, seed, block_ids, worldgen.features);
}
return { blocks, spills: new Int32Array(spills) };
return { blocks, spills: new Int32Array(spills), biomes };
}
// each block an ore replaces becomes the first ore whose noise is above its threshold
+4 -4
View File
@@ -1,6 +1,6 @@
// checks between mods: dependencies, load order, and ids one mod uses from another. pure, so the build, check-mods
// and the server (on .bmod files) all use it
import type { BlockJson, ItemJson, OreJson, RecipeJson } from "./mod_data.ts";
import { type BlockJson, choice_ids, type ItemJson, type OreJson, type RecipeJson } from "./mod_data.ts";
import { BUILTIN_MODELS, type ModelJson } from "./block_models.ts";
export interface ModReport {
@@ -135,15 +135,15 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
for (const { file, json } of mod.recipes) {
switch (json.type) {
case "shaped":
for (const id of Object.values(json.key)) uses(file, id, "item");
for (const id of Object.values(json.key).flatMap(choice_ids)) uses(file, id, "item");
uses(file, json.result.id, "item");
break;
case "furnace":
uses(file, json.input, "item");
for (const id of choice_ids(json.input)) uses(file, id, "item");
uses(file, json.output.id, "item");
break;
case "fuel":
uses(file, json.item, "item");
for (const id of choice_ids(json.item)) uses(file, id, "item");
break;
case "smithing":
uses(file, json.tool, "item");
+47 -17
View File
@@ -1,5 +1,6 @@
// the json formats from MODS.md, and converting them to and from the engine's registry entries.
// the mod loader uses the from_json direction, tests use both to check nothing is lost
import { is_tint_color, type TintColor } from "./worldgen/biome_colors.ts";
import {
type BlockRegistry,
type BlockStateDefinition,
@@ -38,6 +39,7 @@ export interface BlockJson {
variants?: Record<string, BlockVariant>;
render_layer?: RenderLayer;
cull_same?: boolean;
tint?: { color: TintColor; textures?: string[] };
light_emission?: number;
light_opacity?: number;
// replaced by render_layer, true means translucent
@@ -76,15 +78,22 @@ export interface ItemJson {
components?: Record<string, unknown>;
}
// an item a recipe takes: its id, or a list of ids any of which fits, like every kind of planks
export type ItemChoice = string | string[];
export function choice_ids(choice: ItemChoice): string[] {
return typeof choice === "string" ? [choice] : choice;
}
export type RecipeJson =
| {
type: "shaped";
pattern: string[];
key: Record<string, string>;
key: Record<string, ItemChoice>;
result: { id: string; count: number };
}
| { type: "furnace"; input: string; output: { id: string; count: number }; cook_time: number }
| { type: "fuel"; item: string; burn_time: number }
| { type: "furnace"; input: ItemChoice; output: { id: string; count: number }; cook_time: number }
| { type: "fuel"; item: ItemChoice; burn_time: number }
// upgrades a tool at a smithing table, with some of a material and maybe one more item
| {
type: "smithing";
@@ -111,7 +120,7 @@ export function is_mod_recipe(recipe: RecipeJson): recipe is ModRecipeJson {
export interface GridRecipe {
width: number;
height: number;
pattern: (string | undefined)[];
pattern: (ItemChoice | undefined)[];
result: { id: string; count: number };
}
@@ -124,6 +133,7 @@ export function block_to_json(block: BlockRegistry, has_item: boolean): BlockJso
if (block.variants !== undefined) json.variants = block.variants;
if (block.render_layer && block.render_layer !== "solid") json.render_layer = block.render_layer;
if (block.cull_same !== undefined) json.cull_same = block.cull_same;
if (block.tint !== undefined) json.tint = block.tint;
if (block.light_emission !== undefined) json.light_emission = block.light_emission;
if (block.light_opacity !== undefined) json.light_opacity = block.light_opacity;
if (block.alpha !== undefined) json.alpha = block.alpha;
@@ -156,6 +166,7 @@ export function block_from_json(json: BlockJson): { block: BlockRegistry; has_it
const render_layer = json.render_layer ?? (json.transparent ? "translucent" : undefined);
if (render_layer && render_layer !== "solid") block.render_layer = render_layer;
if (json.cull_same !== undefined) block.cull_same = json.cull_same;
if (json.tint !== undefined) block.tint = json.tint;
if (json.light_emission !== undefined) block.light_emission = json.light_emission;
if (json.light_opacity !== undefined) block.light_opacity = json.light_opacity;
if (json.alpha !== undefined) block.alpha = json.alpha;
@@ -206,21 +217,22 @@ export function item_from_json(json: ItemJson): ItemRegistry {
// shaped recipes <-> the grid format
export function grid_recipe_to_json(recipe: GridRecipe): RecipeJson {
const key: Record<string, string> = {};
const key: Record<string, ItemChoice> = {};
// by the choice as json, so equal lists share a letter
const letters = new Map<string, string>();
for (const id of recipe.pattern) {
if (id === undefined || letters.has(id)) continue;
const letter = pick_letter(id, new Set(letters.values()));
letters.set(id, letter);
key[letter] = id;
for (const choice of recipe.pattern) {
if (choice === undefined || letters.has(JSON.stringify(choice))) continue;
const letter = pick_letter(choice_ids(choice)[0], new Set(letters.values()));
letters.set(JSON.stringify(choice), letter);
key[letter] = choice;
}
const pattern: string[] = [];
for (let y = 0; y < recipe.height; y++) {
let row = "";
for (let x = 0; x < recipe.width; x++) {
const id = recipe.pattern[y * recipe.width + x];
row += id === undefined ? " " : letters.get(id);
const choice = recipe.pattern[y * recipe.width + x];
row += choice === undefined ? " " : letters.get(JSON.stringify(choice));
}
pattern.push(row);
}
@@ -231,7 +243,7 @@ export function grid_recipe_to_json(recipe: GridRecipe): RecipeJson {
export function grid_recipe_from_json(json: Extract<RecipeJson, { type: "shaped" }>): GridRecipe {
const height = json.pattern.length;
const width = Math.max(...json.pattern.map((row) => row.length));
const pattern: (string | undefined)[] = [];
const pattern: (ItemChoice | undefined)[] = [];
for (const row of json.pattern) {
for (let x = 0; x < width; x++) {
const letter = row[x] ?? " ";
@@ -351,6 +363,17 @@ export function validate_block(json: unknown): Problems {
for (const key of ["cull_same", "transparent", "collision", "item", "interactive", "replaceable"]) {
if (json[key] !== undefined && typeof json[key] !== "boolean") problems.push(`${key} must be true or false`);
}
if (json.tint !== undefined) {
const tint = json.tint;
if (!is_object(tint) || !is_tint_color(tint.color)) {
problems.push('tint.color must be "grass", "foliage" or a color like "#80a755"');
} else if (
tint.textures !== undefined &&
!(Array.isArray(tint.textures) && tint.textures.every((name) => typeof name === "string"))
) {
problems.push('tint.textures must be a list of texture variables, like ["top"]');
}
}
if (json.alpha !== undefined && (typeof json.alpha !== "number" || json.alpha < 0 || json.alpha > 1)) {
problems.push("alpha must be between 0 and 1");
}
@@ -493,21 +516,21 @@ export function validate_recipe(json: unknown): Problems {
}
}
if (!is_object(json.key)) {
problems.push("key must map letters to item ids");
problems.push("key must map letters to item ids, or lists of them");
} else {
for (const id of Object.values(json.key)) problems.push(...validate_id(id, "key"));
for (const choice of Object.values(json.key)) problems.push(...validate_choice(choice, "key"));
}
problems.push(...validate_stack(json.result, "result"));
break;
}
case "furnace":
problems.push(...validate_id(json.input, "input"), ...validate_stack(json.output, "output"));
problems.push(...validate_choice(json.input, "input"), ...validate_stack(json.output, "output"));
if (!Number.isInteger(json.cook_time) || (json.cook_time as number) < 1) {
problems.push("cook_time must be a positive number of ticks");
}
break;
case "fuel":
problems.push(...validate_id(json.item, "item"));
problems.push(...validate_choice(json.item, "item"));
if (!Number.isInteger(json.burn_time) || (json.burn_time as number) < 1) {
problems.push("burn_time must be a positive number of ticks");
}
@@ -544,6 +567,13 @@ export function validate_ore(json: unknown): Problems {
return problems;
}
// an item id, or a list of them any of which fits
function validate_choice(value: unknown, field: string): Problems {
if (!Array.isArray(value)) return validate_id(value, field);
if (value.length === 0) return [`${field} must list at least one item`];
return value.flatMap((id) => validate_id(id, field));
}
// optional text players see
function validate_text(value: unknown, field: string): Problems {
return value === undefined || (typeof value === "string" && value.length > 0) ? [] : [`${field} must be text`];
+6 -3
View File
@@ -3,6 +3,7 @@ import { BlockRegistry, EverythingRegistry, ItemRegistry } from "./everything_re
import {
block_from_json,
BlockJson,
choice_ids,
grid_recipe_from_json,
GridRecipe,
is_mod_recipe,
@@ -95,11 +96,13 @@ export function register_mod_data(mods: { id: string; data: ModData }[]): Recipe
recipes.shaped.push(grid_recipe_from_json(recipe));
break;
case "furnace":
if (recipes.furnace.has(recipe.input)) fail(`two furnace recipes for ${recipe.input}`);
recipes.furnace.set(recipe.input, { output: recipe.output, cook_time: recipe.cook_time });
for (const input of choice_ids(recipe.input)) {
if (recipes.furnace.has(input)) fail(`two furnace recipes for ${input}`);
recipes.furnace.set(input, { output: recipe.output, cook_time: recipe.cook_time });
}
break;
case "fuel":
recipes.fuel.set(recipe.item, recipe.burn_time);
for (const item of choice_ids(recipe.item)) recipes.fuel.set(item, recipe.burn_time);
break;
case "smithing":
if (
+99
View File
@@ -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);
}
+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));
}
}
+45 -3
View File
@@ -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;