From 6a2858818f22a1eaf760249fb85a01f8f8dbb8aa Mon Sep 17 00:00:00 2001 From: dextudio Date: Fri, 20 Mar 2020 18:45:43 +0600 Subject: [PATCH] fix breaking block in ladder --- src/pocketmine/Player.php | 15 +++++++++++++-- src/pocketmine/level/Level.php | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index c6b8f0f2f..d56711e26 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1931,7 +1931,7 @@ public function handleDataPacket(DataPacket $packet){ $this->actionsNum['CRACK_BLOCK'] = 0; if (!$this->isCreative()) { $block = $this->level->getBlock(new Vector3($packet->x, $packet->y, $packet->z)); - $breakTime = ceil($block->getBreakTime($this->inventory->getItemInHand()) * 20); + $breakTime = ceil($this->getBreakTime($block) * 20); $fireBlock = $block->getSide($packet->face); if ($fireBlock->getId() === Block::FIRE) { $fireBlock->onUpdate(Level::BLOCK_UPDATE_TOUCH); @@ -4344,7 +4344,7 @@ protected function crackBlock($packet) { $isNeedSendPackets = $this->actionsNum['CRACK_BLOCK'] % 4 == 0; $this->actionsNum['CRACK_BLOCK']++; - $breakTime = ceil($block->getBreakTime($this->inventory->getItemInHand()) * 20); + $breakTime = ceil($this->getBreakTime($block) * 20); if ($this->actionsNum['CRACK_BLOCK'] >= $breakTime) { $this->breakBlock($blockPos); } @@ -4364,6 +4364,17 @@ protected function crackBlock($packet) { } } + public function getBreakTime(Block $block, Item $item = null) { + $item = $item??$this->inventory->getItemInHand(); + $breakTime = $block->getBreakTime($item); + $blockUnderPlayer = $this->level->getBlock(new Vector3(floor($this->x), floor($this->y) - 1, floor($this->z))); + + if ($blockUnderPlayer->getId() == Block::LADDER || $blockUnderPlayer->getId() == Block::VINE || !$this->onGround) { + $breakTime *= 5; + } + return $breakTime; + } + /** * @minprotocol 120 * @param SimpleTransactionData[] $transactionsData diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 35dbd4bfc..2d3521fc5 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1205,7 +1205,7 @@ public function useBreakOn(Vector3 $vector, Item &$item = null, Player $player = } } - $breakTime = $player->isCreative() ? 0.15 : $target->getBreakTime($item); + $breakTime = $player->isCreative() ? 0.15 : $player->getBreakTime($target, $item); if (!$ev->getInstaBreak() && ($player->lastBreak + $breakTime) >= microtime(true)) { return false; }