Level: Optimize blockticking coordinate selection

generating 1 large bounded random costs the same as generating 4 small ones, so it makes more sense to do it like this instead.

Note that prior to 7.1 this code would not work due to it not handling 64-bit appropriately.
This commit is contained in:
Dylan K. Taylor 2019-01-25 19:43:16 +00:00
parent 5bf7350ee5
commit c66dc7b273

View File

@ -1089,11 +1089,12 @@ class Level implements ChunkManager, Metadatable{
foreach($chunk->getSubChunks() as $Y => $subChunk){
if(!($subChunk instanceof EmptySubChunk)){
$k = mt_rand(0, 0xfffffffff); //36 bits
for($i = 0; $i < 3; ++$i){
$k = mt_rand(0, 0xfff);
$x = $k & 0x0f;
$y = ($k >> 4) & 0x0f;
$z = ($k >> 8) & 0x0f;
$k >>= 12;
$blockId = $subChunk->getBlockId($x, $y, $z);
if($this->randomTickBlocks[$blockId] !== null){