Basic crops system

This commit is contained in:
2026-09-25 22:49:27 -03:00
parent ef25e66f08
commit 099811670f
22 changed files with 985 additions and 178 deletions
+35 -3
View File
@@ -3,6 +3,7 @@ import { AIR, CHUNK_HEIGHT } from "$/common/constants.ts";
import { BlockRegistry, EverythingRegistry, ItemRegistry } from "$/common/everything_registry.ts";
import { block_from_json, block_to_json, item_from_json, item_to_json } from "$/common/mod_data.ts";
import { generate_raw_chunk } from "$/common/generation.ts";
import { get_state_value } from "$/common/utils.ts";
import { load_worldgen } from "$/common/worldgen_loader.ts";
import { create_mod } from "$/tools/new_mod.ts";
import { PROTOCOL_VERSION } from "$/common/protocol.ts";
@@ -23,9 +24,9 @@ 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, 19);
// 11 items plus the item forms of the 16 blocks that have one
assertEquals(EverythingRegistry.entries("items").length, 27);
assertEquals(EverythingRegistry.entries("blocks").length, 20);
// 14 items plus the item forms of the 17 blocks that have one
assertEquals(EverythingRegistry.entries("items").length, 31);
assertEquals(game.recipes.shaped.length, 5);
assertEquals(game.recipes.furnace.size, 6);
assertEquals(game.recipes.fuel.size, 2);
@@ -34,6 +35,37 @@ Deno.test("the base game loads from mods/bworld", async () => {
assert(EverythingRegistry.get<ItemRegistry>("items", "bworld:watering_can")?.on_create);
});
Deno.test("bone meal grows wheat until it's fully grown", async () => {
const { game, take, send } = await test_game("mods");
game.on_connect(1);
send(1, { type: "hello", name: "alice", protocol: PROTOCOL_VERSION });
send(1, { type: "ready" });
let y = CHUNK_HEIGHT - 1;
while (game.world.get_block_nid(1, y, 1) === AIR) y--;
y += 1;
game.set_block(1, y, 1, "bworld:wheat");
const wheat = EverythingRegistry.get<BlockRegistry>("blocks", "bworld:wheat")!;
const age = () => get_state_value(game.world.get_block_value(1, y, 1), wheat, "age")!;
assertEquals(age(), 0);
send(1, { type: "chat", text: "/give bworld:bone_meal 8" });
const slot = inventory_of(take(1)).findIndex((i: Msg) => i?.id === "bworld:bone_meal");
send(1, { type: "select_slot", slot });
send(1, { type: "move", x: 2.5, y, z: 2.5, yaw: 0, pitch: 0 });
// 2 to 5 stages at a time
send(1, { type: "use_block", x: 1, y, z: 1, face: "top" });
assert(age() >= 2 && age() <= 5, `age ${age()}`);
// at most 3 more uses to reach 7, then it stops using bone meal
for (let i = 0; i < 5; i++) send(1, { type: "use_block", x: 1, y, z: 1, face: "top" });
assertEquals(age(), 7);
const left = inventory_of(take(1))[slot]?.count;
assert(left >= 4 && left <= 6, `${left} bone meal left`);
// nothing got placed on top
assertEquals(game.world.get_block_id(1, y + 1, 1), "bworld:air");
});
Deno.test("mods/bworld json survives going to the registry and back", async () => {
await test_game("mods");
for (const file of Deno.readDirSync("mods/bworld/blocks")) {