Add tiers for watering cans

This commit is contained in:
2026-09-30 00:11:04 -03:00
parent d8d1ee4698
commit 69900f7007
22 changed files with 219 additions and 37 deletions
@@ -0,0 +1,18 @@
{
"format_version": 1,
"item": {
"id": "bworld:copper_watering_can",
"texture": "bworld:copper_watering_can",
"tool": {
"type": "watering_can",
"tier": 1,
"speed": 3.5,
"durability": 5
},
"components": {
"bworld:watering_can": {
"max_water": 32
}
}
}
}
+18
View File
@@ -0,0 +1,18 @@
{
"format_version": 1,
"item": {
"id": "bworld:gold_watering_can",
"texture": "bworld:gold_watering_can",
"tool": {
"type": "watering_can",
"tier": 0,
"speed": 6,
"durability": 9
},
"components": {
"bworld:watering_can": {
"max_water": 64
}
}
}
}
+18
View File
@@ -0,0 +1,18 @@
{
"format_version": 1,
"item": {
"id": "bworld:iron_watering_can",
"texture": "bworld:iron_watering_can",
"tool": {
"type": "watering_can",
"tier": 2,
"speed": 4,
"durability": 7
},
"components": {
"bworld:watering_can": {
"max_water": 48
}
}
}
}
+18
View File
@@ -0,0 +1,18 @@
{
"format_version": 1,
"item": {
"id": "bworld:stone_watering_can",
"texture": "bworld:stone_watering_can",
"tool": {
"type": "watering_can",
"tier": 1,
"speed": 3,
"durability": 3
},
"components": {
"bworld:watering_can": {
"max_water": 24
}
}
}
}
-12
View File
@@ -1,12 +0,0 @@
{
"format_version": 1,
"item": {
"id": "bworld:watering_can",
"texture": "bworld:watering_can",
"components": {
"bworld:watering_can": {
"max_water": 32
}
}
}
}
+18
View File
@@ -0,0 +1,18 @@
{
"format_version": 1,
"item": {
"id": "bworld:wood_watering_can",
"texture": "bworld:wood_watering_can",
"tool": {
"type": "watering_can",
"tier": 0,
"speed": 2,
"durability": 2
},
"components": {
"bworld:watering_can": {
"max_water": 16
}
}
}
}
@@ -0,0 +1,27 @@
{
"format_version": 1,
"recipe": {
"type": "shaped",
"pattern": [
"S ",
" PP",
" PP"
],
"key": {
"P": [
"bworld:planks",
"bworld:spruce_planks",
"bworld:birch_planks",
"bworld:jungle_planks",
"bworld:acacia_planks",
"bworld:dark_oak_planks",
"bworld:cherry_planks"
],
"S": "bworld:stick"
},
"result": {
"id": "bworld:wood_watering_can",
"count": 1
}
}
}
@@ -0,0 +1,12 @@
{
"format_version": 1,
"recipe": {
"type": "smithing",
"tool": "bworld:stone_watering_can",
"material": {
"id": "bworld:copper_ingot",
"count": 5
},
"result": "bworld:copper_watering_can"
}
}
@@ -0,0 +1,12 @@
{
"format_version": 1,
"recipe": {
"type": "smithing",
"tool": "bworld:iron_watering_can",
"material": {
"id": "bworld:gold_ingot",
"count": 5
},
"result": "bworld:gold_watering_can"
}
}
@@ -0,0 +1,12 @@
{
"format_version": 1,
"recipe": {
"type": "smithing",
"tool": "bworld:copper_watering_can",
"material": {
"id": "bworld:iron_ingot",
"count": 5
},
"result": "bworld:iron_watering_can"
}
}
@@ -0,0 +1,12 @@
{
"format_version": 1,
"recipe": {
"type": "smithing",
"tool": "bworld:wood_watering_can",
"material": {
"id": "bworld:stone",
"count": 5
},
"result": "bworld:stone_watering_can"
}
}
+17 -9
View File
@@ -284,7 +284,8 @@ function register_smithing_table(ctx: ServerContext) {
// it's dug up
const FARMLAND = "bworld:hoed_dirt";
const WATERING_CAN = "bworld:watering_can";
// every tier of watering can is a tool of this type, and shares the bworld:watering_can component
const WATERING_CAN = "watering_can";
interface WateringCanData {
water: number;
@@ -332,13 +333,18 @@ interface CropTopParams {
}
function register_farming(ctx: ServerContext) {
const is_can = (id: string | undefined) => id !== undefined && ctx.items.tool(id) === WATERING_CAN;
// how much water each tier holds, from its component. every stack goes through on_create, so every can's tier is
// in here before anything reads it
const capacity = new Map<string, number>();
const is_watered = (x: number, y: number, z: number) =>
ctx.world.get_block(x, y, z) === FARMLAND && ctx.world.get_state(x, y, z, "watered") === 1;
// with the watering can the player holds. true when the click was about watering, so nothing gets placed
const water = (x: number, y: number, z: number, player: Player) => {
const can = player.held_item;
if (can?.id !== WATERING_CAN || ctx.world.get_block(x, y, z) !== FARMLAND) {
if (!can || !is_can(can.id) || ctx.world.get_block(x, y, z) !== FARMLAND) {
return false;
}
const data = can.data as WateringCanData;
@@ -438,7 +444,7 @@ function register_farming(ctx: ServerContext) {
on_interact(block, params, player) {
const held = player.held_item;
// watering a crop waters the farmland under it
if (held?.id === WATERING_CAN) {
if (is_can(held?.id)) {
block.data ??= { days: days_of(block, params) };
return water(block.x, block.y - 1, block.z, player);
}
@@ -490,20 +496,22 @@ function register_farming(ctx: ServerContext) {
ctx.components.register_block("bworld:water_source", {
on_interact(_block, _params, player) {
const can = player.held_item;
if (can?.id !== WATERING_CAN) return false;
const data = can.data as WateringCanData;
can.data = { ...data, water: data.max_water };
if (!can || !is_can(can.id)) return false;
// an upgraded can still has its old tier's max_water in its data, so this goes by its own
const max_water = capacity.get(can.id) ?? (can.data as WateringCanData).max_water;
can.data = { water: max_water, max_water } satisfies WateringCanData;
return true;
},
});
ctx.components.register_item<{ max_water: number }>(WATERING_CAN, {
ctx.components.register_item<{ max_water: number }>("bworld:watering_can", {
on_create(item, params) {
capacity.set(item.id, params.max_water);
item.data = { water: 0, max_water: params.max_water } satisfies WateringCanData;
},
get_lore(item) {
get_lore(item, params) {
const data = item.data as WateringCanData;
return `Water: ${data.water}/${data.max_water}`;
return `Water: ${data.water}/${params.max_water}`;
},
});
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 232 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B