Health and hunger system

This commit is contained in:
2026-09-26 21:07:36 -03:00
parent 0fa6ec4ed3
commit 8d9c85d379
18 changed files with 662 additions and 8 deletions
+18
View File
@@ -364,6 +364,7 @@ block is lit evenly with the block's own light.
| `tool` | none | `tool_type` | Tool type used by blocks' `mining.tool`. |
| `places` | none | `block_id` | Block placed when used on a block face. |
| `max_stack` | `64` | new | Largest stack size. |
| `food` | none | `food` | Makes it edible: `{ "nutrition": 3, "saturation_modifier": 0.6 }`, with Minecraft's meanings (hunger points out of 20, and saturation of nutrition × modifier × 2). Optional `always_edible` (eaten even when full) and `returns` (an item left in the hand, like a bowl). Players eat it by right clicking while hungry. |
| `lore` | none | `lore` | Tooltip text under the name. `\n` starts a new line. |
| `components` | none | `on_create` / `get_lore` | Custom item components, handled by server scripts. |
@@ -645,6 +646,8 @@ events** fire once it has happened.
| `block_place` | ✓ | ✓ | `player`, `block`, `face`, `item` |
| `block_interact` | ✓ | ✓ | `player`, `block`, `item` |
| `chat_send` | ✓ | ✓ | `player`, `message` (before events can change `message`) |
| `player_damage` | ✓ | | `player`, `amount`, `cause` (before events can change `amount`) |
| `player_death` | | ✓ | `player`, `cause`. They've dropped what they carried and respawn right after |
| `player_join` | | ✓ | `player` |
| `player_leave` | | ✓ | `player` |
| `server_start` | | ✓ | none |
@@ -682,6 +685,14 @@ interface Player {
give_item(id: string, count?: number, data?: unknown): void;
send_message(text: string): void;
teleport(x: number, y: number, z: number): void;
readonly health: number; // out of max_health, 20
readonly max_health: number;
readonly food: number; // hunger, out of 20
readonly saturation: number; // never above food
damage(amount: number, cause?: string): void; // cause shows in events and the death message
heal(amount: number): void;
feed(nutrition: number, saturation_modifier: number): void; // like eating
add_exhaustion(amount: number): void; // 4 costs a point of saturation, or of hunger once it's gone
}
interface PlayerList {
@@ -705,6 +716,13 @@ interface ModStorage {
}
```
**Health and hunger** follow Minecraft's rules (`server/game/vitals.ts`). Sprinting, swimming, jumping, breaking blocks,
taking damage and healing add exhaustion, and every 4 of it costs a point of saturation, or of hunger once saturation
is gone. A full stomach heals: quickly while there's saturation, slowly with at least 18 hunger. At 0 hunger players
lose health every 4 seconds, down to half a heart. Falls hurt 1 per block after the first 3, unless they land in water,
and below the world players die. Dying drops everything they carried and respawns them at spawn with full health and
hunger.
**World time** counts ticks since 06:00 of day 1 and never wraps around. A day (06:00 to 18:00) is 36000 ticks, 30
minutes, and a night (18:00 to 06:00) is 12000 ticks, 10 minutes, so in game hours are shorter at night. Dusk is the
first minute of the night and dawn the last, so it's bright all day. `common/time.ts` has `clock`, `format_clock`,