Add a bunch of crops and farmer's delight crops
This commit is contained in:
+1
-1
@@ -41,7 +41,7 @@ Deno.test("packing a mod keeps its data, scripts, textures and credits, and give
|
||||
assert(bmod.credits);
|
||||
|
||||
const bworld = read_bmod(Deno.readFileSync(`${folder}/bworld.bmod`), "bworld.bmod");
|
||||
assertEquals(bworld.data.blocks.length, 21);
|
||||
assertEquals(bworld.data.blocks.length, 23);
|
||||
assertEquals(Object.keys(bworld.scripts), ["server"]);
|
||||
|
||||
Deno.removeSync(sources, { recursive: true });
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
|
||||
@@ -29,7 +29,7 @@ Deno.test("welcome lists what to download, and nothing happens until ready", asy
|
||||
send(2, { type: "hello", name: "bob", protocol: PROTOCOL_VERSION });
|
||||
const [welcome] = take(2);
|
||||
assertEquals(welcome.type, "welcome");
|
||||
assertEquals(welcome.mods.map((m: { id: string }) => m.id), ["bworld"]);
|
||||
assertEquals(welcome.mods.map((m: { id: string }) => m.id), ["bworld", "farmersdelight"]);
|
||||
assert(welcome.mods.every((m: { sha256: string; file: string }) => m.sha256 && m.file));
|
||||
assert(!("players" in welcome) && !("changes" in welcome), "welcome shouldn't have world state");
|
||||
|
||||
|
||||
@@ -23,9 +23,10 @@ const inventory_of = (messages: Msg[]) =>
|
||||
|
||||
Deno.test("the base game loads from mods/bworld", async () => {
|
||||
const { game } = await test_game("mods");
|
||||
assertEquals(EverythingRegistry.entries("blocks").length, 21);
|
||||
const bworld = (entries: [string, unknown][]) => entries.filter(([id]) => id.startsWith("bworld:")).length;
|
||||
assertEquals(bworld(EverythingRegistry.entries("blocks")), 23);
|
||||
// 17 items plus the item forms of the 18 blocks that have one
|
||||
assertEquals(EverythingRegistry.entries("items").length, 35);
|
||||
assertEquals(bworld(EverythingRegistry.entries("items")), 35);
|
||||
assertEquals(game.recipes.shaped.length, 5);
|
||||
assertEquals(game.recipes.furnace.size, 6);
|
||||
assertEquals(game.recipes.fuel.size, 2);
|
||||
@@ -77,6 +78,8 @@ Deno.test("a mod made from the template loads and runs", async () => {
|
||||
send(1, { type: "select_slot", slot: inventory.findIndex((i: Msg) => i?.id === "copper_tools:example_block") });
|
||||
let y = CHUNK_HEIGHT - 1;
|
||||
while (game.world.get_block_nid(1, y, 1) === AIR) y--;
|
||||
// solid ground to build on: placing into water would replace it
|
||||
game.set_block(1, y, 1, "bworld:stone");
|
||||
send(1, { type: "move", x: 2.5, y: y + 1, z: 2.5, yaw: 0, pitch: 0 });
|
||||
send(1, { type: "use_block", x: 1, y, z: 1, face: "top" });
|
||||
assertEquals(game.world.get_block_id(1, y + 1, 1), "copper_tools:example_block");
|
||||
|
||||
Reference in New Issue
Block a user