Blocks interacting on the world api

This commit is contained in:
2026-10-15 12:49:44 -03:00
parent 7faa070d83
commit b43e8fe8b8
15 changed files with 493 additions and 28 deletions
+26
View File
@@ -83,6 +83,27 @@ faster. The client times breaking itself, and the server checks the result.
When it breaks, the block's components' `on_break` runs and it drops `drops` or what its `loot_table` gives, unless it
has `requires_tool` and the player's tool is the wrong type or a tier below `mining.tier`.
### Breaking From Scripts
`ctx.world.break_block(x, y, z)` breaks a block like a player with nothing in their hand, and returns what it dropped,
or `undefined` when there was nothing there. A machine that breaks blocks over time, like a drill, shows its progress
and passes options for how it breaks them:
```ts
const toughness = ctx.blocks.toughness(id); // seconds by hand, Infinity for one that can't be broken
ctx.world.set_break_progress(x, y, z, progress); // cracks, 0 to 1, that every player who sees it sees
// once it's through: drops what the right tool would, and hands them back instead of dropping them
const drops = ctx.world.break_block(x, y, z, { harvest: true, collect: true });
```
`set_break_progress` is like Minecraft's `destroyBlockProgress`. Only a change in the stage the cracks are drawn at is
sent, so setting it every tick costs little. `undefined` takes the cracks off, and so does the block being broken or
replaced. Players who load the chunk later don't see cracks set before, so keep setting it while it's being broken.
`harvest` drops what the right tool would, though nothing holds one, like Create's drills and saws: stone gives
cobblestone. `collect` returns the drops without dropping them, for a machine that puts them somewhere, like onto a
belt.
## Placement
Players place a block by right clicking a face of another block with its item. It goes next to the face they clicked, or
@@ -151,6 +172,11 @@ So it spreads one block a step, falls off edges and spreads again where it lands
its source is gone. It only flows into air, and stops at chunks that aren't loaded. Buckets only pick up sources. Flows
still going when the server stops don't carry on after it starts again until something next to them changes.
`ctx.world.liquid_flow(x, y, z)` says which way the liquid in a block flows, like Minecraft's `FluidState.getFlow`: a
vector 1 long toward the lower liquid beside it, and down where it falls against a wall, or `{ x: 0, y: 0, z: 0 }` where
it's still or there's none. It's the same flow that pushes players and items along, for machines it turns, like a water
wheel.
### Waterlogging
A block that isn't a liquid can hold one, like Minecraft's waterlogged fences. `waterloggable` names the liquid: