Move effects out of cubi
This commit is contained in:
@@ -31,9 +31,6 @@ const SWIM_UP = 0.04;
|
||||
// a jump can't start more often than this while jump is held
|
||||
const JUMP_DELAY = 10;
|
||||
const KNOCKBACK = 0.4;
|
||||
// the base game's effects that work where what they change happens, like minecraft's: in damage and air
|
||||
const RESISTANCE = "bworld:resistance";
|
||||
const WATER_BREATHING = "bworld:water_breathing";
|
||||
|
||||
export interface SavedLivingEntity extends SavedEntity {
|
||||
health?: number;
|
||||
@@ -141,7 +138,7 @@ export abstract class LivingEntity extends Entity {
|
||||
override base_tick() {
|
||||
super.base_tick();
|
||||
if (this.alive) {
|
||||
if (this.eyes_in_water && !this.can_breathe_underwater && !this.has_effect(WATER_BREATHING)) {
|
||||
if (this.eyes_in_water && !this.can_breathe_underwater) {
|
||||
this.air -= 1;
|
||||
if (this.air <= -20) {
|
||||
this.air = 0;
|
||||
@@ -270,11 +267,14 @@ export abstract class LivingEntity extends Entity {
|
||||
|
||||
// health
|
||||
|
||||
// like minecraft's LivingEntity.hurt. returns whether it was hurt
|
||||
// like minecraft's LivingEntity.hurt. mods can change or cancel it first. returns whether it was hurt
|
||||
override hurt(amount: number, source: DamageSource): boolean {
|
||||
if (this.is_invulnerable_to(source) || this.dead || !(amount > 0)) {
|
||||
return false;
|
||||
}
|
||||
amount = this.level.before_hurt(this, amount, source);
|
||||
if (!(amount > 0)) return false;
|
||||
const taken = amount;
|
||||
let fresh = true;
|
||||
if (this.#hurt_cooldown > HURT_COOLDOWN / 2) {
|
||||
if (amount <= this.#last_hurt_amount) return false;
|
||||
@@ -306,24 +306,20 @@ export abstract class LivingEntity extends Entity {
|
||||
}
|
||||
}
|
||||
this.on_hurt(source);
|
||||
this.level.after_hurt(this, taken, source);
|
||||
if (this.dead) {
|
||||
this.die(source);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// after resistance
|
||||
// after mods and the hurt cooldown
|
||||
actually_hurt(amount: number, source: DamageSource) {
|
||||
// absolute damage, take it and theres no counterplay
|
||||
if (source.type === "absolute") {
|
||||
this.health -= amount;
|
||||
return;
|
||||
}
|
||||
|
||||
const resistance = this.get_effect(RESISTANCE);
|
||||
if (resistance && !source.bypasses_invulnerability) {
|
||||
amount = Math.max(0, amount * (25 - (resistance.amplifier + 1) * 5) / 25);
|
||||
}
|
||||
const shielding = this.attribute(
|
||||
source.type === "physical" ? ATTRIBUTES.physical_shielding : ATTRIBUTES.arcane_shielding,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user