Undergarden mod !
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user