Worm bin model

This commit is contained in:
2026-10-12 18:58:38 -03:00
parent 99bdcaeffc
commit 038b6d2caa
16 changed files with 447 additions and 39 deletions
+44 -2
View File
@@ -111,7 +111,7 @@ Deno.test("models that can't be converted are reported, not written", () => {
"item/shiny_ingot": { parent: "gears:item/ingot" },
"block/tilted": {
...GEAR,
elements: [{ ...GEAR.elements[0], rotation: { angle: 30, axis: "x", origin: [8, 8, 8] } }],
elements: [{ ...GEAR.elements[0], rotation: { angle: 200, axis: "x", origin: [8, 8, 8] } }],
},
// these two would both be gears:block_a_b
"block/a/b": GEAR,
@@ -125,7 +125,7 @@ Deno.test("models that can't be converted are reported, not written", () => {
"gears:item/shiny_ingot",
]);
const errors = Object.fromEntries(report.errors.map(({ location, problems }) => [location, problems.join(" ")]));
assertStringIncludes(errors["gears:block/tilted"], "30");
assertStringIncludes(errors["gears:block/tilted"], "200");
assertStringIncludes(errors["gears:block/a_b"] ?? errors["gears:block/a/b"], "--remap");
assertEquals(report.written.length, 1);
});
@@ -361,3 +361,45 @@ Deno.test("locations the remaps skip are left out of every kind, and blocks draw
// it would be drawn with a model that isn't there
assertEquals(JSON.parse(Deno.readTextFileSync(`${output}/gear_stand.json`)).block.model, "bworld:cube");
});
// a blockbench export outside any mod's resources, next to a folder that's a bworld mod
function loose_model(json: unknown) {
const dir = Deno.makeTempDirSync();
Deno.writeTextFileSync(`${dir}/thing.json`, JSON.stringify(json));
const mod = Deno.makeTempDirSync();
Deno.writeTextFileSync(`${mod}/manifest.json`, JSON.stringify({ format_version: 1, id: "tinker" }));
return { file: `${dir}/thing.json`, output: `${mod}/models/thing.json` };
}
Deno.test("a loose model is the mod's its output goes in, and so are its bare texture names", () => {
const { file, output } = loose_model({ textures: { "0": "thing" }, elements: GEAR.elements });
assertThrows(() => import_models(file), Error, "--namespace");
const report = import_models(file, { output });
assertEquals(report.errors, []);
const model = JSON.parse(Deno.readTextFileSync(output)).model;
assertEquals(model.id, "tinker:thing");
assertEquals(model.textures, { "0": "tinker:thing" });
});
Deno.test("blockbench's newer rotations become bworld's, at any angle around one axis", () => {
const element = (rotation: unknown) => ({ ...GEAR.elements[0], rotation });
const { file, output } = loose_model({
textures: { "0": "thing" },
elements: [
element({ x: 0, y: 90, z: 0, origin: [7, 13, 9] }),
element({ x: 0, y: 0, z: 0, origin: [8, 8, 8] }),
element({ angle: 0, axis: "y", origin: [8, 8, 8] }),
],
});
import_models(file, { output });
const model = JSON.parse(Deno.readTextFileSync(output)).model;
assertEquals(validate_model(model), []);
assertEquals(model.elements[0].rotation, { origin: [7, 13, 9], axis: "y", angle: 90 });
// turning by nothing isn't a rotation
assertEquals(model.elements[1].rotation, undefined);
assertEquals(model.elements[2].rotation, undefined);
const { file: tilted } = loose_model({ elements: [element({ x: 45, y: 90, z: 0, origin: [8, 8, 8] })] });
const report = import_models(tilted, { namespace: "tinker" });
assertStringIncludes(report.errors[0].problems[0], "x and y");
});