mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-04 17:06:16 +00:00
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:
@ -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;
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{
|
||||
$this->maxTime = $this->burnTime = $ev->getBurnTime();
|
||||
|
||||
if($this->getBlock()->getId() === Block::FURNACE){
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::BURNING_FURNACE, $this->getBlock()->getDamage()), true);
|
||||
$this->getLevelNonNull()->setBlock($this, BlockFactory::get(Block::BURNING_FURNACE, $this->getBlock()->getDamage()), true);
|
||||
}
|
||||
|
||||
if($this->burnTime > 0 and $ev->isBurning()){
|
||||
@ -211,7 +211,7 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{
|
||||
$ret = true;
|
||||
}else{
|
||||
if($this->getBlock()->getId() === Block::BURNING_FURNACE){
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::FURNACE, $this->getBlock()->getDamage()), true);
|
||||
$this->getLevelNonNull()->setBlock($this, BlockFactory::get(Block::FURNACE, $this->getBlock()->getDamage()), true);
|
||||
}
|
||||
$this->burnTime = $this->cookTime = $this->maxTime = 0;
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ abstract class Tile extends Position{
|
||||
parent::__construct($nbt->getInt(self::TAG_X), $nbt->getInt(self::TAG_Y), $nbt->getInt(self::TAG_Z), $level);
|
||||
$this->readSaveData($nbt);
|
||||
|
||||
$this->getLevel()->addTile($this);
|
||||
$this->getLevelNonNull()->addTile($this);
|
||||
}
|
||||
|
||||
public function getId() : int{
|
||||
|
Reference in New Issue
Block a user