Add all textures and models from create

This commit is contained in:
2026-10-12 18:47:41 -03:00
parent d4eff11f3e
commit 99bdcaeffc
3775 changed files with 66614 additions and 58 deletions
+150 -1
View File
@@ -2,8 +2,10 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import { assert, assertEquals, assertStringIncludes, assertThrows } from "@std/assert";
import { validate_model } from "$/common/mod_data.ts";
import { validate_block, validate_item, validate_model } 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 { convert_mcmeta, import_textures } from "$/tools/importer/textures.ts";
@@ -212,3 +214,150 @@ Deno.test("an animation that doesn't fit its png is an error, not a broken textu
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("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", () => {
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/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: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 draws it in 3D, here it's flat until items can have models
assertEquals(JSON.parse(Deno.readTextFileSync(`${output}/wrench.json`)).item.texture, "gears: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: {}, 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");
});