mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 18:32:55 +00:00
Tile: Removed cyclic dependence on Chunks
Chunks were used by tiles for a couple of things: - 1. for coordinates - which can be gotten using bitshifts - 2. setChanged() - which is unnecessary as seen in the previous commit Removing this circular dependency was actually remarkably easy to do.
This commit is contained in:
@ -2388,7 +2388,6 @@ class Level implements ChunkManager, Metadatable{
|
||||
foreach($oldTiles as $tile){
|
||||
$chunk->addTile($tile);
|
||||
$oldChunk->removeTile($tile);
|
||||
$tile->chunk = $chunk;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2600,8 +2599,18 @@ class Level implements ChunkManager, Metadatable{
|
||||
if($tile->getLevel() !== $this){
|
||||
throw new LevelException("Invalid Tile level");
|
||||
}
|
||||
|
||||
$chunkX = $tile->getFloorX() >> 4;
|
||||
$chunkZ = $tile->getFloorZ() >> 4;
|
||||
|
||||
if(isset($this->chunks[$hash = Level::chunkHash($chunkX, $chunkZ)])){
|
||||
$this->chunks[$hash]->addTile($tile);
|
||||
}else{
|
||||
throw new \InvalidStateException("Attempted to create tile " . get_class($tile) . " in unloaded chunk $chunkX $chunkZ");
|
||||
}
|
||||
|
||||
$this->tiles[$tile->getId()] = $tile;
|
||||
$this->clearChunkCache($tile->getFloorX() >> 4, $tile->getFloorZ() >> 4);
|
||||
$this->clearChunkCache($chunkX, $chunkZ);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2614,9 +2623,15 @@ class Level implements ChunkManager, Metadatable{
|
||||
throw new LevelException("Invalid Tile level");
|
||||
}
|
||||
|
||||
unset($this->tiles[$tile->getId()]);
|
||||
unset($this->updateTiles[$tile->getId()]);
|
||||
$this->clearChunkCache($tile->getFloorX() >> 4, $tile->getFloorZ() >> 4);
|
||||
unset($this->tiles[$tile->getId()], $this->updateTiles[$tile->getId()]);
|
||||
|
||||
$chunkX = $tile->getFloorX() >> 4;
|
||||
$chunkZ = $tile->getFloorZ() >> 4;
|
||||
|
||||
if(isset($this->chunks[$hash = Level::chunkHash($chunkX, $chunkZ)])){
|
||||
$this->chunks[$hash]->removeTile($tile);
|
||||
}
|
||||
$this->clearChunkCache($chunkX, $chunkZ);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user