Curios slots rendering !

This commit is contained in:
2026-10-01 17:57:22 -03:00
parent ea9f3f61bb
commit f2c3cb8135
39 changed files with 1032 additions and 226 deletions
+57
View File
@@ -2,6 +2,7 @@ import { assert, assertEquals, assertThrows } from "@std/assert";
import { check_mods } from "$/tools/check_mods.ts";
import { MAX_TEXTURE_SIZE } from "$/common/constants.ts";
import { create_mod } from "$/tools/new_mod.ts";
import { item_from_json, item_to_json } from "$/common/mod_data.ts";
function temp_mods_dir() {
const dir = Deno.makeTempDirSync({ prefix: "bworld_mods_" });
@@ -26,6 +27,21 @@ function write_json(path: string, value: unknown) {
Deno.writeTextFileSync(path, JSON.stringify(value));
}
// a blockbench model with one bone, a box like an arm's
function geo(bone: string) {
return {
format_version: "1.12.0",
"minecraft:geometry": [{
description: { identifier: "geometry.test", texture_width: 32, texture_height: 32 },
bones: [{
name: bone,
pivot: [-5, 22, 0],
cubes: [{ origin: [-8, 12, -2], size: [4, 12, 4], uv: [16, 0] }],
}],
}],
};
}
Deno.test("a mod made from the template passes the checks", async () => {
const dir = temp_mods_dir();
create_mod("copper_tools", "Copper Tools", dir);
@@ -82,6 +98,16 @@ Deno.test("check-mods finds broken mods", async () => {
});
// not json
Deno.writeTextFileSync(`${mod}/items/bad.json`, "{ nope");
// worn with a model that doesn't exist, as something that isn't { model, texture }, and with a model where nothing
// is named like a player part
const item = (id: string, worn: unknown) => ({ format_version: 1, item: { id, texture: "bworld:coal", worn } });
write_json(
`${mod}/items/ghost.json`,
item("broken:ghost", { model: "broken:no_such_worn", texture: "bworld:coal" }),
);
write_json(`${mod}/items/shapeless.json`, item("broken:shapeless", "broken:hat"));
write_json(`${mod}/items/stiff.json`, item("broken:stiff", { model: "broken:stiff", texture: "bworld:coal" }));
write_json(`${mod}/models/stiff.geo.json`, geo("hat"));
// uses a letter the key doesn't define
write_json(`${mod}/recipes/bad.json`, {
format_version: 1,
@@ -120,7 +146,38 @@ Deno.test("check-mods finds broken mods", async () => {
has(report.errors, "textures/huge.png: is");
has(report.errors, "scripts don't typecheck");
has(report.errors, `depends on "missing_mod", which isn't installed`);
has(report.errors, "entity model broken:no_such_worn doesn't exist");
has(report.errors, "worn must be { model, texture }");
has(report.warnings, "worn model broken:stiff has no bone named like a player part");
has(report.warnings, "texture broken:nope doesn't exist");
has(report.warnings, `uses bworld:stone but doesn't list "bworld" in dependencies`);
Deno.removeSync(dir, { recursive: true });
});
Deno.test("an item can say how it looks worn, with a model for slim arms too", async () => {
const dir = temp_mods_dir();
create_mod("gloves", "Gloves", dir);
const mod = `${dir}/gloves`;
Deno.mkdirSync(`${mod}/models`);
write_json(`${mod}/models/glove_wide.geo.json`, geo("right_arm"));
write_json(`${mod}/models/glove_slim.geo.json`, geo("right_arm"));
const worn = {
model: "gloves:glove_wide",
texture: "gloves:example_item",
slim_model: "gloves:glove_slim",
slim_texture: "gloves:example_item",
};
write_json(`${mod}/items/glove.json`, {
format_version: 1,
item: { id: "gloves:glove", texture: "gloves:example_item", worn },
});
const report = (await check_mods(dir)).find((r) => r.id === "gloves")!;
assertEquals(report.errors, []);
assertEquals(report.warnings, []);
// and the registry, which clients draw from, has it
const glove = JSON.parse(Deno.readTextFileSync(`${mod}/items/glove.json`)).item;
assertEquals(item_from_json(glove).worn, worn);
assertEquals(item_to_json("gloves:glove", item_from_json(glove)).worn, worn);
Deno.removeSync(dir, { recursive: true });
});