Improve a buuuunch of textures and some reworks

This commit is contained in:
2026-09-27 18:05:20 -03:00
parent 9f47c709f1
commit b7ded817d9
186 changed files with 1486 additions and 124 deletions
+2 -2
View File
@@ -37,10 +37,10 @@ function move_to_screen(t: Game, from: number, to: number) {
}
Deno.test("a hoe turns grass and dirt into hoed dirt, anything else places nothing", async () => {
const t = await setup([["bworld:hoe", 1]]);
const t = await setup([["bworld:wood_hoe", 1]]);
t.game.set_block(1, 100, 0, "bworld:grass");
t.game.set_block(2, 100, 0, "bworld:dirt");
t.send(1, { type: "select_slot", slot: slot_of(t.take(1), "bworld:hoe") });
t.send(1, { type: "select_slot", slot: slot_of(t.take(1), "bworld:wood_hoe") });
t.send(1, { type: "use_block", x: 1, y: 100, z: 0, face: "top" });
t.send(1, { type: "use_block", x: 2, y: 100, z: 0, face: "top" });
+1 -1
View File
@@ -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, 23);
assertEquals(bworld.data.blocks.length, 41);
assertEquals(Object.keys(bworld.scripts), ["server"]);
Deno.removeSync(sources, { recursive: true });
+2 -2
View File
@@ -41,12 +41,12 @@ 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:hoe", "bworld:watering_can", "bworld:wheat_seeds 4"]);
const t = await setup(["bworld:wood_hoe", "bworld: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");
t.hold("bworld:hoe");
t.hold("bworld:wood_hoe");
t.use(1, 100, 0);
assertEquals(t.game.world.get_block_id(1, 100, 0), "bworld:hoed_dirt");
+26 -7
View File
@@ -24,13 +24,15 @@ const inventory_of = (messages: Msg[]) =>
Deno.test("the base game loads from mods/bworld", async () => {
const { game } = await test_game("mods");
const bworld = (entries: [string, unknown][]) => entries.filter(([id]) => id.startsWith("bworld:")).length;
assertEquals(bworld(EverythingRegistry.entries("blocks")), 23);
// 18 items plus the item forms of the 18 blocks that have one
assertEquals(bworld(EverythingRegistry.entries("items")), 36);
// the bowl is bworld's 6th, the cooking pot and stove are farmersdelight's
assertEquals(game.recipes.shaped.length, 8);
assertEquals(game.recipes.furnace.size, 6);
assertEquals(game.recipes.fuel.size, 2);
// 7 kinds of log, planks and leaves
assertEquals(bworld(EverythingRegistry.entries("blocks")), 41);
// 33 items (20 of them tools) plus the item forms of the 36 blocks that have one
assertEquals(bworld(EverythingRegistry.entries("items")), 69);
// bworld's 15 (4 wood tools, 7 planks), the cooking pot and stove are farmersdelight's
assertEquals(game.recipes.shaped.length, 17);
// every log smelts and burns
assertEquals(game.recipes.furnace.size, 12);
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);
@@ -219,3 +221,20 @@ Deno.test("broken mods stop the game from starting", async () => {
assert(error.includes("uses component copper_tools:announce, which nothing registered"), error);
Deno.removeSync(dir, { recursive: true });
});
Deno.test("every tier of pickaxe, axe, shovel and hoe exists and can be made", 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),
]);
for (const tier of ["wood", "stone", "copper", "iron", "golden"]) {
for (const tool of ["pickaxe", "axe", "shovel", "hoe"]) {
const id = `bworld:${tier}_${tool}`;
const item = EverythingRegistry.get<ItemRegistry>("items", id);
assertEquals(item?.tool_type, tool, id);
assertEquals(item?.texture_id, id);
assert(made.has(id), `nothing makes ${id}`);
}
}
});
+9 -1
View File
@@ -76,7 +76,15 @@ async function mesh_chunks(radius: number) {
for (let dx = -1; dx <= 1; dx++) chunks.push(generated.get(`${x + dx},${z + dz}`)!.slice());
}
meshes.push(
await ask({ type: "mesh", chunk_x: x, chunk_z: z, version: 1, chunks, camera: [0, 0, 0] }, "meshed"),
await ask({
type: "mesh",
chunk_x: x,
chunk_z: z,
version: 1,
chunks,
biome_colors: chunks.map(() => null),
camera: [0, 0, 0],
}, "meshed"),
);
}
}
+120
View File
@@ -0,0 +1,120 @@
// blocks with a "tint" are drawn in their biome's grass or foliage color, blended across biome edges, or a fixed one
import { assert, assertEquals } from "@std/assert";
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
import { CHUNK_AREA, CHUNK_HEIGHT, CHUNK_SIZE } from "$/common/constants.ts";
import { generate_raw_chunk } from "$/common/generation.ts";
import { BIOME_FOLIAGE_COLORS, BIOME_GRASS_COLORS } from "$/common/worldgen/biome_colors.ts";
import { type LayerMesh, TERRAIN_VERTEX_BYTES } from "$/client/workers/chunk_messages.ts";
import { test_game } from "./helpers.ts";
type Colors = { grass: number; foliage: number };
// one block at x, 10, 8 of the middle chunk, meshed with these biome colors for the middle chunk and the one to its
// -x side (the others aren't there). returns the colors of the quads on its top and on its sides
async function mesh_block(id: string, x: number, middle: Colors, west: Colors | null) {
await test_game("mods");
const blocks = EverythingRegistry.get_registry<BlockRegistry>("blocks");
const block_ids: Record<string, number> = {};
blocks.forEach((b, nid) => block_ids[b.id] = nid);
const worker = new Worker(new URL("../client/workers/chunk_worker.ts", import.meta.url).href, { type: "module" });
worker.postMessage({
type: "init",
blocks_registry: JSON.parse(JSON.stringify(blocks)),
block_ids,
models: {},
textures_info: { "engine:missing": { x: 0, y: 0 } },
image: { width: 1024, height: 1024 },
worldgen_scripts: [],
ores: [],
});
const chunk = new Uint32Array(CHUNK_AREA * CHUNK_HEIGHT);
chunk[10 * CHUNK_AREA + 8 * CHUNK_SIZE + x] = block_ids[id];
const empty = () => new Uint32Array(CHUNK_AREA * CHUNK_HEIGHT);
const chunks = [empty(), empty(), empty(), empty(), chunk, empty(), empty(), empty(), empty()];
const colors = chunks.map(() => null as Uint32Array | null);
const biome_colors = ({ grass, foliage }: Colors) => {
const array = new Uint32Array(CHUNK_AREA * 2);
array.fill(grass, 0, CHUNK_AREA);
array.fill(foliage, CHUNK_AREA);
return array;
};
colors[4] = biome_colors(middle);
if (west) colors[3] = biome_colors(west);
const meshed = await new Promise<{ solid: LayerMesh; cutout: LayerMesh }>((resolve) => {
worker.onmessage = (e) => resolve(e.data);
worker.postMessage({
type: "mesh",
chunk_x: 0,
chunk_z: 0,
version: 1,
chunks,
biome_colors: colors,
camera: [0, 0, 0],
});
});
worker.terminate();
const top: number[][] = [];
const sides: number[][] = [];
for (const mesh of [meshed.solid, meshed.cutout]) {
const f32 = new Float32Array(mesh.vertices.buffer);
for (let quad = 0; quad < mesh.quad_count; quad++) {
const byte = quad * 4 * TERRAIN_VERTEX_BYTES;
const ys = [0, 1, 2, 3].map((k) => f32[(byte + k * TERRAIN_VERTEX_BYTES) / 4 + 1]);
const rgb = [...mesh.vertices.subarray(byte + 16, byte + 19)];
if (ys.every((y) => y === 11)) top.push(rgb);
else if (!ys.every((y) => y === 10)) sides.push(rgb);
}
}
return { top, sides };
}
// the vertex color of an unlit face: the color times the face's directional shade, 1 on top and 0.8 north and south
const shaded = (color: number, shade: number) =>
[color >> 16, (color >> 8) & 0xff, color & 0xff].map((c) => Math.round(shade * c));
Deno.test("the grass block's top is its biome's grass color, and only the top", async () => {
const { top, sides } = await mesh_block("bworld:grass", 8, { grass: 0xff8000, foliage: 0x0000ff }, null);
assertEquals(top, [[255, 128, 0]]);
assertEquals(sides.length, 4);
for (const [r, g, b] of sides) assert(r === g && g === b, "sides aren't tinted");
});
Deno.test("biome colors blend over the 5x5 columns around, across chunk edges", async () => {
// at x 0 the two columns to its -x are in the other chunk: 10 of the 25 are blue, 15 red
const { top } = await mesh_block("bworld:grass", 0, { grass: 0xff0000, foliage: 0 }, {
grass: 0x0000ff,
foliage: 0,
});
assertEquals(top, [[153, 0, 102]]);
});
Deno.test("oak leaves are the biome's foliage color on every side, birch a fixed green, spruce isn't tinted", async () => {
const colors = { grass: 0xff0000, foliage: 0x00ff80 };
const oak = await mesh_block("bworld:leaves", 8, colors, null);
assertEquals(oak.top, [[0, 255, 128]]);
assert(oak.sides.some((rgb) => JSON.stringify(rgb) === JSON.stringify(shaded(0x00ff80, 0.8))));
const birch = await mesh_block("bworld:birch_leaves", 8, colors, null);
assertEquals(birch.top, [shaded(0x80a755, 1)]);
const spruce = await mesh_block("bworld:spruce_leaves", 8, colors, null);
assertEquals(spruce.top, [[255, 255, 255]]);
});
Deno.test("every column the overworld generates has a biome with grass and foliage colors", async () => {
const { game } = await test_game("mods");
const blocks = EverythingRegistry.get_registry<BlockRegistry>("blocks");
const block_ids: Record<string, number> = {};
blocks.forEach((b, nid) => block_ids[b.id] = nid);
for (const [x, z] of [[0, 0], [30, -12], [-80, 45]]) {
const { biomes } = generate_raw_chunk(x, z, game.world.seed, block_ids);
assertEquals(biomes.length, CHUNK_AREA);
for (const biome of biomes) {
assert(biome in BIOME_GRASS_COLORS, `${biome} has no grass color`);
assert(biome in BIOME_FOLIAGE_COLORS, `${biome} has no foliage color`);
}
}
});
+78
View File
@@ -0,0 +1,78 @@
import { assert, assertEquals } from "@std/assert";
import { CHUNK_AREA, CHUNK_SIZE } from "$/common/constants.ts";
import { Container, ItemStack } from "$/common/inventory.ts";
import { CRAFTING_RESULT_SLOT } from "$/common/protocol.ts";
import { generate_raw_chunk } from "$/common/generation.ts";
import { BIOME_TREES, tree_wood } from "$/common/worldgen/trees.ts";
import { update_crafting_result } from "$/server/game/crafting.ts";
import { test_game } from "./helpers.ts";
Deno.test("recipes that take planks take any kind, even mixed, but nothing else", async () => {
const { game } = await test_game("mods");
const craft = (top: string, bottom: string) => {
const grid = new Container(10);
grid.set_item(0, new ItemStack(top, 1));
grid.set_item(3, new ItemStack(bottom, 1));
update_crafting_result(grid, game.recipes.shaped);
return grid.get_item(CRAFTING_RESULT_SLOT);
};
assertEquals(craft("bworld:planks", "bworld:planks")?.type_id, "bworld:stick");
assertEquals(craft("bworld:birch_planks", "bworld:cherry_planks")?.type_id, "bworld:stick");
assertEquals(craft("bworld:birch_planks", "bworld:stone"), undefined);
// and each log makes its own planks
const grid = new Container(10);
grid.set_item(4, new ItemStack("bworld:dark_oak_log", 1));
update_crafting_result(grid, game.recipes.shaped);
assertEquals(grid.get_item(CRAFTING_RESULT_SLOT)?.type_id, "bworld:dark_oak_planks");
// every log burns and smelts
for (const log of ["bworld:log", "bworld:spruce_log", "bworld:cherry_log"]) {
assert(game.recipes.fuel.has(log), log);
assert(game.recipes.furnace.has(log), log);
}
});
Deno.test("trees grow the wood of their kind and biome", async () => {
const { game } = await test_game("mods");
const ids = game.world.block_ids;
const woods: Record<string, string> = {
"bworld:log": "oak",
"bworld:spruce_log": "spruce",
"bworld:birch_log": "birch",
"bworld:jungle_log": "jungle",
"bworld:acacia_log": "acacia",
"bworld:dark_oak_log": "dark_oak",
};
const wood_of = new Map(Object.entries(woods).map(([id, wood]) => [ids[id], wood]));
const ground = new Set([ids["bworld:grass"], ids["bworld:dirt"], ids["bworld:snow"]]);
const leaves_of = new Map(
Object.entries(woods).map(([id, wood]) => [ids[id.replace("log", "leaves")], wood]),
);
const found = new Set<string>();
const found_leaves = new Set<string>();
for (let cx = -8; cx < 8; cx++) {
for (let cz = -8; cz < 8; cz++) {
const { blocks, biomes } = generate_raw_chunk(cx, cz, "wood-test", ids);
blocks.forEach((block, i) => {
const leaves = leaves_of.get(block);
if (leaves) found_leaves.add(leaves);
const wood = wood_of.get(block);
// the bottom of a trunk
if (!wood || !ground.has(blocks[i - CHUNK_AREA])) return;
const column = i % CHUNK_AREA;
const biome = biomes[column];
const allowed = BIOME_TREES[biome].kinds.map((kind) => tree_wood(kind, biome));
assert(
allowed.includes(wood as never),
`${wood} in ${biome} at ${cx * CHUNK_SIZE}, ${cz * CHUNK_SIZE}`,
);
found.add(wood);
});
}
}
assert(found.size >= 3, `only found ${[...found]}`);
// each tree's leaves are its own wood's
assertEquals([...found_leaves].sort(), [...found].sort());
});
+8 -3
View File
@@ -42,7 +42,12 @@ Deno.test("new players spawn on dry land, all in the same place", async () => {
Deno.test("trees grow on the ground, never closer than 4 blocks, even across chunk borders", async () => {
const { game } = await test_game("mods");
const ids = game.world.block_ids;
const log = ids["bworld:log"];
const id_names = Object.fromEntries(Object.entries(ids).map(([name, id]) => [id, name]));
const logs = new Set(
["log", "spruce_log", "birch_log", "jungle_log", "acacia_log", "dark_oak_log", "cherry_log"].map((name) =>
ids[`bworld:${name}`]
),
);
const ground = new Set([ids["bworld:grass"], ids["bworld:dirt"], ids["bworld:snow"]]);
// the bottom log of every trunk, in world coordinates
@@ -52,14 +57,14 @@ Deno.test("trees grow on the ground, never closer than 4 blocks, even across chu
for (let cz = -6; cz < 6; cz++) {
const { blocks, spills } = generate_raw_chunk(cx, cz, "trees-test", ids);
blocks.forEach((block, i) => {
if (block === log && ground.has(blocks[i - CHUNK_AREA])) {
if (logs.has(block) && ground.has(blocks[i - CHUNK_AREA])) {
const x = cx * 16 + (i % 16);
const z = cz * 16 + Math.floor(i / 16) % 16;
trunks.push([x, z]);
}
});
for (let i = 3; i < spills.length; i += 4) {
if (spills[i] === ids["bworld:leaves"]) spilled_leaves++;
if (id_names[spills[i]]?.endsWith("leaves")) spilled_leaves++;
}
}
}