diff --git a/src/block/Banner.php b/src/block/Banner.php index 9bf16b9fd..8abfbf1ef 100644 --- a/src/block/Banner.php +++ b/src/block/Banner.php @@ -99,7 +99,7 @@ class Banner extends Transparent{ public function readStateFromWorld() : void{ parent::readStateFromWorld(); - $tile = $this->pos->getWorld()->getTile($this->pos); + $tile = $this->pos->getWorldNonNull()->getTile($this->pos); if($tile instanceof TileBanner){ $this->baseColor = $tile->getBaseColor(); $this->setPatterns($tile->getPatterns()); @@ -108,7 +108,7 @@ class Banner extends Transparent{ public function writeStateToWorld() : void{ parent::writeStateToWorld(); - $tile = $this->pos->getWorld()->getTile($this->pos); + $tile = $this->pos->getWorldNonNull()->getTile($this->pos); assert($tile instanceof TileBanner); $tile->setBaseColor($this->baseColor); $tile->setPatterns($this->patterns); @@ -171,7 +171,7 @@ class Banner extends Transparent{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::opposite($this->facing))->getId() === BlockLegacyIds::AIR){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } diff --git a/src/block/BaseRail.php b/src/block/BaseRail.php index 017a3953b..4278c2700 100644 --- a/src/block/BaseRail.php +++ b/src/block/BaseRail.php @@ -255,7 +255,7 @@ abstract class BaseRail extends Flowable{ if(isset($otherPossible[$otherSide])){ $otherConnections[] = $otherSide; $other->setConnections($otherConnections); - $this->pos->getWorld()->setBlock($other->pos, $other); + $this->pos->getWorldNonNull()->setBlock($other->pos, $other); $changed = true; $thisConnections[] = $thisSide; @@ -268,7 +268,7 @@ abstract class BaseRail extends Flowable{ if($changed){ $this->setConnections($thisConnections); - $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); } } @@ -287,11 +287,11 @@ abstract class BaseRail extends Flowable{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->isTransparent()){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); }else{ foreach($this->connections as $connection){ if(($connection & self::FLAG_ASCEND) !== 0 and $this->getSide($connection & ~self::FLAG_ASCEND)->isTransparent()){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); break; } } diff --git a/src/block/Bed.php b/src/block/Bed.php index fb5c35f23..5f2636876 100644 --- a/src/block/Bed.php +++ b/src/block/Bed.php @@ -73,7 +73,7 @@ class Bed extends Transparent{ public function readStateFromWorld() : void{ parent::readStateFromWorld(); //read extra state information from the tile - this is an ugly hack - $tile = $this->pos->getWorld()->getTile($this->pos); + $tile = $this->pos->getWorldNonNull()->getTile($this->pos); if($tile instanceof TileBed){ $this->color = $tile->getColor(); } @@ -82,7 +82,7 @@ class Bed extends Transparent{ public function writeStateToWorld() : void{ parent::writeStateToWorld(); //extra block properties storage hack - $tile = $this->pos->getWorld()->getTile($this->pos); + $tile = $this->pos->getWorldNonNull()->getTile($this->pos); if($tile instanceof TileBed){ $tile->setColor($this->color); } @@ -105,11 +105,11 @@ class Bed extends Transparent{ public function setOccupied(bool $occupied = true) : void{ $this->occupied = $occupied; - $this->pos->getWorld()->setBlock($this->pos, $this, false); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this, false); if(($other = $this->getOtherHalf()) !== null){ $other->occupied = $occupied; - $this->pos->getWorld()->setBlock($other->pos, $other, false); + $this->pos->getWorldNonNull()->setBlock($other->pos, $other, false); } } @@ -139,7 +139,7 @@ class Bed extends Transparent{ return true; } - $time = $this->pos->getWorld()->getTimeOfDay(); + $time = $this->pos->getWorldNonNull()->getTimeOfDay(); $isNight = ($time >= World::TIME_NIGHT and $time < World::TIME_SUNRISE); diff --git a/src/block/Block.php b/src/block/Block.php index 0674f6c5e..9aa0459aa 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -150,10 +150,10 @@ class Block{ } public function writeStateToWorld() : void{ - $this->pos->getWorld()->getChunkAtPosition($this->pos)->setFullBlock($this->pos->x & 0xf, $this->pos->y, $this->pos->z & 0xf, $this->getFullId()); + $this->pos->getWorldNonNull()->getChunkAtPosition($this->pos)->setFullBlock($this->pos->x & 0xf, $this->pos->y, $this->pos->z & 0xf, $this->getFullId()); $tileType = $this->idInfo->getTileClass(); - $oldTile = $this->pos->getWorld()->getTile($this->pos); + $oldTile = $this->pos->getWorldNonNull()->getTile($this->pos); if($oldTile !== null){ if($tileType === null or !($oldTile instanceof $tileType)){ $oldTile->close(); @@ -163,7 +163,7 @@ class Block{ } } if($oldTile === null and $tileType !== null){ - $this->pos->getWorld()->addTile(TileFactory::create($tileType, $this->pos->getWorld(), $this->pos->asVector3())); + $this->pos->getWorldNonNull()->addTile(TileFactory::create($tileType, $this->pos->getWorld(), $this->pos->asVector3())); } } @@ -222,10 +222,10 @@ class Block{ * Do the actions needed so the block is broken with the Item */ public function onBreak(Item $item, ?Player $player = null) : bool{ - if(($t = $this->pos->getWorld()->getTile($this->pos)) !== null){ + if(($t = $this->pos->getWorldNonNull()->getTile($this->pos)) !== null){ $t->onBlockDestroyed(); } - $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::AIR()); + $this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::AIR()); return true; } @@ -418,7 +418,7 @@ class Block{ public function getPickedItem(bool $addUserData = false) : Item{ $item = $this->asItem(); if($addUserData){ - $tile = $this->pos->getWorld()->getTile($this->pos); + $tile = $this->pos->getWorldNonNull()->getTile($this->pos); if($tile instanceof Tile){ $nbt = $tile->getCleanedNBT(); if($nbt instanceof CompoundTag){ @@ -480,7 +480,7 @@ class Block{ */ public function getSide(int $side, int $step = 1){ if($this->pos->isValid()){ - return $this->pos->getWorld()->getBlock($this->pos->getSide($side, $step)); + return $this->pos->getWorldNonNull()->getBlock($this->pos->getSide($side, $step)); } throw new \InvalidStateException("Block does not have a valid world"); diff --git a/src/block/BrewingStand.php b/src/block/BrewingStand.php index f4ae81b2b..5f6d6436f 100644 --- a/src/block/BrewingStand.php +++ b/src/block/BrewingStand.php @@ -60,7 +60,7 @@ class BrewingStand extends Transparent{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player instanceof Player){ - $stand = $this->pos->getWorld()->getTile($this->pos); + $stand = $this->pos->getWorldNonNull()->getTile($this->pos); if($stand instanceof TileBrewingStand and $stand->canOpenWith($item->getCustomName())){ $player->setCurrentWindow($stand->getInventory()); } diff --git a/src/block/Button.php b/src/block/Button.php index 23657d764..d9c5bf478 100644 --- a/src/block/Button.php +++ b/src/block/Button.php @@ -64,9 +64,9 @@ abstract class Button extends Flowable{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if(!$this->powered){ $this->powered = true; - $this->pos->getWorld()->setBlock($this->pos, $this); - $this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, $this->getActivationTime()); - $this->pos->getWorld()->addSound($this->pos->add(0.5, 0.5, 0.5), new RedstonePowerOnSound()); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, $this->getActivationTime()); + $this->pos->getWorldNonNull()->addSound($this->pos->add(0.5, 0.5, 0.5), new RedstonePowerOnSound()); } return true; @@ -75,8 +75,8 @@ abstract class Button extends Flowable{ public function onScheduledUpdate() : void{ if($this->powered){ $this->powered = false; - $this->pos->getWorld()->setBlock($this->pos, $this); - $this->pos->getWorld()->addSound($this->pos->add(0.5, 0.5, 0.5), new RedstonePowerOffSound()); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->addSound($this->pos->add(0.5, 0.5, 0.5), new RedstonePowerOffSound()); } } } diff --git a/src/block/Cactus.php b/src/block/Cactus.php index 951666623..1521c078c 100644 --- a/src/block/Cactus.php +++ b/src/block/Cactus.php @@ -76,12 +76,12 @@ class Cactus extends Transparent{ public function onNearbyBlockChange() : void{ $down = $this->getSide(Facing::DOWN); if($down->getId() !== BlockLegacyIds::SAND and !$down->isSameType($this)){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); }else{ foreach(Facing::HORIZONTAL as $side){ $b = $this->getSide($side); if($b->isSolid()){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); break; } } @@ -96,23 +96,23 @@ class Cactus extends Transparent{ if(!$this->getSide(Facing::DOWN)->isSameType($this)){ if($this->age === 15){ for($y = 1; $y < 3; ++$y){ - $b = $this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y + $y, $this->pos->z); + $b = $this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y + $y, $this->pos->z); if($b->getId() === BlockLegacyIds::AIR){ $ev = new BlockGrowEvent($b, VanillaBlocks::CACTUS()); $ev->call(); if($ev->isCancelled()){ break; } - $this->pos->getWorld()->setBlock($b->pos, $ev->getNewState()); + $this->pos->getWorldNonNull()->setBlock($b->pos, $ev->getNewState()); }else{ break; } } $this->age = 0; - $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); }else{ ++$this->age; - $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); } } } diff --git a/src/block/Cake.php b/src/block/Cake.php index e0ef735a4..23ed7b3b8 100644 --- a/src/block/Cake.php +++ b/src/block/Cake.php @@ -78,7 +78,7 @@ class Cake extends Transparent implements FoodSource{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->getId() === BlockLegacyIds::AIR){ //Replace with common break method - $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::AIR()); + $this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::AIR()); } } @@ -131,6 +131,6 @@ class Cake extends Transparent implements FoodSource{ } public function onConsume(Living $consumer) : void{ - $this->pos->getWorld()->setBlock($this->pos, $this->getResidue()); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this->getResidue()); } } diff --git a/src/block/Carpet.php b/src/block/Carpet.php index 0a430b023..65a7bc853 100644 --- a/src/block/Carpet.php +++ b/src/block/Carpet.php @@ -58,7 +58,7 @@ class Carpet extends Flowable{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->getId() === BlockLegacyIds::AIR){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } diff --git a/src/block/Chest.php b/src/block/Chest.php index 523812a38..2f13028e6 100644 --- a/src/block/Chest.php +++ b/src/block/Chest.php @@ -70,7 +70,7 @@ class Chest extends Transparent{ } public function onPostPlace() : void{ - $tile = $this->pos->getWorld()->getTile($this->pos); + $tile = $this->pos->getWorldNonNull()->getTile($this->pos); if($tile instanceof TileChest){ foreach([ Facing::rotateY($this->facing, true), @@ -78,7 +78,7 @@ class Chest extends Transparent{ ] as $side){ $c = $this->getSide($side); if($c instanceof Chest and $c->isSameType($this) and $c->facing === $this->facing){ - $pair = $this->pos->getWorld()->getTile($c->pos); + $pair = $this->pos->getWorldNonNull()->getTile($c->pos); if($pair instanceof TileChest and !$pair->isPaired()){ $pair->pairWith($tile); $tile->pairWith($pair); @@ -92,7 +92,7 @@ class Chest extends Transparent{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player instanceof Player){ - $chest = $this->pos->getWorld()->getTile($this->pos); + $chest = $this->pos->getWorldNonNull()->getTile($this->pos); if($chest instanceof TileChest){ if( !$this->getSide(Facing::UP)->isTransparent() or diff --git a/src/block/CoarseDirt.php b/src/block/CoarseDirt.php index d6e6630a5..05ed9dd94 100644 --- a/src/block/CoarseDirt.php +++ b/src/block/CoarseDirt.php @@ -34,7 +34,7 @@ class CoarseDirt extends Dirt{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($face === Facing::UP and $item instanceof Hoe){ $item->applyDamage(1); - $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::DIRT()); + $this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::DIRT()); return true; } diff --git a/src/block/CocoaBlock.php b/src/block/CocoaBlock.php index 2d315f6ba..c4be19397 100644 --- a/src/block/CocoaBlock.php +++ b/src/block/CocoaBlock.php @@ -89,7 +89,7 @@ class CocoaBlock extends Transparent{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($this->age < 2 and $item instanceof Fertilizer){ $this->age++; - $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); $item->pop(); @@ -102,7 +102,7 @@ class CocoaBlock extends Transparent{ public function onNearbyBlockChange() : void{ $side = $this->getSide(Facing::opposite($this->facing)); if(!($side instanceof Wood) or !$side->getTreeType()->equals(TreeType::JUNGLE())){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } @@ -113,7 +113,7 @@ class CocoaBlock extends Transparent{ public function onRandomTick() : void{ if($this->age < 2 and mt_rand(1, 5) === 1){ $this->age++; - $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); } } diff --git a/src/block/ConcretePowder.php b/src/block/ConcretePowder.php index 432c6ef7c..63cf6c993 100644 --- a/src/block/ConcretePowder.php +++ b/src/block/ConcretePowder.php @@ -38,7 +38,7 @@ class ConcretePowder extends Opaque implements Fallable{ public function onNearbyBlockChange() : void{ if(($block = $this->checkAdjacentWater()) !== null){ - $this->pos->getWorld()->setBlock($this->pos, $block); + $this->pos->getWorldNonNull()->setBlock($this->pos, $block); }else{ $this->startFalling(); } diff --git a/src/block/Crops.php b/src/block/Crops.php index b9c8877f9..0abc97225 100644 --- a/src/block/Crops.php +++ b/src/block/Crops.php @@ -72,7 +72,7 @@ abstract class Crops extends Flowable{ $ev = new BlockGrowEvent($this, $block); $ev->call(); if(!$ev->isCancelled()){ - $this->pos->getWorld()->setBlock($this->pos, $ev->getNewState()); + $this->pos->getWorldNonNull()->setBlock($this->pos, $ev->getNewState()); } $item->pop(); @@ -85,7 +85,7 @@ abstract class Crops extends Flowable{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::FARMLAND){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } @@ -100,7 +100,7 @@ abstract class Crops extends Flowable{ $ev = new BlockGrowEvent($this, $block); $ev->call(); if(!$ev->isCancelled()){ - $this->pos->getWorld()->setBlock($this->pos, $ev->getNewState()); + $this->pos->getWorldNonNull()->setBlock($this->pos, $ev->getNewState()); } } } diff --git a/src/block/DaylightSensor.php b/src/block/DaylightSensor.php index 5892bf0ab..a890a9705 100644 --- a/src/block/DaylightSensor.php +++ b/src/block/DaylightSensor.php @@ -91,7 +91,7 @@ class DaylightSensor extends Transparent{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->inverted = !$this->inverted; $this->power = $this->recalculatePower(); - $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); return true; } @@ -99,18 +99,18 @@ class DaylightSensor extends Transparent{ $newPower = $this->recalculatePower(); if($this->power !== $newPower){ $this->power = $newPower; - $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); } - $this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, 20); + $this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, 20); } private function recalculatePower() : int{ - $lightLevel = $this->pos->getWorld()->getRealBlockSkyLightAt($this->pos->x, $this->pos->y, $this->pos->z); + $lightLevel = $this->pos->getWorldNonNull()->getRealBlockSkyLightAt($this->pos->x, $this->pos->y, $this->pos->z); if($this->inverted){ return 15 - $lightLevel; } - $sunAngle = $this->pos->getWorld()->getSunAnglePercentage(); + $sunAngle = $this->pos->getWorldNonNull()->getSunAnglePercentage(); return max(0, (int) round($lightLevel * cos(($sunAngle + ((($sunAngle < 0.5 ? 0 : 1) - $sunAngle) / 5)) * 2 * M_PI))); } diff --git a/src/block/DeadBush.php b/src/block/DeadBush.php index 988e57665..7828ad494 100644 --- a/src/block/DeadBush.php +++ b/src/block/DeadBush.php @@ -47,7 +47,7 @@ class DeadBush extends Flowable{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->isTransparent()){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } diff --git a/src/block/Dirt.php b/src/block/Dirt.php index 7dab9b009..b368526ea 100644 --- a/src/block/Dirt.php +++ b/src/block/Dirt.php @@ -38,7 +38,7 @@ class Dirt extends Opaque{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($face === Facing::UP and $item instanceof Hoe){ $item->applyDamage(1); - $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::FARMLAND()); + $this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::FARMLAND()); return true; } diff --git a/src/block/Door.php b/src/block/Door.php index ab4ad13e8..c11935662 100644 --- a/src/block/Door.php +++ b/src/block/Door.php @@ -99,7 +99,7 @@ class Door extends Transparent{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->getId() === BlockLegacyIds::AIR){ //Replace with common break method - $this->pos->getWorld()->useBreakOn($this->pos); //this will delete both halves if they exist + $this->pos->getWorldNonNull()->useBreakOn($this->pos); //this will delete both halves if they exist } } @@ -138,11 +138,11 @@ class Door extends Transparent{ $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP); if($other instanceof Door and $other->isSameType($this)){ $other->open = $this->open; - $this->pos->getWorld()->setBlock($other->pos, $other); + $this->pos->getWorldNonNull()->setBlock($other->pos, $other); } - $this->pos->getWorld()->setBlock($this->pos, $this); - $this->pos->getWorld()->addSound($this->pos, new DoorSound()); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->addSound($this->pos, new DoorSound()); return true; } diff --git a/src/block/DoublePlant.php b/src/block/DoublePlant.php index bfb02c8dd..05f82f82a 100644 --- a/src/block/DoublePlant.php +++ b/src/block/DoublePlant.php @@ -77,7 +77,7 @@ class DoublePlant extends Flowable{ public function onNearbyBlockChange() : void{ if(!$this->isValidHalfPlant() or (!$this->top and $this->getSide(Facing::DOWN)->isTransparent())){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } diff --git a/src/block/DragonEgg.php b/src/block/DragonEgg.php index 17546b3f2..52d6158a6 100644 --- a/src/block/DragonEgg.php +++ b/src/block/DragonEgg.php @@ -63,7 +63,7 @@ class DragonEgg extends Transparent implements Fallable{ public function teleport() : void{ for($tries = 0; $tries < 16; ++$tries){ - $block = $this->pos->getWorld()->getBlockAt( + $block = $this->pos->getWorldNonNull()->getBlockAt( $this->pos->x + mt_rand(-16, 16), max(0, min(World::Y_MAX - 1, $this->pos->y + mt_rand(-8, 8))), $this->pos->z + mt_rand(-16, 16) @@ -76,9 +76,9 @@ class DragonEgg extends Transparent implements Fallable{ } $blockPos = $ev->getTo(); - $this->pos->getWorld()->addParticle($this->pos, new DragonEggTeleportParticle($this->pos->x - $blockPos->x, $this->pos->y - $blockPos->y, $this->pos->z - $blockPos->z)); - $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::AIR()); - $this->pos->getWorld()->setBlock($blockPos, $this); + $this->pos->getWorldNonNull()->addParticle($this->pos, new DragonEggTeleportParticle($this->pos->x - $blockPos->x, $this->pos->y - $blockPos->y, $this->pos->z - $blockPos->z)); + $this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::AIR()); + $this->pos->getWorldNonNull()->setBlock($blockPos, $this); break; } } diff --git a/src/block/EnderChest.php b/src/block/EnderChest.php index fbb498f9a..83eb164f6 100644 --- a/src/block/EnderChest.php +++ b/src/block/EnderChest.php @@ -75,7 +75,7 @@ class EnderChest extends Transparent{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player instanceof Player){ - $enderChest = $this->pos->getWorld()->getTile($this->pos); + $enderChest = $this->pos->getWorldNonNull()->getTile($this->pos); if($enderChest instanceof TileEnderChest and $this->getSide(Facing::UP)->isTransparent()){ $player->getEnderChestInventory()->setHolderPosition($this->pos); $player->setCurrentWindow($player->getEnderChestInventory()); diff --git a/src/block/Farmland.php b/src/block/Farmland.php index e04917e92..1752479ce 100644 --- a/src/block/Farmland.php +++ b/src/block/Farmland.php @@ -58,7 +58,7 @@ class Farmland extends Transparent{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::UP)->isSolid()){ - $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::DIRT()); + $this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::DIRT()); } } @@ -70,13 +70,13 @@ class Farmland extends Transparent{ if(!$this->canHydrate()){ if($this->wetness > 0){ $this->wetness--; - $this->pos->getWorld()->setBlock($this->pos, $this, false); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this, false); }else{ - $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::DIRT()); + $this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::DIRT()); } }elseif($this->wetness < 7){ $this->wetness = 7; - $this->pos->getWorld()->setBlock($this->pos, $this, false); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this, false); } } @@ -87,7 +87,7 @@ class Farmland extends Transparent{ for($y = $start->y; $y <= $end->y; ++$y){ for($z = $start->z; $z <= $end->z; ++$z){ for($x = $start->x; $x <= $end->x; ++$x){ - if($this->pos->getWorld()->getBlockAt($x, $y, $z) instanceof Water){ + if($this->pos->getWorldNonNull()->getBlockAt($x, $y, $z) instanceof Water){ return true; } } diff --git a/src/block/FenceGate.php b/src/block/FenceGate.php index 8fc695e7c..88acabe73 100644 --- a/src/block/FenceGate.php +++ b/src/block/FenceGate.php @@ -88,7 +88,7 @@ class FenceGate extends Transparent{ $inWall = $this->checkInWall(); if($inWall !== $this->inWall){ $this->inWall = $inWall; - $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); } } @@ -101,8 +101,8 @@ class FenceGate extends Transparent{ } } - $this->pos->getWorld()->setBlock($this->pos, $this); - $this->pos->getWorld()->addSound($this->pos, new DoorSound()); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->addSound($this->pos, new DoorSound()); return true; } diff --git a/src/block/Fire.php b/src/block/Fire.php index c1b019a48..7adb39584 100644 --- a/src/block/Fire.php +++ b/src/block/Fire.php @@ -88,9 +88,9 @@ class Fire extends Flowable{ public function onNearbyBlockChange() : void{ if(!$this->getSide(Facing::DOWN)->isSolid() and !$this->hasAdjacentFlammableBlocks()){ - $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::AIR()); + $this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::AIR()); }else{ - $this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, mt_rand(30, 40)); + $this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, mt_rand(30, 40)); } } @@ -124,10 +124,10 @@ class Fire extends Flowable{ } if($result !== null){ - $this->pos->getWorld()->setBlock($this->pos, $result); + $this->pos->getWorldNonNull()->setBlock($this->pos, $result); } - $this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, mt_rand(30, 40)); + $this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, mt_rand(30, 40)); if($canSpread){ //TODO: raise upper bound for chance in humid biomes @@ -168,9 +168,9 @@ class Fire extends Flowable{ if(mt_rand(0, $this->age + 9) < 5){ //TODO: check rain $fire = clone $this; $fire->age = min(15, $fire->age + (mt_rand(0, 4) >> 2)); - $this->pos->getWorld()->setBlock($block->pos, $fire); + $this->pos->getWorldNonNull()->setBlock($block->pos, $fire); }else{ - $this->pos->getWorld()->setBlock($block->pos, VanillaBlocks::AIR()); + $this->pos->getWorldNonNull()->setBlock($block->pos, VanillaBlocks::AIR()); } } } diff --git a/src/block/Flower.php b/src/block/Flower.php index 564008585..da81a90d2 100644 --- a/src/block/Flower.php +++ b/src/block/Flower.php @@ -46,7 +46,7 @@ class Flower extends Flowable{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->isTransparent()){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } diff --git a/src/block/FlowerPot.php b/src/block/FlowerPot.php index 1e8edd16f..ddd6d6e47 100644 --- a/src/block/FlowerPot.php +++ b/src/block/FlowerPot.php @@ -61,7 +61,7 @@ class FlowerPot extends Flowable{ public function readStateFromWorld() : void{ parent::readStateFromWorld(); - $tile = $this->pos->getWorld()->getTile($this->pos); + $tile = $this->pos->getWorldNonNull()->getTile($this->pos); if($tile instanceof TileFlowerPot){ $this->setPlant($tile->getPlant()); }else{ @@ -72,7 +72,7 @@ class FlowerPot extends Flowable{ public function writeStateToWorld() : void{ parent::writeStateToWorld(); - $tile = $this->pos->getWorld()->getTile($this->pos); + $tile = $this->pos->getWorldNonNull()->getTile($this->pos); assert($tile instanceof TileFlowerPot); $tile->setPlant($this->plant); } @@ -122,7 +122,7 @@ class FlowerPot extends Flowable{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->isTransparent()){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } @@ -134,7 +134,7 @@ class FlowerPot extends Flowable{ $this->setPlant($plant); $item->pop(); - $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); return true; } diff --git a/src/block/FrostedIce.php b/src/block/FrostedIce.php index 9d957d5fc..2f140cad8 100644 --- a/src/block/FrostedIce.php +++ b/src/block/FrostedIce.php @@ -50,17 +50,17 @@ class FrostedIce extends Ice{ public function onNearbyBlockChange() : void{ if(!$this->checkAdjacentBlocks(2)){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); }else{ - $this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, mt_rand(20, 40)); + $this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, mt_rand(20, 40)); } } public function onRandomTick() : void{ if((!$this->checkAdjacentBlocks(4) or mt_rand(0, 2) === 0) and max( //TODO: move this to World - $this->pos->getWorld()->getHighestAdjacentBlockLight($this->pos->x, $this->pos->y, $this->pos->z), - $this->pos->getWorld()->getHighestAdjacentBlockSkyLight($this->pos->x, $this->pos->y, $this->pos->z) - $this->pos->getWorld()->getSkyLightReduction() + $this->pos->getWorldNonNull()->getHighestAdjacentBlockLight($this->pos->x, $this->pos->y, $this->pos->z), + $this->pos->getWorldNonNull()->getHighestAdjacentBlockSkyLight($this->pos->x, $this->pos->y, $this->pos->z) - $this->pos->getWorldNonNull()->getSkyLightReduction() ) >= 12 - $this->age){ if($this->tryMelt()){ foreach($this->getAllSides() as $block){ @@ -70,7 +70,7 @@ class FrostedIce extends Ice{ } } }else{ - $this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, mt_rand(20, 40)); + $this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, mt_rand(20, 40)); } } @@ -86,7 +86,7 @@ class FrostedIce extends Ice{ continue; } if( - $this->pos->getWorld()->getBlockAt($this->pos->x + $x, $this->pos->y, $this->pos->z + $z) instanceof FrostedIce and + $this->pos->getWorldNonNull()->getBlockAt($this->pos->x + $x, $this->pos->y, $this->pos->z + $z) instanceof FrostedIce and ++$found >= $requirement ){ return true; @@ -103,13 +103,13 @@ class FrostedIce extends Ice{ */ private function tryMelt() : bool{ if($this->age >= 3){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); return true; } $this->age++; - $this->pos->getWorld()->setBlock($this->pos, $this); - $this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, mt_rand(20, 40)); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, mt_rand(20, 40)); return false; } } diff --git a/src/block/Furnace.php b/src/block/Furnace.php index 70ffde36d..f7444dab5 100644 --- a/src/block/Furnace.php +++ b/src/block/Furnace.php @@ -88,7 +88,7 @@ class Furnace extends Opaque{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player instanceof Player){ - $furnace = $this->pos->getWorld()->getTile($this->pos); + $furnace = $this->pos->getWorldNonNull()->getTile($this->pos); if($furnace instanceof TileFurnace and $furnace->canOpenWith($item->getCustomName())){ $player->setCurrentWindow($furnace->getInventory()); } @@ -98,9 +98,9 @@ class Furnace extends Opaque{ } public function onScheduledUpdate() : void{ - $furnace = $this->pos->getWorld()->getTile($this->pos); + $furnace = $this->pos->getWorldNonNull()->getTile($this->pos); if($furnace instanceof TileFurnace and $furnace->onUpdate()){ - $this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, 1); //TODO: check this + $this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, 1); //TODO: check this } } } diff --git a/src/block/Grass.php b/src/block/Grass.php index e42f5a7d5..7c74d4b08 100644 --- a/src/block/Grass.php +++ b/src/block/Grass.php @@ -52,13 +52,13 @@ class Grass extends Opaque{ } public function onRandomTick() : void{ - $lightAbove = $this->pos->getWorld()->getFullLightAt($this->pos->x, $this->pos->y + 1, $this->pos->z); - if($lightAbove < 4 and $this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y + 1, $this->pos->z)->getLightFilter() >= 2){ + $lightAbove = $this->pos->getWorldNonNull()->getFullLightAt($this->pos->x, $this->pos->y + 1, $this->pos->z); + if($lightAbove < 4 and $this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y + 1, $this->pos->z)->getLightFilter() >= 2){ //grass dies $ev = new BlockSpreadEvent($this, $this, VanillaBlocks::DIRT()); $ev->call(); if(!$ev->isCancelled()){ - $this->pos->getWorld()->setBlock($this->pos, $ev->getNewState(), false); + $this->pos->getWorldNonNull()->setBlock($this->pos, $ev->getNewState(), false); } }elseif($lightAbove >= 9){ //try grass spread @@ -67,12 +67,12 @@ class Grass extends Opaque{ $y = mt_rand($this->pos->y - 3, $this->pos->y + 1); $z = mt_rand($this->pos->z - 1, $this->pos->z + 1); - $b = $this->pos->getWorld()->getBlockAt($x, $y, $z); + $b = $this->pos->getWorldNonNull()->getBlockAt($x, $y, $z); if( !($b instanceof Dirt) or $b instanceof CoarseDirt or - $this->pos->getWorld()->getFullLightAt($x, $y + 1, $z) < 4 or - $this->pos->getWorld()->getBlockAt($x, $y + 1, $z)->getLightFilter() >= 2 + $this->pos->getWorldNonNull()->getFullLightAt($x, $y + 1, $z) < 4 or + $this->pos->getWorldNonNull()->getBlockAt($x, $y + 1, $z)->getLightFilter() >= 2 ){ continue; } @@ -80,7 +80,7 @@ class Grass extends Opaque{ $ev = new BlockSpreadEvent($b, $this, VanillaBlocks::GRASS()); $ev->call(); if(!$ev->isCancelled()){ - $this->pos->getWorld()->setBlock($b->pos, $ev->getNewState(), false); + $this->pos->getWorldNonNull()->setBlock($b->pos, $ev->getNewState(), false); } } } @@ -92,17 +92,17 @@ class Grass extends Opaque{ } if($item instanceof Fertilizer){ $item->pop(); - TallGrassObject::growGrass($this->pos->getWorld(), $this->pos, new Random(mt_rand()), 8, 2); + TallGrassObject::growGrass($this->pos->getWorldNonNull(), $this->pos, new Random(mt_rand()), 8, 2); return true; }elseif($item instanceof Hoe){ $item->applyDamage(1); - $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::FARMLAND()); + $this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::FARMLAND()); return true; }elseif($item instanceof Shovel and $this->getSide(Facing::UP)->getId() === BlockLegacyIds::AIR){ $item->applyDamage(1); - $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::GRASS_PATH()); + $this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::GRASS_PATH()); return true; } diff --git a/src/block/GrassPath.php b/src/block/GrassPath.php index e4cf5b274..98611bc2e 100644 --- a/src/block/GrassPath.php +++ b/src/block/GrassPath.php @@ -42,7 +42,7 @@ class GrassPath extends Transparent{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::UP)->isSolid()){ - $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::DIRT()); + $this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::DIRT()); } } diff --git a/src/block/Hopper.php b/src/block/Hopper.php index be6a4b6de..cb402bc28 100644 --- a/src/block/Hopper.php +++ b/src/block/Hopper.php @@ -76,7 +76,7 @@ class Hopper extends Transparent{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player !== null){ - $tile = $this->pos->getWorld()->getTile($this->pos); + $tile = $this->pos->getWorldNonNull()->getTile($this->pos); if($tile instanceof TileHopper){ //TODO: find a way to have inventories open on click without this boilerplate in every block $player->setCurrentWindow($tile->getInventory()); } diff --git a/src/block/Ice.php b/src/block/Ice.php index 2fd60d9f6..a908d2726 100644 --- a/src/block/Ice.php +++ b/src/block/Ice.php @@ -43,7 +43,7 @@ class Ice extends Transparent{ public function onBreak(Item $item, ?Player $player = null) : bool{ if(($player === null or $player->isSurvival()) and !$item->hasEnchantment(Enchantment::SILK_TOUCH())){ - $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::WATER()); + $this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::WATER()); return true; } return parent::onBreak($item, $player); @@ -54,8 +54,8 @@ class Ice extends Transparent{ } public function onRandomTick() : void{ - if($this->pos->getWorld()->getHighestAdjacentBlockLight($this->pos->x, $this->pos->y, $this->pos->z) >= 12){ - $this->pos->getWorld()->useBreakOn($this->pos); + if($this->pos->getWorldNonNull()->getHighestAdjacentBlockLight($this->pos->x, $this->pos->y, $this->pos->z) >= 12){ + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } diff --git a/src/block/ItemFrame.php b/src/block/ItemFrame.php index a28f00f62..885b7eda6 100644 --- a/src/block/ItemFrame.php +++ b/src/block/ItemFrame.php @@ -61,7 +61,7 @@ class ItemFrame extends Flowable{ public function readStateFromWorld() : void{ parent::readStateFromWorld(); - $tile = $this->pos->getWorld()->getTile($this->pos); + $tile = $this->pos->getWorldNonNull()->getTile($this->pos); if($tile instanceof TileItemFrame){ $this->framedItem = $tile->getItem(); if($this->framedItem->isNull()){ @@ -74,7 +74,7 @@ class ItemFrame extends Flowable{ public function writeStateToWorld() : void{ parent::writeStateToWorld(); - $tile = $this->pos->getWorld()->getTile($this->pos); + $tile = $this->pos->getWorldNonNull()->getTile($this->pos); if($tile instanceof TileItemFrame){ $tile->setItem($this->framedItem); $tile->setItemRotation($this->itemRotation); @@ -132,7 +132,7 @@ class ItemFrame extends Flowable{ return true; } - $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); return true; } @@ -142,16 +142,16 @@ class ItemFrame extends Flowable{ return false; } if(lcg_value() <= $this->itemDropChance){ - $this->pos->getWorld()->dropItem($this->pos->add(0.5, 0.5, 0.5), $this->getFramedItem()); + $this->pos->getWorldNonNull()->dropItem($this->pos->add(0.5, 0.5, 0.5), $this->getFramedItem()); } $this->setFramedItem(null); - $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); return true; } public function onNearbyBlockChange() : void{ if(!$this->getSide(Facing::opposite($this->facing))->isSolid()){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } diff --git a/src/block/Ladder.php b/src/block/Ladder.php index 8ff08707e..5d74adaa8 100644 --- a/src/block/Ladder.php +++ b/src/block/Ladder.php @@ -90,7 +90,7 @@ class Ladder extends Transparent{ public function onNearbyBlockChange() : void{ if(!$this->getSide(Facing::opposite($this->facing))->isSolid()){ //Replace with common break method - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } } diff --git a/src/block/Lantern.php b/src/block/Lantern.php index 7f5d790c5..99a441bc3 100644 --- a/src/block/Lantern.php +++ b/src/block/Lantern.php @@ -69,17 +69,17 @@ class Lantern extends Transparent{ } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if(!$this->canAttachTo($this->pos->getWorld()->getBlock($blockReplace->getPos()->up())) and !$this->canAttachTo($this->pos->getWorld()->getBlock($blockReplace->getPos()->down()))){ + if(!$this->canAttachTo($this->pos->getWorldNonNull()->getBlock($blockReplace->getPos()->up())) and !$this->canAttachTo($this->pos->getWorldNonNull()->getBlock($blockReplace->getPos()->down()))){ return false; } - $this->hanging = ($face === Facing::DOWN or !$this->canAttachTo($this->pos->getWorld()->getBlock($blockReplace->getPos()->down()))); + $this->hanging = ($face === Facing::DOWN or !$this->canAttachTo($this->pos->getWorldNonNull()->getBlock($blockReplace->getPos()->down()))); return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function onNearbyBlockChange() : void{ - if(!$this->canAttachTo($this->pos->getWorld()->getBlock($this->hanging ? $this->pos->up() : $this->pos->down()))){ - $this->pos->getWorld()->useBreakOn($this->pos); + if(!$this->canAttachTo($this->pos->getWorldNonNull()->getBlock($this->hanging ? $this->pos->up() : $this->pos->down()))){ + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } } diff --git a/src/block/Leaves.php b/src/block/Leaves.php index 38701ea42..09dd3ca91 100644 --- a/src/block/Leaves.php +++ b/src/block/Leaves.php @@ -78,7 +78,7 @@ class Leaves extends Transparent{ } $visited[$index] = true; - $block = $this->pos->getWorld()->getBlock($pos); + $block = $this->pos->getWorldNonNull()->getBlock($pos); if($block instanceof Wood){ //type doesn't matter return true; } @@ -97,7 +97,7 @@ class Leaves extends Transparent{ public function onNearbyBlockChange() : void{ if(!$this->noDecay and !$this->checkDecay){ $this->checkDecay = true; - $this->pos->getWorld()->setBlock($this->pos, $this, false); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this, false); } } @@ -111,9 +111,9 @@ class Leaves extends Transparent{ $ev->call(); if($ev->isCancelled() or $this->findLog($this->pos)){ $this->checkDecay = false; - $this->pos->getWorld()->setBlock($this->pos, $this, false); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this, false); }else{ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } } diff --git a/src/block/Lever.php b/src/block/Lever.php index d4d7bf6f5..67c65e899 100644 --- a/src/block/Lever.php +++ b/src/block/Lever.php @@ -107,14 +107,14 @@ class Lever extends Flowable{ } if(!$this->getSide($face)->isSolid()){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->powered = !$this->powered; - $this->pos->getWorld()->setBlock($this->pos, $this); - $this->pos->getWorld()->addSound( + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->addSound( $this->pos->add(0.5, 0.5, 0.5), $this->powered ? new RedstonePowerOnSound() : new RedstonePowerOffSound() ); diff --git a/src/block/Liquid.php b/src/block/Liquid.php index 3819f5039..68990cb14 100644 --- a/src/block/Liquid.php +++ b/src/block/Liquid.php @@ -188,7 +188,7 @@ abstract class Liquid extends Transparent{ ++$z; } - $sideBlock = $this->pos->getWorld()->getBlockAt($x, $y, $z); + $sideBlock = $this->pos->getWorldNonNull()->getBlockAt($x, $y, $z); $blockDecay = $this->getEffectiveFlowDecay($sideBlock); if($blockDecay < 0){ @@ -196,7 +196,7 @@ abstract class Liquid extends Transparent{ continue; } - $blockDecay = $this->getEffectiveFlowDecay($this->pos->getWorld()->getBlockAt($x, $y - 1, $z)); + $blockDecay = $this->getEffectiveFlowDecay($this->pos->getWorldNonNull()->getBlockAt($x, $y - 1, $z)); if($blockDecay >= 0){ $realDecay = $blockDecay - ($decay - 8); @@ -216,14 +216,14 @@ abstract class Liquid extends Transparent{ if($this->falling){ if( - !$this->canFlowInto($this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z - 1)) or - !$this->canFlowInto($this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z + 1)) or - !$this->canFlowInto($this->pos->getWorld()->getBlockAt($this->pos->x - 1, $this->pos->y, $this->pos->z)) or - !$this->canFlowInto($this->pos->getWorld()->getBlockAt($this->pos->x + 1, $this->pos->y, $this->pos->z)) or - !$this->canFlowInto($this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y + 1, $this->pos->z - 1)) or - !$this->canFlowInto($this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y + 1, $this->pos->z + 1)) or - !$this->canFlowInto($this->pos->getWorld()->getBlockAt($this->pos->x - 1, $this->pos->y + 1, $this->pos->z)) or - !$this->canFlowInto($this->pos->getWorld()->getBlockAt($this->pos->x + 1, $this->pos->y + 1, $this->pos->z)) + !$this->canFlowInto($this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z - 1)) or + !$this->canFlowInto($this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z + 1)) or + !$this->canFlowInto($this->pos->getWorldNonNull()->getBlockAt($this->pos->x - 1, $this->pos->y, $this->pos->z)) or + !$this->canFlowInto($this->pos->getWorldNonNull()->getBlockAt($this->pos->x + 1, $this->pos->y, $this->pos->z)) or + !$this->canFlowInto($this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y + 1, $this->pos->z - 1)) or + !$this->canFlowInto($this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y + 1, $this->pos->z + 1)) or + !$this->canFlowInto($this->pos->getWorldNonNull()->getBlockAt($this->pos->x - 1, $this->pos->y + 1, $this->pos->z)) or + !$this->canFlowInto($this->pos->getWorldNonNull()->getBlockAt($this->pos->x + 1, $this->pos->y + 1, $this->pos->z)) ){ $vector = $vector->normalize()->add(0, -6, 0); } @@ -252,7 +252,7 @@ abstract class Liquid extends Transparent{ public function onNearbyBlockChange() : void{ $this->checkForHarden(); - $this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, $this->tickRate()); + $this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, $this->tickRate()); } public function onScheduledUpdate() : void{ @@ -261,10 +261,10 @@ abstract class Liquid extends Transparent{ if(!$this->isSource()){ $smallestFlowDecay = -100; $this->adjacentSources = 0; - $smallestFlowDecay = $this->getSmallestFlowDecay($this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z - 1), $smallestFlowDecay); - $smallestFlowDecay = $this->getSmallestFlowDecay($this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z + 1), $smallestFlowDecay); - $smallestFlowDecay = $this->getSmallestFlowDecay($this->pos->getWorld()->getBlockAt($this->pos->x - 1, $this->pos->y, $this->pos->z), $smallestFlowDecay); - $smallestFlowDecay = $this->getSmallestFlowDecay($this->pos->getWorld()->getBlockAt($this->pos->x + 1, $this->pos->y, $this->pos->z), $smallestFlowDecay); + $smallestFlowDecay = $this->getSmallestFlowDecay($this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z - 1), $smallestFlowDecay); + $smallestFlowDecay = $this->getSmallestFlowDecay($this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z + 1), $smallestFlowDecay); + $smallestFlowDecay = $this->getSmallestFlowDecay($this->pos->getWorldNonNull()->getBlockAt($this->pos->x - 1, $this->pos->y, $this->pos->z), $smallestFlowDecay); + $smallestFlowDecay = $this->getSmallestFlowDecay($this->pos->getWorldNonNull()->getBlockAt($this->pos->x + 1, $this->pos->y, $this->pos->z), $smallestFlowDecay); $newDecay = $smallestFlowDecay + $multiplier; $falling = false; @@ -273,12 +273,12 @@ abstract class Liquid extends Transparent{ $newDecay = -1; } - if($this->getEffectiveFlowDecay($this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y + 1, $this->pos->z)) >= 0){ + if($this->getEffectiveFlowDecay($this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y + 1, $this->pos->z)) >= 0){ $falling = true; } if($this->adjacentSources >= 2 and $this instanceof Water){ - $bottomBlock = $this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y - 1, $this->pos->z); + $bottomBlock = $this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y - 1, $this->pos->z); if($bottomBlock->isSolid() or ($bottomBlock instanceof Water and $bottomBlock->isSource())){ $newDecay = 0; $falling = false; @@ -287,17 +287,17 @@ abstract class Liquid extends Transparent{ if($falling !== $this->falling or (!$falling and $newDecay !== $this->decay)){ if(!$falling and $newDecay < 0){ - $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::AIR()); + $this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::AIR()); return; } $this->falling = $falling; $this->decay = $falling ? 0 : $newDecay; - $this->pos->getWorld()->setBlock($this->pos, $this); //local block update will cause an update to be scheduled + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); //local block update will cause an update to be scheduled } } - $bottomBlock = $this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y - 1, $this->pos->z); + $bottomBlock = $this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y - 1, $this->pos->z); $this->flowIntoBlock($bottomBlock, 0, true); @@ -312,19 +312,19 @@ abstract class Liquid extends Transparent{ $flags = $this->getOptimalFlowDirections(); if($flags[0]){ - $this->flowIntoBlock($this->pos->getWorld()->getBlockAt($this->pos->x - 1, $this->pos->y, $this->pos->z), $adjacentDecay, false); + $this->flowIntoBlock($this->pos->getWorldNonNull()->getBlockAt($this->pos->x - 1, $this->pos->y, $this->pos->z), $adjacentDecay, false); } if($flags[1]){ - $this->flowIntoBlock($this->pos->getWorld()->getBlockAt($this->pos->x + 1, $this->pos->y, $this->pos->z), $adjacentDecay, false); + $this->flowIntoBlock($this->pos->getWorldNonNull()->getBlockAt($this->pos->x + 1, $this->pos->y, $this->pos->z), $adjacentDecay, false); } if($flags[2]){ - $this->flowIntoBlock($this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z - 1), $adjacentDecay, false); + $this->flowIntoBlock($this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z - 1), $adjacentDecay, false); } if($flags[3]){ - $this->flowIntoBlock($this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z + 1), $adjacentDecay, false); + $this->flowIntoBlock($this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z + 1), $adjacentDecay, false); } } } @@ -342,10 +342,10 @@ abstract class Liquid extends Transparent{ $ev->call(); if(!$ev->isCancelled()){ if($block->getId() > 0){ - $this->pos->getWorld()->useBreakOn($block->pos); + $this->pos->getWorldNonNull()->useBreakOn($block->pos); } - $this->pos->getWorld()->setBlock($block->pos, $ev->getNewState()); + $this->pos->getWorldNonNull()->setBlock($block->pos, $ev->getNewState()); } } } @@ -373,10 +373,10 @@ abstract class Liquid extends Transparent{ } if(!isset($this->flowCostVisited[$hash = World::blockHash($x, $y, $z)])){ - $blockSide = $this->pos->getWorld()->getBlockAt($x, $y, $z); + $blockSide = $this->pos->getWorldNonNull()->getBlockAt($x, $y, $z); if(!$this->canFlowInto($blockSide)){ $this->flowCostVisited[$hash] = self::BLOCKED; - }elseif($this->pos->getWorld()->getBlockAt($x, $y - 1, $z)->canBeFlowedInto()){ + }elseif($this->pos->getWorldNonNull()->getBlockAt($x, $y - 1, $z)->canBeFlowedInto()){ $this->flowCostVisited[$hash] = self::CAN_FLOW_DOWN; }else{ $this->flowCostVisited[$hash] = self::CAN_FLOW; @@ -425,12 +425,12 @@ abstract class Liquid extends Transparent{ }elseif($j === 3){ ++$z; } - $block = $this->pos->getWorld()->getBlockAt($x, $y, $z); + $block = $this->pos->getWorldNonNull()->getBlockAt($x, $y, $z); if(!$this->canFlowInto($block)){ $this->flowCostVisited[World::blockHash($x, $y, $z)] = self::BLOCKED; continue; - }elseif($this->pos->getWorld()->getBlockAt($x, $y - 1, $z)->canBeFlowedInto()){ + }elseif($this->pos->getWorldNonNull()->getBlockAt($x, $y - 1, $z)->canBeFlowedInto()){ $this->flowCostVisited[World::blockHash($x, $y, $z)] = self::CAN_FLOW_DOWN; $flowCost[$j] = $maxCost = 0; }elseif($maxCost > 0){ @@ -477,13 +477,13 @@ abstract class Liquid extends Transparent{ $ev = new BlockFormEvent($this, $result); $ev->call(); if(!$ev->isCancelled()){ - $this->pos->getWorld()->setBlock($this->pos, $ev->getNewState()); - $this->pos->getWorld()->addSound($this->pos->add(0.5, 0.5, 0.5), new FizzSound(2.6 + (lcg_value() - lcg_value()) * 0.8)); + $this->pos->getWorldNonNull()->setBlock($this->pos, $ev->getNewState()); + $this->pos->getWorldNonNull()->addSound($this->pos->add(0.5, 0.5, 0.5), new FizzSound(2.6 + (lcg_value() - lcg_value()) * 0.8)); } return true; } protected function canFlowInto(Block $block) : bool{ - return $this->pos->getWorld()->isInWorld($block->pos->x, $block->pos->y, $block->pos->z) and $block->canBeFlowedInto() and !($block instanceof Liquid and $block->isSource()); //TODO: I think this should only be liquids of the same type + return $this->pos->getWorldNonNull()->isInWorld($block->pos->x, $block->pos->y, $block->pos->z) and $block->canBeFlowedInto() and !($block instanceof Liquid and $block->isSource()); //TODO: I think this should only be liquids of the same type } } diff --git a/src/block/Mycelium.php b/src/block/Mycelium.php index 47b40364e..7e80a06ae 100644 --- a/src/block/Mycelium.php +++ b/src/block/Mycelium.php @@ -49,13 +49,13 @@ class Mycelium extends Opaque{ $x = mt_rand($this->pos->x - 1, $this->pos->x + 1); $y = mt_rand($this->pos->y - 2, $this->pos->y + 2); $z = mt_rand($this->pos->z - 1, $this->pos->z + 1); - $block = $this->pos->getWorld()->getBlockAt($x, $y, $z); + $block = $this->pos->getWorldNonNull()->getBlockAt($x, $y, $z); if($block->getId() === BlockLegacyIds::DIRT){ if($block->getSide(Facing::UP) instanceof Transparent){ $ev = new BlockSpreadEvent($block, $this, VanillaBlocks::MYCELIUM()); $ev->call(); if(!$ev->isCancelled()){ - $this->pos->getWorld()->setBlock($block->pos, $ev->getNewState()); + $this->pos->getWorldNonNull()->setBlock($block->pos, $ev->getNewState()); } } } diff --git a/src/block/NetherWartPlant.php b/src/block/NetherWartPlant.php index 7ca38d72f..da44b7bde 100644 --- a/src/block/NetherWartPlant.php +++ b/src/block/NetherWartPlant.php @@ -64,7 +64,7 @@ class NetherWartPlant extends Flowable{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::SOUL_SAND){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } @@ -79,7 +79,7 @@ class NetherWartPlant extends Flowable{ $ev = new BlockGrowEvent($this, $block); $ev->call(); if(!$ev->isCancelled()){ - $this->pos->getWorld()->setBlock($this->pos, $ev->getNewState()); + $this->pos->getWorldNonNull()->setBlock($this->pos, $ev->getNewState()); } } } diff --git a/src/block/Note.php b/src/block/Note.php index 3e027c220..54fcf7a1d 100644 --- a/src/block/Note.php +++ b/src/block/Note.php @@ -39,7 +39,7 @@ class Note extends Opaque{ public function readStateFromWorld() : void{ parent::readStateFromWorld(); - $tile = $this->pos->getWorld()->getTile($this->pos); + $tile = $this->pos->getWorldNonNull()->getTile($this->pos); if($tile instanceof TileNote){ $this->pitch = $tile->getPitch(); }else{ @@ -49,7 +49,7 @@ class Note extends Opaque{ public function writeStateToWorld() : void{ parent::writeStateToWorld(); - $tile = $this->pos->getWorld()->getTile($this->pos); + $tile = $this->pos->getWorldNonNull()->getTile($this->pos); assert($tile instanceof TileNote); $tile->setPitch($this->pitch); } diff --git a/src/block/RedMushroom.php b/src/block/RedMushroom.php index 72d3bb5ec..c5e643f21 100644 --- a/src/block/RedMushroom.php +++ b/src/block/RedMushroom.php @@ -41,7 +41,7 @@ class RedMushroom extends Flowable{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->isTransparent()){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } diff --git a/src/block/RedstoneComparator.php b/src/block/RedstoneComparator.php index 7372ab99a..cae56d03f 100644 --- a/src/block/RedstoneComparator.php +++ b/src/block/RedstoneComparator.php @@ -72,7 +72,7 @@ class RedstoneComparator extends Flowable{ public function readStateFromWorld() : void{ parent::readStateFromWorld(); - $tile = $this->pos->getWorld()->getTile($this->pos); + $tile = $this->pos->getWorldNonNull()->getTile($this->pos); if($tile instanceof Comparator){ $this->signalStrength = $tile->getSignalStrength(); } @@ -80,7 +80,7 @@ class RedstoneComparator extends Flowable{ public function writeStateToWorld() : void{ parent::writeStateToWorld(); - $tile = $this->pos->getWorld()->getTile($this->pos); + $tile = $this->pos->getWorldNonNull()->getTile($this->pos); assert($tile instanceof Comparator); $tile->setSignalStrength($this->signalStrength); } @@ -143,13 +143,13 @@ class RedstoneComparator extends Flowable{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->isSubtractMode = !$this->isSubtractMode; - $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); return true; } public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->isTransparent()){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } diff --git a/src/block/RedstoneOre.php b/src/block/RedstoneOre.php index cde5462d0..ef6fcee95 100644 --- a/src/block/RedstoneOre.php +++ b/src/block/RedstoneOre.php @@ -68,7 +68,7 @@ class RedstoneOre extends Opaque{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if(!$this->lit){ $this->lit = true; - $this->pos->getWorld()->setBlock($this->pos, $this); //no return here - this shouldn't prevent block placement + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); //no return here - this shouldn't prevent block placement } return false; } @@ -76,7 +76,7 @@ class RedstoneOre extends Opaque{ public function onNearbyBlockChange() : void{ if(!$this->lit){ $this->lit = true; - $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); } } @@ -87,7 +87,7 @@ class RedstoneOre extends Opaque{ public function onRandomTick() : void{ if($this->lit){ $this->lit = false; - $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); } } diff --git a/src/block/RedstoneRepeater.php b/src/block/RedstoneRepeater.php index 82af3f53d..af15cc322 100644 --- a/src/block/RedstoneRepeater.php +++ b/src/block/RedstoneRepeater.php @@ -99,13 +99,13 @@ class RedstoneRepeater extends Flowable{ if(++$this->delay > 4){ $this->delay = 1; } - $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); return true; } public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->isTransparent()){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } diff --git a/src/block/Sapling.php b/src/block/Sapling.php index 8b0e74f54..c6e8a227f 100644 --- a/src/block/Sapling.php +++ b/src/block/Sapling.php @@ -69,7 +69,7 @@ class Sapling extends Flowable{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($item instanceof Fertilizer){ - Tree::growTree($this->pos->getWorld(), $this->pos->x, $this->pos->y, $this->pos->z, new Random(mt_rand()), $this->treeType); + Tree::growTree($this->pos->getWorldNonNull(), $this->pos->x, $this->pos->y, $this->pos->z, new Random(mt_rand()), $this->treeType); $item->pop(); @@ -81,7 +81,7 @@ class Sapling extends Flowable{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->isTransparent()){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } @@ -90,12 +90,12 @@ class Sapling extends Flowable{ } public function onRandomTick() : void{ - if($this->pos->getWorld()->getFullLightAt($this->pos->x, $this->pos->y, $this->pos->z) >= 8 and mt_rand(1, 7) === 1){ + if($this->pos->getWorldNonNull()->getFullLightAt($this->pos->x, $this->pos->y, $this->pos->z) >= 8 and mt_rand(1, 7) === 1){ if($this->ready){ - Tree::growTree($this->pos->getWorld(), $this->pos->x, $this->pos->y, $this->pos->z, new Random(mt_rand()), $this->treeType); + Tree::growTree($this->pos->getWorldNonNull(), $this->pos->x, $this->pos->y, $this->pos->z, new Random(mt_rand()), $this->treeType); }else{ $this->ready = true; - $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); } } } diff --git a/src/block/Sign.php b/src/block/Sign.php index 17bad1f3a..6c137a222 100644 --- a/src/block/Sign.php +++ b/src/block/Sign.php @@ -86,7 +86,7 @@ class Sign extends Transparent{ public function readStateFromWorld() : void{ parent::readStateFromWorld(); - $tile = $this->pos->getWorld()->getTile($this->pos); + $tile = $this->pos->getWorldNonNull()->getTile($this->pos); if($tile instanceof TileSign){ $this->text = $tile->getText(); } @@ -94,7 +94,7 @@ class Sign extends Transparent{ public function writeStateToWorld() : void{ parent::writeStateToWorld(); - $tile = $this->pos->getWorld()->getTile($this->pos); + $tile = $this->pos->getWorldNonNull()->getTile($this->pos); assert($tile instanceof TileSign); $tile->setText($this->text); } @@ -129,7 +129,7 @@ class Sign extends Transparent{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::opposite($this->facing))->getId() === BlockLegacyIds::AIR){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } @@ -161,7 +161,7 @@ class Sign extends Transparent{ $ev->call(); if(!$ev->isCancelled()){ $this->text = clone $ev->getNewText(); - $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); return true; } diff --git a/src/block/Skull.php b/src/block/Skull.php index e912f19e0..c2675aa53 100644 --- a/src/block/Skull.php +++ b/src/block/Skull.php @@ -67,7 +67,7 @@ class Skull extends Flowable{ public function readStateFromWorld() : void{ parent::readStateFromWorld(); - $tile = $this->pos->getWorld()->getTile($this->pos); + $tile = $this->pos->getWorldNonNull()->getTile($this->pos); if($tile instanceof TileSkull){ $this->skullType = $tile->getSkullType(); $this->rotation = $tile->getRotation(); @@ -77,7 +77,7 @@ class Skull extends Flowable{ public function writeStateToWorld() : void{ parent::writeStateToWorld(); //extra block properties storage hack - $tile = $this->pos->getWorld()->getTile($this->pos); + $tile = $this->pos->getWorldNonNull()->getTile($this->pos); assert($tile instanceof TileSkull); $tile->setRotation($this->rotation); $tile->setSkullType($this->skullType); diff --git a/src/block/SnowLayer.php b/src/block/SnowLayer.php index 9eb43c33c..5a78b9c17 100644 --- a/src/block/SnowLayer.php +++ b/src/block/SnowLayer.php @@ -91,8 +91,8 @@ class SnowLayer extends Flowable implements Fallable{ } public function onRandomTick() : void{ - if($this->pos->getWorld()->getBlockLightAt($this->pos->x, $this->pos->y, $this->pos->z) >= 12){ - $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::AIR(), false); + if($this->pos->getWorldNonNull()->getBlockLightAt($this->pos->x, $this->pos->y, $this->pos->z) >= 12){ + $this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::AIR(), false); } } diff --git a/src/block/Stem.php b/src/block/Stem.php index 6ef52f165..66a9e6268 100644 --- a/src/block/Stem.php +++ b/src/block/Stem.php @@ -45,7 +45,7 @@ abstract class Stem extends Crops{ $ev = new BlockGrowEvent($this, $block); $ev->call(); if(!$ev->isCancelled()){ - $this->pos->getWorld()->setBlock($this->pos, $ev->getNewState()); + $this->pos->getWorldNonNull()->setBlock($this->pos, $ev->getNewState()); } }else{ $grow = $this->getPlant(); @@ -61,7 +61,7 @@ abstract class Stem extends Crops{ $ev = new BlockGrowEvent($side, $grow); $ev->call(); if(!$ev->isCancelled()){ - $this->pos->getWorld()->setBlock($side->pos, $ev->getNewState()); + $this->pos->getWorldNonNull()->setBlock($side->pos, $ev->getNewState()); } } } diff --git a/src/block/Sugarcane.php b/src/block/Sugarcane.php index d3444052f..bc90d89ae 100644 --- a/src/block/Sugarcane.php +++ b/src/block/Sugarcane.php @@ -57,20 +57,20 @@ class Sugarcane extends Flowable{ if($item instanceof Fertilizer){ if(!$this->getSide(Facing::DOWN)->isSameType($this)){ for($y = 1; $y < 3; ++$y){ - $b = $this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y + $y, $this->pos->z); + $b = $this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y + $y, $this->pos->z); if($b->getId() === BlockLegacyIds::AIR){ $ev = new BlockGrowEvent($b, VanillaBlocks::SUGARCANE()); $ev->call(); if($ev->isCancelled()){ break; } - $this->pos->getWorld()->setBlock($b->pos, $ev->getNewState()); + $this->pos->getWorldNonNull()->setBlock($b->pos, $ev->getNewState()); }else{ break; } } $this->age = 0; - $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); } $item->pop(); @@ -84,7 +84,7 @@ class Sugarcane extends Flowable{ public function onNearbyBlockChange() : void{ $down = $this->getSide(Facing::DOWN); if($down->isTransparent() and !$down->isSameType($this)){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } @@ -96,17 +96,17 @@ class Sugarcane extends Flowable{ if(!$this->getSide(Facing::DOWN)->isSameType($this)){ if($this->age === 15){ for($y = 1; $y < 3; ++$y){ - $b = $this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y + $y, $this->pos->z); + $b = $this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y + $y, $this->pos->z); if($b->getId() === BlockLegacyIds::AIR){ - $this->pos->getWorld()->setBlock($b->pos, VanillaBlocks::SUGARCANE()); + $this->pos->getWorldNonNull()->setBlock($b->pos, VanillaBlocks::SUGARCANE()); break; } } $this->age = 0; - $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); }else{ ++$this->age; - $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); } } } diff --git a/src/block/TNT.php b/src/block/TNT.php index 8a9e9a44f..b42b06d5a 100644 --- a/src/block/TNT.php +++ b/src/block/TNT.php @@ -90,14 +90,14 @@ class TNT extends Opaque{ } public function ignite(int $fuse = 80) : void{ - $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::AIR()); + $this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::AIR()); $mot = (new Random())->nextSignedFloat() * M_PI * 2; $nbt = EntityFactory::createBaseNBT($this->pos->add(0.5, 0, 0.5), new Vector3(-sin($mot) * 0.02, 0.2, -cos($mot) * 0.02)); $nbt->setShort("Fuse", $fuse); /** @var PrimedTNT $tnt */ - $tnt = EntityFactory::create(PrimedTNT::class, $this->pos->getWorld(), $nbt); + $tnt = EntityFactory::create(PrimedTNT::class, $this->pos->getWorldNonNull(), $nbt); $tnt->spawnToAll(); } diff --git a/src/block/TallGrass.php b/src/block/TallGrass.php index 88b3ac6ce..99880c446 100644 --- a/src/block/TallGrass.php +++ b/src/block/TallGrass.php @@ -52,7 +52,7 @@ class TallGrass extends Flowable{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->isTransparent()){ //Replace with common break method - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } diff --git a/src/block/Torch.php b/src/block/Torch.php index 001fbba6f..f97ef7d2c 100644 --- a/src/block/Torch.php +++ b/src/block/Torch.php @@ -60,7 +60,7 @@ class Torch extends Flowable{ $face = Facing::opposite($this->facing); if($this->getSide($face)->isTransparent() and !($face === Facing::DOWN and ($below->getId() === BlockLegacyIds::FENCE or $below->getId() === BlockLegacyIds::COBBLESTONE_WALL))){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } diff --git a/src/block/Trapdoor.php b/src/block/Trapdoor.php index ab1d75f53..b0205dadb 100644 --- a/src/block/Trapdoor.php +++ b/src/block/Trapdoor.php @@ -77,8 +77,8 @@ class Trapdoor extends Transparent{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->open = !$this->open; - $this->pos->getWorld()->setBlock($this->pos, $this); - $this->pos->getWorld()->addSound($this->pos, new DoorSound()); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->addSound($this->pos, new DoorSound()); return true; } } diff --git a/src/block/Vine.php b/src/block/Vine.php index b590c740d..9af86636b 100644 --- a/src/block/Vine.php +++ b/src/block/Vine.php @@ -115,9 +115,9 @@ class Vine extends Flowable{ if($changed){ if(count($this->faces) === 0){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); }else{ - $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorldNonNull()->setBlock($this->pos, $this); } } } diff --git a/src/block/WaterLily.php b/src/block/WaterLily.php index e4648d378..87abbc5e5 100644 --- a/src/block/WaterLily.php +++ b/src/block/WaterLily.php @@ -56,7 +56,7 @@ class WaterLily extends Flowable{ public function onNearbyBlockChange() : void{ if(!($this->getSide(Facing::DOWN) instanceof Water)){ - $this->pos->getWorld()->useBreakOn($this->pos); + $this->pos->getWorldNonNull()->useBreakOn($this->pos); } } } diff --git a/src/block/tile/BrewingStand.php b/src/block/tile/BrewingStand.php index 6d34ecfb8..350a8209e 100644 --- a/src/block/tile/BrewingStand.php +++ b/src/block/tile/BrewingStand.php @@ -55,7 +55,7 @@ class BrewingStand extends Spawnable implements Container, Nameable{ parent::__construct($world, $pos); $this->inventory = new BrewingStandInventory($this->pos); $this->inventory->addChangeListeners(CallbackInventoryChangeListener::onAnyChange(function(Inventory $unused) : void{ - $this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, 1); + $this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, 1); })); } diff --git a/src/block/tile/Chest.php b/src/block/tile/Chest.php index ed824a499..3cea05102 100644 --- a/src/block/tile/Chest.php +++ b/src/block/tile/Chest.php @@ -99,7 +99,7 @@ class Chest extends Spawnable implements Container, Nameable{ $this->inventory->removeAllViewers(); if($this->doubleInventory !== null){ - if($this->isPaired() and $this->pos->getWorld()->isChunkLoaded($this->pairX >> 4, $this->pairZ >> 4)){ + if($this->isPaired() and $this->pos->getWorldNonNull()->isChunkLoaded($this->pairX >> 4, $this->pairZ >> 4)){ $this->doubleInventory->removeAllViewers(); if(($pair = $this->getPair()) !== null){ $pair->doubleInventory = null; @@ -137,7 +137,7 @@ class Chest extends Spawnable implements Container, Nameable{ } protected function checkPairing() : void{ - if($this->isPaired() and !$this->pos->getWorld()->isInLoadedTerrain(new Vector3($this->pairX, $this->pos->y, $this->pairZ))){ + if($this->isPaired() and !$this->pos->getWorldNonNull()->isInLoadedTerrain(new Vector3($this->pairX, $this->pos->y, $this->pairZ))){ //paired to a tile in an unloaded chunk $this->doubleInventory = null; @@ -173,7 +173,7 @@ class Chest extends Spawnable implements Container, Nameable{ public function getPair() : ?Chest{ if($this->isPaired()){ - $tile = $this->pos->getWorld()->getTileAt($this->pairX, $this->pos->y, $this->pairZ); + $tile = $this->pos->getWorldNonNull()->getTileAt($this->pairX, $this->pos->y, $this->pairZ); if($tile instanceof Chest){ return $tile; } diff --git a/src/block/tile/Furnace.php b/src/block/tile/Furnace.php index a94491afd..6c7bad919 100644 --- a/src/block/tile/Furnace.php +++ b/src/block/tile/Furnace.php @@ -60,7 +60,7 @@ class Furnace extends Spawnable implements Container, Nameable{ $this->inventory = new FurnaceInventory($this->pos); $this->inventory->addChangeListeners(CallbackInventoryChangeListener::onAnyChange( function(Inventory $unused) : void{ - $this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, 1); + $this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, 1); }) ); } @@ -129,7 +129,7 @@ class Furnace extends Spawnable implements Container, Nameable{ $block = $this->getBlock(); if($block instanceof BlockFurnace and !$block->isLit()){ $block->setLit(true); - $this->pos->getWorld()->setBlock($block->getPos(), $block); + $this->pos->getWorldNonNull()->setBlock($block->getPos(), $block); } if($this->remainingFuelTime > 0 and $ev->isBurning()){ @@ -155,7 +155,7 @@ class Furnace extends Spawnable implements Container, Nameable{ $fuel = $this->inventory->getFuel(); $raw = $this->inventory->getSmelting(); $product = $this->inventory->getResult(); - $smelt = $this->pos->getWorld()->getServer()->getCraftingManager()->matchFurnaceRecipe($raw); + $smelt = $this->pos->getWorldNonNull()->getServer()->getCraftingManager()->matchFurnaceRecipe($raw); $canSmelt = ($smelt instanceof FurnaceRecipe and $raw->getCount() > 0 and (($smelt->getResult()->equals($product) and $product->getCount() < $product->getMaxStackSize()) or $product->isNull())); if($this->remainingFuelTime <= 0 and $canSmelt and $fuel->getFuelTime() > 0 and $fuel->getCount() > 0){ @@ -192,7 +192,7 @@ class Furnace extends Spawnable implements Container, Nameable{ $block = $this->getBlock(); if($block instanceof BlockFurnace and $block->isLit()){ $block->setLit(false); - $this->pos->getWorld()->setBlock($block->getPos(), $block); + $this->pos->getWorldNonNull()->setBlock($block->getPos(), $block); } $this->remainingFuelTime = $this->cookTime = $this->maxFuelTime = 0; } diff --git a/src/block/tile/Tile.php b/src/block/tile/Tile.php index 8a0184bf5..a5ffdfb5f 100644 --- a/src/block/tile/Tile.php +++ b/src/block/tile/Tile.php @@ -95,7 +95,7 @@ abstract class Tile{ } public function getBlock() : Block{ - return $this->pos->getWorld()->getBlock($this->pos); + return $this->pos->getWorldNonNull()->getBlock($this->pos); } public function getPos() : Position{ @@ -130,7 +130,7 @@ abstract class Tile{ $this->closed = true; if($this->pos->isValid()){ - $this->pos->getWorld()->removeTile($this); + $this->pos->getWorldNonNull()->removeTile($this); $this->pos->setWorld(null); } } diff --git a/src/block/utils/FallableTrait.php b/src/block/utils/FallableTrait.php index 90b52b18e..1d22c123e 100644 --- a/src/block/utils/FallableTrait.php +++ b/src/block/utils/FallableTrait.php @@ -56,7 +56,7 @@ trait FallableTrait{ $nbt->setByte("Data", $this->getMeta()); /** @var FallingBlock $fall */ - $fall = EntityFactory::create(FallingBlock::class, $pos->getWorld(), $nbt); + $fall = EntityFactory::create(FallingBlock::class, $pos->getWorldNonNull(), $nbt); $fall->spawnToAll(); } } diff --git a/src/command/defaults/SeedCommand.php b/src/command/defaults/SeedCommand.php index 29017edb5..4f92150bb 100644 --- a/src/command/defaults/SeedCommand.php +++ b/src/command/defaults/SeedCommand.php @@ -44,7 +44,7 @@ class SeedCommand extends VanillaCommand{ } if($sender instanceof Player){ - $seed = $sender->getPosition()->getWorld()->getSeed(); + $seed = $sender->getPosition()->getWorldNonNull()->getSeed(); }else{ $seed = $sender->getServer()->getWorldManager()->getDefaultWorld()->getSeed(); } diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 8affc11b0..0d3dce992 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -1342,7 +1342,7 @@ abstract class Entity{ } if($pos instanceof Position and $pos->world !== null and $pos->world !== $this->getWorld()){ - if(!$this->switchWorld($pos->getWorld())){ + if(!$this->switchWorld($pos->getWorldNonNull())){ return false; } } @@ -1456,7 +1456,7 @@ abstract class Entity{ $pitch = $pitch ?? $pos->pitch; } $from = $this->location->asPosition(); - $to = Position::fromObject($pos, $pos instanceof Position ? $pos->getWorld() : $this->getWorld()); + $to = Position::fromObject($pos, $pos instanceof Position ? $pos->getWorldNonNull() : $this->getWorld()); $ev = new EntityTeleportEvent($this, $from, $to); $ev->call(); if($ev->isCancelled()){ diff --git a/src/entity/Living.php b/src/entity/Living.php index 7acba21d9..dee6381a3 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -206,7 +206,7 @@ abstract class Living extends Entity{ public function hasLineOfSight(Entity $entity) : bool{ //TODO: head height return true; - //return $this->getLevel()->rayTraceBlocks(Vector3::createVector($this->x, $this->y + $this->height, $this->z), Vector3::createVector($entity->x, $entity->y + $entity->height, $entity->z)) === null; + //return $this->getLevelNonNull()->rayTraceBlocks(Vector3::createVector($this->x, $this->y + $this->height, $this->z), Vector3::createVector($entity->x, $entity->y + $entity->height, $entity->z)) === null; } public function getEffects() : EffectManager{ diff --git a/src/entity/Location.php b/src/entity/Location.php index f82cf0bd6..efd9bb411 100644 --- a/src/entity/Location.php +++ b/src/entity/Location.php @@ -68,7 +68,7 @@ class Location extends Position{ } public function __toString(){ - return "Location (world=" . ($this->isValid() ? $this->getWorld()->getDisplayName() : "null") . ", x=$this->x, y=$this->y, z=$this->z, yaw=$this->yaw, pitch=$this->pitch)"; + return "Location (world=" . ($this->isValid() ? $this->getWorldNonNull()->getDisplayName() : "null") . ", x=$this->x, y=$this->y, z=$this->z, yaw=$this->yaw, pitch=$this->pitch)"; } public function equals(Vector3 $v) : bool{ diff --git a/src/inventory/ChestInventory.php b/src/inventory/ChestInventory.php index bf1d3fed4..1aea2a77d 100644 --- a/src/inventory/ChestInventory.php +++ b/src/inventory/ChestInventory.php @@ -51,7 +51,7 @@ class ChestInventory extends BlockInventory{ if(count($this->getViewers()) === 1 and $this->getHolder()->isValid()){ //TODO: this crap really shouldn't be managed by the inventory $this->broadcastBlockEventPacket(true); - $this->getHolder()->getWorld()->addSound($this->getHolder()->add(0.5, 0.5, 0.5), $this->getOpenSound()); + $this->getHolder()->getWorldNonNull()->addSound($this->getHolder()->add(0.5, 0.5, 0.5), $this->getOpenSound()); } } @@ -59,7 +59,7 @@ class ChestInventory extends BlockInventory{ if(count($this->getViewers()) === 1 and $this->getHolder()->isValid()){ //TODO: this crap really shouldn't be managed by the inventory $this->broadcastBlockEventPacket(false); - $this->getHolder()->getWorld()->addSound($this->getHolder()->add(0.5, 0.5, 0.5), $this->getCloseSound()); + $this->getHolder()->getWorldNonNull()->addSound($this->getHolder()->add(0.5, 0.5, 0.5), $this->getCloseSound()); } parent::onClose($who); } @@ -68,6 +68,6 @@ class ChestInventory extends BlockInventory{ $holder = $this->getHolder(); //event ID is always 1 for a chest - $holder->getWorld()->broadcastPacketToViewers($holder, BlockEventPacket::create(1, $isOpen ? 1 : 0, $holder->asVector3())); + $holder->getWorldNonNull()->broadcastPacketToViewers($holder, BlockEventPacket::create(1, $isOpen ? 1 : 0, $holder->asVector3())); } } diff --git a/src/item/Bow.php b/src/item/Bow.php index ec1b7e9e7..1700f1381 100644 --- a/src/item/Bow.php +++ b/src/item/Bow.php @@ -105,7 +105,7 @@ class Bow extends Tool{ } $ev->getProjectile()->spawnToAll(); - $location->getWorld()->addSound($location, new BowShootSound()); + $location->getWorldNonNull()->addSound($location, new BowShootSound()); }else{ $entity->spawnToAll(); } diff --git a/src/item/PaintingItem.php b/src/item/PaintingItem.php index 6330c9e6b..54d6d7ffa 100644 --- a/src/item/PaintingItem.php +++ b/src/item/PaintingItem.php @@ -94,7 +94,7 @@ class PaintingItem extends Item{ $nbt->setInt("TileZ", $clickedPos->getFloorZ()); /** @var Painting $entity */ - $entity = EntityFactory::create(Painting::class, $replacePos->getWorld(), $nbt); + $entity = EntityFactory::create(Painting::class, $replacePos->getWorldNonNull(), $nbt); $this->pop(); $entity->spawnToAll(); diff --git a/src/item/ProjectileItem.php b/src/item/ProjectileItem.php index 62d3e6e4b..27e7b403e 100644 --- a/src/item/ProjectileItem.php +++ b/src/item/ProjectileItem.php @@ -72,7 +72,7 @@ abstract class ProjectileItem extends Item{ $projectile->spawnToAll(); - $location->getWorld()->addSound($location, new ThrowSound()); + $location->getWorldNonNull()->addSound($location, new ThrowSound()); $this->pop(); diff --git a/src/network/mcpe/handler/InGamePacketHandler.php b/src/network/mcpe/handler/InGamePacketHandler.php index b04e97ce1..75b124f85 100644 --- a/src/network/mcpe/handler/InGamePacketHandler.php +++ b/src/network/mcpe/handler/InGamePacketHandler.php @@ -346,7 +346,7 @@ class InGamePacketHandler extends PacketHandler{ }else{ $blocks[] = $blockPos; } - $this->player->getLocation()->getWorld()->sendBlocks([$this->player], $blocks); + $this->player->getLocation()->getWorldNonNull()->sendBlocks([$this->player], $blocks); } } @@ -539,7 +539,7 @@ class InGamePacketHandler extends PacketHandler{ return false; } - $block = $this->player->getLocation()->getWorld()->getBlock($pos); + $block = $this->player->getLocation()->getWorldNonNull()->getBlock($pos); try{ $offset = 0; $nbt = (new NetworkNbtSerializer())->read($packet->namedtag, $offset, 512)->mustGetCompoundTag(); diff --git a/src/network/mcpe/handler/PreSpawnPacketHandler.php b/src/network/mcpe/handler/PreSpawnPacketHandler.php index 1c956a343..435d297b5 100644 --- a/src/network/mcpe/handler/PreSpawnPacketHandler.php +++ b/src/network/mcpe/handler/PreSpawnPacketHandler.php @@ -65,12 +65,12 @@ class PreSpawnPacketHandler extends PacketHandler{ $pk->seed = -1; $pk->dimension = DimensionIds::OVERWORLD; //TODO: implement this properly $pk->worldGamemode = NetworkSession::getClientFriendlyGamemode($this->server->getGamemode()); - $pk->difficulty = $location->getWorld()->getDifficulty(); + $pk->difficulty = $location->getWorldNonNull()->getDifficulty(); $pk->spawnX = $spawnPosition->getFloorX(); $pk->spawnY = $spawnPosition->getFloorY(); $pk->spawnZ = $spawnPosition->getFloorZ(); $pk->hasAchievementsDisabled = true; - $pk->time = $location->getWorld()->getTime(); + $pk->time = $location->getWorldNonNull()->getTime(); $pk->eduEditionOffer = 0; $pk->rainLevel = 0; //TODO: implement these properly $pk->lightningLevel = 0; diff --git a/src/player/Player.php b/src/player/Player.php index 82a9dfdbd..14fa687a4 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -949,7 +949,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, if(!($pos instanceof Position)){ $world = $this->getWorld(); }else{ - $world = $pos->getWorld(); + $world = $pos->getWorldNonNull(); } $this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $world); $this->networkSession->syncPlayerSpawnPoint($this->spawnPosition); @@ -2044,7 +2044,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, } if($this->hasValidSpawnPosition()){ - $nbt->setString("SpawnLevel", $this->spawnPosition->getWorld()->getFolderName()); + $nbt->setString("SpawnLevel", $this->spawnPosition->getWorldNonNull()->getFolderName()); $nbt->setInt("SpawnX", $this->spawnPosition->getFloorX()); $nbt->setInt("SpawnY", $this->spawnPosition->getFloorY()); $nbt->setInt("SpawnZ", $this->spawnPosition->getFloorZ()); @@ -2117,7 +2117,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $ev = new PlayerRespawnEvent($this, $this->getSpawn()); $ev->call(); - $realSpawn = Position::fromObject($ev->getRespawnPosition()->add(0.5, 0, 0.5), $ev->getRespawnPosition()->getWorld()); + $realSpawn = Position::fromObject($ev->getRespawnPosition()->add(0.5, 0, 0.5), $ev->getRespawnPosition()->getWorldNonNull()); $this->teleport($realSpawn); $this->setSprinting(false); diff --git a/src/utils/AssumptionFailedError.php b/src/utils/AssumptionFailedError.php new file mode 100644 index 000000000..df7d2d464 --- /dev/null +++ b/src/utils/AssumptionFailedError.php @@ -0,0 +1,33 @@ +source = $center; - $this->world = $center->getWorld(); + $this->world = $center->getWorldNonNull(); if($size <= 0){ throw new \InvalidArgumentException("Explosion radius must be greater than 0, got $size"); diff --git a/src/world/Position.php b/src/world/Position.php index e5c6e8105..6ea8a0f19 100644 --- a/src/world/Position.php +++ b/src/world/Position.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\world; use pocketmine\math\Vector3; +use pocketmine\utils\AssumptionFailedError; use function assert; class Position extends Vector3{ @@ -70,6 +71,20 @@ class Position extends Vector3{ return $this->world; } + /** + * Returns the position's world if valid. Throws an error if the world is unexpectedly null. + * + * @throws AssumptionFailedError + */ + public function getWorldNonNull() : World{ + $world = $this->getWorld(); + if($world === null){ + throw new AssumptionFailedError("Position world is null"); + } + + return $world; + } + /** * Sets the target world of the position. * @@ -111,7 +126,7 @@ class Position extends Vector3{ } public function __toString(){ - return "Position(world=" . ($this->isValid() ? $this->getWorld()->getDisplayName() : "null") . ",x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")"; + return "Position(level=" . ($this->isValid() ? $this->getWorldNonNull()->getDisplayName() : "null") . ",x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")"; } public function equals(Vector3 $v) : bool{