Single module modding
This commit is contained in:
@@ -93,19 +93,19 @@ summer in `desert`.
|
||||
|
||||
Scripts read the season 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 block, in server, shared and client scripts | `ctx.world.biome_at(x, y, z)` | `ctx.world.season_at(x, y, z)` |
|
||||
| the player on this client | `ctx.player.biome` | `ctx.player.season` |
|
||||
| a feature's chunk, see [Features](index.md) | `chunk.biome_at(x, y, z)` | |
|
||||
| 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 block, in server, shared and client phases | `ctx.world.biome_at(x, y, z)` | `ctx.world.season_at(x, y, z)` |
|
||||
| the player on this client | `ctx.player.biome` | `ctx.player.season` |
|
||||
| a feature's chunk, see [Features](index.md) | `chunk.biome_at(x, y, z)` | |
|
||||
|
||||
`biome_at` is NeoForge's `level.getBiome(pos)`. Entities and players go by the block their feet are in, like
|
||||
`level.getBiome(entity.blockPosition())`. Above and below the world it's the biome at its top or bottom. On the server
|
||||
every block 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.
|
||||
time. In shared rules and client phases it's what that client has loaded, and `undefined` where it has nothing.
|
||||
|
||||
```ts
|
||||
ctx.components.register_block("my_mod:crop", {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# World Generation
|
||||
|
||||
The server generates chunks from the world's seed, and players get the finished chunks. Mods add to what it generates
|
||||
with ores (data) and features (a worldgen script).
|
||||
with ores (data) and features (the worldgen phase).
|
||||
|
||||
## Determinism
|
||||
|
||||
@@ -13,7 +13,7 @@ isn't the same, trees are cut off at chunk borders.
|
||||
- **Never use `Math.random`, `Date`, `performance.now` or anything else that changes between runs.** Use the chunk's
|
||||
`rng` and noise helpers, which are seeded from the world's seed.
|
||||
- Don't keep state between chunks. Chunks generate in any order, and in several worldgen workers at once, each with its
|
||||
own copy of the worldgen scripts (and the game generates a few itself).
|
||||
own copy of the worldgen phases (and the game generates a few itself).
|
||||
- Adding or removing a mod's features only changes chunks that haven't been generated yet, with seams where they meet
|
||||
saved ones.
|
||||
|
||||
@@ -76,12 +76,12 @@ order they were registered. The base game's trees are in `vegetal_decoration`, s
|
||||
|
||||
### Code Features
|
||||
|
||||
The worldgen script registers them:
|
||||
The worldgen phase registers them:
|
||||
|
||||
```ts
|
||||
import type { WorldgenContext } from "cubi/worldgen";
|
||||
|
||||
export function setup(gen: WorldgenContext) {
|
||||
export function worldgen(gen: WorldgenContext) {
|
||||
gen.register_feature("copper_tools:boulders", (chunk) => {
|
||||
if (chunk.rng.next() > 0.1) return;
|
||||
const x = chunk.x * 16 + Math.floor(chunk.rng.next() * 16);
|
||||
@@ -125,7 +125,7 @@ cell agrees on where its tree is.
|
||||
`set_block` can write up to one chunk away, so a tree near the border can grow into the next chunk. Writes into another
|
||||
chunk only fill air, so the result doesn't depend on which chunk generates first.
|
||||
|
||||
Generated blocks don't run `on_create`, and worldgen scripts can't use the server or client API.
|
||||
Generated blocks don't run `on_create`, and worldgen phases can't use the server or client API.
|
||||
|
||||
### Data Features
|
||||
|
||||
@@ -185,7 +185,7 @@ Built in names work with or without `minecraft:`.
|
||||
|
||||
### Types and Modifiers in Code
|
||||
|
||||
A worldgen script can add types and placement modifiers for data features to use, by id:
|
||||
The worldgen phase can add types and placement modifiers for data features to use, by id:
|
||||
|
||||
```ts
|
||||
gen.register_feature_type<{ block: string; height: number }>("copper_tools:pillar", (chunk, config, origin) => {
|
||||
|
||||
Reference in New Issue
Block a user