Curios slots rendering !

This commit is contained in:
2026-10-01 17:57:22 -03:00
parent ea9f3f61bb
commit f2c3cb8135
39 changed files with 1032 additions and 226 deletions
+10
View File
@@ -26,6 +26,7 @@ interface Player {
give_item(id: string, count?: number, data?: unknown): void; // what doesn't fit drops at their feet
send_message(text: string): void;
set_worn(key: string, items: ItemStack[]): void; // what's drawn on them, see Worn Items
teleport(x: number, y: number, z: number): void;
readonly health: number; // out of max_health
@@ -92,6 +93,15 @@ Like Minecraft, an attack right after the last one, or right after changing the
damage, rising to full after `20 / attack_speed` ticks. A bar under the crosshair shows it filling up, and the server
sends players their `attack_speed` whenever it changes so the bar matches.
## Worn Items
`set_worn(key, items)` says what a mod shows on a player, like the base game's curios slots do for what's in them. Each
mod uses its own key, like `"bworld:curios"`, and setting a key replaces its list, `[]` clears it. Only items whose JSON
has [`worn`](../items/index.md#worn-models) show.
Everyone is told what each player wears, the player too, and players joining later get it with the others. It isn't
saved: set it again when the player joins, the way the curios slots do.
## Death
When a player dies, everything they carried falls out where they died, and their tools lose durability (see
+37
View File
@@ -50,6 +50,7 @@ down to 0 is gone.
| `tool` | none | Makes it a [tool](tools.md). |
| `food` | none | Makes it [edible](food.md). |
| `data_textures` | none | Other textures, picked by the stack's `data`, see below. |
| `worn` | none | How it looks worn on a player, see [below](#worn-models). |
| `components` | none | [Item components](#item-components) and their parameters. |
### Textures From Data
@@ -63,6 +64,42 @@ is out:
A stack whose `data.cast` is truthy uses `bworld:fishing_rod_cast`. When several keys are, the first listed wins.
### Worn Models
`worn` says how an item looks on a player who wears it, like Bedrock's attachables. A server script says what a player
wears with [`set_worn`](../entities/players.md#worn-items), and every client draws it on them. There's no third person
view, so players see what others wear, and what's on their own right arm in first person. Artifacts' power glove and
feral claws (`mods/artifacts`) and the base game's giant chestplate are examples.
```json
"worn": {
"model": "artifacts:power_glove_wide",
"texture": "artifacts:power_glove_wide",
"slim_model": "artifacts:power_glove_slim",
"slim_texture": "artifacts:power_glove_slim"
}
```
| Field | Meaning |
| ---------------------------- | ----------------------------------------------------------------------------------------------------- |
| `model` | An [entity model](../entities/index.md#entity-models) from a `models/*.geo.json`, made in Blockbench. |
| `texture` | The texture it's drawn with, laid out for the model's `texture_width` and `texture_height`. |
| `slim_model`, `slim_texture` | Optional, for players with slim (3 pixel wide) arms. The others when not set. |
A bone named like a part of the player, `head`, `body`, `right_arm`, `left_arm`, `right_leg` or `left_leg`, moves with
that part, so a model made over Blockbench's player template lines up. check-mods warns about a model with none of them,
since nothing of it would move. Bones under one of them go with it, and other bones stay with the body.
Things to know when making one:
- **Armor** can use a Minecraft armor texture (64x32, like `textures/entity/equipment/humanoid/` in a mod's assets) as
it is: a box over each part, inflated by 1, with the UVs of Minecraft's armor model. The giant chestplate
(`mods/bworld/models/giant_chestplate.geo.json`) is `body` at `[16, 16]` and both arms at `[40, 16]`.
- **Blockbench's `mirror` isn't supported**, so a box's texture is never flipped. Minecraft mirrors the left arm's and
leg's armor, which here show the right one's texture as it is.
- **Porting a Java mod's model**, like Artifacts' `ArmsMeshDefinitions`: Java models measure y down from the top of the
head, bedrock up from the feet. Keep x and z, and make each y `24 - y`, with a box's origin at its bottom.
## Item Components
Like [block components](../blocks/components.md), item components give items behavior. The server script registers them:
+24 -3
View File
@@ -30,11 +30,14 @@ ores), server scripts (components, events, commands, timers, storage, recipes, c
NeoForge's (menu types, slots, data, buttons and `still_valid` on the server, menu screens on the client, and the
player's inventory as menu 0, which mods can add slots to), client scripts (item and recipe lookups, plain screens,
inventory overlays, `Graphics` in GUI pixels), mod channels, worldgen features and ores, the base game's block behavior
and screens as a mod, and world time. See [Menus](modding/inventories/menus.md) and [Screens](modding/gui/index.md).
and screens as a mod, world time, and worn items (an item's `worn` model, `player.set_worn`, synced to every client and
drawn on other players and on the first person arm). See [Menus](modding/inventories/menus.md),
[Screens](modding/gui/index.md) and [Worn Models](modding/items/index.md#worn-models).
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/game/menu.ts`, `server/load_bmods.ts`, `client/mods.ts`, `client/menu.ts` and
`common/worldgen_loader.ts`.
`server/game/mod_runtime.ts`, `server/game/menu.ts`, `server/load_bmods.ts`, `client/mods.ts`, `client/menu.ts`,
`common/worldgen_loader.ts`, and for worn items `client/rendering/worn_renderer.ts`, `player_model.ts` and
`model_math.ts`.
**In the API types but throwing:** forms, HUD elements, keybinds, `g.slider`, `register_terrain`.
@@ -47,6 +50,10 @@ The code is in `common/mod_loader.ts`, `common/mod_data.ts`, `common/mod_check.t
API, so a mod's bundled copy is a different class. Export it from `bworld/server`, or recognize it by `name`.
- Tools only lose durability when their owner dies. Nothing else uses it.
- The GUI scale is always 3: screens work in GUI pixels like NeoForge's, but there's no option to change it yet.
- Worn models haven't been looked at in the game yet, only tested: Artifacts' power glove and feral claws and the giant
chestplate on other players, wide and slim, and on the first person arm with its equip and swing.
- Blockbench's `mirror` isn't supported in entity models, so the giant chestplate's left sleeve has the right one's
texture unflipped.
## Planned API
@@ -222,6 +229,20 @@ if (!result.canceled && result.selection === 0) player.teleport(0, 100, 0);
- The engine checks every response against the form's definition (types, ranges, option counts, text length) before mod
code sees it.
### More Worn Items
Worn items are drawn by `render_worn`, which puts an item's `worn` model on a player's parts. The same can show more:
- **Mobs' equipment.** `EntityData.equipment` is already synced but never drawn. `render_worn` can draw it on mod
entities whose bones are named like a humanoid's, and held items in their `right_arm`, like Minecraft's
`ItemInHandLayer`.
- **Other players' held items**, in their right hand the same way.
- **Hiding curio slots**, like Curios' render toggles, sent by the client and kept by the curios script.
- **A third person view.** Players would see what they wear themselves with nothing else to change, the local player has
`worn` too.
- **Glint and glowing overlays**, as `glint` and a full bright `overlay_texture` in `worn`, once the renderer has a
glint pass.
### HUD, Keybinds and Mod Channels
- `ctx.hud.register(id, { on_render(g) })` draws every frame after the world, under open screens.