Skip to content

Commit 6a28588

Browse files
committed
fix breaking block in ladder
1 parent ce9b0dc commit 6a28588

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/pocketmine/Player.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,7 +1931,7 @@ public function handleDataPacket(DataPacket $packet){
19311931
$this->actionsNum['CRACK_BLOCK'] = 0;
19321932
if (!$this->isCreative()) {
19331933
$block = $this->level->getBlock(new Vector3($packet->x, $packet->y, $packet->z));
1934-
$breakTime = ceil($block->getBreakTime($this->inventory->getItemInHand()) * 20);
1934+
$breakTime = ceil($this->getBreakTime($block) * 20);
19351935
$fireBlock = $block->getSide($packet->face);
19361936
if ($fireBlock->getId() === Block::FIRE) {
19371937
$fireBlock->onUpdate(Level::BLOCK_UPDATE_TOUCH);
@@ -4344,7 +4344,7 @@ protected function crackBlock($packet) {
43444344
$isNeedSendPackets = $this->actionsNum['CRACK_BLOCK'] % 4 == 0;
43454345
$this->actionsNum['CRACK_BLOCK']++;
43464346

4347-
$breakTime = ceil($block->getBreakTime($this->inventory->getItemInHand()) * 20);
4347+
$breakTime = ceil($this->getBreakTime($block) * 20);
43484348
if ($this->actionsNum['CRACK_BLOCK'] >= $breakTime) {
43494349
$this->breakBlock($blockPos);
43504350
}
@@ -4364,6 +4364,17 @@ protected function crackBlock($packet) {
43644364
}
43654365
}
43664366

4367+
public function getBreakTime(Block $block, Item $item = null) {
4368+
$item = $item??$this->inventory->getItemInHand();
4369+
$breakTime = $block->getBreakTime($item);
4370+
$blockUnderPlayer = $this->level->getBlock(new Vector3(floor($this->x), floor($this->y) - 1, floor($this->z)));
4371+
4372+
if ($blockUnderPlayer->getId() == Block::LADDER || $blockUnderPlayer->getId() == Block::VINE || !$this->onGround) {
4373+
$breakTime *= 5;
4374+
}
4375+
return $breakTime;
4376+
}
4377+
43674378
/**
43684379
* @minprotocol 120
43694380
* @param SimpleTransactionData[] $transactionsData

src/pocketmine/level/Level.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ public function useBreakOn(Vector3 $vector, Item &$item = null, Player $player =
12051205
}
12061206
}
12071207

1208-
$breakTime = $player->isCreative() ? 0.15 : $target->getBreakTime($item);
1208+
$breakTime = $player->isCreative() ? 0.15 : $player->getBreakTime($target, $item);
12091209
if (!$ev->getInstaBreak() && ($player->lastBreak + $breakTime) >= microtime(true)) {
12101210
return false;
12111211
}

0 commit comments

Comments
 (0)