Make players mobs too !

This commit is contained in:
2026-09-30 10:42:52 -03:00
parent 65f27d6099
commit 4fbcca6851
23 changed files with 314 additions and 132 deletions
+3 -7
View File
@@ -1,7 +1,7 @@
// living entities with a mind of their own, like minecraft's Mob: goals decide what to do (see goals.ts) and
// controls turn that into walking, looking and jumping. they can despawn, pick up items and be kept near a home
import { ATTRIBUTES, type AttributeType } from "./attributes.ts";
import { type DamageSource, Entity, finite, type PlayerTarget } from "./entity.ts";
import { type DamageSource, Entity, finite } from "./entity.ts";
import { GoalSelector } from "./goals.ts";
import { ItemEntity } from "./item_entity.ts";
import { EQUIPMENT_SLOTS, type EquipmentSlot, LivingEntity, type SavedLivingEntity } from "./living_entity.ts";
@@ -56,7 +56,7 @@ export abstract class Mob extends LivingEntity {
goals = new GoalSelector();
target_goals = new GoalSelector();
// who it's after, set by target goals
target: LivingEntity | PlayerTarget | undefined;
target: LivingEntity | undefined;
move_control = new MoveControl(this);
look_control = new LookControl(this);
@@ -165,13 +165,9 @@ export abstract class Mob extends LivingEntity {
// fighting
// hits whoever it's attacking with its attack damage, like minecraft's doHurtTarget. returns whether it hurt them
do_hurt_target(target: Entity | PlayerTarget): boolean {
do_hurt_target(target: Entity): boolean {
const damage = this.attribute(ATTRIBUTES.attack_damage);
const source = { cause: "mob_attack", attacker: this, type: "physical" } as const;
if (!(target instanceof Entity)) {
this.level.damage_player(target.id, damage, source);
return true;
}
if (!(target instanceof LivingEntity)) return false;
if (!target.hurt(damage, source)) return false;
const knockback = this.attribute(ATTRIBUTES.attack_knockback);