Fluid containers

This commit is contained in:
2026-10-25 15:02:31 -03:00
parent fc27771a92
commit 26b59a1899
24 changed files with 486 additions and 82 deletions
+10 -7
View File
@@ -3,8 +3,8 @@
// java item models (assets/<namespace>/models/item/*.json) to bworld's items/, for the items that aren't a block's: a
// block's item comes with the block (see blocks.ts). java says an item is a flat sprite with item/generated and its
// layer0 texture, which is what a bworld item is. one java draws in 3D (a wrench) is drawn with its model, which the
// model kind writes, and gets its model's particle texture as its texture
// layer0 texture, which is what a bworld item is, and its layer1 and on are its layers. one java draws in 3D (a wrench)
// is drawn with its model, which the model kind writes, and gets its model's particle texture as its texture
import { join } from "@std/path";
import { FORMAT_VERSION } from "$/common/mod_data.ts";
import { made_by, model_source } from "./models.ts";
@@ -61,10 +61,12 @@ export function import_items(input: string, options: ImportOptions = {}): Import
};
let texture: string | undefined;
let model: string | undefined;
const layers: { texture: string }[] = [];
if (made_by(location, read)?.startsWith("an item sprite")) {
texture = resolve(textures.layer0);
if (textures.layer1 !== undefined) {
report.warnings.push({ location, warning: "only the first layer of sprites with several was kept" });
for (let i = 1; textures[`layer${i}`] !== undefined; i++) {
const layer = resolve(textures[`layer${i}`]);
if (layer !== undefined) layers.push({ texture: to_id(layer, remaps.textures) });
}
} else {
texture = resolve(textures.particle) ?? Object.values(textures).map(resolve).find((t) => t !== undefined);
@@ -81,12 +83,13 @@ export function import_items(input: string, options: ImportOptions = {}): Import
continue;
}
const texture_id = to_id(texture, remaps.textures);
if (!is_valid_id(id) || !is_valid_id(texture_id)) {
report.errors.push({ location, problems: [`its id ${id} or texture ${texture_id} isn't a valid id`] });
if (!is_valid_id(id) || ![texture_id, ...layers.map((layer) => layer.texture)].every(is_valid_id)) {
report.errors.push({ location, problems: [`its id ${id} or one of its textures isn't a valid id`] });
continue;
}
if (!claim(id, location)) continue;
const json = { format_version: FORMAT_VERSION, item: { id, texture: texture_id, ...(model ? { model } : {}) } };
const item = { id, texture: texture_id, ...(model ? { model } : {}), ...(layers.length ? { layers } : {}) };
const json = { format_version: FORMAT_VERSION, item };
report.written.push({
location,
id,