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
+34
View File
@@ -293,6 +293,8 @@ export class MeleeAttackGoal extends Goal {
const distance = (target.x - mob.x) ** 2 + (target.y - mob.y) ** 2 + (target.z - mob.z) ** 2;
if (distance <= reach && this.#cooldown === 0) {
this.#cooldown = this.attack_interval;
// clients see its arm swing, hit or not
mob.level.entity_event(mob, "swing");
mob.do_hurt_target(target);
}
}
@@ -331,6 +333,38 @@ export class NearestAttackablePlayerGoal extends Goal {
}
}
// goes after whoever hurt it last, like minecraft's HurtByTargetGoal, for as long as they're within follow_range
export class HurtByTargetGoal extends Goal {
override flags: GoalFlag[] = ["target"];
// the Mob.times_hurt_by_attacker it last went after someone for, so each hit only starts it once
#handled = 0;
constructor(readonly mob: Mob) {
super();
}
can_use() {
const attacker = this.mob.last_attacker;
return this.mob.times_hurt_by_attacker !== this.#handled && attacker !== undefined && is_alive(attacker);
}
override can_continue_to_use() {
const target = this.mob.target;
const mob = this.mob;
return target !== undefined && is_alive(target) &&
Math.hypot(target.x - mob.x, target.y - mob.y, target.z - mob.z) <= mob.attribute(ATTRIBUTES.follow_range);
}
override start() {
this.#handled = this.mob.times_hurt_by_attacker;
this.mob.target = this.mob.last_attacker;
}
override stop() {
this.mob.target = undefined;
}
}
function is_alive(target: LivingEntity) {
return target.alive;
}