pocketmine\level\Level::doTick PHP Method

doTick() public method

Changes to this function won't be recorded on the version.
public doTick ( integer $currentTick ) : boolean
$currentTick integer
return boolean
    public function doTick(int $currentTick)
    {
        $this->timings->doTick->startTiming();
        $this->checkTime();
        if (++$this->sendTimeTicker === 280) {
            $this->sendTime();
            $this->sendTimeTicker = 0;
        }
        $this->weather->calcWeather($currentTick);
        $this->unloadChunks();
        //Do block updates
        $this->timings->doTickPending->startTiming();
        if ($this->updateQueue->count() > 0 and $this->updateQueue->current()["priority"] <= $currentTick) {
            $block = $this->getBlock($this->updateQueue->extract()["data"]);
            unset($this->updateQueueIndex[Level::blockHash($block->x, $block->y, $block->z)]);
            $block->onUpdate(self::BLOCK_UPDATE_SCHEDULED);
        }
        $this->timings->doTickPending->stopTiming();
        $this->timings->entityTick->startTiming();
        //Update entities that need update
        Timings::$tickEntityTimer->startTiming();
        foreach ($this->updateEntities as $id => $entity) {
            if ($entity->closed or !$entity->onUpdate($currentTick)) {
                unset($this->updateEntities[$id]);
            }
        }
        Timings::$tickEntityTimer->stopTiming();
        $this->timings->entityTick->stopTiming();
        $this->timings->tileEntityTick->startTiming();
        Timings::$tickTileEntityTimer->startTiming();
        //Update tiles that need update
        if (count($this->updateTiles) > 0) {
            foreach ($this->updateTiles as $id => $tile) {
                if ($tile->onUpdate() !== true) {
                    unset($this->updateTiles[$id]);
                }
            }
        }
        Timings::$tickTileEntityTimer->stopTiming();
        $this->timings->tileEntityTick->stopTiming();
        $this->timings->doTickTiles->startTiming();
        if ($currentTick % 2 === 0) {
            $this->tickChunks();
        }
        $this->timings->doTickTiles->stopTiming();
        if (count($this->changedBlocks) > 0) {
            if (count($this->players) > 0) {
                foreach ($this->changedBlocks as $index => $blocks) {
                    unset($this->chunkCache[$index]);
                    Level::getXZ($index, $chunkX, $chunkZ);
                    if (count($blocks) > 512) {
                        $chunk = $this->getChunk($chunkX, $chunkZ);
                        foreach ($this->getChunkPlayers($chunkX, $chunkZ) as $p) {
                            $p->onChunkChanged($chunk);
                        }
                    } else {
                        $this->sendBlocks($this->getChunkPlayers($chunkX, $chunkZ), $blocks, UpdateBlockPacket::FLAG_ALL);
                    }
                }
            } else {
                $this->chunkCache = [];
            }
            $this->changedBlocks = [];
        }
        $this->processChunkRequest();
        if ($this->sleepTicks > 0 and --$this->sleepTicks <= 0) {
            $this->checkSleep();
        }
        foreach ($this->moveToSend as $index => $entry) {
            Level::getXZ($index, $chunkX, $chunkZ);
            foreach ($entry as $e) {
                $this->addChunkPacket($chunkX, $chunkZ, $e);
            }
        }
        $this->moveToSend = [];
        foreach ($this->motionToSend as $index => $entry) {
            Level::getXZ($index, $chunkX, $chunkZ);
            $pk = new SetEntityMotionPacket();
            $pk->entities = $entry;
            $this->addChunkPacket($chunkX, $chunkZ, $pk);
        }
        $this->motionToSend = [];
        foreach ($this->chunkPackets as $index => $entries) {
            Level::getXZ($index, $chunkX, $chunkZ);
            $chunkPlayers = $this->getChunkPlayers($chunkX, $chunkZ);
            if (count($chunkPlayers) > 0) {
                foreach ($entries as $pk) {
                    Server::broadcastPacket($chunkPlayers, $pk);
                }
            }
        }
        $this->chunkPackets = [];
        $this->timings->doTick->stopTiming();
    }
Level