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
+21
View File
@@ -67,6 +67,27 @@ Deno.test("turning a model moves its faces and cullfaces", () => {
assert(east.flush);
});
Deno.test("an x turn tips a model's top to the north, before its y turn", () => {
// a slab's top face, culled by what's above it
const model: ModelJson = {
id: "a:slab",
elements: [{
from: [0, 0, 0],
to: [16, 8, 16],
faces: { top: { texture: "a:x" }, bottom: { texture: "a:x", cullface: "bottom" } },
}],
};
const [top, bottom] = bake_model(model, undefined, 0, 90);
assertEquals(top.face, 3);
// the bottom tips to the south, and is still against the block's edge there
assertEquals([bottom.face, bottom.cull], [2, 2]);
assert(bottom.flush);
const [east] = bake_model(model, undefined, 90, 90);
assertEquals(east.face, 5);
const [down] = bake_model(model, undefined, 0, 180);
assertEquals(down.face, 1);
});
Deno.test("variants pick textures by state", () => {
const { block } = block_from_json(JSON.parse(Deno.readTextFileSync("mods/bworld/blocks/wheat.json")).block);
assertEquals(block_variant(block, { age: 5 }).textures, { crop: "bworld:wheat_stage_5" });
+12
View File
@@ -161,3 +161,15 @@ Deno.test("raycast_blocks goes over the empty half of a slab, and not out of a b
const into = raycast_blocks([0.5, 0.25, 0.5], [1, 0, 0], 20, world)!;
assertEquals([into.x, into.face], [2, "west"]);
});
Deno.test("an x turn turns a model's shape with it", () => {
const slab: ModelJson = {
id: "a:slab",
elements: [{ from: [0, 0, 0], to: [16, 8, 16], faces: { top: { texture: "a:x" } } }],
};
// the bottom half tips to the south half, standing up
assertEquals(model_shape(slab, 0, 90), [[0, 0, 0.5, 1, 1, 1]]);
assertEquals(model_shape(slab, 0, 180), [[0, 0.5, 0, 1, 1, 1]]);
// then y turns the south half to the west
assertEquals(model_shape(slab, 90, 90), [[0, 0, 0, 0.5, 1, 1]]);
});
+12 -1
View File
@@ -12,8 +12,19 @@ import { decode_level_chunk } from "$/common/chunk_streaming.ts";
import { CHUNK_AREA, CHUNK_SIZE, ID_MASK } from "$/common/constants.ts";
import type { SavedChunk, SavedChunks, WorldSave } from "$/server/game/saves.ts";
// mods straight from their source folders, skipping the build: scripts are imported as typescript
// the repo's own mods/, read once: reading and checking every mod's files is most of starting a game in a test. only
// mods/ is kept, since tests change the temporary folders they make between games
let repo_mods: ServerModSource[] | undefined;
// mods straight from their source folders, skipping the build: scripts are imported as typescript. each call gets its
// own copy, so a test that changes what it got can't change another test's
export function mod_sources(mods_dir: string): ServerModSource[] {
if (resolve(mods_dir) !== resolve("mods")) return read_mod_sources(mods_dir);
repo_mods ??= read_mod_sources(mods_dir);
return structuredClone(repo_mods);
}
function read_mod_sources(mods_dir: string): ServerModSource[] {
const mods = load_and_check(mods_dir);
const errors = mods.flatMap((mod) => mod.report.errors.map((e) => `${mod.id}: ${e}`));
if (errors.length) throw new Error(errors.join("\n"));
+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");
});