Tiles now encapsulate positions instead of extending them

This commit is contained in:
Dylan K. Taylor
2019-08-05 19:33:34 +01:00
parent d355d5b5b5
commit 4e5b296c8c
10 changed files with 58 additions and 45 deletions

View File

@ -473,7 +473,8 @@ class Chunk{
throw new \InvalidArgumentException("Attempted to add a garbage closed Tile to a chunk");
}
if(isset($this->tiles[$index = Chunk::blockHash($tile->x, $tile->y, $tile->z)]) and $this->tiles[$index] !== $tile){
$pos = $tile->getPos();
if(isset($this->tiles[$index = Chunk::blockHash($pos->x, $pos->y, $pos->z)]) and $this->tiles[$index] !== $tile){
$this->tiles[$index]->close();
}
$this->tiles[$index] = $tile;
@ -484,7 +485,8 @@ class Chunk{
* @param Tile $tile
*/
public function removeTile(Tile $tile) : void{
unset($this->tiles[Chunk::blockHash($tile->x, $tile->y, $tile->z)]);
$pos = $tile->getPos();
unset($this->tiles[Chunk::blockHash($pos->x, $pos->y, $pos->z)]);
$this->hasChanged = true;
}