Region: Change chunk offset calculation in regions to use bitmasks

I don't know why it wasn't done like this to start with. However this has not been tested yet, so this goes on a different branch for now to test.
This commit is contained in:
Dylan K. Taylor
2017-12-30 19:41:58 +00:00
parent 54b23968e7
commit 4db7a7e57f
2 changed files with 3 additions and 3 deletions

View File

@ -340,7 +340,7 @@ class McRegion extends BaseLevelProvider{
$this->loadRegion($regionX, $regionZ); $this->loadRegion($regionX, $regionZ);
$this->level->timings->syncChunkLoadDataTimer->startTiming(); $this->level->timings->syncChunkLoadDataTimer->startTiming();
/** @noinspection PhpStrictTypeCheckingInspection */ /** @noinspection PhpStrictTypeCheckingInspection */
$chunk = $this->getRegion($regionX, $regionZ)->readChunk($chunkX - $regionX * 32, $chunkZ - $regionZ * 32); $chunk = $this->getRegion($regionX, $regionZ)->readChunk($chunkX & 0x1f, $chunkZ & 0x1f);
if($chunk === null and $create){ if($chunk === null and $create){
$chunk = new Chunk($chunkX, $chunkZ); $chunk = new Chunk($chunkX, $chunkZ);
} }
@ -377,7 +377,7 @@ class McRegion extends BaseLevelProvider{
public function isChunkGenerated(int $chunkX, int $chunkZ) : bool{ public function isChunkGenerated(int $chunkX, int $chunkZ) : bool{
if(($region = $this->getRegion($chunkX >> 5, $chunkZ >> 5)) !== null){ if(($region = $this->getRegion($chunkX >> 5, $chunkZ >> 5)) !== null){
return $region->chunkExists($chunkX - $region->getX() * 32, $chunkZ - $region->getZ() * 32) and $this->getChunk($chunkX - $region->getX() * 32, $chunkZ - $region->getZ() * 32, true)->isGenerated(); return $region->chunkExists($chunkX & 0x1f, $chunkZ & 0x1f) and $this->getChunk($chunkX & 0x1f, $chunkZ & 0x1f, true)->isGenerated();
} }
return false; return false;

View File

@ -183,7 +183,7 @@ class RegionLoader{
$this->lastUsed = time(); $this->lastUsed = time();
$chunkData = $this->levelProvider->nbtSerialize($chunk); $chunkData = $this->levelProvider->nbtSerialize($chunk);
if($chunkData !== false){ if($chunkData !== false){
$this->saveChunk($chunk->getX() - ($this->getX() * 32), $chunk->getZ() - ($this->getZ() * 32), $chunkData); $this->saveChunk($chunk->getX() & 0x1f, $chunk->getZ() & 0x1f, $chunkData);
} }
} }