Item rendering

This commit is contained in:
2026-10-13 22:29:38 -03:00
parent a18b099206
commit b34e97e487
269 changed files with 12566 additions and 3220 deletions
+46 -3
View File
@@ -105,6 +105,32 @@ Deno.test("a folder converts into the same folders, models only there to be pare
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" },
@@ -268,6 +294,21 @@ Deno.test("a blockstate's variants become numbered states, each drawn with its m
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": {
@@ -309,7 +350,7 @@ Deno.test("cubes stay solid, and models that can't be drawn are placeholders", (
assertStringIncludes(report.warnings[0].warning, "placeholder");
});
Deno.test("items that aren't a block's get their sprite as their texture", () => {
Deno.test("items that aren't a block's get their sprite as their texture, or their model when java draws them in 3D", () => {
const output = Deno.makeTempDirSync();
const report = import_items(
assets({
@@ -328,8 +369,10 @@ Deno.test("items that aren't a block's get their sprite as their texture", () =>
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");
// 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", () => {