Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
Improved block breaking time and event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
shoghicp committed Dec 22, 2014
1 parent a677bcb commit 6cb88af
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/pocketmine/level/Level.php
Original file line number Diff line number Diff line change
Expand Up @@ -1208,16 +1208,10 @@ public function useBreakOn(Vector3 $vector, Item &$item = null, Player $player =
if($player instanceof Player){
$ev = new BlockBreakEvent($player, $target, $item, ($player->getGamemode() & 0x01) === 1 ? true : false);

$lastTime = $player->lastBreak - 0.1; //TODO: replace with true lag
if(($player->getGamemode() & 0x01) > 0){
$ev->setInstaBreak(true);
}elseif(($lastTime + $target->getBreakTime($item)) >= microtime(true)){
if($item instanceof Item and !$target->isBreakable($item)){
$ev->setCancelled();
}

if($item instanceof Item and !$target->isBreakable($item) and $ev->getInstaBreak() === false){
$ev->setCancelled();
}
if(!$player->isOp() and ($distance = $this->server->getConfigInt("spawn-protection", 16)) > -1){
$t = new Vector2($target->x, $target->z);
$s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z);
Expand All @@ -1230,8 +1224,13 @@ public function useBreakOn(Vector3 $vector, Item &$item = null, Player $player =
return false;
}

$player->lastBreak = microtime(true);
$breakTime = $player->isCreative() ? 0.15 : $target->getBreakTime($item);

if(!$ev->getInstaBreak() and ($player->lastBreak + $breakTime) >= microtime(true)){
return false;
}

$player->lastBreak = microtime(true);
}elseif($item instanceof Item and !$target->isBreakable($item)){
return false;
}
Expand Down

0 comments on commit 6cb88af

Please sign in to comment.