Added basic support back for block-crack animations when breaking blocks

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)
This commit is contained in:
Dylan K. Taylor 2017-05-05 09:40:55 +01:00
parent 56306f6636
commit 702c129a97
2 changed files with 14 additions and 1 deletions

View File

@ -2591,12 +2591,22 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->level->setBlock($block, new Air());
break;
}
if(!$this->isCreative()){
//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)
$breakTime = ceil($target->getBreakTime($this->inventory->getItemInHand()) * 20);
if($breakTime > 0){
$this->level->broadcastLevelEvent($pos, LevelEventPacket::EVENT_BLOCK_START_BREAK, 65535 / $breakTime);
}
}
$this->lastBreak = microtime(true);
break;
/** @noinspection PhpMissingBreakStatementInspection */
case PlayerActionPacket::ACTION_ABORT_BREAK:
$this->lastBreak = PHP_INT_MAX;
break;
case PlayerActionPacket::ACTION_STOP_BREAK:
$this->level->broadcastLevelEvent($pos, LevelEventPacket::EVENT_BLOCK_STOP_BREAK);
break;
case PlayerActionPacket::ACTION_RELEASE_ITEM:
if($this->startAction > -1 and $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION)){

View File

@ -88,6 +88,9 @@ class LevelEventPacket extends DataPacket{
const EVENT_CAULDRON_TAKE_WATER = 3507;
const EVENT_CAULDRON_ADD_DYE = 3508;
const EVENT_BLOCK_START_BREAK = 3600;
const EVENT_BLOCK_STOP_BREAK = 3601;
const EVENT_SET_DATA = 4000;
const EVENT_PLAYERS_SLEEPING = 9800;