Start working on entities
This commit is contained in:
+14
-2
@@ -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>;
|
||||
|
||||
Reference in New Issue
Block a user