Single module modding
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# Block Components
|
||||
|
||||
A block's JSON says what it is. Components say what it _does_. A component is a set of handlers a server script
|
||||
A block's JSON says what it is. Components say what it _does_. A component is a set of handlers the server phase
|
||||
registers under an id. Any block that lists that id in its `components` gets that behavior, with its own parameters.
|
||||
|
||||
This is how every block that does something works, including the base game's chests, furnaces and crops. One component
|
||||
@@ -20,7 +20,7 @@ A block can list several. Their handlers run in the listed order.
|
||||
|
||||
## Registering a Component
|
||||
|
||||
In the server script:
|
||||
In the server phase:
|
||||
|
||||
```ts
|
||||
import type { ServerContext } from "cubi/server";
|
||||
@@ -30,7 +30,7 @@ interface OxidizesParams {
|
||||
into: string;
|
||||
}
|
||||
|
||||
export function setup(ctx: ServerContext) {
|
||||
export function server(ctx: ServerContext) {
|
||||
ctx.components.register_block<OxidizesParams>("copper_tools:oxidizes", {
|
||||
on_create(block) {
|
||||
block.data = { age: 0 };
|
||||
@@ -53,9 +53,9 @@ export function setup(ctx: ServerContext) {
|
||||
|
||||
Items have components the same way, and so do [status effects](../entities/effects.md#effect-components).
|
||||
|
||||
Components can only be registered during `setup`, and only in the mod's own namespace. Once every mod's `setup` has run,
|
||||
a block or item that lists a component nobody registered stops the server from starting, naming the block and the
|
||||
component.
|
||||
Components can only be registered while the server phase runs, and only in the mod's own namespace. Once every mod's
|
||||
server phase has run, a block or item that lists a component nobody registered stops the server from starting, naming
|
||||
the block and the component.
|
||||
|
||||
## Handlers
|
||||
|
||||
@@ -145,14 +145,14 @@ not in memory counts as loaded, and reading it reads it from the save.
|
||||
## Rules
|
||||
|
||||
A component's rules decide a block's states from where it's placed, what's around it and being right clicked. They're
|
||||
registered in the mod's [shared script](../concepts/sides.md#shared-scripts) instead, under the same id, because clients
|
||||
run them too: that's how a player sees a fence join its neighbors the moment they place it, instead of a moment later
|
||||
when the server answers. A component can have rules, handlers, or both, and a block can list one that only has rules.
|
||||
registered in the mod's [shared phase](../concepts/sides.md#shared) instead, under the same id, because clients run them
|
||||
too: that's how a player sees a fence join its neighbors the moment they place it, instead of a moment later when the
|
||||
server answers. A component can have rules, handlers, or both, and a block can list one that only has rules.
|
||||
|
||||
```ts
|
||||
import type { SharedContext } from "cubi/shared";
|
||||
|
||||
export function setup(ctx: SharedContext) {
|
||||
export function shared(ctx: SharedContext) {
|
||||
ctx.components.register_block("copper_tools:pipe", {
|
||||
state_for_placement(placement, params) {/* ... */},
|
||||
on_neighbor_change(block, params, neighbor) {/* ... */},
|
||||
@@ -167,7 +167,7 @@ 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. | |
|
||||
| `on_interact(block, params, interaction)` | A player right clicks it. | `true` if it did something |
|
||||
|
||||
Here `block` is `{ id, x, y, z }`, without tile data, which clients never have. `ctx.world` in a shared script has
|
||||
Here `block` is `{ id, x, y, z }`, without tile data, which clients never have. `ctx.world` in the shared phase has
|
||||
`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. `ctx.blocks.components(id)` gives any block's
|
||||
components and their params, like on the server, for rules that look at what's around them, like a shaft lining up with
|
||||
@@ -329,7 +329,7 @@ catch up. If it's further behind than that, it skips the rest and logs a warning
|
||||
| `bworld:crop_top` | see [Crops](crops.md) | The top half of a two block crop, like rice. |
|
||||
| `bworld:water_source` | none | Refills the watering can. |
|
||||
| `bworld:fishable` | `loot_table`? | The fishing rod's hook floats on it and fish bite there when it lands in it. What's caught is `loot_table`, `bworld:gameplay/fishing` when not given, built from the fish whose `fluid` is this block. |
|
||||
| `bworld:trapdoor` | none | Opens and closes when right clicked, and is placed like Minecraft's (both are rules, in the shared script). Needs `facing` (2 bits), `half` and `open` states, see `blocks/oak_trapdoor.json`. |
|
||||
| `bworld:trapdoor` | none | Opens and closes when right clicked, and is placed like Minecraft's (both are rules, in the shared phase). Needs `facing` (2 bits), `half` and `open` states, see `blocks/oak_trapdoor.json`. |
|
||||
| `bworld:fence` | `connects_to` | Joins the blocks in the tag `connects_to` and sturdy sides of other blocks, except leaves. Needs the `north`, `east`, `south` and `west` states. |
|
||||
|
||||
Item components work the same way, see [Items](../items/index.md#item-components).
|
||||
|
||||
Reference in New Issue
Block a user