From 8efe7fcfb0b0f86e86e127b1c0c7b3200f77d196 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 10 May 2020 11:50:31 +0100 Subject: [PATCH] World: allow configuring blocks-per-tick for random updating this makes it much easier to observe and debug stuff that depends on it, such as grass, crop and tree growth, since they'll happen much faster. A future improvement would be to have the update function use a non-global random so that the output can be reproduced using a given seed. --- resources/pocketmine.yml | 3 +++ src/world/World.php | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/resources/pocketmine.yml b/resources/pocketmine.yml index fdbc80f6f7..e218eaf404 100644 --- a/resources/pocketmine.yml +++ b/resources/pocketmine.yml @@ -120,6 +120,9 @@ chunk-ticking: per-tick: 40 #Radius of chunks around a player to tick tick-radius: 3 + #Number of blocks inside ticking areas' subchunks that get ticked every tick. Higher values will accelerate events + #like tree and plant growth, but at a higher performance cost. + blocks-per-subchunk-per-tick: 3 #IDs of blocks not to perform random ticking on. disable-block-ticking: #- 2 # grass diff --git a/src/world/World.php b/src/world/World.php index 054737ce97..4964461907 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -125,6 +125,8 @@ class World implements ChunkManager{ public const DIFFICULTY_NORMAL = 2; public const DIFFICULTY_HARD = 3; + public const DEFAULT_TICKED_BLOCKS_PER_SUBCHUNK_PER_TICK = 3; + /** @var Player[] */ private $players = []; @@ -226,6 +228,8 @@ class World implements ChunkManager{ private $chunkTickRadius; /** @var int */ private $chunksPerTick; + /** @var int */ + private $tickedBlocksPerSubchunkPerTick = self::DEFAULT_TICKED_BLOCKS_PER_SUBCHUNK_PER_TICK; /** @var bool[] */ private $randomTickBlocks = []; @@ -342,6 +346,7 @@ class World implements ChunkManager{ $this->chunkTickRadius = min($this->server->getViewDistance(), max(1, (int) $this->server->getProperty("chunk-ticking.tick-radius", 4))); $this->chunksPerTick = (int) $this->server->getProperty("chunk-ticking.per-tick", 40); + $this->tickedBlocksPerSubchunkPerTick = (int) $this->server->getProperty("chunk-ticking.blocks-per-subchunk-per-tick", self::DEFAULT_TICKED_BLOCKS_PER_SUBCHUNK_PER_TICK); $this->chunkPopulationQueueSize = (int) $this->server->getProperty("chunk-generation.population-queue-size", 2); $dontTickBlocks = array_fill_keys($this->server->getProperty("chunk-ticking.disable-block-ticking", []), true); @@ -910,8 +915,12 @@ class World implements ChunkManager{ foreach($chunk->getSubChunks() as $Y => $subChunk){ if(!$subChunk->isEmptyFast()){ - $k = mt_rand(0, 0xfffffffff); //36 bits - for($i = 0; $i < 3; ++$i){ + $k = 0; + for($i = 0; $i < $this->tickedBlocksPerSubchunkPerTick; ++$i){ + if(($i % 5) === 0){ + //60 bits will be used by 5 blocks (12 bits each) + $k = mt_rand(0, (1 << 60) - 1); + } $x = $k & 0x0f; $y = ($k >> 4) & 0x0f; $z = ($k >> 8) & 0x0f;