Scrap !!
This commit is contained in:
+21
-6
@@ -368,6 +368,8 @@ export interface ItemJson {
|
||||
data_textures?: Record<string, string>;
|
||||
// see ItemRegistry.model
|
||||
model?: string;
|
||||
// see ItemRegistry.entity
|
||||
entity?: string;
|
||||
// tier and speed default to 0 and 2
|
||||
tool?: Omit<ToolProperties, "tier" | "speed"> & Partial<ToolProperties>;
|
||||
places?: string;
|
||||
@@ -390,6 +392,7 @@ const item_schema: z.ZodType<ItemJson> = z.object({
|
||||
texture: id.optional(),
|
||||
data_textures: z.record(z.string(), id).optional(),
|
||||
model: id.optional(),
|
||||
entity: id.optional(),
|
||||
tool: z.object({
|
||||
type: z.string(),
|
||||
durability: z.int().min(1),
|
||||
@@ -429,19 +432,24 @@ const item_schema: z.ZodType<ItemJson> = z.object({
|
||||
components: json_object.optional(),
|
||||
});
|
||||
|
||||
// a kind of entity, drawn with an entity model and one texture, or without a model as its texture facing the camera
|
||||
const ENTITY_BEHAVIORS = ["animal", "monster", "scripted", "object"];
|
||||
|
||||
// a kind of entity, drawn with an entity model and one texture, or without a model as its texture facing the camera.
|
||||
// an object without a model is drawn as the item it holds
|
||||
const entity_schema = z.object({
|
||||
id,
|
||||
// an entity model, see EntityModelJson
|
||||
model: id.optional(),
|
||||
texture: id,
|
||||
// only an object can go without one
|
||||
texture: id.optional(),
|
||||
// "animal" (the default) wanders around, panics when hurt and looks at players. "monster" goes after players it
|
||||
// sees and whoever hurts it, and despawns far from players, like minecraft's zombies. "scripted" stays where
|
||||
// scripts put it: no gravity, ai or health, and it isn't saved with the world, like the fishing hook. any other id
|
||||
// is a behavior a mod's script registers
|
||||
// scripts put it: no gravity, ai or health, and it isn't saved with the world, like the fishing hook. "object" lies
|
||||
// around like a dropped item, holding one, without ai or health (see ItemRegistry.entity). any other id is a
|
||||
// behavior a mod's script registers
|
||||
behavior: z.custom<string>(
|
||||
(value) => ["animal", "monster", "scripted"].includes(value as string) || id.safeParse(value).success,
|
||||
'must be "animal", "monster", "scripted" or a behavior id like "my_mod:thing"',
|
||||
(value) => ENTITY_BEHAVIORS.includes(value as string) || id.safeParse(value).success,
|
||||
'must be "animal", "monster", "scripted", "object" or a behavior id like "my_mod:thing"',
|
||||
).optional(),
|
||||
// what natural spawning counts it as, see entity_category
|
||||
category: z.enum(["monster", "creature"]).optional(),
|
||||
@@ -465,6 +473,11 @@ const entity_schema = z.object({
|
||||
loot_table: loot_table_id.optional(),
|
||||
// what it sounds like: <sounds>/hurt, /death, /step and /ambient, see ENTITY_SOUNDS
|
||||
sounds: sound_prefix.optional(),
|
||||
// how much bigger it's drawn than its model (or its texture, or its item), 1 when not set. its box stays the same
|
||||
scale: z.number().positive().optional(),
|
||||
}).refine((entity) => entity.texture !== undefined || entity.behavior === "object", {
|
||||
path: ["texture"],
|
||||
message: "is needed unless it's an object",
|
||||
});
|
||||
|
||||
export type EntityJson = z.infer<typeof entity_schema>;
|
||||
@@ -899,6 +912,7 @@ export function item_to_json(id: string, item: ItemRegistry): ItemJson {
|
||||
const json: ItemJson = { id, texture: item.texture_id };
|
||||
if (item.data_textures !== undefined) json.data_textures = item.data_textures;
|
||||
if (item.model !== undefined) json.model = item.model;
|
||||
if (item.entity !== undefined) json.entity = item.entity;
|
||||
if (item.tool !== undefined) json.tool = item.tool;
|
||||
if (item.block_id !== undefined) json.places = item.block_id;
|
||||
if (item.max_stack !== undefined) json.max_stack = item.max_stack;
|
||||
@@ -929,6 +943,7 @@ function item_fields(json: ItemJson): Partial<ItemRegistry> {
|
||||
const item: Partial<ItemRegistry> = {};
|
||||
if (json.data_textures !== undefined) item.data_textures = json.data_textures;
|
||||
if (json.model !== undefined) item.model = json.model;
|
||||
if (json.entity !== undefined) item.entity = json.entity;
|
||||
if (json.tool !== undefined) item.tool = { tier: 0, speed: 2, ...json.tool };
|
||||
if (json.places !== undefined) item.block_id = json.places;
|
||||
if (json.max_stack !== undefined) item.max_stack = json.max_stack;
|
||||
|
||||
Reference in New Issue
Block a user