From 949cf78f1cd90ca00a5e1d8dc8f08df737d8c788 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 1 Jul 2017 17:35:06 +1000 Subject: [PATCH] Fix drowning not being accurate time --- MCGalaxy/Player/Player.Fields.cs | 3 ++- MCGalaxy/Player/PlayerPhysics.cs | 24 +++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/MCGalaxy/Player/Player.Fields.cs b/MCGalaxy/Player/Player.Fields.cs index 036bc1816..0fffca15d 100644 --- a/MCGalaxy/Player/Player.Fields.cs +++ b/MCGalaxy/Player/Player.Fields.cs @@ -201,7 +201,8 @@ namespace MCGalaxy { //Movement public int oldIndex = -1, lastWalkthrough = -1, oldFallY = 10000; - public int fallCount = 0, drownCount = 0; + public int fallCount = 0; + public DateTime drownTime = DateTime.MaxValue; //Games public DateTime lastDeath = DateTime.UtcNow; diff --git a/MCGalaxy/Player/PlayerPhysics.cs b/MCGalaxy/Player/PlayerPhysics.cs index c59efd703..1ad4c5d23 100644 --- a/MCGalaxy/Player/PlayerPhysics.cs +++ b/MCGalaxy/Player/PlayerPhysics.cs @@ -73,7 +73,7 @@ namespace MCGalaxy.Blocks.Physics { p.HandleDeath(ExtBlock.Air, null, false, true); p.fallCount = 0; - p.drownCount = 0; + p.drownTime = DateTime.MaxValue; return; } @@ -82,12 +82,16 @@ namespace MCGalaxy.Blocks.Physics { else if (min.Y > p.oldFallY) p.fallCount = 0; // e.g. flying up p.oldFallY = min.Y; - p.drownCount = 0; + p.drownTime = DateTime.MaxValue; } internal static void Drown(Player p, AABB bb) { - Vec3S32 P = bb.Max; - ExtBlock bHead = GetSurvivalBlock(p, (ushort)P.X, (ushort)P.Y, (ushort)P.Z); + // Want to check block at centre of bounding box + bb.Max.X -= (bb.Max.X - bb.Min.X) / 2; + bb.Max.Z -= (bb.Max.Z - bb.Min.Z) / 2; + + Vec3S32 P = bb.BlockMax; + ExtBlock bHead = GetSurvivalBlock(p, P.X, P.Y, P.Z); if (bHead.IsPhysicsType) bHead.BlockID = Block.Convert(bHead.BlockID); switch (bHead.BlockID) { @@ -96,18 +100,20 @@ namespace MCGalaxy.Blocks.Physics { case Block.lava: case Block.lavastill: p.fallCount = 0; - p.drownCount++; + DateTime now = DateTime.UtcNow; + // level drown is in 10ths of a second + if (p.drownTime == DateTime.MaxValue) + p.drownTime = now.AddSeconds(p.level.Config.DrownTime / 10.0); - // level drown is in 10ths of a second, and there are 100 ticks/second - if (p.drownCount > p.level.Config.DrownTime * 10) { + if (now > p.drownTime) { p.HandleDeath((ExtBlock)Block.water); - p.drownCount = 0; + p.drownTime = DateTime.MaxValue; } break; default: bool isGas = p.level.CollideType(bHead) == CollideType.WalkThrough; if (!isGas) p.fallCount = 0; - p.drownCount = 0; + p.drownTime = DateTime.MaxValue; break; } }