Undergarden mod !

This commit is contained in:
2026-09-30 17:30:14 -03:00
parent cbc9edfd60
commit 0052faa24d
21 changed files with 545 additions and 46 deletions
+27 -4
View File
@@ -1,10 +1,20 @@
// the kinds of entity mods define in entities/<name>.json (see EntityJson): animals that wander around, panic when hurt
// and look at players now and then, like minecraft's simpler animals, and scripted ones that stay where scripts put them
// and look at players now and then, like minecraft's simpler animals, monsters that go after players, and scripted
// ones that stay where scripts put them
import type { EntityJson } from "$/common/mod_data.ts";
import { ATTRIBUTES, type AttributeType } from "./attributes.ts";
import { Entity } from "./entity.ts";
import type { EntityFactory } from "./entity_types.ts";
import { FloatGoal, LookAtPlayerGoal, PanicGoal, RandomLookAroundGoal, RandomStrollGoal } from "./goals.ts";
import {
FloatGoal,
HurtByTargetGoal,
LookAtPlayerGoal,
MeleeAttackGoal,
NearestAttackablePlayerGoal,
PanicGoal,
RandomLookAroundGoal,
RandomStrollGoal,
} from "./goals.ts";
import { Mob } from "./mob.ts";
// the entity's class. the attributes are read while LivingEntity is being built, before any field of a subclass is
@@ -14,6 +24,8 @@ export function mod_entity_factory(json: EntityJson): EntityFactory {
return (level) => new ScriptedEntity(level, json);
}
const monster = json.behavior === "monster";
class ModEntity extends Mob {
readonly type = json.id;
override width = json.width;
@@ -27,10 +39,21 @@ export function mod_entity_factory(json: EntityJson): EntityFactory {
[ATTRIBUTES.movement_speed, json.movement_speed ?? 0.25],
[ATTRIBUTES.physical_shielding, json.physical_shielding ?? 0],
[ATTRIBUTES.arcane_shielding, json.arcane_shielding ?? 0],
[ATTRIBUTES.attack_damage, json.attack_damage ?? 2],
];
}
override register_goals() {
if (monster) {
// like undergarden's rotspawn and minecraft's zombies
this.goals.add_goal(0, new FloatGoal(this));
this.goals.add_goal(1, new MeleeAttackGoal(this, 1.25));
this.goals.add_goal(2, new RandomStrollGoal(this, 0.6));
this.goals.add_goal(3, new RandomLookAroundGoal(this));
this.target_goals.add_goal(0, new HurtByTargetGoal(this));
this.target_goals.add_goal(1, new NearestAttackablePlayerGoal(this));
return;
}
this.goals.add_goal(0, new FloatGoal(this));
this.goals.add_goal(1, new PanicGoal(this, 1.4));
this.goals.add_goal(5, new RandomStrollGoal(this, 1));
@@ -38,9 +61,9 @@ export function mod_entity_factory(json: EntityJson): EntityFactory {
this.goals.add_goal(7, new RandomLookAroundGoal(this));
}
// animals stay, like minecraft's farm animals
// animals stay, like minecraft's farm animals. monsters go away when no player is near
override remove_when_far_away() {
return false;
return monster;
}
}
return (level) => new ModEntity(level);