mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-15 16:05:28 +00:00
Improve block break progress
closes #6500 This fixes break time animations for mining fatigue and haste, and improves the underwater and on-ground behaviour. on-ground is still not quite right for reasons not related to this PR (see #6547). I'm also not quite sure the underwater logic is correct (in water vs underwater?) but it's definitely better than what we have currently.
This commit is contained in:
parent
88937f1785
commit
0a9a45a126
@ -25,6 +25,8 @@ namespace pocketmine\player;
|
|||||||
|
|
||||||
use pocketmine\block\Block;
|
use pocketmine\block\Block;
|
||||||
use pocketmine\entity\animation\ArmSwingAnimation;
|
use pocketmine\entity\animation\ArmSwingAnimation;
|
||||||
|
use pocketmine\entity\effect\VanillaEffects;
|
||||||
|
use pocketmine\item\enchantment\VanillaEnchantments;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\network\mcpe\protocol\LevelEventPacket;
|
use pocketmine\network\mcpe\protocol\LevelEventPacket;
|
||||||
@ -65,11 +67,29 @@ final class SurvivalBlockBreakHandler{
|
|||||||
if(!$this->block->getBreakInfo()->isBreakable()){
|
if(!$this->block->getBreakInfo()->isBreakable()){
|
||||||
return 0.0;
|
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;
|
$breakTimePerTick = $this->block->getBreakInfo()->getBreakTime($this->player->getInventory()->getItemInHand()) * 20;
|
||||||
|
if(!$this->player->isOnGround() && !$this->player->isFlying()){
|
||||||
|
$breakTimePerTick *= 5;
|
||||||
|
}
|
||||||
|
if($this->player->isUnderwater() && !$this->player->getArmorInventory()->getHelmet()->hasEnchantment(VanillaEnchantments::AQUA_AFFINITY())){
|
||||||
|
$breakTimePerTick *= 5;
|
||||||
|
}
|
||||||
if($breakTimePerTick > 0){
|
if($breakTimePerTick > 0){
|
||||||
return 1 / $breakTimePerTick;
|
$progressPerTick = 1 / $breakTimePerTick;
|
||||||
|
|
||||||
|
$haste = $this->player->getEffects()->get(VanillaEffects::HASTE());
|
||||||
|
if($haste !== null){
|
||||||
|
$hasteLevel = $haste->getEffectLevel();
|
||||||
|
$progressPerTick *= (1 + 0.2 * $hasteLevel) * (1.2 ** $hasteLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
$miningFatigue = $this->player->getEffects()->get(VanillaEffects::MINING_FATIGUE());
|
||||||
|
if($miningFatigue !== null){
|
||||||
|
$miningFatigueLevel = $miningFatigue->getEffectLevel();
|
||||||
|
$progressPerTick *= 0.21 ** $miningFatigueLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $progressPerTick;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -82,7 +102,10 @@ final class SurvivalBlockBreakHandler{
|
|||||||
$newBreakSpeed = $this->calculateBreakProgressPerTick();
|
$newBreakSpeed = $this->calculateBreakProgressPerTick();
|
||||||
if(abs($newBreakSpeed - $this->breakSpeed) > 0.0001){
|
if(abs($newBreakSpeed - $this->breakSpeed) > 0.0001){
|
||||||
$this->breakSpeed = $newBreakSpeed;
|
$this->breakSpeed = $newBreakSpeed;
|
||||||
//TODO: sync with client
|
$this->player->getWorld()->broadcastPacketToViewers(
|
||||||
|
$this->blockPos,
|
||||||
|
LevelEventPacket::create(LevelEvent::BLOCK_BREAK_SPEED, (int) (65535 * $this->breakSpeed), $this->blockPos)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->breakProgress += $this->breakSpeed;
|
$this->breakProgress += $this->breakSpeed;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user