Curios and artifacts !

This commit is contained in:
2026-09-30 15:22:32 -03:00
parent 342b45d593
commit 3af5f6e54b
45 changed files with 729 additions and 43 deletions
+26
View File
@@ -37,6 +37,10 @@ interface Player {
heal(amount: number): void;
feed(nutrition: number, saturation_modifier: number): void;
add_exhaustion(amount: number): void;
attribute(id: string): number;
add_modifier(attribute: string, modifier: AttributeModifier): void;
remove_modifier(attribute: string, id: string): boolean;
}
```
@@ -64,6 +68,28 @@ even when their game isn't running, like in a background tab.
`damage(amount, cause)` hurts them like anything else would. `cause` shows in the `player_damage` and `player_death`
[events](../concepts/events.md) and in the death message. Before events can change the amount or cancel it.
## Attributes
A player's stats are attributes, like Minecraft's: a base value that modifiers change without touching it.
| Attribute | Base | Meaning |
| ---------------------- | ---- | -------------------------------------------------------------------------- |
| `bworld:attack_damage` | 1 | How much their hits do. |
| `bworld:attack_speed` | 4 | Full strength attacks a second. Hitting sooner than that does less damage. |
```ts
player.add_modifier("bworld:attack_damage", { id: "my_mod:rage", amount: 2, operation: "add_value" });
player.attribute("bworld:attack_damage"); // 3
player.remove_modifier("bworld:attack_damage", "my_mod:rage");
```
The value is the base, plus every `add_value`, plus that times the amount of each `add_multiplied_base`, then times 1
plus the amount of each `add_multiplied_total`. A modifier with the same id replaces the old one. Modifiers aren't
saved: a mod that gives them should give them again when the player joins, the way Curios does for worn items.
Like Minecraft, an attack right after the last one, or right after changing the held item, does only a fifth of the
damage, rising to full after `20 / attack_speed` ticks.
## Death
When a player dies, everything they carried falls out where they died, and their tools lose durability (see
+2 -3
View File
@@ -110,8 +110,7 @@ The client and server APIs have types for these, but calling them throws for now
- **Custom screens** (`ctx.ui.register_screen` and `open` on the client, `open_screen` on the server): whole screens
drawn with `Graphics`, opened by the server with some props.
- **HUD elements** (`ctx.hud.register`): drawing over the world every frame.
- **Keybinds** (`ctx.input.bind`).
- **Mod channels** (`ctx.net`), for a mod's client and server scripts to talk. Without them, a client script can't send
anything to the server.
- **Keybinds** (`ctx.input.bind`). Until then, an inventory overlay can check `g.key_pressed` while an inventory is
open.
See [the modding plan](../../modding_plan.md) for how they're meant to work.
+1
View File
@@ -54,6 +54,7 @@ Give the block `"interactive": true` so clients don't guess that the click place
| `filter` | What can be put in: `"smeltable"` (has a furnace recipe), `"fuel"`, or a function `(item) => boolean`. |
| `output_only` | Can only be taken from, all at once, like the furnace result. |
| `on_take` | For `output_only` slots: runs when a player takes from it, before they get the item. Return `false` to stop them. |
| `icon` | A texture drawn in the slot while it's empty, like Minecraft's armor slots. |
`rows` sets the height of the screen's area in slots. By default it fits the slots and bars.
+3
View File
@@ -96,6 +96,9 @@ and items list them with their parameters:
At a block, the block's own [interaction](../blocks/components.md#interacting) comes first. An item with `on_use` is
used instead of being placed.
`ctx.items.components(id)` gives the components an item's JSON lists and their parameters, so a mod can read its
components' parameters for an item without a stack, like Curios does for `curios:attribute_modifiers`.
`on_use` doesn't say which block was clicked. For that, pair it with a block component's `on_interact`, the way the
watering can uses `bworld:water_source`, or subscribe to the `block_interact` [event](../concepts/events.md).
+9 -6
View File
@@ -59,10 +59,7 @@ server code are never sent at all. See [Sides](../concepts/sides.md#what-each-si
## Mod Channels
> [!NOTE]
> Not built yet. `ctx.net` exists on both sides but throws.
Mod channels will let a mod's client and server scripts send each other JSON messages:
Mod channels let a mod's client and server scripts send each other JSON messages:
```ts
// server.ts
@@ -75,5 +72,11 @@ ctx.net.on("copper_tools:heat", (data) => {/* ... */});
ctx.net.send("copper_tools:reset_stats", {});
```
Until then, the server reaches the client through what's already synced: [container screens](../inventories/menus.md)
and their properties, item stack `data`, block states, and displayed items.
- Channel ids are in the mod's namespace, and a mod only listens and sends on its own.
- A message from a client is at most 16 KB of JSON, and each player can send at most 60 a second. The server drops
anything over that without telling anyone.
- Everything a client sends is untrusted: check it like a click or a chat message.
- A handler that throws is logged under its mod, and the other handlers still run.
Curios (`mods/curios`) is a small example: its client script's button sends `curios:open`, and its server script opens
the curio slots for that player.
+5 -5
View File
@@ -26,13 +26,13 @@ A mod is built from up to three layers. Most mods only need the first one or two
server and worldgen scripts), delivery to clients (hashed downloads, the confirm screen for other sites, credits), the
data layer (blocks, block models with variants, items, recipes including mods' own types, entities and entity models,
ores), server scripts (components, events, commands, timers, storage, recipes, containers, container screens, displayed
items), client scripts (item and recipe lookups, inventory overlays with `Graphics`), worldgen features and ores, the
base game's block behavior as a mod, and world time.
items), client scripts (item and recipe lookups, inventory overlays with `Graphics`), mod channels, worldgen features
and ores, the base game's block behavior as a mod, and world time.
The code is in `common/mod_loader.ts`, `common/mod_data.ts`, `common/mod_check.ts`, `common/bmod.ts`,
`server/game/mod_runtime.ts`, `server/load_bmods.ts`, `client/mods.ts` and `common/worldgen_loader.ts`.
**In the API types but throwing:** forms, custom screens, HUD elements, keybinds, mod channels, `g.slider`, `g.slots`,
**In the API types but throwing:** forms, custom screens, HUD elements, keybinds, `g.slider`, `g.slots`,
`register_terrain`.
**Not built at all:** common scripts, the registry freeze and hash, overrides, engine access.
@@ -315,8 +315,8 @@ manifest and its checks, and making the engine hookable where mods will want it.
client and a worldgen method, hooks on one method run in priority order, and a throwing hook is logged without breaking
the game.
**Phase 4: the rest of the Game API.** Mod channels, keybinds, forms, custom screens and HUD elements. More events:
items picked up and dropped, containers clicked, players moving between chunks, entities.
**Phase 4: the rest of the Game API.** Keybinds, forms, custom screens and HUD elements. More events: items picked up
and dropped, containers clicked, players moving between chunks, entities.
**Phase 5: gameplay out of the engine.** Everything marked phase 5 in the table above moves into `mods/bworld`. Mining
rules become something `mods/bworld` sets, with the engine asking it on both sides so clients still predict breaking.