Skip to content

Commit

Permalink
fix breaking block in ladder
Browse files Browse the repository at this point in the history
  • Loading branch information
dexdurable committed Mar 20, 2020
1 parent ce9b0dc commit 6a28588
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/pocketmine/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/pocketmine/level/Level.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 6a28588

Please sign in to comment.