Start working on entities

This commit is contained in:
2026-11-21 10:53:33 -03:00
parent 65865033c1
commit 60a7cae86e
7 changed files with 150 additions and 11 deletions
+14 -2
View File
@@ -430,8 +430,14 @@ const entity_schema = z.object({
texture: id,
// "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
behavior: z.enum(["animal", "monster", "scripted"]).optional(),
// 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
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"',
).optional(),
// what natural spawning counts it as, see entity_category
category: z.enum(["monster", "creature"]).optional(),
// its collision box in blocks, width is for both x and z
width: z.number().positive().max(16),
height: z.number().positive().max(16),
@@ -449,6 +455,12 @@ const entity_schema = z.object({
export type EntityJson = z.infer<typeof entity_schema>;
// like minecraft's MobCategory: monsters can spawn on their own and go away when no player is near, creatures stay.
// monster behavior makes one a monster unless it says otherwise
export function entity_category(json: EntityJson): "monster" | "creature" {
return json.category ?? (json.behavior === "monster" ? "monster" : "creature");
}
// like minecraft's MobEffectCategory, "neutral" when not set
const effect_category = z.enum(["beneficial", "harmful", "neutral"]);
export type EffectCategory = z.infer<typeof effect_category>;