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
+28 -1
View File
@@ -41,7 +41,7 @@ game's are in `mods/bworld/worldgen/biomes/`.
| 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` |
| `season` | `spring`, `summer`, `autumn` or `winter`, see [Seasons](#seasons) | `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 |
@@ -70,3 +70,30 @@ Biome ids are what features' `biome_at` gives and what spawns list. The base gam
`bworld:jagged_peaks` and `bworld:frozen_peaks`.
`/locatebiome <id>` finds the nearest one.
## Seasons
A biome's season is fixed by its json, it doesn't change over the year. Scripts read it where something is:
| Where | Biome | Season |
| ------------------------------------------------ | -------------------------- | --------------------------- |
| a block in a server component, like `on_tick` | `block.biome` | `block.season` |
| an entity from `ctx.world.spawn_entity` | `entity.biome` | `entity.season` |
| a player, on the server | `player.biome` | `player.season` |
| any column, in server, shared and client scripts | `ctx.world.biome_at(x, z)` | `ctx.world.season_at(x, z)` |
| the player on this client | `ctx.player.biome` | `ctx.player.season` |
Entities and players go by the column their feet are in. On the server a column always has a biome: in a chunk that
isn't loaded it's what generation makes there, which takes a while the first time. In shared rules and client scripts
it's what that client has loaded, and `undefined` where it has nothing.
```ts
ctx.components.register_block("my_mod:crop", {
on_new_day(block) {
if (block.season === "winter") return; // doesn't grow in winter
// ...
},
});
```
`Season` is exported from `bworld/server`, `bworld/client` and `bworld/shared`.