Files
bworld/tests/importer_test.ts
2026-11-12 20:41:13 -03:00

606 lines
26 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
// SPDX-License-Identifier: AGPL-3.0-or-later
import { assert, assertEquals, assertStringIncludes, assertThrows } from "@std/assert";
import { validate_block, validate_item, validate_model, validate_recipe } from "@/common/mod_data.ts";
import type { ModelFileJson } from "@/common/block_models.ts";
import { import_blocks } from "@/tools/importer/blocks.ts";
import { import_items } from "@/tools/importer/items.ts";
import { import_models } from "@/tools/importer/models.ts";
import { import_recipes } from "@/tools/importer/recipes.ts";
import { import_tags } from "@/tools/importer/tags.ts";
import { convert_mcmeta, import_textures } from "@/tools/importer/textures.ts";
// a java mod's resources in a temporary folder: { "block/gear": {...} } is assets/<namespace>/models/block/gear.json
function resources(models: Record<string, unknown>, namespace = "gears"): string {
const root = Deno.makeTempDirSync();
for (const [path, json] of Object.entries(models)) {
const file = `${root}/assets/${namespace}/models/${path}.json`;
Deno.mkdirSync(file.slice(0, file.lastIndexOf("/")), { recursive: true });
Deno.writeTextFileSync(file, JSON.stringify(json));
}
return root;
}
function convert(models: Record<string, unknown>, path: string): ModelFileJson {
const root = resources(models);
const report = import_models(`${root}/assets/gears/models/${path}.json`);
assertEquals(report.errors, []);
return JSON.parse(report.written[0].text!).model;
}
const GEAR = {
credit: "Made with Blockbench",
texture_size: [32, 32],
textures: { "0": "gears:block/gear", particle: "gears:block/gear" },
elements: [{
name: "hub",
from: [4, 0, 4],
to: [12, 4, 12],
rotation: { angle: 22.5, axis: "y", origin: [8, 8, 8] },
faces: {
up: { uv: [0, 0, 8, 8], texture: "#0", cullface: "up" },
down: { uv: [0, 0, 8, 8], texture: "#0", cullface: "down", tintindex: 0 },
north: { uv: [0, 8, 8, 12], texture: "#0", rotation: 90 },
},
}],
};
Deno.test("a java block model becomes a bworld model that passes its checks", () => {
const model = convert({ "block/gear": GEAR }, "block/gear");
assertEquals(validate_model(model), []);
// folders are joined into the id, the way textures in subfolders are named
assertEquals(model.id, "gears:block_gear");
// particle comes along too, since some models draw faces with it
assertEquals(model.textures, { "0": "gears:block_gear", particle: "gears:block_gear" });
const [hub] = model.elements!;
assertEquals(Object.keys(hub.faces).sort(), ["bottom", "north", "top"]);
assertEquals(hub.faces.top, { texture: "#0", uv: [0, 0, 8, 8], cullface: "top" });
assertEquals(hub.faces.north?.rotation, 90);
assertEquals(hub.rotation, { origin: [8, 8, 8], axis: "y", angle: 22.5 });
});
Deno.test("a model keeps its parent, which bworld merges in when it loads", () => {
const model = convert({
"block/gear": GEAR,
"block/gear_brass": { parent: "gears:block/gear", textures: { "0": "gears:block/brass_gear" } },
}, "block/gear_brass");
assertEquals(model, {
id: "gears:block_gear_brass",
parent: "gears:block_gear",
textures: { "0": "gears:block_brass_gear" },
});
});
Deno.test("minecraft's template parents become the base game's, and others need a remap", () => {
const cube = convert(
{ "block/casing": { parent: "minecraft:block/cube_all", textures: { all: "block/stone" } } },
"block/casing",
);
assertEquals(cube.parent, "bworld:cube_all");
// minecraft's block textures are taken to be the base game's of the same name
assertEquals(cube.textures?.all, "bworld:stone");
assertEquals(convert({ "block/steps": { parent: "block/stairs" } }, "block/steps").parent, "bworld:stairs");
const root = resources({ "block/stand": { parent: "block/lectern" } });
const report = import_models(`${root}/assets/gears/models/block/stand.json`);
assertStringIncludes(report.errors[0].problems[0], "--remap");
});
Deno.test("a folder converts into the same folders, models only there to be parents included", () => {
const root = resources({
"block/gear": GEAR,
"block/large/gear": { parent: "gears:block/gear" },
// block/block only holds display transforms, so this keeps its textures and nothing else
"block/template": { parent: "block/block", textures: { "0": "gears:block/gear" } },
});
const output = Deno.makeTempDirSync();
const report = import_models(root, { output });
assertEquals(report.errors, []);
for (const path of ["block/gear", "block/large/gear", "block/template"]) {
const json = JSON.parse(Deno.readTextFileSync(`${output}/${path}.json`));
assertEquals(json.format_version, 1);
assertEquals(validate_model(json.model), []);
}
assertEquals(JSON.parse(Deno.readTextFileSync(`${output}/block/template.json`)).model.parent, undefined);
});
Deno.test("display transforms for the places bworld shows items are kept, and a root of only those is a parent", () => {
const display = {
gui: { rotation: [30, 45, 0], translation: [0, 0, 0], scale: [0.625, 0.625, 0.625] },
ground: { translation: [0, 3, 0], scale: [0.25, 0.25, 0.25] },
thirdperson_righthand: { rotation: [75, 45, 0] },
head: { scale: [1.5, 1.5, 1.5] },
};
const root = resources({
"block/block": { parent: "block/block", display },
"block/gear": { ...GEAR, parent: "gears:block/block" },
"item/third_person": {
parent: "block/block",
display: { thirdperson_righthand: display.thirdperson_righthand },
},
});
const output = Deno.makeTempDirSync();
const report = import_models(root, { output });
assertEquals(report.errors, []);
const block = JSON.parse(Deno.readTextFileSync(`${output}/block/block.json`)).model;
assertEquals(block, { id: "gears:block_block", display: { gui: display.gui, ground: display.ground } });
assertEquals(validate_model(block), []);
assertEquals(JSON.parse(Deno.readTextFileSync(`${output}/block/gear.json`)).model.parent, "gears:block_block");
// nothing in it is for a place bworld shows items
assertEquals(report.skipped.map(({ location }) => location), ["gears:item/third_person"]);
});
Deno.test("models that can't be converted are reported, not written", () => {
const root = resources({
"block/obj": { loader: "forge:obj", model: "gears:models/block/thing.obj" },
"item/ingot": { parent: "item/generated", textures: { layer0: "gears:item/ingot" } },
// a sprite's child is a sprite too
"item/shiny_ingot": { parent: "gears:item/ingot" },
"block/tilted": {
...GEAR,
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,
"block/a_b": GEAR,
});
const output = Deno.makeTempDirSync();
const report = import_models(root, { output });
assertEquals(report.skipped.map(({ location }) => location).sort(), [
"gears:block/obj",
"gears:item/ingot",
"gears:item/shiny_ingot",
]);
const errors = Object.fromEntries(report.errors.map(({ location, problems }) => [location, problems.join(" ")]));
assertStringIncludes(errors["gears:block/tilted"], "200");
assertStringIncludes(errors["gears:block/a_b"] ?? errors["gears:block/a/b"], "--remap");
assertEquals(report.written.length, 1);
});
Deno.test("--remap renames locations before they become ids", () => {
const root = resources({ "block/gear": GEAR });
const report = import_models(`${root}/assets/gears/models/block/gear.json`, {
remaps: {
textures: { "gears:block/": "cogs:" },
models: { "gears:block/gear": "cogs:big_gear" },
ids: {},
tags: {},
},
});
const model = JSON.parse(report.written[0].text!).model;
assertEquals(model.id, "cogs:big_gear");
assertEquals(model.textures, { "0": "cogs:gear", particle: "cogs:gear" });
});
// a png with only the header, which is all that's read to size it
function png(width: number, height: number): Uint8Array {
const bytes = new Uint8Array(33);
bytes.set([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0, 0, 0, 13, 0x49, 0x48, 0x44, 0x52]);
const view = new DataView(bytes.buffer);
view.setUint32(16, width);
view.setUint32(20, height);
return bytes;
}
// textures in a temporary resources folder: { "gears:block/gear": [16, 16] }, with a .png.mcmeta when given
function textures(files: Record<string, { size: [number, number]; mcmeta?: unknown }>): string {
const root = Deno.makeTempDirSync();
for (const [location, { size, mcmeta }] of Object.entries(files)) {
const [namespace, path] = location.split(":");
const file = `${root}/assets/${namespace}/textures/${path}.png`;
Deno.mkdirSync(file.slice(0, file.lastIndexOf("/")), { recursive: true });
Deno.writeFileSync(file, png(...size));
if (mcmeta !== undefined) Deno.writeTextFileSync(`${file}.mcmeta`, JSON.stringify(mcmeta));
}
return root;
}
Deno.test("textures keep their folders, so bworld names them like the models that use them", () => {
const root = textures({
"gears:block/gear": { size: [16, 16] },
"gears:block/belt/scroll": {
size: [16, 64],
mcmeta: { animation: { frametime: 2, interpolate: true }, villager: { hat: "full" } },
},
});
const output = Deno.makeTempDirSync();
const report = import_textures(root, { output });
assertEquals(report.errors, []);
assertEquals(report.written.filter(({ copy }) => copy).map(({ id }) => id).sort(), [
"gears:block_belt_scroll",
"gears:block_gear",
]);
assertEquals(Deno.readFileSync(`${output}/block/gear.png`), png(16, 16));
// the animation is the same format, only renamed, and what bworld can't use is left out
const animation = JSON.parse(Deno.readTextFileSync(`${output}/block/belt/scroll.json`));
assertEquals(animation, { animation: { frametime: 2, interpolate: true } });
assertEquals(report.warnings.length, 1);
});
Deno.test("textures bworld can't use are reported, and minecraft's aren't copied", () => {
const root = textures({
"gears:gui/panorama": { size: [512, 512] },
// 3 rows of 16 don't split into 16×32 frames
"gears:block/uneven": { size: [16, 48], mcmeta: { animation: { height: 32 } } },
"minecraft:block/stone": { size: [16, 16] },
});
const output = Deno.makeTempDirSync();
const report = import_textures(root, { output });
assertEquals(report.skipped.map(({ location }) => location).sort(), [
"gears:gui/panorama",
"minecraft:block/stone",
]);
assertEquals(report.errors.map(({ location }) => location), ["gears:block/uneven"]);
assertEquals(report.written, []);
});
Deno.test("a folder with two mods' textures needs --namespace to pick one", () => {
const root = textures({ "gears:block/gear": { size: [16, 16] }, "belts:block/belt": { size: [16, 16] } });
const output = Deno.makeTempDirSync();
assertThrows(() => import_textures(root, { output }), Error, "--namespace");
const report = import_textures(root, { output, namespace: "belts" });
assertEquals(report.written.map(({ id }) => id), ["belts:block_belt"]);
});
Deno.test("an animation that doesn't fit its png is an error, not a broken texture", () => {
const { problems } = convert_mcmeta({ animation: { frames: [0, 5] } }, { width: 16, height: 32 });
assert(problems.length > 0);
});
// a java mod's blockstates and models in a temporary folder, as { "blockstates/gear": {...}, "models/block/gear": {...} }
function assets(files: Record<string, unknown>): string {
const root = Deno.makeTempDirSync();
for (const [path, json] of Object.entries(files)) {
const file = `${root}/assets/gears/${path}.json`;
Deno.mkdirSync(file.slice(0, file.lastIndexOf("/")), { recursive: true });
Deno.writeTextFileSync(file, JSON.stringify(json));
}
return root;
}
function import_block(files: Record<string, unknown>, name: string) {
const output = Deno.makeTempDirSync();
const report = import_blocks(assets(files), { output });
assertEquals(report.errors, []);
const json = JSON.parse(Deno.readTextFileSync(`${output}/${name}.json`));
assertEquals(validate_block(json.block), []);
return { block: json.block, report };
}
Deno.test("a blockstate's variants become numbered states, each drawn with its model turned", () => {
const { block } = import_block({
"blockstates/shaft": {
variants: {
"axis=x,waterlogged=false": { model: "gears:block/shaft", x: 90, y: 90 },
"axis=x,waterlogged=true": { model: "gears:block/shaft", x: 90, y: 90 },
"axis=y,waterlogged=false": { model: "gears:block/shaft" },
"axis=y,waterlogged=true": { model: "gears:block/shaft" },
"axis=z,waterlogged=false": { model: "gears:block/shaft", x: -90 },
"axis=z,waterlogged=true": { model: "gears:block/shaft", x: -90 },
},
},
"models/block/shaft": GEAR,
"models/item/shaft": { parent: "gears:block/shaft" },
}, "shaft");
// waterlogged never changes how it looks, so it isn't a state
assertEquals(block.states, [{ name: "axis", bits: 2, default: 1 }]);
assertEquals(block.variants["axis=0"], { model: "gears:block_shaft", x: 90, y: 90 });
// java's -90 is bworld's 270
assertEquals(block.variants["axis=2"], { model: "gears:block_shaft", x: 270 });
// not a full cube, so what's behind it isn't hidden
assertEquals(block.render_layer, "cutout");
assertEquals(block.item_model, "gears:item_shaft");
assertEquals(block.drops, "gears:shaft");
});
Deno.test("uvlock carries over, so turned textures stay where they are on an unturned block", () => {
const { block, report } = import_block({
"blockstates/steps": {
variants: {
"facing=east": { model: "gears:block/steps" },
"facing=south": { model: "gears:block/steps", y: 90, uvlock: true },
},
},
"models/block/steps": GEAR,
}, "steps");
assertEquals(block.variants["facing=1"], { model: "gears:block_steps", y: 90, uvlock: true });
assertEquals(block.variants["facing=0"], { model: "gears:block_steps" });
assertEquals(report.warnings, []);
});
Deno.test("multipart blockstates become parts, one for each way a part can be drawn", () => {
const { block } = import_block({
"blockstates/pipe": {
multipart: [
{ apply: { model: "gears:block/pipe_core" } },
{ when: { north: "true|side" }, apply: { model: "gears:block/pipe_arm" } },
{ when: { OR: [{ up: "true" }, { down: "true" }] }, apply: { model: "gears:block/pipe_arm", x: 90 } },
],
},
"models/block/pipe_core": GEAR,
"models/block/pipe_arm": GEAR,
}, "pipe");
assertEquals(block.parts.length, 5);
assertEquals(block.parts[0], { model: "gears:block_pipe_core" });
assertEquals(block.parts.map((part: { when?: string }) => part.when).slice(1), [
"north=1",
"north=2",
"up=1",
"down=1",
]);
// a block without an item model has no item, like java's
assertEquals(block.item, false);
});
Deno.test("cubes stay solid, and models that can't be drawn are placeholders", () => {
const { block: casing } = import_block({
"blockstates/casing": { variants: { "": { model: "gears:block/casing" } } },
"models/block/casing": { parent: "minecraft:block/cube_all", textures: { all: "gears:block/casing" } },
}, "casing");
assertEquals(casing.model, "gears:block_casing");
assertEquals(casing.render_layer, undefined);
assertEquals(casing.variants, undefined);
const { block: tube, report } = import_block({
"blockstates/tube": { variants: { "": { model: "gears:block/tube" } } },
"models/block/tube": { loader: "forge:obj", model: "gears:models/tube.obj" },
}, "tube");
assertEquals(tube.model, "bworld:cube");
assertStringIncludes(report.warnings[0].warning, "placeholder");
});
Deno.test("items that aren't a block's get their sprite as their texture and layers, or their model when java draws them in 3D", () => {
const output = Deno.makeTempDirSync();
const report = import_items(
assets({
"blockstates/gear": { variants: { "": { model: "gears:block/gear" } } },
"models/block/gear": GEAR,
"models/item/gear": { parent: "gears:block/gear" },
"models/item/sheet": { parent: "item/generated", textures: { layer0: "gears:item/sheet" } },
"models/item/trimmed_sheet": {
parent: "item/generated",
textures: { layer0: "gears:item/sheet", layer1: "gears:item/trim" },
},
"models/item/wrench": { parent: "gears:item/wrench/item" },
"models/item/wrench/item": { textures: { handle: "gears:item/wrench" }, elements: GEAR.elements },
}),
{ output },
);
assertEquals(report.errors, []);
// the gear's item comes with its block, and the wrench's model parts aren't items
assertEquals(report.written.map(({ id }) => id).sort(), ["gears:sheet", "gears:trimmed_sheet", "gears:wrench"]);
const sheet = JSON.parse(Deno.readTextFileSync(`${output}/sheet.json`)).item;
assertEquals(sheet, { id: "gears:sheet", texture: "gears:item_sheet" });
assertEquals(validate_item(sheet), []);
// java's other layers are drawn over the first
const trimmed = JSON.parse(Deno.readTextFileSync(`${output}/trimmed_sheet.json`)).item;
assertEquals(trimmed.layers, [{ texture: "gears:item_trim" }]);
assertEquals(validate_item(trimmed), []);
// the model kind writes its model, and its texture is its model's
const wrench = JSON.parse(Deno.readTextFileSync(`${output}/wrench.json`)).item;
assertEquals(wrench, { id: "gears:wrench", texture: "gears:item_wrench", model: "gears:item_wrench" });
assertEquals(validate_item(wrench), []);
});
Deno.test("a multipart block is placed in a state that draws something, like a wall with its post", () => {
const { block } = import_block({
"blockstates/wall": {
multipart: [
{ when: { up: "true" }, apply: { model: "gears:block/wall_post" } },
{ when: { north: "low|tall" }, apply: { model: "gears:block/wall_side" } },
],
},
"models/block/wall_post": GEAR,
"models/block/wall_side": GEAR,
}, "wall");
const up = block.states.find((state: { name: string }) => state.name === "up");
const north = block.states.find((state: { name: string }) => state.name === "north");
assertEquals(up.default, 1);
// "none", the value no part is drawn for, is where its sides start
assertEquals(north.default, 0);
});
Deno.test("locations the remaps skip are left out of every kind, and blocks drawn with them get a placeholder", () => {
const root = assets({
"blockstates/nether_gear": { variants: { "": { model: "gears:block/nether_gear" } } },
"blockstates/gear_stand": { variants: { "": { model: "gears:block/nether_gear" } } },
"models/block/nether_gear": GEAR,
"models/block/gear": GEAR,
});
const remaps = { textures: {}, models: {}, ids: {}, tags: {}, skip: ["nether"] };
const models = import_models(root, { output: Deno.makeTempDirSync(), remaps });
assertEquals(models.written.map(({ id }) => id), ["gears:block_gear"]);
assertEquals(models.skipped.map(({ location }) => location), ["gears:block/nether_gear"]);
const output = Deno.makeTempDirSync();
const blocks = import_blocks(root, { output, remaps });
assertEquals(blocks.written.map(({ id }) => id), ["gears:gear_stand"]);
// 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");
});
// a java mod's data in a temporary folder: { "gears/tags/items/teeth": {...} } is data/gears/tags/items/teeth.json
function data(files: Record<string, unknown>): string {
const root = Deno.makeTempDirSync();
for (const [path, json] of Object.entries(files)) {
const file = `${root}/data/${path}.json`;
Deno.mkdirSync(file.slice(0, file.lastIndexOf("/")), { recursive: true });
Deno.writeTextFileSync(file, JSON.stringify(json));
}
return root;
}
// a mods folder with one mod, gears, that has the block gears:gear and the item tag #gears:teeth: what an import
// into it checks against
function gears_mod(): string {
const mod = `${Deno.makeTempDirSync()}/gears`;
const write = (path: string, json: unknown) => {
Deno.mkdirSync(`${mod}/${path.slice(0, path.lastIndexOf("/"))}`, { recursive: true });
Deno.writeTextFileSync(`${mod}/${path}`, JSON.stringify(json));
};
write("manifest.json", { format_version: 1, id: "gears", name: "Gears", version: "1.0.0" });
write("blocks/gear.json", { format_version: 1, block: { id: "gears:gear", textures: "cubi:missing" } });
write("tags/items/gears/teeth.json", { format_version: 1, tag: { values: ["gears:gear"] } });
return mod;
}
Deno.test("tags keep their entries, renamed, and ones that don't exist here become optional", async () => {
const mod = gears_mod();
const report = await import_tags(
data({
"gears/tags/items/spinning": {
values: ["gears:gear", "minecraft:stone", "#forge:ingots/brass", { id: "other:cog", required: false }],
remove: ["gears:old_gear"],
},
"forge/tags/items/ingots/brass": { replace: true, values: ["gears:gear"] },
"gears/tags/fluids/oil": { values: ["gears:oil"] },
}),
{ output: `${mod}/tags` },
);
assertEquals(report.errors, []);
assertEquals(report.skipped.map(({ location }) => location), ["gears:fluids/oil"]);
const read = (path: string) => JSON.parse(Deno.readTextFileSync(`${mod}/tags/items/${path}.json`)).tag;
// forge's shared tags are c's, and bworld has no stone here, so it's kept for when it does
assertEquals(read("gears/spinning"), {
values: [
"gears:gear",
{ id: "bworld:stone", required: false },
"#c:ingots/brass",
{ id: "other:cog", required: false },
],
remove: ["gears:old_gear"],
});
assertEquals(read("c/ingots/brass"), { replace: true, values: ["gears:gear"] });
assertStringIncludes(report.warnings[0].warning, "bworld:stone");
});
Deno.test("create's pressing recipes keep their shape, with bworld's item choices, from 0.5's and 6.0's json", async () => {
const mod = gears_mod();
const report = await import_recipes(
data({
// 0.5 named results' items "item", and an ingredient that's a list is one any of whose items fit
"gears/recipes/pressing/teeth": {
type: "create:pressing",
ingredients: [[{ tag: "gears:teeth" }, { item: "gears:gear" }]],
results: [{ item: "gears:gear", count: 2 }],
processingTime: 100,
},
"gears/recipe/pressing/gear": {
type: "create:pressing",
ingredients: [{ item: "gears:gear" }],
results: [{ id: "gears:gear" }, { id: "gears:gear", chance: 0.5 }, { id: "gears:gear", chance: 1 }],
},
"gears/recipe/pressing/granite": {
type: "create:pressing",
ingredients: [{ item: "minecraft:granite" }],
results: [{ id: "gears:gear" }],
},
}),
{ output: `${mod}/recipes` },
);
assertEquals(report.errors, []);
const read = (path: string) => JSON.parse(Deno.readTextFileSync(`${mod}/recipes/${path}.json`)).recipe;
assertEquals(read("pressing/teeth"), {
type: "create:pressing",
ingredients: [["#gears:teeth", "gears:gear"]],
results: [{ id: "gears:gear", count: 2 }],
processing_time: 100,
});
// a chance is only kept when it isn't certain
assertEquals(read("pressing/gear").results, [
{ id: "gears:gear", count: 1 },
{ id: "gears:gear", count: 1, chance: 0.5 },
{ id: "gears:gear", count: 1 },
]);
assertEquals(report.skipped.map(({ location }) => location), ["gears:pressing/granite"]);
});
Deno.test("stonecutting recipes become bworld's, and ones it can't use are reported", async () => {
const mod = gears_mod();
const cut = (ingredient: unknown, result: unknown, extra = {}) => ({
type: "minecraft:stonecutting",
ingredient,
result,
...extra,
});
const report = await import_recipes(
data({
// before 1.20.5 the count is the recipe's, after it the result's. 1.21 renamed the folder
"gears/recipes/gear_from_teeth": cut({ tag: "gears:teeth" }, "gears:gear", { count: 2 }),
"gears/recipe/cut/gear": cut([{ item: "gears:gear" }, { tag: "gears:teeth" }], {
id: "gears:gear",
count: 3,
}),
"gears/recipes/from_granite": cut({ item: "minecraft:granite" }, "gears:gear"),
"gears/recipes/from_bolts": cut({ tag: "gears:bolts" }, "gears:gear"),
"gears/recipes/with_other_mod": cut({ item: "gears:gear" }, "gears:gear", {
"neoforge:conditions": [{ type: "neoforge:mod_loaded", modid: "other" }],
}),
"gears/recipes/smelted": {
type: "minecraft:smelting",
ingredient: { item: "gears:gear" },
result: "gears:gear",
},
}),
{ output: `${mod}/recipes` },
);
assertEquals(report.errors, []);
const read = (path: string) => JSON.parse(Deno.readTextFileSync(`${mod}/recipes/${path}.json`)).recipe;
assertEquals(read("gear_from_teeth"), {
type: "bworld:stonecutting",
input: "#gears:teeth",
output: { id: "gears:gear", count: 2 },
});
assertEquals(read("cut/gear").input, ["gears:gear", "#gears:teeth"]);
assertEquals(read("cut/gear").output, { id: "gears:gear", count: 3 });
assertEquals(validate_recipe(read("gear_from_teeth")), []);
// granite and #gears:bolts don't exist here, the condition can't be checked, and smelting isn't converted yet
assertEquals(
report.skipped.map(({ location }) => location).sort(),
["gears:from_bolts", "gears:from_granite", "gears:smelted", "gears:with_other_mod"],
);
});