All the stone cutter recipes

This commit is contained in:
2026-10-12 21:07:06 -03:00
parent bea5f10a12
commit dfc6a6d77b
521 changed files with 5052 additions and 60 deletions
+111 -3
View File
@@ -2,11 +2,13 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import { assert, assertEquals, assertStringIncludes, assertThrows } from "@std/assert";
import { validate_block, validate_item, validate_model } from "$/common/mod_data.ts";
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
@@ -133,7 +135,12 @@ Deno.test("models that can't be converted are reported, not written", () => {
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" } },
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");
@@ -350,7 +357,7 @@ Deno.test("locations the remaps skip are left out of every kind, and blocks draw
"models/block/nether_gear": GEAR,
"models/block/gear": GEAR,
});
const remaps = { textures: {}, models: {}, skip: ["nether"] };
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"]);
@@ -403,3 +410,104 @@ Deno.test("blockbench's newer rotations become bworld's, at any angle around one
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: "engine: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", () => {
const mod = gears_mod();
const report = 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("stonecutting recipes become bworld's, and ones it can't use are reported", () => {
const mod = gears_mod();
const cut = (ingredient: unknown, result: unknown, extra = {}) => ({
type: "minecraft:stonecutting",
ingredient,
result,
...extra,
});
const report = 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"],
);
});