diff --git a/client/client.ts b/client/client.ts index 6ac3193..cf56438 100644 --- a/client/client.ts +++ b/client/client.ts @@ -301,6 +301,7 @@ export class Client { player.yaw, player.pitch, picked?.distance ?? BLOCK_REACH, + this.game_mode.held_item()?.targets_liquids, ); this.entity_hit = picked && !this.hit_result ? picked.entity : undefined; } diff --git a/client/game_mode.ts b/client/game_mode.ts index 2c56776..ea53db4 100644 --- a/client/game_mode.ts +++ b/client/game_mode.ts @@ -34,7 +34,7 @@ export class MultiPlayerGameMode { // called every tick the attack button is held on a block continue_destroy_block(hit: BlockHitResult) { const block_info = EverythingRegistry.get_by_id("blocks", hit.block)!; - const tool = this.#held_item()?.tool; + const tool = this.held_item()?.tool; // looking at another block starts it over const pos = this.destroy_pos; @@ -75,7 +75,7 @@ export class MultiPlayerGameMode { const current = level.get_block(target.x, target.y, target.z); const below = level.get_block(target.x, target.y - 1, target.z); const below_id = EverythingRegistry.get_by_id("blocks", below)?.id ?? AIR_ID; - const held = this.#held_item(); + const held = this.held_item(); // items with components might do something else on the server, like on_use const place_id = held?.components ? undefined : held?.block_id; const place_block = place_id !== undefined @@ -150,7 +150,7 @@ export class MultiPlayerGameMode { return inventories.inventory.get_slot(inventories.hotbar_selected); } - #held_item() { + held_item() { return EverythingRegistry.get("items", this.#held_slot().type_id ?? ""); } } diff --git a/client/level/client_level.ts b/client/level/client_level.ts index 9f45283..3d5f668 100644 --- a/client/level/client_level.ts +++ b/client/level/client_level.ts @@ -665,7 +665,8 @@ export class ClientLevel { } // the first block along the view of something at x/y/z looking at yaw/pitch, like minecraft's pick. it has to go - // into one of the block's boxes (see common/block_shapes.ts), so it looks past the empty half of a slab + // into one of the block's boxes (see common/block_shapes.ts), so it looks past the empty half of a slab. it looks + // through liquids unless liquids is set, see ItemRegistry.targets_liquids pick( x: number, y: number, @@ -673,6 +674,7 @@ export class ClientLevel { yaw: number, pitch: number, max_distance = 6, + liquids = false, step = 0.05, ): BlockHitResult | undefined { const cos_pitch = Math.cos(pitch); @@ -702,6 +704,9 @@ export class ClientLevel { continue; } const info = this.#blocks[block]; + if (!liquids && is_liquid_block(info)) { + continue; + } const hit = clip_shape( info ? shape_at(info, value) : FULL_SHAPE, bx, diff --git a/common/everything_registry.ts b/common/everything_registry.ts index 45b0cbf..3443cde 100644 --- a/common/everything_registry.ts +++ b/common/everything_registry.ts @@ -248,6 +248,9 @@ export interface ItemRegistry { lore?: string; food?: FoodProperties; worn?: WornProperties; + // whether players holding it aim at liquids, like buckets and fishing rods. others look through them, so they can + // break and place blocks under water + targets_liquids?: boolean; components?: Record; on_create?(item: ItemStack): void; diff --git a/common/mod_data.ts b/common/mod_data.ts index ea741aa..0ef287c 100644 --- a/common/mod_data.ts +++ b/common/mod_data.ts @@ -119,6 +119,8 @@ export interface ItemJson { food?: FoodProperties; // how it looks worn on a player worn?: WornProperties; + // see ItemRegistry.targets_liquids + targets_liquids?: boolean; name?: string; lore?: string; components?: Record; @@ -370,6 +372,7 @@ export function item_to_json(id: string, item: ItemRegistry): ItemJson { if (item.base_sell_value !== undefined) json.base_sell_value = item.base_sell_value; if (item.food !== undefined) json.food = item.food; if (item.worn !== undefined) json.worn = item.worn; + if (item.targets_liquids !== undefined) json.targets_liquids = item.targets_liquids; if (item.name !== undefined) json.name = item.name; if (item.lore !== undefined) json.lore = item.lore; if (item.components) json.components = item.components; @@ -396,6 +399,7 @@ function item_fields(json: ItemJson): Partial { if (json.base_sell_value !== undefined) item.base_sell_value = json.base_sell_value; if (json.food !== undefined) item.food = json.food; if (json.worn !== undefined) item.worn = json.worn; + if (json.targets_liquids !== undefined) item.targets_liquids = json.targets_liquids; if (json.name !== undefined) item.name = json.name; if (json.lore !== undefined) item.lore = json.lore; if (json.components) item.components = json.components; @@ -815,6 +819,9 @@ export function validate_item(json: unknown): Problems { if (json.base_sell_value !== undefined && !is_whole(json.base_sell_value)) { problems.push("base_sell_value must be a whole number of 0 or more"); } + if (json.targets_liquids !== undefined && typeof json.targets_liquids !== "boolean") { + problems.push("targets_liquids must be true or false"); + } if (json.tool !== undefined) { const tool = json.tool; if (!is_object(tool) || typeof tool.type !== "string") { diff --git a/docs/modding/items/index.md b/docs/modding/items/index.md index 99a1526..41e865f 100644 --- a/docs/modding/items/index.md +++ b/docs/modding/items/index.md @@ -39,20 +39,21 @@ down to 0 is gone. ## Properties -| Field | Default | Meaning | -| ----------------- | ------------------- | ------------------------------------------------------------------------------------ | -| `id` | required | The item's id. | -| `texture` | required | The texture it's drawn with. Leave it out to [fill in a block's item](#block-items). | -| `name` | from the id | What players see. `copper_tools:copper_ingot` is "Copper Ingot" when not set. | -| `lore` | none | Tooltip text under the name. `\n` starts a new line. | -| `max_stack` | `64`, `1` for tools | How many fit in one slot. | -| `base_sell_value` | none | What one is worth when sold, a whole number of 0 or more. | -| `places` | none | A block it places when used on a block, like seeds. | -| `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. | +| Field | Default | Meaning | +| ----------------- | ------------------- | ------------------------------------------------------------------------------------- | +| `id` | required | The item's id. | +| `texture` | required | The texture it's drawn with. Leave it out to [fill in a block's item](#block-items). | +| `name` | from the id | What players see. `copper_tools:copper_ingot` is "Copper Ingot" when not set. | +| `lore` | none | Tooltip text under the name. `\n` starts a new line. | +| `max_stack` | `64`, `1` for tools | How many fit in one slot. | +| `base_sell_value` | none | What one is worth when sold, a whole number of 0 or more. | +| `places` | none | A block it places when used on a block, like seeds. | +| `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). | +| `targets_liquids` | `false` | Players holding it aim at liquids, like buckets and fishing rods. Others aim through. | +| `components` | none | [Item components](#item-components) and their parameters. | ### Textures From Data diff --git a/mods/bworld/items/bucket.json b/mods/bworld/items/bucket.json index 9e73743..96d09b4 100644 --- a/mods/bworld/items/bucket.json +++ b/mods/bworld/items/bucket.json @@ -3,6 +3,7 @@ "item": { "id": "bworld:bucket", "texture": "bworld:bucket", + "targets_liquids": true, "max_stack": 16, "base_sell_value": 180 } diff --git a/mods/bworld/items/copper_watering_can.json b/mods/bworld/items/copper_watering_can.json index ee97628..02fd48a 100644 --- a/mods/bworld/items/copper_watering_can.json +++ b/mods/bworld/items/copper_watering_can.json @@ -3,6 +3,7 @@ "item": { "id": "bworld:copper_watering_can", "texture": "bworld:copper_watering_can", + "targets_liquids": true, "tool": { "type": "watering_can", "tier": 1, diff --git a/mods/bworld/items/fishing_rod.json b/mods/bworld/items/fishing_rod.json index cbc4d5f..45f96f1 100644 --- a/mods/bworld/items/fishing_rod.json +++ b/mods/bworld/items/fishing_rod.json @@ -6,6 +6,7 @@ "data_textures": { "cast": "bworld:fishing_rod_cast" }, + "targets_liquids": true, "max_stack": 1, "lore": "Right click water to cast, and again when something bites.", "components": { diff --git a/mods/bworld/items/gold_watering_can.json b/mods/bworld/items/gold_watering_can.json index 00816ad..0295edb 100644 --- a/mods/bworld/items/gold_watering_can.json +++ b/mods/bworld/items/gold_watering_can.json @@ -3,6 +3,7 @@ "item": { "id": "bworld:gold_watering_can", "texture": "bworld:gold_watering_can", + "targets_liquids": true, "tool": { "type": "watering_can", "tier": 0, diff --git a/mods/bworld/items/iron_watering_can.json b/mods/bworld/items/iron_watering_can.json index 1a9d7fa..2fdd8f3 100644 --- a/mods/bworld/items/iron_watering_can.json +++ b/mods/bworld/items/iron_watering_can.json @@ -3,6 +3,7 @@ "item": { "id": "bworld:iron_watering_can", "texture": "bworld:iron_watering_can", + "targets_liquids": true, "tool": { "type": "watering_can", "tier": 2, diff --git a/mods/bworld/items/stone_watering_can.json b/mods/bworld/items/stone_watering_can.json index 45d0720..1adcf06 100644 --- a/mods/bworld/items/stone_watering_can.json +++ b/mods/bworld/items/stone_watering_can.json @@ -3,6 +3,7 @@ "item": { "id": "bworld:stone_watering_can", "texture": "bworld:stone_watering_can", + "targets_liquids": true, "tool": { "type": "watering_can", "tier": 1, diff --git a/mods/bworld/items/wood_watering_can.json b/mods/bworld/items/wood_watering_can.json index 7bc2f7a..c65f3f2 100644 --- a/mods/bworld/items/wood_watering_can.json +++ b/mods/bworld/items/wood_watering_can.json @@ -3,6 +3,7 @@ "item": { "id": "bworld:wood_watering_can", "texture": "bworld:wood_watering_can", + "targets_liquids": true, "tool": { "type": "watering_can", "tier": 0,