From 038b6d2caafb4cd88a73c93141c87dedaee6d1f3 Mon Sep 17 00:00:00 2001 From: Paula Date: Mon, 12 Oct 2026 18:58:38 -0300 Subject: [PATCH] Worm bin model --- common/block_models.ts | 2 +- common/mod_data.ts | 4 +- docs/modding/resources/models.md | 2 +- mods/bworld/blocks/worm_bin.json | 9 +- mods/bworld/models/worm_bin.json | 330 ++++++++++++++++++++++++ mods/bworld/textures/worm_bin.png | Bin 0 -> 4542 bytes mods/bworld/textures/worm_bin_front.png | Bin 300 -> 0 bytes mods/bworld/textures/worm_bin_side.png | Bin 268 -> 0 bytes mods/bworld/textures/worm_bin_top.png | Bin 347 -> 0 bytes tests/importer_test.ts | 46 +++- tools/importer.ts | 3 +- tools/importer/blocks.ts | 2 +- tools/importer/items.ts | 2 +- tools/importer/models.ts | 37 ++- tools/importer/resources.ts | 47 +++- tools/importer/textures.ts | 2 +- 16 files changed, 447 insertions(+), 39 deletions(-) create mode 100644 mods/bworld/models/worm_bin.json create mode 100644 mods/bworld/textures/worm_bin.png delete mode 100644 mods/bworld/textures/worm_bin_front.png delete mode 100644 mods/bworld/textures/worm_bin_side.png delete mode 100644 mods/bworld/textures/worm_bin_top.png diff --git a/common/block_models.ts b/common/block_models.ts index 5d73767..6a22e46 100644 --- a/common/block_models.ts +++ b/common/block_models.ts @@ -29,7 +29,7 @@ export interface ModelElementJson { rotation?: { origin: [number, number, number]; axis: "x" | "y" | "z"; - // -45, -22.5, 0, 22.5 or 45 + // degrees, any from -180 to 180. minecraft only takes -45, -22.5, 0, 22.5 or 45, blockbench's newer models any angle: number; // stretch the rotated faces back to the block's size, like the cross model does rescale?: boolean; diff --git a/common/mod_data.ts b/common/mod_data.ts index a30d2f2..0573526 100644 --- a/common/mod_data.ts +++ b/common/mod_data.ts @@ -808,10 +808,10 @@ export function validate_model(json: unknown): Problems { if (rotation !== undefined) { if ( !is_object(rotation) || !["x", "y", "z"].includes(rotation.axis as string) || - ![-45, -22.5, 0, 22.5, 45].includes(rotation.angle as number) || !Array.isArray(rotation.origin) + typeof rotation.angle !== "number" || Math.abs(rotation.angle) > 180 || !Array.isArray(rotation.origin) ) { problems.push( - `${where}.rotation must be { origin, axis: x, y or z, angle: -45, -22.5, 0, 22.5 or 45 }`, + `${where}.rotation must be { origin, axis: x, y or z, angle: degrees from -180 to 180 }`, ); } } diff --git a/docs/modding/resources/models.md b/docs/modding/resources/models.md index 1d89cae..cafd41e 100644 --- a/docs/modding/resources/models.md +++ b/docs/modding/resources/models.md @@ -68,7 +68,7 @@ on every face, since `top` and `bottom` default to `#side`. | `parent` | Another model this one starts from, see [Parents](#parents). | | `textures` | Defaults for texture variables. Values are texture ids or other variables, like `"#side"`. | | `elements[].from`, `to` | Opposite corners of the box, `[x, y, z]` in pixels. | -| `elements[].rotation` | `{ origin, axis, angle, rescale }`: turns the box around `origin` on `x`, `y` or `z` by -45, -22.5, 0, 22.5 or 45 degrees. `rescale` stretches it back to the block's width. | +| `elements[].rotation` | `{ origin, axis, angle, rescale }`: turns the box around `origin` on `x`, `y` or `z` by `angle` degrees, from -180 to 180. `rescale` stretches it back to the block's width. | | `elements[].shade` | Darker faces on the sides and bottom. `true` by default, plants turn it off. | | `elements[].faces` | Any of `top`, `bottom`, `north`, `south`, `west` and `east`. | | `faces.*.texture` | A variable like `"#side"`, filled in by the block's `textures`, or a texture id. | diff --git a/mods/bworld/blocks/worm_bin.json b/mods/bworld/blocks/worm_bin.json index ae1cd05..d15dab2 100644 --- a/mods/bworld/blocks/worm_bin.json +++ b/mods/bworld/blocks/worm_bin.json @@ -3,11 +3,10 @@ "block": { "id": "bworld:worm_bin", "name": "Worm Bin", - "textures": { - "front": "bworld:worm_bin_front", - "side": "bworld:worm_bin_side", - "top": "bworld:worm_bin_top" - }, + "model": "bworld:worm_bin", + "textures": {}, + "item_model": "bworld:worm_bin", + "render_layer": "cutout", "states": [ { "name": "facing", diff --git a/mods/bworld/models/worm_bin.json b/mods/bworld/models/worm_bin.json new file mode 100644 index 0000000..276e6cd --- /dev/null +++ b/mods/bworld/models/worm_bin.json @@ -0,0 +1,330 @@ +{ + "format_version": 1, + "model": { + "id": "bworld:worm_bin", + "textures": { "0": "bworld:worm_bin", "particle": "bworld:worm_bin" }, + "elements": [ + { + "from": [8, 13, 8], + "to": [9, 14, 12], + "rotation": { "origin": [7, 13, 9], "axis": "y", "angle": 90 }, + "faces": { + "north": { "texture": "#0", "uv": [9.25, 11.5, 9.5, 11.75] }, + "east": { "texture": "#0", "uv": [8.5, 11.25, 9.5, 11.5] }, + "south": { "texture": "#0", "uv": [9.5, 11.5, 9.75, 11.75] }, + "west": { "texture": "#0", "uv": [9.5, 11.25, 10.5, 11.5] }, + "top": { "texture": "#0", "uv": [4.5, 5.5, 4.75, 6.5] }, + "bottom": { "texture": "#0", "uv": [4.75, 5.5, 5, 6.5] } + } + }, + { + "from": [9, 12, 7], + "to": [10, 13, 8], + "faces": { + "north": { "texture": "#0", "uv": [9.75, 11.5, 10, 11.75] }, + "east": { "texture": "#0", "uv": [10, 11.5, 10.25, 11.75] }, + "south": { "texture": "#0", "uv": [10.25, 11.5, 10.5, 11.75] }, + "west": { "texture": "#0", "uv": [11, 11.5, 11.25, 11.75] }, + "top": { "texture": "#0", "uv": [11.25, 11.5, 11.5, 11.75] }, + "bottom": { "texture": "#0", "uv": [11.5, 11.5, 11.75, 11.75] } + } + }, + { + "from": [6, 12, 7], + "to": [7, 13, 8], + "faces": { + "north": { "texture": "#0", "uv": [2, 11.75, 2.25, 12] }, + "east": { "texture": "#0", "uv": [2.25, 11.75, 2.5, 12] }, + "south": { "texture": "#0", "uv": [2.5, 11.75, 2.75, 12] }, + "west": { "texture": "#0", "uv": [2.75, 11.75, 3, 12] }, + "top": { "texture": "#0", "uv": [3, 11.75, 3.25, 12] }, + "bottom": { "texture": "#0", "uv": [3.25, 11.75, 3.5, 12] } + } + }, + { + "from": [3, 11, 3], + "to": [13, 12, 13], + "faces": { + "north": { "texture": "#0", "uv": [11, 3.5, 13.5, 3.75] }, + "east": { "texture": "#0", "uv": [11, 3.75, 13.5, 4] }, + "south": { "texture": "#0", "uv": [11, 4, 13.5, 4.25] }, + "west": { "texture": "#0", "uv": [11, 4.25, 13.5, 4.5] }, + "top": { "texture": "#0", "uv": [5, 5, 7.5, 7.5] }, + "bottom": { "texture": "#0", "uv": [0, 5.5, 2.5, 8] } + } + }, + { + "from": [13, 11, 7], + "to": [21, 12, 8], + "rotation": { "origin": [15, 11, 6], "axis": "y", "angle": -90 }, + "faces": { + "north": { "texture": "#0", "uv": [11, 6.25, 13, 6.5] }, + "east": { "texture": "#0", "uv": [11.75, 3.25, 12, 3.5] }, + "south": { "texture": "#0", "uv": [6.5, 11, 8.5, 11.25] }, + "west": { "texture": "#0", "uv": [3.5, 11.75, 3.75, 12] }, + "top": { "texture": "#0", "uv": [11, 6.5, 13, 6.75] }, + "bottom": { "texture": "#0", "uv": [11, 6.75, 13, 7] } + } + }, + { + "from": [2, 11, 7], + "to": [10, 12, 8], + "rotation": { "origin": [4, 11, 6], "axis": "y", "angle": -90 }, + "faces": { + "north": { "texture": "#0", "uv": [11, 7, 13, 7.25] }, + "east": { "texture": "#0", "uv": [3.75, 11.75, 4, 12] }, + "south": { "texture": "#0", "uv": [11, 7.25, 13, 7.5] }, + "west": { "texture": "#0", "uv": [7.5, 11.75, 7.75, 12] }, + "top": { "texture": "#0", "uv": [11, 7.5, 13, 7.75] }, + "bottom": { "texture": "#0", "uv": [11, 7.75, 13, 8] } + } + }, + { + "from": [4, 11, 13], + "to": [12, 12, 14], + "faces": { + "north": { "texture": "#0", "uv": [11, 8, 13, 8.25] }, + "east": { "texture": "#0", "uv": [7.75, 11.75, 8, 12] }, + "south": { "texture": "#0", "uv": [11, 8.25, 13, 8.5] }, + "west": { "texture": "#0", "uv": [8, 11.75, 8.25, 12] }, + "top": { "texture": "#0", "uv": [8.5, 11, 10.5, 11.25] }, + "bottom": { "texture": "#0", "uv": [11, 8.5, 13, 8.75] } + } + }, + { + "from": [4, 11, 2], + "to": [12, 12, 3], + "faces": { + "north": { "texture": "#0", "uv": [11, 8.75, 13, 9] }, + "east": { "texture": "#0", "uv": [8.25, 11.75, 8.5, 12] }, + "south": { "texture": "#0", "uv": [11, 9, 13, 9.25] }, + "west": { "texture": "#0", "uv": [8.5, 11.75, 8.75, 12] }, + "top": { "texture": "#0", "uv": [11, 9.25, 13, 9.5] }, + "bottom": { "texture": "#0", "uv": [11, 9.5, 13, 9.75] } + } + }, + { + "from": [16, 11, 7], + "to": [20, 12, 8], + "rotation": { "origin": [16, 11, 6], "axis": "y", "angle": -90 }, + "faces": { + "north": { "texture": "#0", "uv": [11, 11.25, 12, 11.5] }, + "east": { "texture": "#0", "uv": [8.75, 11.75, 9, 12] }, + "south": { "texture": "#0", "uv": [11.5, 0, 12.5, 0.25] }, + "west": { "texture": "#0", "uv": [9, 11.75, 9.25, 12] }, + "top": { "texture": "#0", "uv": [11.5, 0.25, 12.5, 0.5] }, + "bottom": { "texture": "#0", "uv": [11.5, 0.5, 12.5, 0.75] } + } + }, + { + "from": [3, 11, 7], + "to": [7, 12, 8], + "rotation": { "origin": [3, 11, 6], "axis": "y", "angle": -90 }, + "faces": { + "north": { "texture": "#0", "uv": [11.5, 0.75, 12.5, 1] }, + "east": { "texture": "#0", "uv": [9.25, 11.75, 9.5, 12] }, + "south": { "texture": "#0", "uv": [11.5, 1, 12.5, 1.25] }, + "west": { "texture": "#0", "uv": [9.5, 11.75, 9.75, 12] }, + "top": { "texture": "#0", "uv": [11.5, 1.25, 12.5, 1.5] }, + "bottom": { "texture": "#0", "uv": [11.5, 1.5, 12.5, 1.75] } + } + }, + { + "from": [6, 11, 14], + "to": [10, 12, 15], + "faces": { + "north": { "texture": "#0", "uv": [11.5, 1.75, 12.5, 2] }, + "east": { "texture": "#0", "uv": [9.75, 11.75, 10, 12] }, + "south": { "texture": "#0", "uv": [2, 11.5, 3, 11.75] }, + "west": { "texture": "#0", "uv": [10, 11.75, 10.25, 12] }, + "top": { "texture": "#0", "uv": [11.5, 2, 12.5, 2.25] }, + "bottom": { "texture": "#0", "uv": [11.5, 2.25, 12.5, 2.5] } + } + }, + { + "from": [6, 11, 1], + "to": [10, 12, 2], + "faces": { + "north": { "texture": "#0", "uv": [11.5, 2.5, 12.5, 2.75] }, + "east": { "texture": "#0", "uv": [10.25, 11.75, 10.5, 12] }, + "south": { "texture": "#0", "uv": [11.5, 2.75, 12.5, 3] }, + "west": { "texture": "#0", "uv": [10.5, 11.75, 10.75, 12] }, + "top": { "texture": "#0", "uv": [3, 11.5, 4, 11.75] }, + "bottom": { "texture": "#0", "uv": [11.5, 3, 12.5, 3.25] } + } + }, + { + "from": [3, 0, 3], + "to": [13, 11, 13], + "faces": { + "north": { "texture": "#0", "uv": [0, 0, 2.5, 2.75] }, + "east": { "texture": "#0", "uv": [2.5, 0, 5, 2.75] }, + "south": { "texture": "#0", "uv": [0, 2.75, 2.5, 5.5] }, + "west": { "texture": "#0", "uv": [2.5, 2.75, 5, 5.5] }, + "top": { "texture": "#0", "uv": [5, 0, 7.5, 2.5] }, + "bottom": { "texture": "#0", "uv": [5, 2.5, 7.5, 5] } + } + }, + { + "from": [4, 0, 2], + "to": [12, 11, 3], + "faces": { + "north": { "texture": "#0", "uv": [2.5, 5.5, 4.5, 8.25] }, + "east": { "texture": "#0", "uv": [6, 10.25, 6.25, 13] }, + "south": { "texture": "#0", "uv": [7.5, 0, 9.5, 2.75] }, + "west": { "texture": "#0", "uv": [6.25, 10.25, 6.5, 13] }, + "top": { "texture": "#0", "uv": [2, 11, 4, 11.25] }, + "bottom": { "texture": "#0", "uv": [11, 4.5, 13, 4.75] } + } + }, + { + "from": [13, 0, 7], + "to": [21, 11, 8], + "rotation": { "origin": [15, 0, 6], "axis": "y", "angle": -90 }, + "faces": { + "north": { "texture": "#0", "uv": [7.5, 2.75, 9.5, 5.5] }, + "east": { "texture": "#0", "uv": [10.5, 3.5, 10.75, 6.25] }, + "south": { "texture": "#0", "uv": [4.5, 7.5, 6.5, 10.25] }, + "west": { "texture": "#0", "uv": [10.5, 6.25, 10.75, 9] }, + "top": { "texture": "#0", "uv": [11, 4.75, 13, 5] }, + "bottom": { "texture": "#0", "uv": [11, 5, 13, 5.25] } + } + }, + { + "from": [16, 0, 7], + "to": [20, 11, 8], + "rotation": { "origin": [16, 0, 6], "axis": "y", "angle": -90 }, + "faces": { + "north": { "texture": "#0", "uv": [8.5, 8.25, 9.5, 11] }, + "east": { "texture": "#0", "uv": [10.5, 9, 10.75, 11.75] }, + "south": { "texture": "#0", "uv": [9.5, 0, 10.5, 2.75] }, + "west": { "texture": "#0", "uv": [0, 10.75, 0.25, 13.5] }, + "top": { "texture": "#0", "uv": [11, 10.25, 12, 10.5] }, + "bottom": { "texture": "#0", "uv": [11, 10.5, 12, 10.75] } + } + }, + { + "from": [2, 0, 7], + "to": [10, 11, 8], + "rotation": { "origin": [4, 0, 6], "axis": "y", "angle": -90 }, + "faces": { + "north": { "texture": "#0", "uv": [7.5, 5.5, 9.5, 8.25] }, + "east": { "texture": "#0", "uv": [0.25, 10.75, 0.5, 13.5] }, + "south": { "texture": "#0", "uv": [0, 8, 2, 10.75] }, + "west": { "texture": "#0", "uv": [0.5, 10.75, 0.75, 13.5] }, + "top": { "texture": "#0", "uv": [11, 5.25, 13, 5.5] }, + "bottom": { "texture": "#0", "uv": [11, 5.5, 13, 5.75] } + } + }, + { + "from": [3, 0, 7], + "to": [7, 11, 8], + "rotation": { "origin": [3, 0, 6], "axis": "y", "angle": -90 }, + "faces": { + "north": { "texture": "#0", "uv": [9.5, 2.75, 10.5, 5.5] }, + "east": { "texture": "#0", "uv": [0.75, 10.75, 1, 13.5] }, + "south": { "texture": "#0", "uv": [9.5, 5.5, 10.5, 8.25] }, + "west": { "texture": "#0", "uv": [1, 10.75, 1.25, 13.5] }, + "top": { "texture": "#0", "uv": [11, 10.75, 12, 11] }, + "bottom": { "texture": "#0", "uv": [11, 11, 12, 11.25] } + } + }, + { + "from": [6, 0, 1], + "to": [10, 11, 2], + "faces": { + "north": { "texture": "#0", "uv": [9.5, 8.25, 10.5, 11] }, + "east": { "texture": "#0", "uv": [1.25, 10.75, 1.5, 13.5] }, + "south": { "texture": "#0", "uv": [4, 10.25, 5, 13] }, + "west": { "texture": "#0", "uv": [1.5, 10.75, 1.75, 13.5] }, + "top": { "texture": "#0", "uv": [2, 11.25, 3, 11.5] }, + "bottom": { "texture": "#0", "uv": [3, 11.25, 4, 11.5] } + } + }, + { + "from": [6, 0, 14], + "to": [10, 11, 15], + "faces": { + "north": { "texture": "#0", "uv": [5, 10.25, 6, 13] }, + "east": { "texture": "#0", "uv": [1.75, 10.75, 2, 13.5] }, + "south": { "texture": "#0", "uv": [10.5, 0, 11.5, 2.75] }, + "west": { "texture": "#0", "uv": [10.75, 3.5, 11, 6.25] }, + "top": { "texture": "#0", "uv": [6.5, 11.25, 7.5, 11.5] }, + "bottom": { "texture": "#0", "uv": [7.5, 11.25, 8.5, 11.5] } + } + }, + { + "from": [4, 0, 13], + "to": [12, 11, 14], + "faces": { + "north": { "texture": "#0", "uv": [2, 8.25, 4, 11] }, + "east": { "texture": "#0", "uv": [10.75, 6.25, 11, 9] }, + "south": { "texture": "#0", "uv": [6.5, 8.25, 8.5, 11] }, + "west": { "texture": "#0", "uv": [10.75, 9, 11, 11.75] }, + "top": { "texture": "#0", "uv": [11, 5.75, 13, 6] }, + "bottom": { "texture": "#0", "uv": [11, 6, 13, 6.25] } + } + }, + { + "from": [5, 9, 14], + "to": [6, 12, 15], + "faces": { + "north": { "texture": "#0", "uv": [4, 8.25, 4.25, 9] }, + "east": { "texture": "#0", "uv": [4.25, 8.25, 4.5, 9] }, + "south": { "texture": "#0", "uv": [4, 9, 4.25, 9.75] }, + "west": { "texture": "#0", "uv": [4.25, 9, 4.5, 9.75] }, + "top": { "texture": "#0", "uv": [8.25, 11.5, 8.5, 11.75] }, + "bottom": { "texture": "#0", "uv": [8.5, 11.5, 8.75, 11.75] } + } + }, + { + "from": [10, 9, 14], + "to": [11, 12, 15], + "faces": { + "north": { "texture": "#0", "uv": [6.5, 11.5, 6.75, 12.25] }, + "east": { "texture": "#0", "uv": [6.75, 11.5, 7, 12.25] }, + "south": { "texture": "#0", "uv": [7, 11.5, 7.25, 12.25] }, + "west": { "texture": "#0", "uv": [7.25, 11.5, 7.5, 12.25] }, + "top": { "texture": "#0", "uv": [8.75, 11.5, 9, 11.75] }, + "bottom": { "texture": "#0", "uv": [9, 11.5, 9.25, 11.75] } + } + }, + { + "from": [6, 4, 0], + "to": [10, 7, 1], + "faces": { + "north": { "texture": "#0", "uv": [6.5, 7.5, 7.5, 8.25] }, + "east": { "texture": "#0", "uv": [4.5, 6.5, 4.75, 7.25] }, + "south": { "texture": "#0", "uv": [10.5, 2.75, 11.5, 3.5] }, + "west": { "texture": "#0", "uv": [4.75, 6.5, 5, 7.25] }, + "top": { "texture": "#0", "uv": [11, 9.75, 12, 10] }, + "bottom": { "texture": "#0", "uv": [11, 10, 12, 10.25] } + } + }, + { + "from": [9, 7, 0], + "to": [10, 8, 1], + "faces": { + "north": { "texture": "#0", "uv": [4.5, 7.25, 4.75, 7.5] }, + "east": { "texture": "#0", "uv": [4.75, 7.25, 5, 7.5] }, + "south": { "texture": "#0", "uv": [2, 8, 2.25, 8.25] }, + "west": { "texture": "#0", "uv": [2.25, 8, 2.5, 8.25] }, + "top": { "texture": "#0", "uv": [4, 9.75, 4.25, 10] }, + "bottom": { "texture": "#0", "uv": [4.25, 9.75, 4.5, 10] } + } + }, + { + "from": [6, 7, 0], + "to": [7, 8, 1], + "faces": { + "north": { "texture": "#0", "uv": [4, 10, 4.25, 10.25] }, + "east": { "texture": "#0", "uv": [4.25, 10, 4.5, 10.25] }, + "south": { "texture": "#0", "uv": [11.5, 3.25, 11.75, 3.5] }, + "west": { "texture": "#0", "uv": [7.5, 11.5, 7.75, 11.75] }, + "top": { "texture": "#0", "uv": [7.75, 11.5, 8, 11.75] }, + "bottom": { "texture": "#0", "uv": [8, 11.5, 8.25, 11.75] } + } + } + ] + } +} diff --git a/mods/bworld/textures/worm_bin.png b/mods/bworld/textures/worm_bin.png new file mode 100644 index 0000000000000000000000000000000000000000..bf532f8f20f9f2a8c312e691f6bb93fac96b2d02 GIT binary patch literal 4542 zcmV;v5kc;WP)q_*3}v0d5ntCeKyNl_Hv`+m;M?oPjN$fcIMB9|gpZ5?>X zvomw&&bjxVd+s^kId{w#&%Efq@a7BdGp{`3KKb1*yHEb@9DU{Qo^+pi`Dyq0*S}7B z-c>!3?w|U>*KXDOF6;f{)9#6Xf8KrJjS~yybv~UspZJdx?#Xvgx-Y){qWj#Bo^5Fd zt2|7@G+_Eo_yRsGc^E*=sllzfa9xo2Ghdk{s8wpH+9azwU)uST;b$lK4-wfLh5>(< zAHir4{;;1VtNS-O8gF14L?a8g=Ayy@*;xlp-sY(JPXScRRk+SA0f3iojn8WQsrRmt zQHQQgpXqUOIRomO&XsZncFsnnRPmmz=Et;ij>n`bCLBy76L)^r4WB^`sB)G`Rs}T* zr?H+HFyZeGAP@=QZXKmW0e04cG*)eOsvXlxmSLwYR5{ztOf_&{$fTNukRQ*XJX@Tr z$608sEA=!fBz3N_ypz}C?~G#l!*LWT2!Ggz=(ZT5_e2rd5=C@4w(6!#sgDLPwQA-f zHLFSO?JA}|you>^lPJy>xM~_y#Q+T6>V2o|;BFm>3)7gnFooH3Q?RM_*I&Ja%decn z#F-4!&a$py2*m(>2$!y2i(+E1=zyduX z_=3L0j5RX4Jhxi&mPuhc3#VYUEEONuXQ(%faDVsW_d9s!xn53^09lRw>Dv=Wd~d%; zefP#!-IDq6OUH5e*$1)dk*)OQ{zZ&}Tz4CfZN=W-If6sa9`nxeU4t-)9#v6mGSnAB z|NcR2|J7aIbCs`z`VS27y#c86;h}C1L&&xD?;k*Xe}4;$&BwN3 GzTdnLyB|MD z%b!B(&=$ZNlX$fs}+i^$Jzy{x zf+kOdTZaZ@B}>STW>B6fK^@c@yj25UAmlJsC=w+WX7Y`Xmc1@b7g3lja==AT_!6ds zD`Z+ulw017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=@&ht^MdfFz9`DrljTWFCM_~=l86Z@4|aF6B+_Q$_n|r zsA1hfC}SMpwGd^DsjldzJ}-Nua*?#Jt1pZ$PEMFcuX`}+?IKA)3yeE-VY+ffR4=-J zT4c*ZWa6z1kaBUlUJJ>(E5_LR=uQtZZ+&P76wqkNY495kZ(&w=3$`D>*Hi5SU%DR$ zzjhP{zj_pVo;ZZz<9o2>q3w+NiVL=2E&XYJ*VI0}ItdtXnDR0i3xJ13)m7xi%QgR- z%nr3oy|WIi5W*=KP!mx1`o zTZnFV{nSJE)y@OFuzMxrUFE_|}8pGO)(O z+Z>(xXaf2$LA)G>tU41F!!QhdbowoP@JFxV{Xcva=fC*|6q0T{I*i?4JdEv+@AaxK z_fzH$kVU}LTt}Wmr1Eo*$Gv2V?nQ^caU45eco6%(^uXNtP^KfZ0004JNkl?@hfRA1n}}Yo}1r$s>y?toL8JMQT`dn!B*y ze(c+AXCT8wMu8~PW7zN`9(6kP`BMvnQrYQW{_92eDibxl-myzh0CIy1>Oa2>o!dxXaK+eXWutOx?U^aPQ7p1^u78FResjWl~H8SBIenfX%xH&QFp5+S$gqZ zJ%_vdruV6=z=u>dBiKnJrzUL*Lo=uAwNNjOmkiiic-+l*%?y(a<#drVpGTgtx|N;# zLQ57`2CQA9CYy9L-|IK*yn?E&v%-Pb6e*eTj7(f1#*Z<$nT&HHm^8%e>_G#qv znE*bGv)0Kzf2IMQl;)?A*Jm2=X`HoA_W3gn=%h6NFL)=LI3~& literal 0 HcmV?d00001 diff --git a/mods/bworld/textures/worm_bin_front.png b/mods/bworld/textures/worm_bin_front.png deleted file mode 100644 index ab5a1c77675c64c223c1944821417841d71bb6c7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 300 zcmV+{0n`48P) zJqp4=6ofxR%2kLKf*8;!+gMl$fz%$rQ+Os16cB6`Az&4-Q_)foE#k&xcjMncn%Ots zBg3nWXY$Td-LTKM>P?3LxB&IGz>nnDVSwZ2Ky%c>(H}1RQ~uec`vw4@(eY?>yvpqg za@-tDz`J1aT|u0BTUZCf?Ts`}NaKWXd#haH0!D#poIoV;$^7NhE6yp1^K1LM@(zma zUe{-1(B_o@|EM`?WgX}m%qQ#?E5p;nKpAk^pYn3_fK4J0IBA>!pN~f^uwJ5qdupzwH}gEM#oD;onQB*ub>_FCxTFydp4U&lQD`G?)@ z%@)apJA-i_fXO^TvRiGMc$CHzSq?yy#u(XXsmrSMJ)Dl3_aeMf>SPzKO_)jZn z7w?YpNx)ttiM9GksL1li3fe_oRxP1d4vkDm5&3|0v%~=CHT3nC;#MF^V*svY8B2E{ S9Mii100001w5fXj(ui=;?VEKaE)WK!rYbjd|XugQyW$>v_nBsl0$#Ly-LO3+}MwbUV= zn0S)fzSH4+&-;Eqt>M^Svq4w4H^uw;?op}hbzoVaFCPH32c3c`2epP{do2qR-lX=R zQ@llApzUIooahSxviB@sVOw)qGDNR4m&g3u9boRx05~0;{T@*&jS^n(p8zn-yvuTt z0nocX=iub1VCU{k4G2A70cCLL`B+Z%UkNZwLF~Q}9`9BD_v01D<)N~c60lrk^hOtr z6DR>`lvH5Lv43vhD>twl`~L}=z&fQ-g7)RdTft4z0D{SMXJas#5_&$G+)svdAA&}c ttd$$;kRQn~1! { "item/shiny_ingot": { parent: "gears:item/ingot" }, "block/tilted": { ...GEAR, - elements: [{ ...GEAR.elements[0], rotation: { angle: 30, axis: "x", origin: [8, 8, 8] } }], + elements: [{ ...GEAR.elements[0], rotation: { angle: 200, axis: "x", origin: [8, 8, 8] } }], }, // these two would both be gears:block_a_b "block/a/b": GEAR, @@ -125,7 +125,7 @@ Deno.test("models that can't be converted are reported, not written", () => { "gears:item/shiny_ingot", ]); const errors = Object.fromEntries(report.errors.map(({ location, problems }) => [location, problems.join(" ")])); - assertStringIncludes(errors["gears:block/tilted"], "30"); + assertStringIncludes(errors["gears:block/tilted"], "200"); assertStringIncludes(errors["gears:block/a_b"] ?? errors["gears:block/a/b"], "--remap"); assertEquals(report.written.length, 1); }); @@ -361,3 +361,45 @@ Deno.test("locations the remaps skip are left out of every kind, and blocks draw // it would be drawn with a model that isn't there assertEquals(JSON.parse(Deno.readTextFileSync(`${output}/gear_stand.json`)).block.model, "bworld:cube"); }); + +// a blockbench export outside any mod's resources, next to a folder that's a bworld mod +function loose_model(json: unknown) { + const dir = Deno.makeTempDirSync(); + Deno.writeTextFileSync(`${dir}/thing.json`, JSON.stringify(json)); + const mod = Deno.makeTempDirSync(); + Deno.writeTextFileSync(`${mod}/manifest.json`, JSON.stringify({ format_version: 1, id: "tinker" })); + return { file: `${dir}/thing.json`, output: `${mod}/models/thing.json` }; +} + +Deno.test("a loose model is the mod's its output goes in, and so are its bare texture names", () => { + const { file, output } = loose_model({ textures: { "0": "thing" }, elements: GEAR.elements }); + assertThrows(() => import_models(file), Error, "--namespace"); + const report = import_models(file, { output }); + assertEquals(report.errors, []); + const model = JSON.parse(Deno.readTextFileSync(output)).model; + assertEquals(model.id, "tinker:thing"); + assertEquals(model.textures, { "0": "tinker:thing" }); +}); + +Deno.test("blockbench's newer rotations become bworld's, at any angle around one axis", () => { + const element = (rotation: unknown) => ({ ...GEAR.elements[0], rotation }); + const { file, output } = loose_model({ + textures: { "0": "thing" }, + elements: [ + element({ x: 0, y: 90, z: 0, origin: [7, 13, 9] }), + element({ x: 0, y: 0, z: 0, origin: [8, 8, 8] }), + element({ angle: 0, axis: "y", origin: [8, 8, 8] }), + ], + }); + import_models(file, { output }); + const model = JSON.parse(Deno.readTextFileSync(output)).model; + assertEquals(validate_model(model), []); + assertEquals(model.elements[0].rotation, { origin: [7, 13, 9], axis: "y", angle: 90 }); + // turning by nothing isn't a rotation + assertEquals(model.elements[1].rotation, undefined); + assertEquals(model.elements[2].rotation, undefined); + + const { file: tilted } = loose_model({ elements: [element({ x: 45, y: 90, z: 0, origin: [8, 8, 8] })] }); + const report = import_models(tilted, { namespace: "tinker" }); + assertStringIncludes(report.errors[0].problems[0], "x and y"); +}); diff --git a/tools/importer.ts b/tools/importer.ts index a7e7a82..18ffd53 100644 --- a/tools/importer.ts +++ b/tools/importer.ts @@ -30,7 +30,8 @@ kinds: options: --output PATH the file (for one input file) or the folder to write. one model without it is printed --namespace NS the namespace, when the input isn't inside assets//, or the only one to take from a - folder with several + folder with several. a file outside assets/ is otherwise the mod's that --output is in, and its + bare names (a texture "gear") are that mod's too, the way blockbench exports them --parents FOLDER another folder to follow parent models through, like another mod's resources. can be repeated --remap FILE json that renames locations before they become ids, longest match first, and leaves out locations that match a "skip" pattern: diff --git a/tools/importer/blocks.ts b/tools/importer/blocks.ts index e184622..515f0e1 100644 --- a/tools/importer/blocks.ts +++ b/tools/importer/blocks.ts @@ -76,7 +76,7 @@ const CUBES = [ export function import_blocks(input: string, options: ImportOptions = {}): ImportReport { if (options.output === undefined) throw new Error("--output is needed for blocks"); const remaps = options.remaps ?? DEFAULT_REMAPS; - const files = input_files(input, "blockstates", ".json", options.namespace); + const files = input_files(input, "blockstates", ".json", options.namespace, options.output); // models say how a block is drawn (a full cube or not, cutout or translucent) and whether it has an item const read = model_source(models_near(input, files.map(({ root }) => root), options)); const report = empty_report(); diff --git a/tools/importer/items.ts b/tools/importer/items.ts index f6e037a..6e1d946 100644 --- a/tools/importer/items.ts +++ b/tools/importer/items.ts @@ -31,7 +31,7 @@ export function import_items(input: string, options: ImportOptions = {}): Import if (options.output === undefined) throw new Error("--output is needed for items"); const remaps = options.remaps ?? DEFAULT_REMAPS; // an item is a model directly in models/item, the folders under it are parts of models - const files = input_files(input, "models", ".json", options.namespace) + const files = input_files(input, "models", ".json", options.namespace, options.output) .filter(({ root, file }) => /^item\/[^/]+$/.test(location_of(root, file, ".json").path)); const roots = [...new Set(files.map(({ root }) => root))]; const read = model_source(models_near(input, roots, options)); diff --git a/tools/importer/models.ts b/tools/importer/models.ts index 6c96617..89d6b79 100644 --- a/tools/importer/models.ts +++ b/tools/importer/models.ts @@ -44,7 +44,6 @@ const FACE_NAMES: Record = { west: "west", east: "east", }; -const ANGLES = [-45, -22.5, 0, 22.5, 45]; // item models that are a flat sprite or drawn by code, not boxes, and so is anything that has one as a parent const NOT_BOXES: Record = { @@ -74,7 +73,7 @@ export function import_models(input: string, options: ImportOptions = {}): Impor const remaps = options.remaps ?? DEFAULT_REMAPS; const single = is_file(input); if (!single && options.output === undefined) throw new Error("--output is needed to convert a folder"); - const files = input_files(input, "models", ".json", options.namespace); + const files = input_files(input, "models", ".json", options.namespace, options.output); const read = model_source([ ...new Set(files.map(({ root }) => root)), ...(options.parents ?? []).flatMap((dir) => find_roots(dir, "models")), @@ -87,7 +86,8 @@ export function import_models(input: string, options: ImportOptions = {}): Impor const where = location_of(root, file, ".json"); const location = location_string(where); if (skips(location, remaps, report)) continue; - const result = convert_model(location, read, remaps); + // a loose file's bare texture names are its own, like blockbench writes them + const result = convert_model(location, read, remaps, root.loose ? root.namespace : "minecraft"); if (result.kind === "skipped") report.skipped.push({ location, reason: result.reason }); else if (result.kind === "error") report.errors.push({ location, problems: result.problems }); else if (claim(result.id, location)) { @@ -124,7 +124,8 @@ export function model_source(roots: ResourceRoot[]): ModelSource { }; } -export function convert_model(location: string, read: ModelSource, remaps: Remaps): ModelResult { +// bare is the namespace of textures named without one +export function convert_model(location: string, read: ModelSource, remaps: Remaps, bare = "minecraft"): ModelResult { const json = read(location_string(parse_location(location))); if (!json) return { kind: "error", problems: [`${location} wasn't found`] }; const made = made_by(location, read); @@ -137,7 +138,7 @@ export function convert_model(location: string, read: ModelSource, remaps: Remap } const texture = (value: string, where: string) => { if (value.startsWith("#")) return value; - const id = to_id(value, remaps.textures); + const id = to_id(value, remaps.textures, bare); if (!is_valid_id(id)) problems.push(`${where}: "${value}" doesn't make a valid texture id (${id})`); return id; }; @@ -208,16 +209,28 @@ function convert_element( }; const out = { from: point("from"), to: point("to") } as ModelElementJson; + // { axis, angle }, or blockbench's newer { x, y, z } with a turn around each const rotation = element.rotation as Record | undefined; - if (rotation && rotation.angle !== 0) { - if (!ANGLES.includes(rotation.angle as number)) { - problems.push(`${where}.rotation: an angle of ${rotation.angle} isn't one of ${ANGLES.join(", ")}`); + const turns = rotation === undefined + ? [] + : typeof rotation.axis === "string" + ? [[rotation.axis, rotation.angle]] + : ["x", "y", "z"].map((axis) => [axis, rotation[axis] ?? 0]); + const turned = turns.filter(([, angle]) => angle !== 0); + if (turned.length > 1) { + problems.push( + `${where}.rotation turns around ${turned.map(([axis]) => axis).join(" and ")} at once, bworld only one`, + ); + } else if (turned.length === 1) { + const [[axis, angle]] = turned; + if (typeof angle !== "number" || Math.abs(angle) > 180) { + problems.push(`${where}.rotation: ${angle} isn't an angle from -180 to 180`); } out.rotation = { - origin: rotation.origin as [number, number, number], - axis: rotation.axis as "x" | "y" | "z", - angle: rotation.angle as number, - ...(rotation.rescale === true ? { rescale: true } : {}), + origin: rotation!.origin as [number, number, number], + axis: axis as "x" | "y" | "z", + angle: angle as number, + ...(rotation!.rescale === true ? { rescale: true } : {}), }; } if (element.shade === false) out.shade = false; diff --git a/tools/importer/resources.ts b/tools/importer/resources.ts index 195fdde..ccdbc87 100644 --- a/tools/importer/resources.ts +++ b/tools/importer/resources.ts @@ -12,10 +12,11 @@ export interface Location { path: string; } -export function parse_location(value: string): Location { +// bare is the namespace of a location written without one: minecraft's, in a mod's resources +export function parse_location(value: string, bare = "minecraft"): Location { const colon = value.indexOf(":"); return colon < 0 - ? { namespace: "minecraft", path: value } + ? { namespace: bare, path: value } : { namespace: value.slice(0, colon), path: value.slice(colon + 1) }; } @@ -53,8 +54,8 @@ function template_remaps(): Remap { ); } -export function remap_location(location: string, remap: Remap = {}): Location { - const full = location_string(parse_location(location)); +export function remap_location(location: string, remap: Remap = {}, bare = "minecraft"): Location { + const full = location_string(parse_location(location, bare)); for (const from of Object.keys(remap).sort((a, b) => b.length - a.length)) { const prefix = from.endsWith("/") || from.endsWith(":"); if (prefix ? full.startsWith(from) : full === from) { @@ -64,8 +65,8 @@ export function remap_location(location: string, remap: Remap = {}): Location { return parse_location(full); } -export function to_id(location: string, remap: Remap = {}): string { - const { namespace, path } = remap_location(location, remap); +export function to_id(location: string, remap: Remap = {}, bare = "minecraft"): string { + const { namespace, path } = remap_location(location, remap, bare); return `${namespace}:${path.replaceAll("/", "_")}`; } @@ -77,6 +78,9 @@ export function is_valid_id(id: string): boolean { export interface ResourceRoot { namespace: string; dir: string; + // not in a mod's assets/ but a loose folder, like blockbench's exports. what it names without a namespace is its + // own, not minecraft's: a texture "gear" next to a model is that model's texture + loose?: boolean; } // the roots of a kind inside a folder: every assets// under it (only namespace's, when it's given), or @@ -93,7 +97,7 @@ export function find_roots(input: string, kind: string, namespace?: string): Res } } } - if (roots.length === 0) return namespace ? [{ namespace, dir }] : []; + if (roots.length === 0) return namespace ? [{ namespace, dir, loose: true }] : []; return namespace ? roots.filter((root) => root.namespace === namespace) : roots; } @@ -103,12 +107,21 @@ export interface InputFile { file: string; } -// what to convert: one file, or every file with the extension in a folder's roots of a kind -export function input_files(input: string, kind: string, extension: string, namespace?: string): InputFile[] { +// what to convert: one file, or every file with the extension in a folder's roots of a kind. a file outside any +// assets/ folder is the namespace's, or the mod's that output is in +export function input_files( + input: string, + kind: string, + extension: string, + namespace?: string, + output?: string, +): InputFile[] { if (is_file(input)) { - const root = enclosing_root(input, kind) ?? (namespace && { namespace, dir: dirname(resolve(input)) }); - if (!root) throw new Error(`can't tell ${input}'s namespace: pass --namespace`); - return [{ root, file: resolve(input) }]; + const enclosing = enclosing_root(input, kind); + if (enclosing) return [{ root: enclosing, file: resolve(input) }]; + const loose = namespace ?? (output && mod_namespace(output)); + if (!loose) throw new Error(`can't tell ${input}'s namespace: pass --namespace, or an --output in a mod`); + return [{ root: { namespace: loose, dir: dirname(resolve(input)), loose: true }, file: resolve(input) }]; } const roots = find_roots(input, kind, namespace); if (roots.length === 0) { @@ -169,6 +182,16 @@ function read_dir(dir: string): Deno.DirEntry[] { } } +// the id of the mod a path is in, from the manifest.json of the nearest folder up that has one +export function mod_namespace(path: string): string | undefined { + for (let dir = dirname(resolve(path)); dir !== dirname(dir); dir = dirname(dir)) { + if (!is_file(`${dir}/manifest.json`)) continue; + const id = JSON.parse(Deno.readTextFileSync(`${dir}/manifest.json`)).id; + return typeof id === "string" ? id : undefined; + } + return undefined; +} + export function is_file(path: string): boolean { try { return Deno.statSync(path).isFile; diff --git a/tools/importer/textures.ts b/tools/importer/textures.ts index 636e15f..c88f198 100644 --- a/tools/importer/textures.ts +++ b/tools/importer/textures.ts @@ -60,7 +60,7 @@ export function import_textures(input: string, options: ImportOptions = {}): Imp const single = is_file(input); const report = empty_report(); const claim = id_claims(report); - const files = input_files(input, "textures", ".png", options.namespace); + const files = input_files(input, "textures", ".png", options.namespace, options.output); // a texture gets its namespace from the mod it's in, so two namespaces' textures can't share one folder const namespaces = [...new Set(files.map(({ root }) => root.namespace))].filter((ns) => ns !== "minecraft"); if (namespaces.length > 1) {