Health and hunger system
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import {
|
||||
type BlockRegistry,
|
||||
type BlockStateDefinition,
|
||||
type FoodProperties,
|
||||
type ItemRegistry,
|
||||
RENDER_LAYERS,
|
||||
type RenderLayer,
|
||||
@@ -68,6 +69,7 @@ export interface ItemJson {
|
||||
tool?: string;
|
||||
places?: string;
|
||||
max_stack?: number;
|
||||
food?: FoodProperties;
|
||||
name?: string;
|
||||
lore?: string;
|
||||
components?: Record<string, unknown>;
|
||||
@@ -166,6 +168,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.food !== undefined) json.food = item.food;
|
||||
if (item.name !== undefined) json.name = item.name;
|
||||
if (item.lore !== undefined) json.lore = item.lore;
|
||||
if (item.components) json.components = item.components;
|
||||
@@ -177,6 +180,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.food !== undefined) item.food = json.food;
|
||||
if (json.name !== undefined) item.name = json.name;
|
||||
if (json.lore !== undefined) item.lore = json.lore;
|
||||
if (json.components) item.components = json.components;
|
||||
@@ -434,6 +438,20 @@ export function validate_item(json: unknown): Problems {
|
||||
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");
|
||||
}
|
||||
if (json.food !== undefined) {
|
||||
const food = json.food;
|
||||
if (
|
||||
!is_object(food) || !Number.isInteger(food.nutrition) || (food.nutrition as number) < 0 ||
|
||||
typeof food.saturation_modifier !== "number" || food.saturation_modifier < 0
|
||||
) {
|
||||
problems.push("food must be { nutrition, saturation_modifier }, nutrition a whole number");
|
||||
} else {
|
||||
if (food.always_edible !== undefined && typeof food.always_edible !== "boolean") {
|
||||
problems.push("food.always_edible must be true or false");
|
||||
}
|
||||
if (food.returns !== undefined) problems.push(...validate_id(food.returns, "food.returns"));
|
||||
}
|
||||
}
|
||||
return problems;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user