Change how targetting liquids work
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
+3
-3
@@ -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<BlockRegistry>("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<BlockRegistry>("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<ItemRegistry>("items", this.#held_slot().type_id ?? "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -248,6 +248,9 @@ export interface ItemRegistry<T = unknown | undefined> {
|
||||
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<string, unknown>;
|
||||
|
||||
on_create?(item: ItemStack<T>): void;
|
||||
|
||||
@@ -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<string, unknown>;
|
||||
@@ -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<ItemRegistry> {
|
||||
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") {
|
||||
|
||||
+15
-14
@@ -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
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"item": {
|
||||
"id": "bworld:bucket",
|
||||
"texture": "bworld:bucket",
|
||||
"targets_liquids": true,
|
||||
"max_stack": 16,
|
||||
"base_sell_value": 180
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"item": {
|
||||
"id": "bworld:copper_watering_can",
|
||||
"texture": "bworld:copper_watering_can",
|
||||
"targets_liquids": true,
|
||||
"tool": {
|
||||
"type": "watering_can",
|
||||
"tier": 1,
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"item": {
|
||||
"id": "bworld:gold_watering_can",
|
||||
"texture": "bworld:gold_watering_can",
|
||||
"targets_liquids": true,
|
||||
"tool": {
|
||||
"type": "watering_can",
|
||||
"tier": 0,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"item": {
|
||||
"id": "bworld:iron_watering_can",
|
||||
"texture": "bworld:iron_watering_can",
|
||||
"targets_liquids": true,
|
||||
"tool": {
|
||||
"type": "watering_can",
|
||||
"tier": 2,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"item": {
|
||||
"id": "bworld:stone_watering_can",
|
||||
"texture": "bworld:stone_watering_can",
|
||||
"targets_liquids": true,
|
||||
"tool": {
|
||||
"type": "watering_can",
|
||||
"tier": 1,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"item": {
|
||||
"id": "bworld:wood_watering_can",
|
||||
"texture": "bworld:wood_watering_can",
|
||||
"targets_liquids": true,
|
||||
"tool": {
|
||||
"type": "watering_can",
|
||||
"tier": 0,
|
||||
|
||||
Reference in New Issue
Block a user