From 617cebe2e024b034e16fe5e91362f6533934f7dd Mon Sep 17 00:00:00 2001 From: Holly Date: Sun, 5 Nov 2023 13:30:17 +0000 Subject: [PATCH] Prevent fall damage if in water --- server/entities/Entity.ts | 3 +-- server/entities/EntityLiving.ts | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/server/entities/Entity.ts b/server/entities/Entity.ts index b02a755..8e88db9 100644 --- a/server/entities/Entity.ts +++ b/server/entities/Entity.ts @@ -187,8 +187,7 @@ export class Entity implements IEntity { updateFalling(distance:number) { if (this.onGround) { - if (this.fallDistance > 0) - { + if (this.fallDistance > 0) { this.fall(this.fallDistance); this.fallDistance = 0; } diff --git a/server/entities/EntityLiving.ts b/server/entities/EntityLiving.ts index 4fb163b..29995a5 100644 --- a/server/entities/EntityLiving.ts +++ b/server/entities/EntityLiving.ts @@ -21,9 +21,11 @@ export class EntityLiving extends Entity { public constructor(world:World) { super(world); - this.fallDistance = this.timeInWater = 0; + this.timeInWater = 0; this.headHeight = 1.62; + this.fallDistance = Number.MIN_VALUE; + this.lastHealth = this.health; } @@ -41,8 +43,8 @@ export class EntityLiving extends Entity { } } - isInWater() { - return this.world.getChunkBlockId(this.chunk, this.position.x, this.position.y + this.headHeight, this.position.z) === Block.waterStill.blockId; + isInWater(fromHead:boolean) { + return this.world.getChunkBlockId(this.chunk, this.position.x, this.position.y + (fromHead ? this.headHeight : 0), this.position.z) === Block.waterStill.blockId; } fall(distance:number) { @@ -55,12 +57,8 @@ export class EntityLiving extends Entity { onTick() { super.onTick(); - if (!this.onGround) { - this.fallDistance - } - // Drowning - if (this.isInWater()) { + if (this.isInWater(true)) { if (this.timeInWater == Number.MIN_SAFE_INTEGER) { this.timeInWater = 320; } @@ -71,5 +69,9 @@ export class EntityLiving extends Entity { } else { this.timeInWater = Number.MIN_SAFE_INTEGER; } + + if (this.isInWater(false)) { + this.fallDistance = 0; + } } } \ No newline at end of file