Engine entity work

This commit is contained in:
2026-11-21 11:07:22 -03:00
parent e1c2b13d1f
commit edce5bac29
5 changed files with 277 additions and 12 deletions
+11 -2
View File
@@ -21,13 +21,18 @@ import {
import { Mob, type MobCategory } from "./mob.ts";
// the entity's class. the attributes are read while LivingEntity is being built, before any field of a subclass is
// set, so each kind gets its own class that has its json already
export function mod_entity_factory(json: EntityJson): EntityFactory {
// set, so each kind gets its own class that has its json already. behaviors are mods' (see ctx.entities), looked up
// when a mob first thinks, after every script has registered its own
export function mod_entity_factory(
json: EntityJson,
behaviors: ReadonlyMap<string, (mob: Mob) => void>,
): EntityFactory {
if (json.behavior === "scripted") {
return (level) => new ScriptedEntity(level, json);
}
const monster = json.behavior === "monster";
const behavior = json.behavior?.includes(":") ? json.behavior : undefined;
const category = entity_category(json);
class ModEntity extends Mob {
@@ -52,6 +57,10 @@ export function mod_entity_factory(json: EntityJson): EntityFactory {
}
override register_goals() {
if (behavior) {
behaviors.get(behavior)!(this);
return;
}
if (monster) {
// like undergarden's rotspawn and minecraft's zombies
this.goals.add_goal(0, new FloatGoal(this));