From 8fe581ea935b8a016cf8fcd26e8007990bd1bff6 Mon Sep 17 00:00:00 2001 From: paulaboks Date: Tue, 29 Sep 2026 17:54:17 -0300 Subject: [PATCH] Improve tools system --- .gitignore | 1 + MODS.md | 13 ++++---- client/game_mode.ts | 4 +-- client/gui/tooltip.ts | 3 ++ common/everything_registry.ts | 17 ++++++++++- common/inventory.ts | 2 +- common/mod_data.ts | 34 ++++++++++++++++++--- mods/bworld/blocks/copper_ore.json | 3 +- mods/bworld/blocks/gold_ore.json | 3 +- mods/bworld/blocks/iron_ore.json | 3 +- mods/bworld/blocks/tin_ore.json | 3 +- mods/bworld/items/copper_axe.json | 7 ++++- mods/bworld/items/copper_hoe.json | 7 ++++- mods/bworld/items/copper_pickaxe.json | 7 ++++- mods/bworld/items/copper_shovel.json | 7 ++++- mods/bworld/items/golden_axe.json | 7 ++++- mods/bworld/items/golden_hoe.json | 7 ++++- mods/bworld/items/golden_pickaxe.json | 7 ++++- mods/bworld/items/golden_shovel.json | 7 ++++- mods/bworld/items/iron_axe.json | 7 ++++- mods/bworld/items/iron_hoe.json | 7 ++++- mods/bworld/items/iron_pickaxe.json | 7 ++++- mods/bworld/items/iron_shovel.json | 7 ++++- mods/bworld/items/stone_axe.json | 7 ++++- mods/bworld/items/stone_hoe.json | 7 ++++- mods/bworld/items/stone_pickaxe.json | 7 ++++- mods/bworld/items/stone_shovel.json | 7 ++++- mods/bworld/items/wood_axe.json | 7 ++++- mods/bworld/items/wood_hoe.json | 7 ++++- mods/bworld/items/wood_pickaxe.json | 7 ++++- mods/bworld/items/wood_shovel.json | 7 ++++- mods/farmersdelight/items/copper_knife.json | 7 ++++- mods/farmersdelight/items/gold_knife.json | 7 ++++- mods/farmersdelight/items/iron_knife.json | 7 ++++- mods/farmersdelight/items/stone_knife.json | 7 ++++- mods/farmersdelight/items/wood_knife.json | 7 ++++- server/game/game_server.ts | 6 ++-- server/game/mod_runtime.ts | 4 +-- tests/mod_loading_test.ts | 3 +- 39 files changed, 225 insertions(+), 49 deletions(-) diff --git a/.gitignore b/.gitignore index caa9837..2e97f61 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ build/ world/ server_mods/ dist/ +ports/ \ No newline at end of file diff --git a/MODS.md b/MODS.md index c0566be..1dfefce 100644 --- a/MODS.md +++ b/MODS.md @@ -248,9 +248,10 @@ program**, so the server and each client can number blocks differently. Saves an | `light_opacity` | see meaning | `light_opacity` | How much light passing through it loses, 0-15. Defaults to `15` (blocks all light) for solid blocks and `0` otherwise. Leaves and water use `1`. | | `alpha` | `1` | `alpha` | Opacity for translucent blocks. | | `collision` | `true` | `has_collision` | Whether entities collide with it. | -| `mining.toughness` | unbreakable | `toughness` | Seconds to break by hand. A matching tool is 2× faster. | +| `mining.toughness` | unbreakable | `toughness` | Seconds to break by hand. A matching tool is its `tool.speed` times faster. | | `mining.tool` | none | `tool_to_break` | Tool type that speeds it up, like `pickaxe`, `axe` or `shovel`. | | `mining.requires_tool` | `false` | `requires_tool` | Only drops when broken with `mining.tool`. | +| `mining.tier` | `0` | `tool_tier` | With `requires_tool`, the lowest `tool.tier` it drops for, like Minecraft's `incorrect_for_*_tool` tags. Iron ore is `1`, so a wood pickaxe gets nothing. | | `drops` | nothing | `drop_table` | Item id dropped on the ground when broken, for players to pick up. | | `item` | `true` | `register_block_item` | Also register an item that places this block, with the same id. | | `interactive` | `false` | `interactive` | Right clicking it does something (opens a screen), so clients don't guess it places a block. | @@ -409,10 +410,8 @@ clicked on somewhere it can go and eaten otherwise. "item": { "id": "copper_tools:copper_pickaxe", "texture": "copper_tools:copper_pickaxe", - "tool": "pickaxe", - "max_stack": 1, - "lore": "Better than wood, worse than iron.", - "components": { "copper_tools:durability": { "max": 250 } } + "tool": { "type": "pickaxe", "tier": 1, "speed": 3.5, "durability": 190 }, + "lore": "Better than wood, worse than iron." } } ``` @@ -423,9 +422,9 @@ clicked on somewhere it can go and eaten otherwise. | `name` | from the id | `name` | What players see, like `"Copper Pickaxe"`. Made from the id when not set. | | `texture` | required | `texture_id` | Texture id. | | `data_textures` | none | `data_textures` | `{ "cast": "bworld:fishing_rod_cast" }`: a stack whose `data` has that key set is drawn with that texture instead, like a cast fishing rod. The first key that's set wins. | -| `tool` | none | `tool_type` | Tool type used by blocks' `mining.tool`. | +| `tool` | none | `tool` | Makes it a tool, like Fabric's `ToolMaterial`: `type` (matched against blocks' `mining.tool`, like `"pickaxe"`), `tier` (default `0`, see blocks' `mining.tier`), `speed` (default `2`, how many times faster than a hand) and `durability` (shown in its tooltip, nothing uses it up yet). The base game's tiers are wood and gold `0`, stone and copper `1`, iron `2`. | | `places` | none | `block_id` | Block placed when used on a block face. | -| `max_stack` | `64` | new | Largest stack size. | +| `max_stack` | `64`, `1` for tools | new | Largest stack size. | | `food` | none | `food` | Makes it edible: `{ "nutrition": 3, "saturation_modifier": 0.6 }`, with Minecraft's meanings (hunger points out of 20, and saturation of nutrition × modifier × 2). Optional `always_edible` (eaten even when full) and `returns` (an item left in the hand, like a bowl). Players eat it by right clicking while hungry. | | `lore` | none | `lore` | Tooltip text under the name. `\n` starts a new line. | | `components` | none | `on_create` / `get_lore` | Custom item components, handled by server scripts. | diff --git a/client/game_mode.ts b/client/game_mode.ts index 1627a9e..abf96dc 100644 --- a/client/game_mode.ts +++ b/client/game_mode.ts @@ -28,11 +28,11 @@ 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_type = this.#held_item()?.tool_type; + const tool = this.#held_item()?.tool; this.destroy_pos = { x: hit.x, y: hit.y, z: hit.z }; this.destroy_time = block_info.toughness ?? 9999; - this.destroy_progress += TICK_DELTA * (tool_type === block_info.tool_to_break ? 2 : 1); + this.destroy_progress += TICK_DELTA * (tool && tool.type === block_info.tool_to_break ? tool.speed : 1); if (this.destroy_progress >= this.destroy_time) { // show it right away, the server decides drops and corrects us if it disagrees diff --git a/client/gui/tooltip.ts b/client/gui/tooltip.ts index fc29a60..5819b02 100644 --- a/client/gui/tooltip.ts +++ b/client/gui/tooltip.ts @@ -29,6 +29,9 @@ export function item_tooltip(item: ItemStack): TooltipLine[] { if (info?.food) { lines.push({ text: `Restores ${info.food.nutrition} hunger`, color: FOOD_COLOR }); } + if (info?.tool) { + lines.push({ text: `Durability: ${info.tool.durability}`, color: LORE_COLOR }); + } const static_lore = info?.lore; for (const lore of [static_lore, item.lore]) { for (const text of lore?.split("\n") ?? []) { diff --git a/common/everything_registry.ts b/common/everything_registry.ts index 1f6b13a..adb23bd 100644 --- a/common/everything_registry.ts +++ b/common/everything_registry.ts @@ -122,6 +122,8 @@ export interface BlockRegistry { toughness?: number; requires_tool?: boolean; tool_to_break?: string; + // the lowest tool tier it drops for when requires_tool, like minecraft's incorrect_for_*_tool tags. 0 when not set + tool_tier?: number; drop_table?: string; states?: BlockStateDefinition[]; @@ -147,6 +149,18 @@ export interface BlockRegistry { compiled_states?: CompiledStateDefinition[]; } +// what a tool is made of, like fabric's ToolMaterial +export interface ToolProperties { + // like "pickaxe", matched against blocks' tool_to_break + type: string; + // blocks that need a tool only drop for tools of their tool_tier or higher. wood and gold are 0, stone 1, iron 2 + tier: number; + // how many times faster than a hand it breaks blocks of its type + speed: number; + // how much use it can take. nothing uses it up yet + durability: number; +} + // what eating an item does, like minecraft's food properties export interface FoodProperties { // hunger points it restores, a bar is 20 @@ -166,7 +180,8 @@ export interface ItemRegistry { // what players see, like "Iron Ingot". made from the id when not set, see display_name in common/utils.ts name?: string; block_id?: string; - tool_type?: string; + tool?: ToolProperties; + // 1 for tools and 64 for everything else when not set max_stack?: number; lore?: string; food?: FoodProperties; diff --git a/common/inventory.ts b/common/inventory.ts index 0766199..684a954 100644 --- a/common/inventory.ts +++ b/common/inventory.ts @@ -21,7 +21,7 @@ export class ItemStack { const item_info = EverythingRegistry.get("items", type_id); this.type_id = type_id; this.amount = amount; - this.max_amount = max_amount ?? item_info?.max_stack ?? 64; + this.max_amount = max_amount ?? item_info?.max_stack ?? (item_info?.tool ? 1 : 64); this.data = undefined; if (item_info?.on_create) { item_info.on_create(this); diff --git a/common/mod_data.ts b/common/mod_data.ts index 93281b6..626a259 100644 --- a/common/mod_data.ts +++ b/common/mod_data.ts @@ -8,6 +8,7 @@ import { type ItemRegistry, RENDER_LAYERS, type RenderLayer, + type ToolProperties, } from "./everything_registry.ts"; import { type BlockVariant, MODEL_FACES, type ModelFace } from "./block_models.ts"; @@ -46,7 +47,7 @@ export interface BlockJson { transparent?: boolean; alpha?: number; collision?: boolean; - mining?: { toughness: number; tool?: string; requires_tool?: boolean }; + mining?: { toughness: number; tool?: string; requires_tool?: boolean; tier?: number }; drops?: string; item?: boolean; interactive?: boolean; @@ -72,7 +73,8 @@ export interface ItemJson { texture: string; // data key -> texture, see ItemRegistry.data_textures data_textures?: Record; - tool?: string; + // tier and speed default to 0 and 2 + tool?: Omit & Partial; places?: string; max_stack?: number; food?: FoodProperties; @@ -194,6 +196,7 @@ export function block_to_json(block: BlockRegistry, has_item: boolean): BlockJso json.mining = { toughness: block.toughness }; if (block.tool_to_break !== undefined) json.mining.tool = block.tool_to_break; if (block.requires_tool) json.mining.requires_tool = true; + if (block.tool_tier) json.mining.tier = block.tool_tier; } if (block.drop_table !== undefined) json.drops = block.drop_table; if (!has_item) json.item = false; @@ -227,6 +230,7 @@ export function block_from_json(json: BlockJson): { block: BlockRegistry; has_it block.toughness = json.mining.toughness; block.requires_tool = json.mining.requires_tool ?? false; if (json.mining.tool !== undefined) block.tool_to_break = json.mining.tool; + if (json.mining.tier) block.tool_tier = json.mining.tier; } if (json.drops !== undefined) block.drop_table = json.drops; if (json.interactive) block.interactive = true; @@ -247,7 +251,7 @@ export function item_to_json(id: string, item: ItemRegistry): ItemJson { } const json: ItemJson = { id, texture: item.texture_id }; if (item.data_textures !== undefined) json.data_textures = item.data_textures; - if (item.tool_type !== undefined) json.tool = item.tool_type; + if (item.tool !== undefined) json.tool = item.tool; if (item.block_id !== undefined) json.places = item.block_id; if (item.max_stack !== undefined) json.max_stack = item.max_stack; if (item.food !== undefined) json.food = item.food; @@ -260,7 +264,7 @@ export function item_to_json(id: string, item: ItemRegistry): ItemJson { export function item_from_json(json: ItemJson): ItemRegistry { const item: ItemRegistry = { texture_id: json.texture }; if (json.data_textures !== undefined) item.data_textures = json.data_textures; - if (json.tool !== undefined) item.tool_type = json.tool; + if (json.tool !== undefined) item.tool = { tier: 0, speed: 2, ...json.tool }; if (json.places !== undefined) item.block_id = json.places; if (json.max_stack !== undefined) item.max_stack = json.max_stack; if (json.food !== undefined) item.food = json.food; @@ -436,6 +440,8 @@ export function validate_block(json: unknown): Problems { if (json.mining !== undefined) { if (!is_object(json.mining) || typeof json.mining.toughness !== "number" || json.mining.toughness < 0) { problems.push("mining.toughness must be a number of seconds"); + } else if (json.mining.tier !== undefined && !is_whole(json.mining.tier)) { + problems.push("mining.tier must be a whole number of 0 or more"); } } if (json.drops !== undefined) problems.push(...validate_id(json.drops, "drops")); @@ -535,6 +541,10 @@ function validate_textures(value: unknown, field: string, allow_variables = fals ); } +function is_whole(value: unknown): value is number { + return Number.isInteger(value) && (value as number) >= 0; +} + export function validate_item(json: unknown): Problems { if (!is_object(json)) return ["item must be an object"]; const problems = validate_id(json.id, "id"); @@ -552,6 +562,22 @@ export function validate_item(json: unknown): Problems { if (json.max_stack !== undefined && (!Number.isInteger(json.max_stack) || (json.max_stack as number) < 1)) { problems.push("max_stack must be a positive whole number"); } + if (json.tool !== undefined) { + const tool = json.tool; + if (!is_object(tool) || typeof tool.type !== "string") { + problems.push('tool must be { type, durability }, like "pickaxe"'); + } else { + if (!is_whole(tool.durability) || tool.durability < 1) { + problems.push("tool.durability must be a positive whole number"); + } + if (tool.tier !== undefined && !is_whole(tool.tier)) { + problems.push("tool.tier must be a whole number of 0 or more"); + } + if (tool.speed !== undefined && (typeof tool.speed !== "number" || tool.speed <= 0)) { + problems.push("tool.speed must be a positive number"); + } + } + } if (json.food !== undefined) { const food = json.food; if ( diff --git a/mods/bworld/blocks/copper_ore.json b/mods/bworld/blocks/copper_ore.json index 1308910..42e014d 100644 --- a/mods/bworld/blocks/copper_ore.json +++ b/mods/bworld/blocks/copper_ore.json @@ -6,7 +6,8 @@ "mining": { "toughness": 5, "tool": "pickaxe", - "requires_tool": true + "requires_tool": true, + "tier": 1 }, "drops": "bworld:copper_ore" } diff --git a/mods/bworld/blocks/gold_ore.json b/mods/bworld/blocks/gold_ore.json index cec013c..2aa79a1 100644 --- a/mods/bworld/blocks/gold_ore.json +++ b/mods/bworld/blocks/gold_ore.json @@ -6,7 +6,8 @@ "mining": { "toughness": 5, "tool": "pickaxe", - "requires_tool": true + "requires_tool": true, + "tier": 1 }, "drops": "bworld:gold_ore" } diff --git a/mods/bworld/blocks/iron_ore.json b/mods/bworld/blocks/iron_ore.json index 032bafe..105cb51 100644 --- a/mods/bworld/blocks/iron_ore.json +++ b/mods/bworld/blocks/iron_ore.json @@ -6,7 +6,8 @@ "mining": { "toughness": 5, "tool": "pickaxe", - "requires_tool": true + "requires_tool": true, + "tier": 1 }, "drops": "bworld:iron_ore" } diff --git a/mods/bworld/blocks/tin_ore.json b/mods/bworld/blocks/tin_ore.json index 5e99e65..a4f77ca 100644 --- a/mods/bworld/blocks/tin_ore.json +++ b/mods/bworld/blocks/tin_ore.json @@ -6,7 +6,8 @@ "mining": { "toughness": 5, "tool": "pickaxe", - "requires_tool": true + "requires_tool": true, + "tier": 1 }, "drops": "bworld:tin_ore" } diff --git a/mods/bworld/items/copper_axe.json b/mods/bworld/items/copper_axe.json index 8f7582a..f34d2ae 100644 --- a/mods/bworld/items/copper_axe.json +++ b/mods/bworld/items/copper_axe.json @@ -3,6 +3,11 @@ "item": { "id": "bworld:copper_axe", "texture": "bworld:copper_axe", - "tool": "axe" + "tool": { + "type": "axe", + "tier": 1, + "speed": 3.5, + "durability": 190 + } } } diff --git a/mods/bworld/items/copper_hoe.json b/mods/bworld/items/copper_hoe.json index e24bb76..503de34 100644 --- a/mods/bworld/items/copper_hoe.json +++ b/mods/bworld/items/copper_hoe.json @@ -3,6 +3,11 @@ "item": { "id": "bworld:copper_hoe", "texture": "bworld:copper_hoe", - "tool": "hoe" + "tool": { + "type": "hoe", + "tier": 1, + "speed": 3.5, + "durability": 190 + } } } diff --git a/mods/bworld/items/copper_pickaxe.json b/mods/bworld/items/copper_pickaxe.json index a72cf76..06af996 100644 --- a/mods/bworld/items/copper_pickaxe.json +++ b/mods/bworld/items/copper_pickaxe.json @@ -3,6 +3,11 @@ "item": { "id": "bworld:copper_pickaxe", "texture": "bworld:copper_pickaxe", - "tool": "pickaxe" + "tool": { + "type": "pickaxe", + "tier": 1, + "speed": 3.5, + "durability": 190 + } } } diff --git a/mods/bworld/items/copper_shovel.json b/mods/bworld/items/copper_shovel.json index bf2311a..0c6b1d6 100644 --- a/mods/bworld/items/copper_shovel.json +++ b/mods/bworld/items/copper_shovel.json @@ -3,6 +3,11 @@ "item": { "id": "bworld:copper_shovel", "texture": "bworld:copper_shovel", - "tool": "shovel" + "tool": { + "type": "shovel", + "tier": 1, + "speed": 3.5, + "durability": 190 + } } } diff --git a/mods/bworld/items/golden_axe.json b/mods/bworld/items/golden_axe.json index 06e3916..0591382 100644 --- a/mods/bworld/items/golden_axe.json +++ b/mods/bworld/items/golden_axe.json @@ -3,6 +3,11 @@ "item": { "id": "bworld:golden_axe", "texture": "bworld:golden_axe", - "tool": "axe" + "tool": { + "type": "axe", + "tier": 0, + "speed": 6, + "durability": 32 + } } } diff --git a/mods/bworld/items/golden_hoe.json b/mods/bworld/items/golden_hoe.json index 96fbf5f..3a3c75e 100644 --- a/mods/bworld/items/golden_hoe.json +++ b/mods/bworld/items/golden_hoe.json @@ -3,6 +3,11 @@ "item": { "id": "bworld:golden_hoe", "texture": "bworld:golden_hoe", - "tool": "hoe" + "tool": { + "type": "hoe", + "tier": 0, + "speed": 6, + "durability": 32 + } } } diff --git a/mods/bworld/items/golden_pickaxe.json b/mods/bworld/items/golden_pickaxe.json index 61cd3f5..85f49fa 100644 --- a/mods/bworld/items/golden_pickaxe.json +++ b/mods/bworld/items/golden_pickaxe.json @@ -3,6 +3,11 @@ "item": { "id": "bworld:golden_pickaxe", "texture": "bworld:golden_pickaxe", - "tool": "pickaxe" + "tool": { + "type": "pickaxe", + "tier": 0, + "speed": 6, + "durability": 32 + } } } diff --git a/mods/bworld/items/golden_shovel.json b/mods/bworld/items/golden_shovel.json index 36a17e3..60cd84e 100644 --- a/mods/bworld/items/golden_shovel.json +++ b/mods/bworld/items/golden_shovel.json @@ -3,6 +3,11 @@ "item": { "id": "bworld:golden_shovel", "texture": "bworld:golden_shovel", - "tool": "shovel" + "tool": { + "type": "shovel", + "tier": 0, + "speed": 6, + "durability": 32 + } } } diff --git a/mods/bworld/items/iron_axe.json b/mods/bworld/items/iron_axe.json index 20e4dd9..48cdc91 100644 --- a/mods/bworld/items/iron_axe.json +++ b/mods/bworld/items/iron_axe.json @@ -3,6 +3,11 @@ "item": { "id": "bworld:iron_axe", "texture": "bworld:iron_axe", - "tool": "axe" + "tool": { + "type": "axe", + "tier": 2, + "speed": 4, + "durability": 250 + } } } diff --git a/mods/bworld/items/iron_hoe.json b/mods/bworld/items/iron_hoe.json index 6853730..6094309 100644 --- a/mods/bworld/items/iron_hoe.json +++ b/mods/bworld/items/iron_hoe.json @@ -3,6 +3,11 @@ "item": { "id": "bworld:iron_hoe", "texture": "bworld:iron_hoe", - "tool": "hoe" + "tool": { + "type": "hoe", + "tier": 2, + "speed": 4, + "durability": 250 + } } } diff --git a/mods/bworld/items/iron_pickaxe.json b/mods/bworld/items/iron_pickaxe.json index 3534b4d..1d35767 100644 --- a/mods/bworld/items/iron_pickaxe.json +++ b/mods/bworld/items/iron_pickaxe.json @@ -3,6 +3,11 @@ "item": { "id": "bworld:iron_pickaxe", "texture": "bworld:iron_pickaxe", - "tool": "pickaxe" + "tool": { + "type": "pickaxe", + "tier": 2, + "speed": 4, + "durability": 250 + } } } diff --git a/mods/bworld/items/iron_shovel.json b/mods/bworld/items/iron_shovel.json index 2df0589..fdd99f6 100644 --- a/mods/bworld/items/iron_shovel.json +++ b/mods/bworld/items/iron_shovel.json @@ -3,6 +3,11 @@ "item": { "id": "bworld:iron_shovel", "texture": "bworld:iron_shovel", - "tool": "shovel" + "tool": { + "type": "shovel", + "tier": 2, + "speed": 4, + "durability": 250 + } } } diff --git a/mods/bworld/items/stone_axe.json b/mods/bworld/items/stone_axe.json index ed5466b..b18f6d4 100644 --- a/mods/bworld/items/stone_axe.json +++ b/mods/bworld/items/stone_axe.json @@ -3,6 +3,11 @@ "item": { "id": "bworld:stone_axe", "texture": "bworld:stone_axe", - "tool": "axe" + "tool": { + "type": "axe", + "tier": 1, + "speed": 3, + "durability": 131 + } } } diff --git a/mods/bworld/items/stone_hoe.json b/mods/bworld/items/stone_hoe.json index 57df3d6..c516d35 100644 --- a/mods/bworld/items/stone_hoe.json +++ b/mods/bworld/items/stone_hoe.json @@ -3,6 +3,11 @@ "item": { "id": "bworld:stone_hoe", "texture": "bworld:stone_hoe", - "tool": "hoe" + "tool": { + "type": "hoe", + "tier": 1, + "speed": 3, + "durability": 131 + } } } diff --git a/mods/bworld/items/stone_pickaxe.json b/mods/bworld/items/stone_pickaxe.json index 4a5cfcd..6a8d973 100644 --- a/mods/bworld/items/stone_pickaxe.json +++ b/mods/bworld/items/stone_pickaxe.json @@ -3,6 +3,11 @@ "item": { "id": "bworld:stone_pickaxe", "texture": "bworld:stone_pickaxe", - "tool": "pickaxe" + "tool": { + "type": "pickaxe", + "tier": 1, + "speed": 3, + "durability": 131 + } } } diff --git a/mods/bworld/items/stone_shovel.json b/mods/bworld/items/stone_shovel.json index 85fad72..90251ea 100644 --- a/mods/bworld/items/stone_shovel.json +++ b/mods/bworld/items/stone_shovel.json @@ -3,6 +3,11 @@ "item": { "id": "bworld:stone_shovel", "texture": "bworld:stone_shovel", - "tool": "shovel" + "tool": { + "type": "shovel", + "tier": 1, + "speed": 3, + "durability": 131 + } } } diff --git a/mods/bworld/items/wood_axe.json b/mods/bworld/items/wood_axe.json index df8a067..d407feb 100644 --- a/mods/bworld/items/wood_axe.json +++ b/mods/bworld/items/wood_axe.json @@ -3,6 +3,11 @@ "item": { "id": "bworld:wood_axe", "texture": "bworld:wood_axe", - "tool": "axe" + "tool": { + "type": "axe", + "tier": 0, + "speed": 2, + "durability": 59 + } } } diff --git a/mods/bworld/items/wood_hoe.json b/mods/bworld/items/wood_hoe.json index 3ed47b5..3bb0a6b 100644 --- a/mods/bworld/items/wood_hoe.json +++ b/mods/bworld/items/wood_hoe.json @@ -3,6 +3,11 @@ "item": { "id": "bworld:wood_hoe", "texture": "bworld:wood_hoe", - "tool": "hoe" + "tool": { + "type": "hoe", + "tier": 0, + "speed": 2, + "durability": 59 + } } } diff --git a/mods/bworld/items/wood_pickaxe.json b/mods/bworld/items/wood_pickaxe.json index ebb6616..6122127 100644 --- a/mods/bworld/items/wood_pickaxe.json +++ b/mods/bworld/items/wood_pickaxe.json @@ -3,6 +3,11 @@ "item": { "id": "bworld:wood_pickaxe", "texture": "bworld:wood_pickaxe", - "tool": "pickaxe" + "tool": { + "type": "pickaxe", + "tier": 0, + "speed": 2, + "durability": 59 + } } } diff --git a/mods/bworld/items/wood_shovel.json b/mods/bworld/items/wood_shovel.json index 708c982..5b6b62f 100644 --- a/mods/bworld/items/wood_shovel.json +++ b/mods/bworld/items/wood_shovel.json @@ -3,6 +3,11 @@ "item": { "id": "bworld:wood_shovel", "texture": "bworld:wood_shovel", - "tool": "shovel" + "tool": { + "type": "shovel", + "tier": 0, + "speed": 2, + "durability": 59 + } } } diff --git a/mods/farmersdelight/items/copper_knife.json b/mods/farmersdelight/items/copper_knife.json index c2f7c3a..4766077 100644 --- a/mods/farmersdelight/items/copper_knife.json +++ b/mods/farmersdelight/items/copper_knife.json @@ -3,6 +3,11 @@ "item": { "id": "farmersdelight:copper_knife", "texture": "farmersdelight:copper_knife", - "tool": "knife" + "tool": { + "type": "knife", + "tier": 1, + "speed": 3.5, + "durability": 190 + } } } diff --git a/mods/farmersdelight/items/gold_knife.json b/mods/farmersdelight/items/gold_knife.json index d3c44cb..2e12c7c 100644 --- a/mods/farmersdelight/items/gold_knife.json +++ b/mods/farmersdelight/items/gold_knife.json @@ -3,6 +3,11 @@ "item": { "id": "farmersdelight:gold_knife", "texture": "farmersdelight:gold_knife", - "tool": "knife" + "tool": { + "type": "knife", + "tier": 0, + "speed": 6, + "durability": 32 + } } } diff --git a/mods/farmersdelight/items/iron_knife.json b/mods/farmersdelight/items/iron_knife.json index af7c627..9d874e7 100644 --- a/mods/farmersdelight/items/iron_knife.json +++ b/mods/farmersdelight/items/iron_knife.json @@ -3,6 +3,11 @@ "item": { "id": "farmersdelight:iron_knife", "texture": "farmersdelight:iron_knife", - "tool": "knife" + "tool": { + "type": "knife", + "tier": 2, + "speed": 4, + "durability": 250 + } } } diff --git a/mods/farmersdelight/items/stone_knife.json b/mods/farmersdelight/items/stone_knife.json index a09dffb..0e7ff48 100644 --- a/mods/farmersdelight/items/stone_knife.json +++ b/mods/farmersdelight/items/stone_knife.json @@ -3,6 +3,11 @@ "item": { "id": "farmersdelight:stone_knife", "texture": "farmersdelight:stone_knife", - "tool": "knife" + "tool": { + "type": "knife", + "tier": 1, + "speed": 3, + "durability": 131 + } } } diff --git a/mods/farmersdelight/items/wood_knife.json b/mods/farmersdelight/items/wood_knife.json index 57faa66..bc363b8 100644 --- a/mods/farmersdelight/items/wood_knife.json +++ b/mods/farmersdelight/items/wood_knife.json @@ -3,6 +3,11 @@ "item": { "id": "farmersdelight:wood_knife", "texture": "farmersdelight:wood_knife", - "tool": "knife" + "tool": { + "type": "knife", + "tier": 0, + "speed": 2, + "durability": 59 + } } } diff --git a/server/game/game_server.ts b/server/game/game_server.ts index 96e6d0c..7c15b5b 100644 --- a/server/game/game_server.ts +++ b/server/game/game_server.ts @@ -540,14 +540,16 @@ export class GameServer { } // breaks a block the way breaking it by hand does: its components' on_break, then what it drops. without the - // right tool (or without a player) blocks that need one drop nothing + // right tool of a high enough tier (or without a player) blocks that need one drop nothing destroy_block(x: number, y: number, z: number, player?: ServerPlayer) { const info = this.world.get_block_info(x, y, z); if (!info) { return; } const held = EverythingRegistry.get("items", player?.held_item?.type_id ?? ""); - const drops = info.drop_table && (!info.requires_tool || held?.tool_type === info.tool_to_break); + const tool = held?.tool; + const right_tool = tool !== undefined && tool.type === info.tool_to_break && tool.tier >= (info.tool_tier ?? 0); + const drops = info.drop_table && (!info.requires_tool || right_tool); this.set_block(x, y, z, AIR_ID, player); if (drops) { this.pop_item(x, y, z, new ItemStack(info.drop_table!)); diff --git a/server/game/mod_runtime.ts b/server/game/mod_runtime.ts index 566b392..015f075 100644 --- a/server/game/mod_runtime.ts +++ b/server/game/mod_runtime.ts @@ -490,12 +490,12 @@ export class ModRuntime { max_stack: (id) => { const item = EverythingRegistry.get("items", id); if (!item) throw new Error(`unknown item ${id}`); - return item.max_stack ?? 64; + return item.max_stack ?? (item.tool ? 1 : 64); }, tool: (id) => { const item = EverythingRegistry.get("items", id); if (!item) throw new Error(`unknown item ${id}`); - return item.tool_type; + return item.tool?.type; }, }, recipes: { diff --git a/tests/mod_loading_test.ts b/tests/mod_loading_test.ts index 53c2ab8..9cdd23b 100644 --- a/tests/mod_loading_test.ts +++ b/tests/mod_loading_test.ts @@ -234,7 +234,8 @@ Deno.test("every tier of pickaxe, axe, shovel and hoe exists and can be made", a for (const tool of ["pickaxe", "axe", "shovel", "hoe"]) { const id = `bworld:${tier}_${tool}`; const item = EverythingRegistry.get("items", id); - assertEquals(item?.tool_type, tool, id); + assertEquals(item?.tool?.type, tool, id); + assert(item!.tool!.durability > 0, id); assertEquals(item?.texture_id, id); assert(made.has(id), `nothing makes ${id}`); }