Throw exceptions when entities/tiles are created on chunks that don't exist

These assertions don't make sense. Since the chunk field is used below in both cases, the chunk should **never** be null no matter what.
This commit is contained in:
Dylan K. Taylor 2018-01-02 13:12:54 +00:00
parent c9e2e8980f
commit c747c7d025
2 changed files with 7 additions and 2 deletions

View File

@ -494,7 +494,10 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$pos = $this->namedtag->getListTag("Pos")->getAllValues();
$this->chunk = $level->getChunk(((int) $pos[0]) >> 4, ((int) $pos[2]) >> 4, true);
assert($this->chunk !== null);
if($this->chunk === null){
throw new \InvalidStateException("Cannot create entities in unloaded chunks");
}
$this->setLevel($level);
$this->server = $level->getServer();

View File

@ -146,7 +146,9 @@ abstract class Tile extends Position{
$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);
assert($this->chunk !== null);
if($this->chunk === null){
throw new \InvalidStateException("Cannot create tiles in unloaded chunks");
}
$this->name = "";
$this->id = Tile::$tileCount++;