Seasons based on a calendar
This commit is contained in:
@@ -2,11 +2,13 @@
|
||||
// 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 { farming_day } from "../time.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 long each season lasts. day 1 to 49 is spring, 50 to 98 summer and so on, a year is 196 days
|
||||
export const SEASON_DAYS = 49;
|
||||
|
||||
// how a biome covers its ground, like minecraft's surface rules. blocks are ids
|
||||
export interface SurfaceJson {
|
||||
@@ -22,7 +24,7 @@ export interface SurfaceJson {
|
||||
|
||||
export interface BiomeJson {
|
||||
id: string;
|
||||
// spring when not set
|
||||
// a season it's always in, like winter for snowy biomes. when not set it follows the calendar, see calendar_season
|
||||
season?: Season;
|
||||
surface: SurfaceJson;
|
||||
// "#rrggbb", minecraft's grass, foliage and water colors, which blocks pick with "tint". plains' when not set
|
||||
@@ -36,7 +38,7 @@ export interface BiomeJson {
|
||||
// what's registered in "biomes", with the defaults filled in
|
||||
export interface Biome {
|
||||
id: string;
|
||||
season: Season;
|
||||
season?: Season;
|
||||
surface: Required<SurfaceJson>;
|
||||
// 0xRRGGBB
|
||||
colors: { grass?: number; foliage?: number; water?: number };
|
||||
@@ -48,7 +50,7 @@ export function biome_from_json(json: BiomeJson): Biome {
|
||||
const color = (value: string | undefined) => value === undefined ? undefined : parseInt(value.slice(1), 16);
|
||||
return {
|
||||
id: json.id,
|
||||
season: json.season ?? DEFAULT_SEASON,
|
||||
season: json.season,
|
||||
surface: {
|
||||
top: surface.top,
|
||||
filler: surface.filler,
|
||||
@@ -74,9 +76,16 @@ export function biome_ids(): string[] {
|
||||
return EverythingRegistry.entries<Biome>("biomes").map(([id]) => id);
|
||||
}
|
||||
|
||||
// a biome's season, spring for one that isn't registered, like a removed mod's
|
||||
export function biome_season(id: string): Season {
|
||||
return get_biome(id)?.season ?? DEFAULT_SEASON;
|
||||
// the season on a farming day (see farming_day in common/time.ts), which is 0 on the first day and goes up at 06:00
|
||||
export function calendar_season(day: number): Season {
|
||||
const days_into_year = (day % (SEASON_DAYS * 4) + SEASON_DAYS * 4) % (SEASON_DAYS * 4);
|
||||
return SEASONS[Math.floor(days_into_year / SEASON_DAYS)];
|
||||
}
|
||||
|
||||
// a biome's season at a world time: its own when its json sets one, the calendar's otherwise, like for one that
|
||||
// isn't registered (a removed mod's)
|
||||
export function biome_season(id: string, time: number): Season {
|
||||
return get_biome(id)?.season ?? calendar_season(farming_day(time));
|
||||
}
|
||||
|
||||
// the logs and leaves a kind of tree grows in a biome
|
||||
|
||||
Reference in New Issue
Block a user