Remove reimporting logic from importer

This commit is contained in:
2026-10-28 21:47:52 -03:00
parent 872db88066
commit fa0748a9c5
7 changed files with 16 additions and 81 deletions
+5 -5
View File
@@ -66,7 +66,7 @@ Six rules that keep the work small:
1. **Import data, don't hand-write it.** One tool converts Create's models, textures, blockstates, recipes, tags, loot,
names and worldgen into bworld's formats, and reports what it couldn't convert. Hundreds of blocks then cost the same
as one, and re-running it after a fix redoes all of them. This replaces Create's datagen entirely.
as one. It's run once to start from, and what it made is edited by hand after. This replaces Create's datagen.
2. **Port Create's architecture onto bworld's, not its classes.** Create builds every machine from a few shared pieces
(block entity behaviours, a rotation network, processing recipes, instance types). Each piece becomes one bworld
piece, and then the machines are mostly data plus a little code (see [Architecture](#architecture)).
@@ -123,10 +123,10 @@ shared tags to `c`, which is what bworld calls them. A mod's remap file is where
| `sound` | `assets/*/sounds.json`, `sounds/**.ogg` | sounds, once the engine has them (S8) | |
| `mod` | all of the above | a whole mod folder with a manifest, and one report | |
Block properties (shape, tool, toughness) aren't in any data file: Java mods set them in code. `mod` writes a block for
each blockstate with placeholder properties, and a per-mod table fills them in. For Create that table is
`mods/create/import/blocks.json`. Built for `blockstate` as `--blocks FILE`: each block's fields in it, like its
`components`, replace the ones the importer would write, and a block it names that isn't made is an error.
Block properties (shape, tool, toughness) aren't in any data file: Java mods set them in code. `blockstate` writes a
block for each blockstate with placeholder properties, and what a block really has, like its `components`, is written
into its file by hand after. The importer is a starting point, not something to run again over a mod that's been worked
on, since that would write over those changes.
**What `model` does today.** It keeps `parent`, since the engine merges parents in when it loads (see
[Parents](docs/modding/resources/models.md#parents)), and remaps it like any id. Minecraft's template parents (`cube`,
+8 -7
View File
@@ -1,14 +1,15 @@
# Importing Create
`textures/`, `models/`, `blocks/`, `items/`, `tags/` and `recipes/` are made by the importer from Create 0.5.0.j's
resources, a checkout of it in `ports/create1.19.3`. Nothing in them is edited by hand, so to change them, change the
importer or `remap.json` and import again:
`textures/`, `models/`, `blocks/`, `items/`, `tags/` and `recipes/` were first made by the importer from Create
0.5.0.j's resources, a checkout of it in `ports/create1.19.3`, and are edited by hand since, as blocks get what they do.
Importing again would write over that, so it's only for bringing in something new, into a folder of its own to copy
from. These are the commands they were made with:
```sh
rm -rf mods/create/textures mods/create/models mods/create/blocks mods/create/items mods/create/tags mods/create/recipes
deno task import texture ports/create1.19.3/src --namespace create --output mods/create/textures --remap mods/create/import/remap.json
deno task import model ports/create1.19.3/src --namespace create --output mods/create/models --remap mods/create/import/remap.json
deno task import blockstate ports/create1.19.3/src --namespace create --output mods/create/blocks --remap mods/create/import/remap.json --blocks mods/create/import/blocks.json
deno task import blockstate ports/create1.19.3/src --namespace create --output mods/create/blocks --remap mods/create/import/remap.json
deno task import item ports/create1.19.3/src --namespace create --output mods/create/items --remap mods/create/import/remap.json
deno task import tag ports/create1.19.3/src/generated --namespace create --output mods/create/tags --remap mods/create/import/remap.json
deno task import tag ports/create1.19.3/src/generated --namespace forge --output mods/create/tags --remap mods/create/import/remap.json
@@ -21,9 +22,9 @@ then tags, then recipes. Forge's shared tags, like `forge:ingots/brass`, become
Create's stonecutting and pressing ones so far. The stonecutting ones that cut a stone bworld doesn't have yet (granite,
diorite, deepslate, calcite, tuff, dripstone) are left out until it does, and so is pressing paper and dirt paths.
Java sets what blocks do in code, so every block gets placeholders (a second to mine with anything, dropping itself).
`blocks.json` gives blocks what they have instead, by id, like the components that make a shaft turn and a hand crank
turn it. Each block's fields there replace the ones the importer would write.
Java sets what blocks do in code, so every block got placeholders (a second to mine with anything, dropping itself).
What a block really has, like the components that make a shaft turn and a hand crank turn it, is written into its file
in `blocks/` by hand.
`remap.json` gives three of Create's models other names, since `block/radial_chassis/side_x` and
`block/radial_chassis_side_x` would both be `create:block_radial_chassis_side_x`.
-30
View File
@@ -1,30 +0,0 @@
{
"create:shaft": {
"components": {
"create:kinetic": { "axis": "axis" }
}
},
"create:cogwheel": {
"components": {
"create:kinetic": { "axis": "axis", "cog": "small" }
}
},
"create:large_cogwheel": {
"components": {
"create:kinetic": { "axis": "axis", "cog": "large" }
}
},
"create:mechanical_press": {
"components": {
"create:kinetic": { "facing": "facing", "horizontal": true },
"create:mechanical_press": {}
}
},
"create:hand_crank": {
"interactive": true,
"components": {
"create:kinetic": { "facing": "facing", "shaft": "back" },
"create:hand_crank": { "speed": 32 }
}
}
}
-22
View File
@@ -294,28 +294,6 @@ Deno.test("a blockstate's variants become numbered states, each drawn with its m
assertEquals(block.drops, "gears:shaft");
});
Deno.test("a block table gives blocks what java sets in code, over the placeholders", () => {
const files = {
"blockstates/crank": { variants: { "": { model: "gears:block/crank" } } },
"models/block/crank": GEAR,
};
const output = Deno.makeTempDirSync();
const components = { "gears:turns": { speed: 32 } };
const report = import_blocks(assets(files), {
output,
blocks: { "gears:crank": { components, mining: { toughness: 2 } } },
});
assertEquals(report.errors, []);
const { block } = JSON.parse(Deno.readTextFileSync(`${output}/crank.json`));
assertEquals(validate_block(block), []);
assertEquals(block.components, components);
assertEquals(block.mining, { toughness: 2 });
// a block the table names that wasn't made is an error, so a typo can't go unnoticed
const typo = import_blocks(assets(files), { output, blocks: { "gears:cranck": { components } } });
assertEquals(typo.errors.map(({ location }) => location), ["gears:cranck"]);
});
Deno.test("uvlock carries over, so turned textures stay where they are on an unturned block", () => {
const { block, report } = import_block({
"blockstates/steps": {
+2 -5
View File
@@ -47,9 +47,7 @@ options:
{ "textures": { "minecraft:block/": "bworld:" }, "models": {}, "ids": {}, "tags": {},
"skip": ["crimson"] }
minecraft's block and item textures, blocks, items and tags become bworld's of the same name,
and forge's shared tags c's, unless it says otherwise
--blocks FILE json of fields blocks get by id, over the placeholders, for blockstate. what java sets in
code, like components and mining: { "gears:shaft": { "components": {...} } }`;
and forge's shared tags c's, unless it says otherwise`;
function parse_args(args: string[]) {
const positional: string[] = [];
@@ -73,8 +71,7 @@ function parse_args(args: string[]) {
tags: { ...DEFAULT_REMAPS.tags, ...remap.tags },
...(remap.skip ? { skip: remap.skip } : {}),
};
} else if (arg === "--blocks") options.blocks = JSON.parse(Deno.readTextFileSync(value()));
else if (arg.startsWith("--")) throw new Error(`unknown option ${arg}`);
} else if (arg.startsWith("--")) throw new Error(`unknown option ${arg}`);
else positional.push(arg);
}
return { positional, options };
+1 -9
View File
@@ -4,7 +4,7 @@
// java blockstates (assets/<namespace>/blockstates/*.json) to bworld's blocks/, so a mod's blocks can be placed and look
// right: their states, and the model each state is drawn with, turned. how a block behaves isn't in any data file (java
// mods set mining, sounds and what blocks do in code), so every block gets the same placeholders: a second to break with
// anything, dropping itself. --blocks gives some of them more, see ImportOptions.blocks
// anything, dropping itself, and what they really have is written by hand after
import { dirname, join } from "@std/path";
import { FORMAT_VERSION } from "$/common/mod_data.ts";
import { is_empty, made_by, model_source, type ModelSource } from "./models.ts";
@@ -95,19 +95,11 @@ export function import_blocks(input: string, options: ImportOptions = {}): Impor
const result = convert_blockstate(location, json, read, remaps);
if (result.kind === "error") report.errors.push({ location, problems: result.problems });
else if (claim(result.id, location)) {
Object.assign(result.json.block, options.blocks?.[result.id]);
for (const warning of result.warnings) report.warnings.push({ location, warning });
const text = format_json(result.json) + "\n";
report.written.push({ location, id: result.id, file: join(options.output, `${where.path}.json`), text });
}
}
// a typo in the table would otherwise quietly give a block nothing
const written = new Set(report.written.map(({ id }) => id));
for (const id of Object.keys(options.blocks ?? {})) {
if (!written.has(id)) {
report.errors.push({ location: id, problems: ["--blocks has it, but no block was made for it"] });
}
}
write_report(report);
return report;
}
-3
View File
@@ -254,9 +254,6 @@ export interface ImportOptions {
// more folders to look things up in, like parent models from another mod
parents?: string[];
remaps?: Remaps;
// fields blocks get by id, over the placeholders, like their components or how long they take to mine. java sets
// those in code, so a mod's import keeps them in a table, like mods/create/import/blocks.json
blocks?: Record<string, Record<string, unknown>>;
}
// one file an import makes: text to write, or a file to copy