Start working on entities
This commit is contained in:
+7
-2
@@ -7,6 +7,7 @@ import {
|
||||
type BlockJson,
|
||||
choice_list,
|
||||
type EffectJson,
|
||||
entity_category,
|
||||
type EntityJson,
|
||||
type EntityModelJson,
|
||||
type FluidJson,
|
||||
@@ -380,6 +381,8 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
if (json.model !== undefined) uses(file, json.model, "entity model");
|
||||
uses(file, json.texture, "texture");
|
||||
if (json.loot_table) uses(file, json.loot_table, "loot table");
|
||||
// scripts register behaviors, the server checks them when it starts
|
||||
if (json.behavior?.includes(":")) check_namespace(file, json.behavior);
|
||||
}
|
||||
for (const { file, json } of mod.loot_tables ?? []) {
|
||||
const refs = loot_references(json);
|
||||
@@ -527,8 +530,10 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
|
||||
check_namespace(file, json.entity);
|
||||
const entity = entity_jsons.get(json.entity);
|
||||
if (!entity) errors.push(`${file}: entity ${json.entity} doesn't exist`);
|
||||
else if (entity.behavior !== "monster") {
|
||||
errors.push(`${file}: ${json.entity} isn't a monster, only monsters spawn on their own for now`);
|
||||
else if (entity_category(entity) !== "monster") {
|
||||
errors.push(
|
||||
`${file}: ${json.entity} isn't in the monster category, only monsters spawn on their own for now`,
|
||||
);
|
||||
}
|
||||
for (const biome of json.biomes ?? []) {
|
||||
check_namespace(file, biome);
|
||||
|
||||
+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