Deprecated CallbackTask, moved sleep checking to level

This commit is contained in:
Shoghi Cervantes
2015-04-25 17:28:30 +02:00
parent 1d8c29add7
commit 7ad98d4659
6 changed files with 84 additions and 71 deletions

View File

@ -203,6 +203,8 @@ class Level implements ChunkManager, Metadatable{
/** @var \SplFixedArray */
private $blockStates;
public $sleepTicks = 0;
private $chunkTickRadius;
private $chunkTickList = [];
private $chunksPerTick;
@ -644,9 +646,35 @@ class Level implements ChunkManager, Metadatable{
$this->processChunkRequest();
if($this->sleepTicks > 0 and --$this->sleepTicks <= 0){
$this->checkSleep();
}
$this->timings->doTick->stopTiming();
}
public function checkSleep(){
$resetTime = true;
foreach($this->getPlayers() as $p){
if(!$p->isSleeping()){
$resetTime = false;
break;
}
}
if($resetTime){
$time = $this->getTime() % Level::TIME_FULL;
if($time >= Level::TIME_NIGHT and $time < Level::TIME_SUNRISE){
$this->setTime($this->getTime() + Level::TIME_FULL - $time);
foreach($this->getPlayers() as $p){
$p->stopSleep();
}
}
}
}
/**
* @param Player[] $target
* @param Block[] $blocks