mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +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:
@ -67,7 +67,7 @@ abstract class Spawnable extends Tile{
|
||||
}
|
||||
|
||||
$pk = $this->createSpawnPacket();
|
||||
$this->level->addChunkPacket($this->chunk->getX(), $this->chunk->getZ(), $pk);
|
||||
$this->level->addChunkPacket($this->getFloorX() >> 4, $this->getFloorZ() >> 4, $pk);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,9 +78,7 @@ abstract class Spawnable extends Tile{
|
||||
$this->spawnCompoundCache = null;
|
||||
$this->spawnToAll();
|
||||
|
||||
if($this->chunk !== null){
|
||||
$this->level->clearChunkCache($this->chunk->getX(), $this->chunk->getZ());
|
||||
}
|
||||
$this->level->clearChunkCache($this->getFloorX() >> 4, $this->getFloorZ() >> 4);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,7 +31,6 @@ use pocketmine\block\Block;
|
||||
use pocketmine\event\Timings;
|
||||
use pocketmine\event\TimingsHandler;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\level\format\Chunk;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\level\Position;
|
||||
use pocketmine\math\Vector3;
|
||||
@ -69,8 +68,6 @@ abstract class Tile extends Position{
|
||||
/** @var string[][] */
|
||||
private static $saveNames = [];
|
||||
|
||||
/** @var Chunk */
|
||||
public $chunk;
|
||||
/** @var string */
|
||||
public $name;
|
||||
/** @var int */
|
||||
@ -161,10 +158,6 @@ abstract class Tile extends Position{
|
||||
$this->namedtag = $nbt;
|
||||
$this->server = $level->getServer();
|
||||
$this->setLevel($level);
|
||||
$this->chunk = $level->getChunk($this->namedtag->getInt(self::TAG_X) >> 4, $this->namedtag->getInt(self::TAG_Z) >> 4, false);
|
||||
if($this->chunk === null){
|
||||
throw new \InvalidStateException("Cannot create tiles in unloaded chunks");
|
||||
}
|
||||
|
||||
$this->name = "";
|
||||
$this->id = Tile::$tileCount++;
|
||||
@ -172,7 +165,6 @@ abstract class Tile extends Position{
|
||||
$this->y = $this->namedtag->getInt(self::TAG_Y);
|
||||
$this->z = $this->namedtag->getInt(self::TAG_Z);
|
||||
|
||||
$this->chunk->addTile($this);
|
||||
$this->getLevel()->addTile($this);
|
||||
}
|
||||
|
||||
@ -276,11 +268,7 @@ abstract class Tile extends Position{
|
||||
public function close() : void{
|
||||
if(!$this->closed){
|
||||
$this->closed = true;
|
||||
unset($this->level->updateTiles[$this->id]);
|
||||
if($this->chunk instanceof Chunk){
|
||||
$this->chunk->removeTile($this);
|
||||
$this->chunk = null;
|
||||
}
|
||||
|
||||
if(($level = $this->getLevel()) instanceof Level){
|
||||
$level->removeTile($this);
|
||||
$this->setLevel(null);
|
||||
|
Reference in New Issue
Block a user