Add a bunch of crops and farmer's delight crops

This commit is contained in:
2026-09-26 21:35:17 -03:00
parent 8d9c85d379
commit 7e5bcaa239
77 changed files with 980 additions and 81 deletions
+99
View File
@@ -141,3 +141,102 @@ Deno.test("crops grow far from every player, and mornings skipped by /time still
// the world's day is the same one scripts see
assertEquals(t.game.world.day, 4);
});
// plants a crop on farmland at x, 100, 0 and waters it every day for days mornings, returning its age each morning
function grow(t: Awaited<ReturnType<typeof setup>>, x: number, crop: string, days: number) {
t.game.set_block(x, 100, 0, "bworld:hoed_dirt");
t.game.set_block(x, 101, 0, crop);
const ages: number[] = [];
for (let day = 0; day < days; day++) {
t.game.set_block_state(x, 100, 0, 1);
t.next_morning();
ages.push(t.state(x, 101, 0, "age")!);
}
return ages;
}
Deno.test("each crop takes its own number of watered days to grow", async () => {
const t = await setup();
// the stage for each morning, spread over its days, fully grown on the last one
assertEquals(grow(t, 0, "bworld:carrots", 3), [1, 2, 3]);
assertEquals(grow(t, 1, "bworld:potatoes", 6), [0, 1, 1, 2, 2, 3]);
assertEquals(grow(t, 2, "bworld:wheat", 7), [1, 2, 3, 4, 5, 6, 7]);
assertEquals(grow(t, -1, "farmersdelight:onions", 4), [0, 1, 2, 3]);
const cabbage = grow(t, -2, "farmersdelight:cabbages", 12);
assertEquals(cabbage.at(-2), 6, "not grown a day early");
assertEquals(cabbage.at(-1), 7);
// grown crops stay grown
t.game.set_block_state(0, 100, 0, 1);
t.next_morning();
assertEquals(t.state(0, 101, 0, "age"), 3);
});
Deno.test("potatoes and carrots are planted on farmland, and eaten anywhere else", async () => {
const t = await setup(["bworld:potato 3"]);
t.game.set_block(1, 100, 0, "bworld:hoed_dirt");
t.game.players()[0].vitals.food = 10;
t.hold("bworld:potato");
t.use(1, 100, 0);
assertEquals(t.game.world.get_block_id(1, 101, 0), "bworld:potatoes");
assertEquals(t.game.players()[0].vitals.food, 10, "planted, not eaten");
// on stone it can't be planted, so it's eaten
t.use(0, 99, 1);
assertEquals(t.game.world.get_block_id(0, 100, 1), "bworld:air");
assertEquals(t.game.players()[0].vitals.food, 11);
});
Deno.test("tomatoes take 11 days, are picked by hand, and grow back in 4", async () => {
const t = await setup();
const ages = grow(t, 1, "farmersdelight:tomatoes", 11);
assertEquals(ages.at(-1), 7);
assertEquals(ages.at(-2), 6);
t.use(1, 101, 0);
const picked = t.game.item_entities().map((e) => e.item.to_data());
assertEquals(picked.length, 1);
assertEquals(picked[0].id, "farmersdelight:tomato");
assert(picked[0].count >= 1 && picked[0].count <= 2);
assertEquals(t.game.world.get_block_id(1, 101, 0), "farmersdelight:tomatoes", "the plant stays");
assertEquals(t.state(1, 101, 0, "age"), 4, "back to a young vine");
// 3 watered mornings isn't enough, the 4th is
for (let day = 0; day < 4; day++) {
t.game.set_block_state(1, 100, 0, 1);
t.next_morning();
assertEquals(t.state(1, 101, 0, "age"), day < 3 ? Math.floor((7 + day + 1) * 7 / 11) : 7);
}
});
Deno.test("rice is planted in water, grows panicles on top without watering, and leaves its water when harvested", async () => {
const t = await setup(["farmersdelight:rice 2"]);
t.game.set_block(1, 99, 0, "bworld:dirt");
t.game.set_block(1, 100, 0, "bworld:water");
t.game.set_block(2, 100, 0, "bworld:hoed_dirt");
// not on land
t.hold("farmersdelight:rice");
t.use(2, 100, 0);
assertEquals(t.game.world.get_block_id(2, 101, 0), "bworld:air");
// into the water, standing on the dirt under it
t.use(1, 100, 0);
assertEquals(t.game.world.get_block_id(1, 100, 0), "farmersdelight:rice");
for (let day = 0; day < 3; day++) t.next_morning();
assertEquals(t.state(1, 100, 0, "age"), 3);
assertEquals(t.game.world.get_block_id(1, 101, 0), "bworld:air");
for (let day = 0; day < 3; day++) t.next_morning();
assertEquals(t.game.world.get_block_id(1, 101, 0), "farmersdelight:rice_panicles");
assertEquals(t.state(1, 101, 0, "age"), 3, "fully grown after 6 days");
assertEquals(t.state(1, 100, 0, "age"), 4, "the stalk holding them up");
// breaking the panicles harvests the whole plant
t.send(1, { type: "break_block", x: 1, y: 101, z: 0 });
// the stalk goes the next tick, and its water comes back the one after
t.game.tick();
t.game.tick();
const dropped = t.game.item_entities().map((e) => e.item.type_id).sort();
assertEquals(dropped, ["farmersdelight:rice", "farmersdelight:rice_panicle"]);
assertEquals(t.game.world.get_block_id(1, 100, 0), "bworld:water");
assertEquals(t.game.world.get_block_id(1, 101, 0), "bworld:air");
});