From cd1b50774512e09736b78df025163ab9b26bd528 Mon Sep 17 00:00:00 2001 From: KingCol13 <48412633+KingCol13@users.noreply.github.com> Date: Fri, 2 Oct 2020 23:57:17 +0300 Subject: Fix instant mining of blocks not being recognised, tweak anti-cheat (#4938) * Tried to fix a small issue... Ended up rewriting a bunch of god awful, opaque code with no source and no sense. Who names a function GetPlayerRelativeBlockHardness??? It's gone now. We're safe again. * Testing anti-cheat. * Tidy up debug logging. * Remove empty member declaration. * Rewrite GetDigSpeed slightly for better readability. * GetMiningProgressPerTick now returns 1 when instantly mined. Fixed hasily written typo. * Comment style and typo fixes. --- src/ClientHandle.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/ClientHandle.cpp') diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 848190127..e8c684e68 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1301,8 +1301,8 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc m_LastDigBlockZ = a_BlockZ; if ( - (m_Player->IsGameModeCreative()) || // In creative mode, digging is done immediately - cBlockInfo::IsOneHitDig(a_OldBlock) // One-hit blocks get destroyed immediately, too + (m_Player->IsGameModeCreative()) || // In creative mode, digging is done immediately + m_Player->CanInstantlyMine(a_OldBlock) // Sometimes the player is fast enough to instantly mine ) { HandleBlockDigFinished(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_OldBlock, a_OldMeta); @@ -1366,10 +1366,10 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo } } - if (!m_Player->IsGameModeCreative() && !cBlockInfo::IsOneHitDig(a_OldBlock)) + if (!m_Player->IsGameModeCreative() && !m_Player->CanInstantlyMine(a_OldBlock)) { - // Fix for very fast tools. - m_BreakProgress += m_Player->GetPlayerRelativeBlockHardness(a_OldBlock); + m_BreakProgress += m_Player->GetMiningProgressPerTick(a_OldBlock); + // Check for very fast tools. Maybe instead of FASTBREAK_PERCENTAGE we should check we are within x multiplied by the progress per tick if (m_BreakProgress < FASTBREAK_PERCENTAGE) { LOGD("Break progress of player %s was less than expected: %f < %f\n", m_Player->GetName().c_str(), m_BreakProgress * 100, FASTBREAK_PERCENTAGE * 100); @@ -1410,7 +1410,7 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo World->DigBlock(absPos); } - // Damage the tool: + // Damage the tool, but not for 0 hardness blocks: auto dlAction = cBlockInfo::IsOneHitDig(a_OldBlock) ? cItemHandler::dlaBreakBlockInstant : cItemHandler::dlaBreakBlock; m_Player->UseEquippedItem(dlAction); @@ -2120,7 +2120,7 @@ void cClientHandle::Tick(float a_Dt) if (m_HasStartedDigging) { BLOCKTYPE Block = m_Player->GetWorld()->GetBlock(m_LastDigBlockX, m_LastDigBlockY, m_LastDigBlockZ); - m_BreakProgress += m_Player->GetPlayerRelativeBlockHardness(Block); + m_BreakProgress += m_Player->GetMiningProgressPerTick(Block); } ProcessProtocolInOut(); -- cgit v1.2.3