diff options
author | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2016-06-02 00:46:24 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2016-06-02 00:46:24 +0200 |
commit | a5ec2d8ca2b319675091a6b93716ec7e0a688422 (patch) | |
tree | b7ec1016b27ed4c358c47251417983413cef878c /src/Entities/Pawn.cpp | |
parent | LuaState: Inter-plugin calls now support simple tables. (#3220) (diff) | |
download | cuberite-a5ec2d8ca2b319675091a6b93716ec7e0a688422.tar cuberite-a5ec2d8ca2b319675091a6b93716ec7e0a688422.tar.gz cuberite-a5ec2d8ca2b319675091a6b93716ec7e0a688422.tar.bz2 cuberite-a5ec2d8ca2b319675091a6b93716ec7e0a688422.tar.lz cuberite-a5ec2d8ca2b319675091a6b93716ec7e0a688422.tar.xz cuberite-a5ec2d8ca2b319675091a6b93716ec7e0a688422.tar.zst cuberite-a5ec2d8ca2b319675091a6b93716ec7e0a688422.zip |
Diffstat (limited to 'src/Entities/Pawn.cpp')
-rw-r--r-- | src/Entities/Pawn.cpp | 53 |
1 files changed, 15 insertions, 38 deletions
diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index 462fa5057..682475409 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -250,24 +250,6 @@ void cPawn::TargetingMe(cMonster * a_Monster) -void cPawn::SetPosition(double a_PosX, double a_PosY, double a_PosZ) -{ - SetPosition({a_PosX, a_PosY, a_PosZ}); -} - - - - - -void cPawn::SetPosition(const Vector3d & a_Position) -{ - super::SetPosition(a_Position); - m_LastGroundHeight = a_Position.y; // Prevent fall damage on teleport -} - - - - void cPawn::HandleFalling(void) { @@ -324,8 +306,8 @@ void cPawn::HandleFalling(void) int x, y, z; } BlockSampleOffsets[] = { - { 0, 0, 0 }, - { 0, -1, 0 }, + { 0, 0, 0 }, // TODO: something went wrong here (offset 0?) + { 0, -1, 0 }, // Potentially causes mis-detection (IsFootInWater) when player stands on block diagonal to water (i.e. on side of pool) }; /* Here's the rough outline of how this mechanism works: @@ -368,12 +350,6 @@ void cPawn::HandleFalling(void) } } - // Update the ground height to have the highest position of the player (i.e. jumping up adds to the eventual fall damage) - if (!OnGround) - { - m_LastGroundHeight = std::max(m_LastGroundHeight, GetPosY()); - } - /* So here's the use of the rules above: */ /* 1. Falling in water absorbs all fall damage */ bool FallDamageAbsorbed = IsFootInWater; @@ -381,17 +357,14 @@ void cPawn::HandleFalling(void) /* 2. Falling in liquid (lava, water, cobweb) or hitting a slime block resets the "fall zenith". Note: Even though the pawn bounces back with no damage after hitting the slime block, the "fall zenith" will continue to increase back up when flying upwards - which is good */ - bool FallDistanceReset = IsFootOnSlimeBlock || IsFootInLiquid; - bool IsFlying = false; bool ShouldBounceOnSlime = true; - if (GetEntityType() == eEntityType::etPlayer) + if (IsPlayer()) { - cPlayer * Player = static_cast<cPlayer *>(this); - IsFlying = Player->IsFlying(); + auto Player = static_cast<cPlayer *>(this); /* 3. If the player is flying or climbing, absorb fall damage */ - FallDamageAbsorbed |= IsFlying || Player->IsClimbing(); + FallDamageAbsorbed |= Player->IsFlying() || Player->IsClimbing(); /* 4. If the player is about to bounce on a slime block and is not crouching, absorb all fall damage */ ShouldBounceOnSlime = !Player->IsCrouched(); @@ -407,10 +380,18 @@ void cPawn::HandleFalling(void) NOTE: this will only work in some cases; should be done in HandlePhysics() */ if (IsFootOnSlimeBlock && ShouldBounceOnSlime) { - SetSpeedY(-GetSpeedY()); + // TODO: doesn't work too well, causes dissatisfactory experience for players on slime blocks - SetSpeedY(-GetSpeedY()); } - if (!IsFlying && OnGround) + // TODO: put player speed into GetSpeedY, and use that. + // If flying, climbing, swimming, or going up... + if (FallDamageAbsorbed || ((GetPosition() - m_LastPosition).y > 0)) + { + // ...update the ground height to have the highest position of the player (i.e. jumping up adds to the eventual fall damage) + m_LastGroundHeight = GetPosY(); + } + + if (OnGround) { auto Damage = static_cast<int>(m_LastGroundHeight - GetPosY() - 3.0); if ((Damage > 0) && !FallDamageAbsorbed) @@ -434,10 +415,6 @@ void cPawn::HandleFalling(void) /* Note: it is currently possible to fall through lava and still die from fall damage because of the client skipping an update about the lava block. This can only be resolved by somehow integrating these above checks into the tracer in HandlePhysics. */ - if (FallDistanceReset) - { - m_LastGroundHeight = GetPosY(); - } } |