Position: add getLevelNonNull()

this allows assuming that a position has a valid world in places where it's never expected to not be valid. Since this is the vast majority of usages, it eliminates a lot of possible null-pointer warnings given by static analysers.
TODO: Consider whether we can make Position->getLevel/World use this behaviour out of the box in the next major version.
This commit is contained in:
Dylan K. Taylor
2020-04-14 11:08:37 +01:00
parent 6e08b622b3
commit a2543ff80d
76 changed files with 229 additions and 183 deletions

View File

@ -121,7 +121,7 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{
* @return void
*/
protected function checkPairing(){
if($this->isPaired() and !$this->getLevel()->isInLoadedTerrain(new Vector3($this->pairX, $this->y, $this->pairZ))){
if($this->isPaired() and !$this->getLevelNonNull()->isInLoadedTerrain(new Vector3($this->pairX, $this->y, $this->pairZ))){
//paired to a tile in an unloaded chunk
$this->doubleInventory = null;
@ -160,7 +160,7 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{
public function getPair() : ?Chest{
if($this->isPaired()){
$tile = $this->getLevel()->getTileAt($this->pairX, $this->y, $this->pairZ);
$tile = $this->getLevelNonNull()->getTileAt($this->pairX, $this->y, $this->pairZ);
if($tile instanceof Chest){
return $tile;
}