Make fishing rods not actually target water

This commit is contained in:
2026-10-07 18:00:37 -03:00
parent b128da0631
commit b6b10e35e2
10 changed files with 374 additions and 70 deletions
+1 -1
View File
@@ -164,7 +164,7 @@ catch up. If it's further behind than that, it skips the rest and logs a warning
| `bworld:crop` | see [Crops](crops.md) | Grows a stage every morning its farmland was watered. |
| `bworld:crop_top` | see [Crops](crops.md) | The top half of a two block crop, like rice. |
| `bworld:water_source` | none | Refills the watering can. |
| `bworld:fishable` | none | Can be fished in with the fishing rod. |
| `bworld:fishable` | none | The fishing rod's hook floats on it and fish bite there when it lands in it. |
| `bworld:trapdoor` | none | Opens and closes when right clicked, and is placed like Minecraft's (its rules are in the shared script). Needs `facing` (2 bits), `half` and `open` states, see `blocks/oak_trapdoor.json`. |
| `bworld:fence` | `connects_to` | Joins the blocks in the tag `connects_to` and sturdy sides of other blocks, except leaves. Needs the `north`, `east`, `south` and `west` states. |
+27
View File
@@ -158,3 +158,30 @@ still going when the server stops don't carry on after it starts again until som
grass, leaves and water, or a fixed color like `"#80a755"`. `textures` lists the texture variables to tint, like only
the grass block's top. Without it every texture is tinted. In inventories, where there's no biome, the block uses
plains' color.
## Raycasts
Server scripts find the first block on a line with `ctx.world.raycast`, like Minecraft's `Level.clip`. The fishing rod's
hook uses it to see where it lands, and with a player's
[`eye_position` and `look_direction`](../entities/players.md#the-player-api) it finds what they're looking at:
```ts
const hit = ctx.world.raycast(from, to, { liquids: "any" });
if (hit && "bworld:fishable" in ctx.blocks.components(hit.id)) {
// hit.x, hit.y, hit.z is the block, hit.face the side it went in by, hit.position the exact point
}
```
It hits what entities bump into, so it goes through plants and other blocks with `"collision": false`. `liquids` is like
Minecraft's `ClipContext.Fluid`:
| `liquids` | Hits |
| ------------------ | ------------------------------------------- |
| `"none"` (default) | No liquids, it goes through them. |
| `"source_only"` | Liquid sources, going through flowing ones. |
| `"any"` | Every liquid. |
A liquid is hit at its surface, which is lower where it flows. It returns `undefined` when nothing is in the way.
`ctx.blocks.components(id)` gives the components a block's json lists and their params, like `ctx.items.components`, and
`ctx.blocks.exists(id)` whether a block exists.
+13
View File
@@ -20,6 +20,8 @@ interface Player {
readonly id: string;
readonly name: string;
readonly position: { x: number; y: number; z: number }; // their feet
readonly eye_position: { x: number; y: number; z: number }; // where they see from, lower while swimming
readonly look_direction: { x: number; y: number; z: number }; // which way they look, 1 long
readonly inventory: Container; // 36 slots, the hotbar is 0-8
readonly selected_slot: number;
readonly held_item: ItemStack | undefined;
@@ -54,6 +56,17 @@ interface Player {
`inventory` is a live [container](../inventories/containers.md), and `held_item` a live stack: changing them changes
what the player has.
`eye_position` and `look_direction` are for aiming. With [`ctx.world.raycast`](../blocks/index.md#raycasts) they find
what a player is looking at, like Minecraft's `getPlayerPOVHitResult`:
```ts
const eye = player.eye_position;
const look = player.look_direction;
const reach = 5;
const to = { x: eye.x + look.x * reach, y: eye.y + look.y * reach, z: eye.z + look.z * reach };
const hit = ctx.world.raycast(eye, to, { liquids: "source_only" });
```
## Health and Hunger
Players follow Minecraft's rules, with 20 health (10 hearts) and 20 hunger: