Skip to content

Commit

Permalink
add pmmp#5581
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshy3282 committed Oct 2, 2024
1 parent 2369880 commit 8ef2b86
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Additions
> https://github.com/pmmp/PocketMine-MP/pull/5467
> https://github.com/pmmp/PocketMine-MP/pull/5497
> https://github.com/pmmp/PocketMine-MP/pull/5502
> https://github.com/pmmp/PocketMine-MP/pull/5581

## What is this?
Expand Down
29 changes: 25 additions & 4 deletions src/player/SurvivalBlockBreakHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use pocketmine\block\Block;
use pocketmine\entity\animation\ArmSwingAnimation;
use pocketmine\entity\effect\VanillaEffects;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelEventPacket;
Expand Down Expand Up @@ -65,11 +66,31 @@ private function calculateBreakProgressPerTick() : float{
if(!$this->block->getBreakInfo()->isBreakable()){
return 0.0;
}
//TODO: improve this to take stuff like swimming, ladders, enchanted tools into account, fix wrong tool break time calculations for bad tools (pmmp/PocketMine-MP#211)
$breakTimePerTick = $this->block->getBreakInfo()->getBreakTime($this->player->getInventory()->getItemInHand()) * 20;
// todo maybe add a setting that turns this off or uses the legacy simple version.
$breakTimeSeconds = $this->block->getBreakInfo()->getBreakTime($this->player->getInventory()->getItemInHand());

if($breakTimePerTick > 0){
return 1 / $breakTimePerTick;
if($this->player->isUnderwater()){
$breakTimeSeconds *= 5;
}
if(!$this->player->isFlying() && $this->player->getInAirTicks() > 0){
$breakTimeSeconds *= 5;
}
if($this->player->canClimb() && $this->player->getWorld()->getBlock($this->player->getPosition())->canClimb()){
$breakTimeSeconds *= 5;
}

$effects = $this->player->getEffects();
if(($miningFatigue = $effects->get(VanillaEffects::MINING_FATIGUE())) !== null){
$breakTimeSeconds *= 4.75 ** $miningFatigue->getEffectLevel();
}
if(($haste = $effects->get(VanillaEffects::HASTE())) !== null){
$breakTimeSeconds -= $breakTimeSeconds * 0.2 * min($haste->getEffectLevel(), 5);
}

$breakTimeTicks = $breakTimeSeconds * 20;

if($breakTimeTicks > 0){
return 1 / $breakTimeTicks;
}
return 1;
}
Expand Down

0 comments on commit 8ef2b86

Please sign in to comment.