Improved block breaking timing, added faster block breaking with swords

This commit is contained in:
Shoghi Cervantes 2015-08-08 00:33:52 +02:00
parent fcba9596d6
commit b3efb733a2
4 changed files with 29 additions and 5 deletions

View File

@ -2087,7 +2087,7 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
switch($packet->action){
case 0: //Start break
if($pos->distanceSquared($this) > 10000){
if($this->lastBreak !== PHP_INT_MAX or $pos->distanceSquared($this) > 10000){
break;
}
$target = $this->level->getBlock($pos);
@ -2099,6 +2099,9 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
}
$this->lastBreak = microtime(true);
break;
case 1: //Abort!
$this->lastBreak = PHP_INT_MAX;
break;
case 5: //Shot arrow
if($this->startAction > -1 and $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION)){
if($this->inventory->getItemInHand()->getId() === Item::BOW) {

View File

@ -796,6 +796,10 @@ class Block extends Position implements Metadatable{
$base *= 3.33;
}
if($item->isSword()){
$base *= 0.5;
}
return $base;
}

View File

@ -60,7 +60,19 @@ abstract class Tool extends Item{
return true;
}
if($this->isHoe()){
if($object instanceof Block){
if(
$object->getToolType() === Tool::TYPE_PICKAXE and $this->isPickaxe() or
$object->getToolType() === Tool::TYPE_SHOVEL and $this->isShovel() or
$object->getToolType() === Tool::TYPE_AXE and $this->isAxe() or
$object->getToolType() === Tool::TYPE_SWORD and $this->isSword() or
$object->getToolType() === Tool::TYPE_SHEARS and $this->isShears()
){
$this->meta++;
}elseif(!$this->isShears() and $object->getBreakTime($this) > 0){
$this->meta += 2;
}
}elseif($this->isHoe()){
if(($object instanceof Block) and ($object->getId() === self::GRASS or $object->getId() === self::DIRT)){
$this->meta++;
}
@ -108,7 +120,7 @@ abstract class Tool extends Item{
public function isUnbreakable(){
$tag = $this->getNamedTagEntry("Unbreakable");
return $tag instanceof Byte and $tag->getValue() > 0;
return $tag !== null and $tag->getValue() > 0;
}
public function isPickaxe(){

View File

@ -1527,7 +1527,12 @@ class Level implements ChunkManager, Metadatable{
return false;
}
$breakTime = $player->isCreative() ? 0.15 : $target->getBreakTime($item);
$breakTime = $target->getBreakTime($item);
if($player->isCreative() and $breakTime > 0.15){
$breakTime = 0.15;
}
if($player->hasEffect(Effect::SWIFTNESS)){
$breakTime *= 1 - (0.2 * ($player->getEffect(Effect::SWIFTNESS)->getAmplifier() + 1));
}
@ -1542,7 +1547,7 @@ class Level implements ChunkManager, Metadatable{
return false;
}
$player->lastBreak = PHP_INT_MAX;
$player->lastBreak = microtime(true);
$drops = $ev->getDrops();