Fishing !

This commit is contained in:
2026-09-28 13:33:40 -03:00
parent 2488c6f8dc
commit 84a622c3f1
27 changed files with 367 additions and 21 deletions
+12
View File
@@ -69,6 +69,8 @@ export interface OreJson {
export interface ItemJson {
id: string;
texture: string;
// data key -> texture, see ItemRegistry.data_textures
data_textures?: Record<string, string>;
tool?: string;
places?: string;
max_stack?: number;
@@ -192,6 +194,7 @@ export function item_to_json(id: string, item: ItemRegistry): ItemJson {
throw new Error(`${id} picks its texture with a function, which json can't hold`);
}
const json: ItemJson = { id, texture: item.texture_id };
if (item.data_textures !== undefined) json.data_textures = item.data_textures;
if (item.tool_type !== undefined) json.tool = item.tool_type;
if (item.block_id !== undefined) json.places = item.block_id;
if (item.max_stack !== undefined) json.max_stack = item.max_stack;
@@ -204,6 +207,7 @@ export function item_to_json(id: string, item: ItemRegistry): ItemJson {
export function item_from_json(json: ItemJson): ItemRegistry {
const item: ItemRegistry = { texture_id: json.texture };
if (json.data_textures !== undefined) item.data_textures = json.data_textures;
if (json.tool !== undefined) item.tool_type = json.tool;
if (json.places !== undefined) item.block_id = json.places;
if (json.max_stack !== undefined) item.max_stack = json.max_stack;
@@ -477,6 +481,14 @@ export function validate_item(json: unknown): Problems {
if (!is_object(json)) return ["item must be an object"];
const problems = validate_id(json.id, "id");
problems.push(...validate_id(json.texture, "texture"));
if (json.data_textures !== undefined) {
if (!is_object(json.data_textures)) problems.push("data_textures must be { data key: texture id }");
else {
for (const [key, id] of Object.entries(json.data_textures)) {
problems.push(...validate_id(id, `data_textures.${key}`));
}
}
}
if (json.places !== undefined) problems.push(...validate_id(json.places, "places"));
problems.push(...validate_text(json.name, "name"), ...validate_text(json.lore, "lore"));
if (json.max_stack !== undefined && (!Number.isInteger(json.max_stack) || (json.max_stack as number) < 1)) {