Seasons api
This commit is contained in:
@@ -69,8 +69,9 @@ component.
|
||||
| `on_second(block, params, dt)` | Every second, near a player. | |
|
||||
| `on_new_day(block, params, day)` | Every morning at 06:00, anywhere in the world. | |
|
||||
|
||||
`block` is `{ id, x, y, z, data }`, where `data` is the block's [tile data](tiledata.md). `params` is what the block's
|
||||
JSON lists for this component, and `dt` is in seconds.
|
||||
`block` is `{ id, x, y, z, biome, season, data }`, where `data` is the block's [tile data](tiledata.md) and `biome` and
|
||||
`season` are its column's (see [Seasons](../worldgen/biomes.md#seasons)). `params` is what the block's JSON lists for
|
||||
this component, and `dt` is in seconds.
|
||||
|
||||
## Rules
|
||||
|
||||
@@ -96,7 +97,8 @@ export function setup(ctx: SharedContext) {
|
||||
| `on_neighbor_change(block, params, neighbor)` | A block on one of its 6 sides is placed, broken or changes its states. | |
|
||||
|
||||
Here `block` is `{ id, x, y, z }`, without tile data, which clients never have. `ctx.world` in a shared script has
|
||||
`get_block`, `get_state`, `set_state` and `is_face_sturdy`, and only works inside rules.
|
||||
`get_block`, `get_state`, `set_state`, `is_face_sturdy`, `biome_at` and `season_at` (see
|
||||
[Seasons](../worldgen/biomes.md#seasons)), and only works inside rules.
|
||||
|
||||
### Neighbors
|
||||
|
||||
|
||||
@@ -147,6 +147,8 @@ interface EntityRef {
|
||||
readonly id: string; // this entity's own id
|
||||
readonly type: string; // its kind, like "bworld:fishing_hook"
|
||||
readonly position: { x: number; y: number; z: number };
|
||||
readonly biome: string; // where its feet are, see ../worldgen/biomes.md#seasons
|
||||
readonly season: Season; // that biome's
|
||||
readonly removed: boolean;
|
||||
teleport(x: number, y: number, z: number): void;
|
||||
remove(): void;
|
||||
|
||||
@@ -22,6 +22,8 @@ interface Player {
|
||||
readonly position: { x: number; y: number; z: number }; // their feet
|
||||
readonly eye_position: { x: number; y: number; z: number }; // where they see from, lower while swimming
|
||||
readonly look_direction: { x: number; y: number; z: number }; // which way they look, 1 long
|
||||
readonly biome: string; // where their feet are, see ../worldgen/biomes.md#seasons
|
||||
readonly season: Season; // that biome's
|
||||
readonly inventory: Container; // 36 slots, the hotbar is 0-8
|
||||
readonly selected_slot: number;
|
||||
readonly held_item: ItemStack | undefined;
|
||||
|
||||
@@ -141,7 +141,9 @@ Client scripts can read what the client knows, to show it:
|
||||
ctx.player.name;
|
||||
ctx.player.position; // { x, y, z }
|
||||
ctx.player.is_swimming(); // see ../entities/players.md#swimming
|
||||
ctx.player.biome; // and ctx.player.season, see ../worldgen/biomes.md#seasons
|
||||
ctx.world.get_block(x, y, z); // a block id, what this client sees
|
||||
ctx.world.biome_at(x, z); // and ctx.world.season_at(x, z), undefined where nothing's loaded
|
||||
ctx.world.time; // see Time
|
||||
ctx.items.ids(); // every item, in load order
|
||||
ctx.items.exists(id);
|
||||
|
||||
@@ -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`.
|
||||
|
||||
Reference in New Issue
Block a user