Player api
This commit is contained in:
@@ -115,11 +115,12 @@ a slab's sides and plants aren't.
|
||||
### Placing
|
||||
|
||||
`state_for_placement` picks the states a block is placed with, like Minecraft's `getStateForPlacement`. `placement` is
|
||||
`{ x, y, z, face, hit, facing }`: where it's going, the face of the block that was clicked, where on that block the
|
||||
click was (from 0 to 1 on each axis), and the way the player looks along the ground. It returns states by name, and the
|
||||
rest keep their defaults, except that a 2 bit `facing` already faces the player. It runs before the server checks that
|
||||
no one is in the way, so that's checked against the shape the block will really have. A trapdoor clicked onto the upper
|
||||
half of a block's side hangs in the top half:
|
||||
`{ x, y, z, face, hit, facing, sneaking }`: where it's going, the face of the block that was clicked, where on that
|
||||
block the click was (from 0 to 1 on each axis), the way the player looks along the ground, and whether they're
|
||||
[sneaking](../entities/players.md#sneaking), for blocks that sneaking places the other way round. It returns states by
|
||||
name, and the rest keep their defaults, except that a 2 bit `facing` already faces the player. It runs before the server
|
||||
checks that no one is in the way, so that's checked against the shape the block will really have. A trapdoor clicked
|
||||
onto the upper half of a block's side hangs in the top half:
|
||||
|
||||
```ts
|
||||
state_for_placement(placement): Record<string, number> {
|
||||
@@ -142,8 +143,10 @@ the block had no components.
|
||||
A rule's `on_interact` also runs on the clicking player's client, so they see what it does right away instead of waiting
|
||||
for the server, like a trapdoor opening. It's for clicks that only change states with `ctx.world.set_state`, like
|
||||
Minecraft's `useWithoutItem`: anything that needs the server, like opening a screen, giving items or tile data, goes in
|
||||
the handler. `interaction` is `{ face, hit, facing }`: the face that was clicked, where on it (from 0 to 1 on each
|
||||
axis), and the way the player looks along the ground. The trapdoor's is in `mods/bworld/scripts/shared.ts`:
|
||||
the handler. `interaction` is `{ face, hit, facing, sneaking }`: the face that was clicked, where on it (from 0 to 1 on
|
||||
each axis), the way the player looks along the ground, and whether they're sneaking. A player sneaking with an item in
|
||||
hand doesn't interact at all: no `on_interact` runs, and the item is used or placed against the block instead. The
|
||||
trapdoor's is in `mods/bworld/scripts/shared.ts`:
|
||||
|
||||
```ts
|
||||
on_interact(block) {
|
||||
|
||||
Reference in New Issue
Block a user