Tooltips
This commit is contained in:
@@ -31,6 +31,7 @@ export interface ManifestJson {
|
||||
|
||||
export interface BlockJson {
|
||||
id: string;
|
||||
name?: string;
|
||||
textures: BlockTextures;
|
||||
model?: string;
|
||||
variants?: Record<string, BlockVariant>;
|
||||
@@ -66,6 +67,7 @@ export interface ItemJson {
|
||||
tool?: string;
|
||||
places?: string;
|
||||
max_stack?: number;
|
||||
name?: string;
|
||||
lore?: string;
|
||||
components?: Record<string, unknown>;
|
||||
}
|
||||
@@ -100,6 +102,7 @@ export interface GridRecipe {
|
||||
|
||||
export function block_to_json(block: BlockRegistry, has_item: boolean): BlockJson {
|
||||
const json: BlockJson = { id: block.id, textures: block.textures };
|
||||
if (block.name !== undefined) json.name = block.name;
|
||||
if (block.model !== undefined) json.model = block.model;
|
||||
if (block.variants !== undefined) json.variants = block.variants;
|
||||
if (block.render_layer && block.render_layer !== "solid") json.render_layer = block.render_layer;
|
||||
@@ -128,6 +131,7 @@ export function block_from_json(json: BlockJson): { block: BlockRegistry; has_it
|
||||
textures: json.textures,
|
||||
has_collision: json.collision ?? true,
|
||||
};
|
||||
if (json.name !== undefined) block.name = json.name;
|
||||
if (json.model !== undefined) block.model = json.model;
|
||||
if (json.variants !== undefined) block.variants = json.variants;
|
||||
const render_layer = json.render_layer ?? (json.transparent ? "translucent" : undefined);
|
||||
@@ -159,6 +163,7 @@ export function item_to_json(id: string, item: ItemRegistry): ItemJson {
|
||||
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;
|
||||
if (item.name !== undefined) json.name = item.name;
|
||||
if (item.lore !== undefined) json.lore = item.lore;
|
||||
if (item.components) json.components = item.components;
|
||||
return json;
|
||||
@@ -169,6 +174,7 @@ export function item_from_json(json: ItemJson): ItemRegistry {
|
||||
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;
|
||||
if (json.name !== undefined) item.name = json.name;
|
||||
if (json.lore !== undefined) item.lore = json.lore;
|
||||
if (json.components) item.components = json.components;
|
||||
return item;
|
||||
@@ -318,6 +324,7 @@ export function validate_block(json: unknown): Problems {
|
||||
problems.push(`${key} must be a whole number from 0 to 15`);
|
||||
}
|
||||
}
|
||||
problems.push(...validate_text(json.name, "name"));
|
||||
for (const key of ["cull_same", "transparent", "collision", "item", "interactive", "replaceable"]) {
|
||||
if (json[key] !== undefined && typeof json[key] !== "boolean") problems.push(`${key} must be true or false`);
|
||||
}
|
||||
@@ -413,6 +420,7 @@ export function validate_item(json: unknown): Problems {
|
||||
const problems = validate_id(json.id, "id");
|
||||
problems.push(...validate_id(json.texture, "texture"));
|
||||
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)) {
|
||||
problems.push("max_stack must be a positive whole number");
|
||||
}
|
||||
@@ -481,6 +489,11 @@ export function validate_ore(json: unknown): Problems {
|
||||
return problems;
|
||||
}
|
||||
|
||||
// optional text players see
|
||||
function validate_text(value: unknown, field: string): Problems {
|
||||
return value === undefined || (typeof value === "string" && value.length > 0) ? [] : [`${field} must be text`];
|
||||
}
|
||||
|
||||
function validate_id(value: unknown, field: string): Problems {
|
||||
return typeof value === "string" && ID_PATTERN.test(value) ? [] : [`${field} must be an id like "my_mod:thing"`];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user