From 900f95c42b9b6ff333cc60640c17fb197025e280 Mon Sep 17 00:00:00 2001 From: KingCol13 <48412633+KingCol13@users.noreply.github.com> Date: Tue, 19 Apr 2022 00:05:51 +0100 Subject: Check height is within world for pistons and digging (#5396) * Fixes piston and digging crashes. --- src/Blocks/BlockPiston.cpp | 11 ++++++----- src/Entities/Player.cpp | 10 +++++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Blocks/BlockPiston.cpp b/src/Blocks/BlockPiston.cpp index 31f15a467..afed8bae0 100644 --- a/src/Blocks/BlockPiston.cpp +++ b/src/Blocks/BlockPiston.cpp @@ -215,6 +215,12 @@ bool cBlockPistonHandler::CanPushBlock( Vector3iSet & a_BlocksPushed, const Vector3i & a_PushDir ) { + if (!cChunkDef::IsValidHeight(a_BlockPos.y)) + { + // Can't push a void block. + return false; + } + const static std::array pushingDirs = { { @@ -228,11 +234,6 @@ bool cBlockPistonHandler::CanPushBlock( NIBBLETYPE currMeta; a_World.GetBlockTypeMeta(a_BlockPos, currBlock, currMeta); - if (!cChunkDef::IsValidHeight(a_BlockPos.y)) - { - return !a_RequirePushable; - } - if (currBlock == E_BLOCK_AIR) { // Air can be pushed diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index c2c3b51ea..07460fe98 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -2577,9 +2577,17 @@ float cPlayer::GetLiquidHeightPercent(NIBBLETYPE a_Meta) bool cPlayer::IsInsideWater() { + const auto EyePos = GetEyePosition().Floor(); + + if (!cChunkDef::IsValidHeight(EyePos.y)) + { + // Not in water if in void. + return false; + } + BLOCKTYPE Block; NIBBLETYPE Meta; - m_World->GetBlockTypeMeta(GetEyePosition().Floor(), Block, Meta); + m_World->GetBlockTypeMeta(EyePos, Block, Meta); if ((Block != E_BLOCK_WATER) && (Block != E_BLOCK_STATIONARY_WATER)) { -- cgit v1.2.3