Single module modding
This commit is contained in:
@@ -7,12 +7,12 @@ above them.
|
||||
|
||||
## Layers
|
||||
|
||||
A client script registers layers during `setup`, with ids in its namespace:
|
||||
The client phase registers layers while it runs, with ids in its namespace:
|
||||
|
||||
```ts
|
||||
import type { ClientContext } from "cubi/client";
|
||||
|
||||
export function setup(ctx: ClientContext) {
|
||||
export function client(ctx: ClientContext) {
|
||||
ctx.hud.register("thirst:water", {
|
||||
on_render(g, hud) {
|
||||
// a row of drops above the hunger, on the right
|
||||
@@ -48,7 +48,7 @@ side without raising it, and chat goes above that.
|
||||
|
||||
## Overlay Messages
|
||||
|
||||
A server script's message with `{ overlay: true }` (see `Player.send_message`) isn't chat: it goes to the client scripts
|
||||
The server phase's message with `{ overlay: true }` (see `Player.send_message`) isn't chat: it goes to the client phases
|
||||
that listen for it, and the base game shows it above the hotbar for a few seconds:
|
||||
|
||||
```ts
|
||||
|
||||
@@ -43,8 +43,8 @@ interface Screen {
|
||||
```
|
||||
|
||||
The server can't open one directly. Like a NeoForge payload handler calling `setScreen`, the server sends a
|
||||
[mod channel](../networking/index.md) message, and the client script's handler opens it, as above. A screen that needs
|
||||
to tell the server something sends a message back the same way. `ctx.ui.close()` closes the screen on top. A screen that
|
||||
[mod channel](../networking/index.md) message, and the client phase's handler opens it, as above. A screen that needs to
|
||||
tell the server something sends a message back the same way. `ctx.ui.close()` closes the screen on top. A screen that
|
||||
throws is closed, with the error in the console.
|
||||
|
||||
## Inventory Overlays
|
||||
@@ -56,7 +56,7 @@ game's fishing minigame. `mods/recipe_viewer` is one.
|
||||
```ts
|
||||
import type { ClientContext } from "cubi/client";
|
||||
|
||||
export function setup(ctx: ClientContext) {
|
||||
export function client(ctx: ClientContext) {
|
||||
ctx.ui.add_inventory_overlay({
|
||||
on_render(g, screen) {
|
||||
// screen is the inventory's box, and what's in the slot under the mouse
|
||||
@@ -168,7 +168,7 @@ pushes its own:
|
||||
```ts
|
||||
import { type ClientContext, TOOLTIP_PRIORITY } from "cubi/client";
|
||||
|
||||
export function setup(ctx: ClientContext) {
|
||||
export function client(ctx: ClientContext) {
|
||||
ctx.ui.add_item_tooltip((item, lines) => {
|
||||
const value = ctx.items.sell_value(item.id, item.data);
|
||||
if (value === undefined) return;
|
||||
@@ -203,7 +203,7 @@ so a mod's can go between them:
|
||||
|
||||
## Reading Game State
|
||||
|
||||
Client scripts can read what the client knows, to show it:
|
||||
The client phase can read what the client knows, to show it:
|
||||
|
||||
```ts
|
||||
ctx.player.name;
|
||||
@@ -226,12 +226,12 @@ ctx.blocks.components(id); // the same for a block, like what a crab pot catches
|
||||
ctx.fluids.ids(); // every fluid, in load order
|
||||
ctx.fluids.mod(id); // the name of the mod that added it
|
||||
ctx.fluids.name(fluid); // and color, exists and same, see ../resources/fluids.md#using-fluids
|
||||
ctx.loot.table(id); // a loot table file's JSON, or undefined. tables server scripts make aren't here
|
||||
ctx.loot.table(id); // a loot table file's JSON, or undefined. tables server phases make aren't here
|
||||
ctx.recipes.list(type?); // every recipe as its JSON, including mods' own types
|
||||
ctx.options.key_inventory; // the key the player has bound, like Minecraft's Options key mappings
|
||||
```
|
||||
|
||||
`ctx.player`, `ctx.world` and `ctx.options` only work once the player is in the world, not during `setup`.
|
||||
`ctx.player`, `ctx.world` and `ctx.options` only work once the player is in the world, not while the client phase runs.
|
||||
|
||||
To draw blocks that move, like a shaft that turns, register a [visual](../blocks/visuals.md) with
|
||||
`ctx.render.register_visual`.
|
||||
@@ -245,7 +245,7 @@ checks `g.key_pressed(ctx.options.key_inventory)` and calls `ctx.ui.close()`, th
|
||||
The client and server APIs have types for these, but calling them throws for now:
|
||||
|
||||
- **Forms** (`ctx.ui.message_form`, `action_form` and `modal_form` on the server): simple dialogs defined entirely by
|
||||
the server script, like Bedrock's server forms. They'll be menus whose screens the engine draws.
|
||||
the server phase, like Bedrock's server forms. They'll be menus whose screens the engine draws.
|
||||
- **Keybinds** (`ctx.input.bind`). Until then, an inventory overlay can check `g.key_pressed` while an inventory is
|
||||
open.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user