mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 02:08:21 +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:
@ -50,11 +50,10 @@ class ChorusFruit extends Food{
|
||||
}
|
||||
|
||||
public function onConsume(Living $consumer){
|
||||
$level = $consumer->getLevel();
|
||||
assert($level !== null);
|
||||
$level = $consumer->getLevelNonNull();
|
||||
|
||||
$minX = $consumer->getFloorX() - 8;
|
||||
$minY = min($consumer->getFloorY(), $consumer->getLevel()->getWorldHeight()) - 8;
|
||||
$minY = min($consumer->getFloorY(), $consumer->getLevelNonNull()->getWorldHeight()) - 8;
|
||||
$minZ = $consumer->getFloorZ() - 8;
|
||||
|
||||
$maxX = $minX + 16;
|
||||
|
@ -93,7 +93,7 @@ class PaintingItem extends Item{
|
||||
$nbt->setInt("TileY", $blockClicked->getFloorY());
|
||||
$nbt->setInt("TileZ", $blockClicked->getFloorZ());
|
||||
|
||||
$entity = Entity::createEntity("Painting", $blockReplace->getLevel(), $nbt);
|
||||
$entity = Entity::createEntity("Painting", $blockReplace->getLevelNonNull(), $nbt);
|
||||
|
||||
if($entity instanceof Entity){
|
||||
$this->pop();
|
||||
|
Reference in New Issue
Block a user