Seasons api

This commit is contained in:
2026-10-08 13:42:18 -03:00
parent 7e7ac8f6f4
commit dd66d6caa7
16 changed files with 231 additions and 10 deletions
+14 -4
View File
@@ -1,7 +1,7 @@
// what client scripts get, see docs/modding/gui/index.md
import type { Id, ItemStack, KeyCode, ModInfo, Position, TagApi } from "./shared.ts";
import type { Id, ItemStack, KeyCode, ModInfo, Position, Season, TagApi } from "./shared.ts";
export type { Id, ItemStack, KeyCode, ModInfo, Position, TagApi, TagRegistry } from "./shared.ts";
export type { Id, ItemStack, KeyCode, ModInfo, Position, Season, TagApi, TagRegistry } from "./shared.ts";
export interface ClientContext {
mod: ModInfo;
@@ -12,11 +12,21 @@ export interface ClientContext {
// the way jei's recipes screen checks options.keyInventory
options: KeyMappings;
net: ClientNet;
// is_swimming: lying flat in water in the 0.8 tall box, like minecraft's isSwimming
player: { readonly name: string; readonly position: Readonly<Position>; is_swimming(): boolean };
// is_swimming: lying flat in water in the 0.8 tall box, like minecraft's isSwimming. biome and season are where
// their feet are, undefined until that chunk loads
player: {
readonly name: string;
readonly position: Readonly<Position>;
readonly biome: Id | undefined;
readonly season: Season | undefined;
is_swimming(): boolean;
};
// read only, what this client sees
world: {
get_block(x: number, y: number, z: number): Id | undefined;
// the column's biome and its season, undefined when the chunk isn't loaded
biome_at(x: number, z: number): Id | undefined;
season_at(x: number, z: number): Season | undefined;
// ticks since 06:00 of day 1, see ServerWorld.time
readonly time: number;
};
+15 -2
View File
@@ -1,10 +1,10 @@
// what server scripts get, see docs/modding/
import type { EventSignal, Face, Id, ItemStack, ModInfo, Position, TagApi } from "./shared.ts";
import type { EventSignal, Face, Id, ItemStack, ModInfo, Position, Season, TagApi } from "./shared.ts";
import type { ArgumentType, CommandNode } from "../commands.ts";
export type { ArgumentType, CommandContext, CommandNode, Suggestion } from "../commands.ts";
export type { EventSignal, Face, Id, ItemStack, ModInfo, Position, TagApi, TagRegistry } from "./shared.ts";
export type { EventSignal, Face, Id, ItemStack, ModInfo, Position, Season, TagApi, TagRegistry } from "./shared.ts";
export interface ServerContext {
mod: ModInfo;
@@ -34,6 +34,9 @@ export interface BlockRef {
readonly x: number;
readonly y: number;
readonly z: number;
// the biome of its column and that biome's season, see ServerWorld.biome_at
readonly biome: Id;
readonly season: Season;
// tile data, any json value. saved with the world, never sent to clients
// deno-lint-ignore no-explicit-any
data: any;
@@ -221,6 +224,10 @@ export interface ServerWorld {
// into, so it goes through plants and other blocks without collision. undefined when nothing is in the way
raycast(from: Position, to: Position, options?: RaycastOptions): RaycastHit | undefined;
is_loaded(x: number, z: number): boolean;
// the column's biome, like "bworld:plains", and that biome's season. in chunks that aren't loaded it's what
// generation makes there, which takes a while the first time
biome_at(x: number, z: number): Id;
season_at(x: number, z: number): Season;
readonly seed: string;
// ticks since 06:00 of day 1. a day is 36000 ticks (06:00 to 18:00), a night 12000
readonly time: number;
@@ -252,6 +259,9 @@ export interface EntityRef {
readonly id: string;
readonly type: Id;
readonly position: Readonly<Position>;
// the biome where its feet are and that biome's season
readonly biome: Id;
readonly season: Season;
readonly removed: boolean;
teleport(x: number, y: number, z: number): void;
remove(): void;
@@ -265,6 +275,9 @@ export interface Player {
// ctx.world.raycast(player.eye_position, ...)
readonly eye_position: Readonly<Position>;
readonly look_direction: Readonly<Position>;
// the biome where their feet are and that biome's season
readonly biome: Id;
readonly season: Season;
readonly inventory: Container; // 36 slots, hotbar is 0-8
readonly selected_slot: number;
readonly held_item: ItemStack | undefined;
+6
View File
@@ -3,6 +3,9 @@
export type Id = string;
// a biome's season, from its json. see docs/modding/worldgen/biomes.md
export type Season = "spring" | "summer" | "autumn" | "winter";
export interface ItemStack {
readonly id: Id;
count: number;
@@ -76,6 +79,9 @@ export interface SharedWorld {
// whether the block's side is a full square things can attach to, like minecraft's isFaceSturdy: its collision
// shape covers the whole face. false for air, plants, water and the sides of a slab
is_face_sturdy(x: number, y: number, z: number, face: Face): boolean;
// the column's biome, like "bworld:plains", and that biome's season. undefined when the chunk isn't loaded
biome_at(x: number, z: number): Id | undefined;
season_at(x: number, z: number): Season | undefined;
}
// a block in the world, for rules
+5
View File
@@ -74,6 +74,11 @@ 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 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];