Add tiers for watering cans
This commit is contained in:
@@ -39,7 +39,9 @@ The base game's tiers:
|
||||
|
||||
Tool types don't have to be the base game's. A mod can add a `"sickle"` type and blocks with `"tool": "sickle"`, and a
|
||||
server script can check a held item's type with `ctx.items.tool(id)`, like the base game's `bworld:hoeable` does for
|
||||
hoes.
|
||||
hoes. The base game's watering cans are tools of type `"watering_can"` that no block is mined with: they come in the
|
||||
same five tiers with the same durability, and each holds more water than the last (16, 24, 32, 48 and 64), set by its
|
||||
`bworld:watering_can` component.
|
||||
|
||||
## Durability
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"item": {
|
||||
"id": "bworld:watering_can",
|
||||
"texture": "bworld:watering_can",
|
||||
"components": {
|
||||
"bworld:watering_can": {
|
||||
"max_water": 32
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -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 |
@@ -159,18 +159,18 @@ Deno.test("the last bone meal is used up", async () => {
|
||||
});
|
||||
|
||||
Deno.test("a new watering can starts empty, and players are told so in its lore", async () => {
|
||||
const t = await setup([["bworld:watering_can", 1]]);
|
||||
const can = last_container(t.take(1), "inventory").find((i: Msg) => i?.id === "bworld:watering_can");
|
||||
const t = await setup([["bworld:copper_watering_can", 1]]);
|
||||
const can = last_container(t.take(1), "inventory").find((i: Msg) => i?.id === "bworld:copper_watering_can");
|
||||
assertEquals(can.data, { water: 0, max_water: 32 });
|
||||
assertEquals(can.lore, "Water: 0/32");
|
||||
|
||||
// lore is worked out for players, it isn't saved
|
||||
const saved = JSON.parse(t.game.save().level);
|
||||
const saved_can = saved.players.alice?.inventory?.find((i: Msg) => i?.id === "bworld:watering_can");
|
||||
const saved_can = saved.players.alice?.inventory?.find((i: Msg) => i?.id === "bworld:copper_watering_can");
|
||||
assert(!saved_can || saved_can.lore === undefined);
|
||||
t.game.on_disconnect(1);
|
||||
const after = JSON.parse(t.game.save().level).players.alice.inventory.find((i: Msg) =>
|
||||
i?.id === "bworld:watering_can"
|
||||
i?.id === "bworld:copper_watering_can"
|
||||
);
|
||||
assertEquals(after.lore, undefined);
|
||||
});
|
||||
|
||||
@@ -41,7 +41,7 @@ async function setup(items: string[] = []) {
|
||||
}
|
||||
|
||||
Deno.test("hoe, fill the can, plant, water, and the crop grows the next morning", async () => {
|
||||
const t = await setup(["bworld:wood_hoe", "bworld:watering_can", "bworld:wheat_seeds 4"]);
|
||||
const t = await setup(["bworld:wood_hoe", "bworld:copper_watering_can", "bworld:wheat_seeds 4"]);
|
||||
t.game.set_block(1, 100, 0, "bworld:grass");
|
||||
t.game.set_block(0, 100, 1, "bworld:grass");
|
||||
t.game.set_block(2, 100, 0, "bworld:water");
|
||||
@@ -58,7 +58,7 @@ Deno.test("hoe, fill the can, plant, water, and the crop grows the next morning"
|
||||
assertEquals(t.game.world.get_block_id(1, 101, 0), "bworld:wheat");
|
||||
|
||||
// a new can is empty, water fills it, and watering the crop waters the farmland under it
|
||||
t.hold("bworld:watering_can");
|
||||
t.hold("bworld:copper_watering_can");
|
||||
t.take(1);
|
||||
t.use(1, 101, 0);
|
||||
assert(t.take(1).some((m) => m.type === "chat" && m.text.includes("empty")));
|
||||
@@ -66,7 +66,7 @@ Deno.test("hoe, fill the can, plant, water, and the crop grows the next morning"
|
||||
t.use(2, 100, 0);
|
||||
t.use(1, 101, 0);
|
||||
assertEquals(t.state(1, 100, 0, "watered"), 1);
|
||||
const can = t.inventory_now().find((i) => i?.id === "bworld:watering_can");
|
||||
const can = t.inventory_now().find((i) => i?.id === "bworld:copper_watering_can");
|
||||
assertEquals(can?.data, { water: 31, max_water: 32 });
|
||||
|
||||
// nothing happens during the day
|
||||
|
||||
@@ -27,17 +27,17 @@ Deno.test("the base game loads from mods/bworld", async () => {
|
||||
const bworld = (entries: [string, unknown][]) => entries.filter(([id]) => id.startsWith("bworld:")).length;
|
||||
// 7 kinds of log, planks and leaves
|
||||
assertEquals(bworld(EverythingRegistry.entries("blocks")), 42);
|
||||
// 38 items (20 of them tools) plus the item forms of the 37 blocks that have one
|
||||
assertEquals(bworld(EverythingRegistry.entries("items")), 75);
|
||||
// bworld's 16 (4 wood tools, 7 planks, the fishing rod), the cooking pot, stove, cutting board and wood knife are
|
||||
// farmersdelight's
|
||||
assertEquals(game.recipes.shaped.length, 20);
|
||||
// every log and fish smelts, every log burns
|
||||
assertEquals(game.recipes.furnace.size, 14);
|
||||
// 42 items (25 of them tools) plus the item forms of the 37 blocks that have one
|
||||
assertEquals(bworld(EverythingRegistry.entries("items")), 79);
|
||||
// bworld's 18 (4 wood tools, the wood watering can, 7 planks, the fishing rod, the smithing table), the cooking pot,
|
||||
// stove, cutting board and wood knife are farmersdelight's
|
||||
assertEquals(game.recipes.shaped.length, 22);
|
||||
// every log and fish smelts, every log burns, and so do sand into glass and cobblestone into stone
|
||||
assertEquals(game.recipes.furnace.size, 16);
|
||||
assertEquals(game.recipes.fuel.size, 8);
|
||||
assertEquals(EverythingRegistry.get<BlockRegistry>("blocks", "bworld:water")?.replaceable, true);
|
||||
// still has its code until it's a component
|
||||
assert(EverythingRegistry.get<ItemRegistry>("items", "bworld:watering_can")?.on_create);
|
||||
assert(EverythingRegistry.get<ItemRegistry>("items", "bworld:copper_watering_can")?.on_create);
|
||||
});
|
||||
|
||||
Deno.test("mods/bworld json survives going to the registry and back", async () => {
|
||||
@@ -242,6 +242,25 @@ Deno.test("every tier of pickaxe, axe, shovel and hoe exists and can be made", a
|
||||
}
|
||||
});
|
||||
|
||||
Deno.test("every tier of watering can exists, can be made and holds more than the last", async () => {
|
||||
const { game } = await test_game("mods");
|
||||
const made = new Set([
|
||||
...game.recipes.shaped.map((recipe) => recipe.result.id),
|
||||
...game.recipes.smithing.map((recipe) => recipe.result),
|
||||
]);
|
||||
let last = 0;
|
||||
for (const tier of ["wood", "stone", "copper", "iron", "gold"]) {
|
||||
const id = `bworld:${tier}_watering_can`;
|
||||
const item = EverythingRegistry.get<ItemRegistry>("items", id);
|
||||
assertEquals(item?.tool?.type, "watering_can", id);
|
||||
assertEquals(item?.texture_id, id);
|
||||
assert(made.has(id), `nothing makes ${id}`);
|
||||
const max_water = (item?.components?.["bworld:watering_can"] as { max_water: number }).max_water;
|
||||
assert(max_water > last, id);
|
||||
last = max_water;
|
||||
}
|
||||
});
|
||||
|
||||
Deno.test("a lit furnace shows its lit front", async () => {
|
||||
await test_game("mods");
|
||||
const furnace = EverythingRegistry.get<BlockRegistry>("blocks", "bworld:furnace")!;
|
||||
|
||||
Reference in New Issue
Block a user