From 670ad9eb9dfa07cb4d141aaf67aa64b3f091ebf0 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 29 Jun 2020 21:19:46 +0100 Subject: [PATCH] Position: rename getWorldNonNull() to getWorld(), remove original getWorld() --- src/block/Banner.php | 6 +- src/block/BaseRail.php | 8 +-- src/block/Bed.php | 10 +-- src/block/Block.php | 18 ++--- src/block/BrewingStand.php | 2 +- src/block/Button.php | 10 +-- src/block/Cactus.php | 12 ++-- src/block/Cake.php | 4 +- src/block/Carpet.php | 2 +- src/block/Chest.php | 6 +- src/block/CoarseDirt.php | 2 +- src/block/CocoaBlock.php | 6 +- src/block/ConcretePowder.php | 2 +- src/block/Crops.php | 6 +- src/block/DaylightSensor.php | 10 +-- src/block/DeadBush.php | 2 +- src/block/Dirt.php | 2 +- src/block/Door.php | 8 +-- src/block/DoublePlant.php | 2 +- src/block/DragonEgg.php | 8 +-- src/block/EnderChest.php | 2 +- src/block/Farmland.php | 10 +-- src/block/FenceGate.php | 6 +- src/block/Fire.php | 12 ++-- src/block/Flower.php | 2 +- src/block/FlowerPot.php | 8 +-- src/block/FrostedIce.php | 18 ++--- src/block/Furnace.php | 6 +- src/block/Grass.php | 20 +++--- src/block/GrassPath.php | 2 +- src/block/Hopper.php | 2 +- src/block/Ice.php | 6 +- src/block/ItemFrame.php | 12 ++-- src/block/Ladder.php | 2 +- src/block/Lantern.php | 8 +-- src/block/Leaves.php | 8 +-- src/block/Lever.php | 6 +- src/block/Liquid.php | 66 +++++++++---------- src/block/Mycelium.php | 4 +- src/block/NetherWartPlant.php | 4 +- src/block/Note.php | 4 +- src/block/RedMushroom.php | 2 +- src/block/RedstoneComparator.php | 8 +-- src/block/RedstoneOre.php | 6 +- src/block/RedstoneRepeater.php | 4 +- src/block/Sapling.php | 10 +-- src/block/Sign.php | 8 +-- src/block/Skull.php | 4 +- src/block/SnowLayer.php | 4 +- src/block/Stem.php | 4 +- src/block/Sugarcane.php | 16 ++--- src/block/TNT.php | 4 +- src/block/TallGrass.php | 2 +- src/block/Torch.php | 2 +- src/block/Trapdoor.php | 4 +- src/block/Vine.php | 4 +- src/block/WaterLily.php | 2 +- src/block/inventory/ChestInventory.php | 6 +- src/block/tile/BrewingStand.php | 2 +- src/block/tile/Chest.php | 6 +- src/block/tile/ContainerTrait.php | 2 +- src/block/tile/Furnace.php | 8 +-- src/block/tile/Tile.php | 4 +- src/block/utils/FallableTrait.php | 6 +- src/command/defaults/ParticleCommand.php | 2 +- src/command/defaults/SeedCommand.php | 2 +- src/command/defaults/SetWorldSpawnCommand.php | 2 +- src/command/defaults/SpawnpointCommand.php | 2 +- src/command/defaults/TeleportCommand.php | 2 +- src/entity/Entity.php | 10 +-- src/entity/Location.php | 2 +- src/item/Bow.php | 2 +- src/item/PaintingItem.php | 2 +- src/item/ProjectileItem.php | 2 +- src/network/mcpe/NetworkSession.php | 4 +- .../mcpe/handler/InGamePacketHandler.php | 4 +- .../mcpe/handler/PreSpawnPacketHandler.php | 4 +- src/player/Player.php | 8 +-- src/world/Explosion.php | 2 +- src/world/Position.php | 28 ++------ src/world/World.php | 4 +- 81 files changed, 259 insertions(+), 275 deletions(-) diff --git a/src/block/Banner.php b/src/block/Banner.php index 2be5e82e7..c9ba9c5c9 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->getWorldNonNull()->getTile($this->pos); + $tile = $this->pos->getWorld()->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->getWorldNonNull()->getTile($this->pos); + $tile = $this->pos->getWorld()->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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); } } diff --git a/src/block/BaseRail.php b/src/block/BaseRail.php index 4278c2700..017a3953b 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->getWorldNonNull()->setBlock($other->pos, $other); + $this->pos->getWorld()->setBlock($other->pos, $other); $changed = true; $thisConnections[] = $thisSide; @@ -268,7 +268,7 @@ abstract class BaseRail extends Flowable{ if($changed){ $this->setConnections($thisConnections); - $this->pos->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorld()->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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); break; } } diff --git a/src/block/Bed.php b/src/block/Bed.php index a5176d1b4..57c643fef 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->getWorldNonNull()->getTile($this->pos); + $tile = $this->pos->getWorld()->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->getWorldNonNull()->getTile($this->pos); + $tile = $this->pos->getWorld()->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->getWorldNonNull()->setBlock($this->pos, $this, false); + $this->pos->getWorld()->setBlock($this->pos, $this, false); if(($other = $this->getOtherHalf()) !== null){ $other->occupied = $occupied; - $this->pos->getWorldNonNull()->setBlock($other->pos, $other, false); + $this->pos->getWorld()->setBlock($other->pos, $other, false); } } @@ -139,7 +139,7 @@ class Bed extends Transparent{ return true; } - $time = $this->pos->getWorldNonNull()->getTimeOfDay(); + $time = $this->pos->getWorld()->getTimeOfDay(); $isNight = ($time >= World::TIME_NIGHT and $time < World::TIME_SUNRISE); diff --git a/src/block/Block.php b/src/block/Block.php index cb131fcc0..46123eaab 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -79,7 +79,7 @@ class Block{ } public function __clone(){ - $this->pos = Position::fromObject($this->pos, $this->pos->getWorldNonNull()); + $this->pos = Position::fromObject($this->pos, $this->pos->getWorld()); } public function getIdInfo() : BlockIdentifier{ @@ -148,10 +148,10 @@ class Block{ } public function writeStateToWorld() : void{ - $this->pos->getWorldNonNull()->getChunkAtPosition($this->pos)->setFullBlock($this->pos->x & 0xf, $this->pos->y, $this->pos->z & 0xf, $this->getFullId()); + $this->pos->getWorld()->getChunkAtPosition($this->pos)->setFullBlock($this->pos->x & 0xf, $this->pos->y, $this->pos->z & 0xf, $this->getFullId()); $tileType = $this->idInfo->getTileClass(); - $oldTile = $this->pos->getWorldNonNull()->getTile($this->pos); + $oldTile = $this->pos->getWorld()->getTile($this->pos); if($oldTile !== null){ if($tileType === null or !($oldTile instanceof $tileType)){ $oldTile->close(); @@ -165,8 +165,8 @@ class Block{ * @var Tile $tile * @see Tile::__construct() */ - $tile = new $tileType($this->pos->getWorldNonNull(), $this->pos->asVector3()); - $this->pos->getWorldNonNull()->addTile($tile); + $tile = new $tileType($this->pos->getWorld(), $this->pos->asVector3()); + $this->pos->getWorld()->addTile($tile); } } @@ -225,10 +225,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->getWorldNonNull()->getTile($this->pos)) !== null){ + if(($t = $this->pos->getWorld()->getTile($this->pos)) !== null){ $t->onBlockDestroyed(); } - $this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::AIR()); + $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::AIR()); return true; } @@ -417,7 +417,7 @@ class Block{ public function getPickedItem(bool $addUserData = false) : Item{ $item = $this->asItem(); if($addUserData){ - $tile = $this->pos->getWorldNonNull()->getTile($this->pos); + $tile = $this->pos->getWorld()->getTile($this->pos); if($tile instanceof Tile){ $nbt = $tile->getCleanedNBT(); if($nbt instanceof CompoundTag){ @@ -479,7 +479,7 @@ class Block{ */ public function getSide(int $side, int $step = 1){ if($this->pos->isValid()){ - return $this->pos->getWorldNonNull()->getBlock($this->pos->getSide($side, $step)); + return $this->pos->getWorld()->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 5f6d6436f..f4ae81b2b 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->getWorldNonNull()->getTile($this->pos); + $stand = $this->pos->getWorld()->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 d9c5bf478..23657d764 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->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()); + $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()); } return true; @@ -75,8 +75,8 @@ abstract class Button extends Flowable{ public function onScheduledUpdate() : void{ if($this->powered){ $this->powered = false; - $this->pos->getWorldNonNull()->setBlock($this->pos, $this); - $this->pos->getWorldNonNull()->addSound($this->pos->add(0.5, 0.5, 0.5), new RedstonePowerOffSound()); + $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorld()->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 1521c078c..951666623 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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); }else{ foreach(Facing::HORIZONTAL as $side){ $b = $this->getSide($side); if($b->isSolid()){ - $this->pos->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->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->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y + $y, $this->pos->z); + $b = $this->pos->getWorld()->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->getWorldNonNull()->setBlock($b->pos, $ev->getNewState()); + $this->pos->getWorld()->setBlock($b->pos, $ev->getNewState()); }else{ break; } } $this->age = 0; - $this->pos->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorld()->setBlock($this->pos, $this); }else{ ++$this->age; - $this->pos->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorld()->setBlock($this->pos, $this); } } } diff --git a/src/block/Cake.php b/src/block/Cake.php index 4554c71a0..4575cd99e 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->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::AIR()); + $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::AIR()); } } @@ -127,6 +127,6 @@ class Cake extends Transparent implements FoodSource{ } public function onConsume(Living $consumer) : void{ - $this->pos->getWorldNonNull()->setBlock($this->pos, $this->getResidue()); + $this->pos->getWorld()->setBlock($this->pos, $this->getResidue()); } } diff --git a/src/block/Carpet.php b/src/block/Carpet.php index 65a7bc853..0a430b023 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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); } } diff --git a/src/block/Chest.php b/src/block/Chest.php index 2f13028e6..523812a38 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->getWorldNonNull()->getTile($this->pos); + $tile = $this->pos->getWorld()->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->getWorldNonNull()->getTile($c->pos); + $pair = $this->pos->getWorld()->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->getWorldNonNull()->getTile($this->pos); + $chest = $this->pos->getWorld()->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 05ed9dd94..d6e6630a5 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->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::DIRT()); + $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::DIRT()); return true; } diff --git a/src/block/CocoaBlock.php b/src/block/CocoaBlock.php index 02534a10a..5191f61c4 100644 --- a/src/block/CocoaBlock.php +++ b/src/block/CocoaBlock.php @@ -85,7 +85,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->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorld()->setBlock($this->pos, $this); $item->pop(); @@ -98,7 +98,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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); } } @@ -109,7 +109,7 @@ class CocoaBlock extends Transparent{ public function onRandomTick() : void{ if($this->age < 2 and mt_rand(1, 5) === 1){ $this->age++; - $this->pos->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorld()->setBlock($this->pos, $this); } } diff --git a/src/block/ConcretePowder.php b/src/block/ConcretePowder.php index 2154acce1..581396586 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->getWorldNonNull()->setBlock($this->pos, $block); + $this->pos->getWorld()->setBlock($this->pos, $block); }else{ $this->startFalling(); } diff --git a/src/block/Crops.php b/src/block/Crops.php index 1d96ff210..ff0570d87 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->getWorldNonNull()->setBlock($this->pos, $ev->getNewState()); + $this->pos->getWorld()->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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); } } @@ -100,7 +100,7 @@ abstract class Crops extends Flowable{ $ev = new BlockGrowEvent($this, $block); $ev->call(); if(!$ev->isCancelled()){ - $this->pos->getWorldNonNull()->setBlock($this->pos, $ev->getNewState()); + $this->pos->getWorld()->setBlock($this->pos, $ev->getNewState()); } } } diff --git a/src/block/DaylightSensor.php b/src/block/DaylightSensor.php index a890a9705..5892bf0ab 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->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorld()->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->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorld()->setBlock($this->pos, $this); } - $this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, 20); + $this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, 20); } private function recalculatePower() : int{ - $lightLevel = $this->pos->getWorldNonNull()->getRealBlockSkyLightAt($this->pos->x, $this->pos->y, $this->pos->z); + $lightLevel = $this->pos->getWorld()->getRealBlockSkyLightAt($this->pos->x, $this->pos->y, $this->pos->z); if($this->inverted){ return 15 - $lightLevel; } - $sunAngle = $this->pos->getWorldNonNull()->getSunAnglePercentage(); + $sunAngle = $this->pos->getWorld()->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 611c67596..e4de2c8ab 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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); } } diff --git a/src/block/Dirt.php b/src/block/Dirt.php index b368526ea..7dab9b009 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->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::FARMLAND()); + $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::FARMLAND()); return true; } diff --git a/src/block/Door.php b/src/block/Door.php index c11935662..ab4ad13e8 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->getWorldNonNull()->useBreakOn($this->pos); //this will delete both halves if they exist + $this->pos->getWorld()->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->getWorldNonNull()->setBlock($other->pos, $other); + $this->pos->getWorld()->setBlock($other->pos, $other); } - $this->pos->getWorldNonNull()->setBlock($this->pos, $this); - $this->pos->getWorldNonNull()->addSound($this->pos, new DoorSound()); + $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorld()->addSound($this->pos, new DoorSound()); return true; } diff --git a/src/block/DoublePlant.php b/src/block/DoublePlant.php index d96a537fa..3505e1ac6 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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); } } diff --git a/src/block/DragonEgg.php b/src/block/DragonEgg.php index 52d6158a6..17546b3f2 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->getWorldNonNull()->getBlockAt( + $block = $this->pos->getWorld()->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->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); + $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); break; } } diff --git a/src/block/EnderChest.php b/src/block/EnderChest.php index 83eb164f6..fbb498f9a 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->getWorldNonNull()->getTile($this->pos); + $enderChest = $this->pos->getWorld()->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 a18d6119f..f715f7d81 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->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::DIRT()); + $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::DIRT()); } } @@ -70,13 +70,13 @@ class Farmland extends Transparent{ if(!$this->canHydrate()){ if($this->wetness > 0){ $this->wetness--; - $this->pos->getWorldNonNull()->setBlock($this->pos, $this, false); + $this->pos->getWorld()->setBlock($this->pos, $this, false); }else{ - $this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::DIRT()); + $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::DIRT()); } }elseif($this->wetness < 7){ $this->wetness = 7; - $this->pos->getWorldNonNull()->setBlock($this->pos, $this, false); + $this->pos->getWorld()->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->getWorldNonNull()->getBlockAt($x, $y, $z) instanceof Water){ + if($this->pos->getWorld()->getBlockAt($x, $y, $z) instanceof Water){ return true; } } diff --git a/src/block/FenceGate.php b/src/block/FenceGate.php index 88acabe73..8fc695e7c 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->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorld()->setBlock($this->pos, $this); } } @@ -101,8 +101,8 @@ class FenceGate extends Transparent{ } } - $this->pos->getWorldNonNull()->setBlock($this->pos, $this); - $this->pos->getWorldNonNull()->addSound($this->pos, new DoorSound()); + $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorld()->addSound($this->pos, new DoorSound()); return true; } diff --git a/src/block/Fire.php b/src/block/Fire.php index 7adb39584..c1b019a48 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->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::AIR()); + $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::AIR()); }else{ - $this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, mt_rand(30, 40)); + $this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, mt_rand(30, 40)); } } @@ -124,10 +124,10 @@ class Fire extends Flowable{ } if($result !== null){ - $this->pos->getWorldNonNull()->setBlock($this->pos, $result); + $this->pos->getWorld()->setBlock($this->pos, $result); } - $this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, mt_rand(30, 40)); + $this->pos->getWorld()->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->getWorldNonNull()->setBlock($block->pos, $fire); + $this->pos->getWorld()->setBlock($block->pos, $fire); }else{ - $this->pos->getWorldNonNull()->setBlock($block->pos, VanillaBlocks::AIR()); + $this->pos->getWorld()->setBlock($block->pos, VanillaBlocks::AIR()); } } } diff --git a/src/block/Flower.php b/src/block/Flower.php index da81a90d2..564008585 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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); } } diff --git a/src/block/FlowerPot.php b/src/block/FlowerPot.php index a60e8bc09..d547bf0b5 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->getWorldNonNull()->getTile($this->pos); + $tile = $this->pos->getWorld()->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->getWorldNonNull()->getTile($this->pos); + $tile = $this->pos->getWorld()->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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); } } @@ -134,7 +134,7 @@ class FlowerPot extends Flowable{ $this->setPlant($plant); $item->pop(); - $this->pos->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorld()->setBlock($this->pos, $this); return true; } diff --git a/src/block/FrostedIce.php b/src/block/FrostedIce.php index 2f140cad8..9d957d5fc 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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); }else{ - $this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, mt_rand(20, 40)); + $this->pos->getWorld()->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->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() + $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() ) >= 12 - $this->age){ if($this->tryMelt()){ foreach($this->getAllSides() as $block){ @@ -70,7 +70,7 @@ class FrostedIce extends Ice{ } } }else{ - $this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, mt_rand(20, 40)); + $this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, mt_rand(20, 40)); } } @@ -86,7 +86,7 @@ class FrostedIce extends Ice{ continue; } if( - $this->pos->getWorldNonNull()->getBlockAt($this->pos->x + $x, $this->pos->y, $this->pos->z + $z) instanceof FrostedIce and + $this->pos->getWorld()->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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); return true; } $this->age++; - $this->pos->getWorldNonNull()->setBlock($this->pos, $this); - $this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, mt_rand(20, 40)); + $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, mt_rand(20, 40)); return false; } } diff --git a/src/block/Furnace.php b/src/block/Furnace.php index f7444dab5..70ffde36d 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->getWorldNonNull()->getTile($this->pos); + $furnace = $this->pos->getWorld()->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->getWorldNonNull()->getTile($this->pos); + $furnace = $this->pos->getWorld()->getTile($this->pos); if($furnace instanceof TileFurnace and $furnace->onUpdate()){ - $this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, 1); //TODO: check this + $this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, 1); //TODO: check this } } } diff --git a/src/block/Grass.php b/src/block/Grass.php index 67bbcfb0f..becdf86de 100644 --- a/src/block/Grass.php +++ b/src/block/Grass.php @@ -56,13 +56,13 @@ class Grass extends Opaque{ } public function onRandomTick() : void{ - $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){ + $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){ //grass dies $ev = new BlockSpreadEvent($this, $this, VanillaBlocks::DIRT()); $ev->call(); if(!$ev->isCancelled()){ - $this->pos->getWorldNonNull()->setBlock($this->pos, $ev->getNewState(), false); + $this->pos->getWorld()->setBlock($this->pos, $ev->getNewState(), false); } }elseif($lightAbove >= 9){ //try grass spread @@ -71,12 +71,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->getWorldNonNull()->getBlockAt($x, $y, $z); + $b = $this->pos->getWorld()->getBlockAt($x, $y, $z); if( !($b instanceof Dirt) or $b instanceof CoarseDirt or - $this->pos->getWorldNonNull()->getFullLightAt($x, $y + 1, $z) < 4 or - $this->pos->getWorldNonNull()->getBlockAt($x, $y + 1, $z)->getLightFilter() >= 2 + $this->pos->getWorld()->getFullLightAt($x, $y + 1, $z) < 4 or + $this->pos->getWorld()->getBlockAt($x, $y + 1, $z)->getLightFilter() >= 2 ){ continue; } @@ -84,7 +84,7 @@ class Grass extends Opaque{ $ev = new BlockSpreadEvent($b, $this, VanillaBlocks::GRASS()); $ev->call(); if(!$ev->isCancelled()){ - $this->pos->getWorldNonNull()->setBlock($b->pos, $ev->getNewState(), false); + $this->pos->getWorld()->setBlock($b->pos, $ev->getNewState(), false); } } } @@ -96,17 +96,17 @@ class Grass extends Opaque{ } if($item instanceof Fertilizer){ $item->pop(); - TallGrassObject::growGrass($this->pos->getWorldNonNull(), $this->pos, new Random(mt_rand()), 8, 2); + TallGrassObject::growGrass($this->pos->getWorld(), $this->pos, new Random(mt_rand()), 8, 2); return true; }elseif($item instanceof Hoe){ $item->applyDamage(1); - $this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::FARMLAND()); + $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::FARMLAND()); return true; }elseif($item instanceof Shovel and $this->getSide(Facing::UP)->getId() === BlockLegacyIds::AIR){ $item->applyDamage(1); - $this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::GRASS_PATH()); + $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::GRASS_PATH()); return true; } diff --git a/src/block/GrassPath.php b/src/block/GrassPath.php index 011d0525b..f94fcba54 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->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::DIRT()); + $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::DIRT()); } } diff --git a/src/block/Hopper.php b/src/block/Hopper.php index cb402bc28..be6a4b6de 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->getWorldNonNull()->getTile($this->pos); + $tile = $this->pos->getWorld()->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 b825991ab..ef2917997 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->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::WATER()); + $this->pos->getWorld()->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->getWorldNonNull()->getHighestAdjacentBlockLight($this->pos->x, $this->pos->y, $this->pos->z) >= 12){ - $this->pos->getWorldNonNull()->useBreakOn($this->pos); + if($this->pos->getWorld()->getHighestAdjacentBlockLight($this->pos->x, $this->pos->y, $this->pos->z) >= 12){ + $this->pos->getWorld()->useBreakOn($this->pos); } } diff --git a/src/block/ItemFrame.php b/src/block/ItemFrame.php index 621e32250..084030dd8 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->getWorldNonNull()->getTile($this->pos); + $tile = $this->pos->getWorld()->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->getWorldNonNull()->getTile($this->pos); + $tile = $this->pos->getWorld()->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->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorld()->setBlock($this->pos, $this); return true; } @@ -142,16 +142,16 @@ class ItemFrame extends Flowable{ return false; } if(lcg_value() <= $this->itemDropChance){ - $this->pos->getWorldNonNull()->dropItem($this->pos->add(0.5, 0.5, 0.5), clone $this->framedItem); + $this->pos->getWorld()->dropItem($this->pos->add(0.5, 0.5, 0.5), clone $this->framedItem); } $this->setFramedItem(null); - $this->pos->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorld()->setBlock($this->pos, $this); return true; } public function onNearbyBlockChange() : void{ if(!$this->getSide(Facing::opposite($this->facing))->isSolid()){ - $this->pos->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); } } diff --git a/src/block/Ladder.php b/src/block/Ladder.php index 5d74adaa8..8ff08707e 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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); } } } diff --git a/src/block/Lantern.php b/src/block/Lantern.php index 99a441bc3..7f5d790c5 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->getWorldNonNull()->getBlock($blockReplace->getPos()->up())) and !$this->canAttachTo($this->pos->getWorldNonNull()->getBlock($blockReplace->getPos()->down()))){ + if(!$this->canAttachTo($this->pos->getWorld()->getBlock($blockReplace->getPos()->up())) and !$this->canAttachTo($this->pos->getWorld()->getBlock($blockReplace->getPos()->down()))){ return false; } - $this->hanging = ($face === Facing::DOWN or !$this->canAttachTo($this->pos->getWorldNonNull()->getBlock($blockReplace->getPos()->down()))); + $this->hanging = ($face === Facing::DOWN or !$this->canAttachTo($this->pos->getWorld()->getBlock($blockReplace->getPos()->down()))); return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function onNearbyBlockChange() : void{ - if(!$this->canAttachTo($this->pos->getWorldNonNull()->getBlock($this->hanging ? $this->pos->up() : $this->pos->down()))){ - $this->pos->getWorldNonNull()->useBreakOn($this->pos); + if(!$this->canAttachTo($this->pos->getWorld()->getBlock($this->hanging ? $this->pos->up() : $this->pos->down()))){ + $this->pos->getWorld()->useBreakOn($this->pos); } } } diff --git a/src/block/Leaves.php b/src/block/Leaves.php index 07bd70ff0..27da9fa7d 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->getWorldNonNull()->getBlock($pos); + $block = $this->pos->getWorld()->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->getWorldNonNull()->setBlock($this->pos, $this, false); + $this->pos->getWorld()->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->getWorldNonNull()->setBlock($this->pos, $this, false); + $this->pos->getWorld()->setBlock($this->pos, $this, false); }else{ - $this->pos->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); } } } diff --git a/src/block/Lever.php b/src/block/Lever.php index 67c65e899..d4d7bf6f5 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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); } } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->powered = !$this->powered; - $this->pos->getWorldNonNull()->setBlock($this->pos, $this); - $this->pos->getWorldNonNull()->addSound( + $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorld()->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 195b62529..ac7b5a95f 100644 --- a/src/block/Liquid.php +++ b/src/block/Liquid.php @@ -188,7 +188,7 @@ abstract class Liquid extends Transparent{ ++$z; } - $sideBlock = $this->pos->getWorldNonNull()->getBlockAt($x, $y, $z); + $sideBlock = $this->pos->getWorld()->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->getWorldNonNull()->getBlockAt($x, $y - 1, $z)); + $blockDecay = $this->getEffectiveFlowDecay($this->pos->getWorld()->getBlockAt($x, $y - 1, $z)); if($blockDecay >= 0){ $realDecay = $blockDecay - ($decay - 8); @@ -218,14 +218,14 @@ abstract class Liquid extends Transparent{ if($this->falling){ if( - !$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)) + !$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)) ){ $vector = $vector->normalize()->add(0, -6, 0); } @@ -252,7 +252,7 @@ abstract class Liquid extends Transparent{ public function onNearbyBlockChange() : void{ if(!$this->checkForHarden()){ - $this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, $this->tickRate()); + $this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, $this->tickRate()); } } @@ -262,10 +262,10 @@ abstract class Liquid extends Transparent{ if(!$this->isSource()){ $smallestFlowDecay = -100; $this->adjacentSources = 0; - $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); + $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); $newDecay = $smallestFlowDecay + $multiplier; $falling = false; @@ -274,12 +274,12 @@ abstract class Liquid extends Transparent{ $newDecay = -1; } - if($this->getEffectiveFlowDecay($this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y + 1, $this->pos->z)) >= 0){ + if($this->getEffectiveFlowDecay($this->pos->getWorld()->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->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y - 1, $this->pos->z); + $bottomBlock = $this->pos->getWorld()->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; @@ -288,17 +288,17 @@ abstract class Liquid extends Transparent{ if($falling !== $this->falling or (!$falling and $newDecay !== $this->decay)){ if(!$falling and $newDecay < 0){ - $this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::AIR()); + $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::AIR()); return; } $this->falling = $falling; $this->decay = $falling ? 0 : $newDecay; - $this->pos->getWorldNonNull()->setBlock($this->pos, $this); //local block update will cause an update to be scheduled + $this->pos->getWorld()->setBlock($this->pos, $this); //local block update will cause an update to be scheduled } } - $bottomBlock = $this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y - 1, $this->pos->z); + $bottomBlock = $this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y - 1, $this->pos->z); $this->flowIntoBlock($bottomBlock, 0, true); @@ -313,19 +313,19 @@ abstract class Liquid extends Transparent{ $flags = $this->getOptimalFlowDirections(); if($flags[0]){ - $this->flowIntoBlock($this->pos->getWorldNonNull()->getBlockAt($this->pos->x - 1, $this->pos->y, $this->pos->z), $adjacentDecay, false); + $this->flowIntoBlock($this->pos->getWorld()->getBlockAt($this->pos->x - 1, $this->pos->y, $this->pos->z), $adjacentDecay, false); } if($flags[1]){ - $this->flowIntoBlock($this->pos->getWorldNonNull()->getBlockAt($this->pos->x + 1, $this->pos->y, $this->pos->z), $adjacentDecay, false); + $this->flowIntoBlock($this->pos->getWorld()->getBlockAt($this->pos->x + 1, $this->pos->y, $this->pos->z), $adjacentDecay, false); } if($flags[2]){ - $this->flowIntoBlock($this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z - 1), $adjacentDecay, false); + $this->flowIntoBlock($this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z - 1), $adjacentDecay, false); } if($flags[3]){ - $this->flowIntoBlock($this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z + 1), $adjacentDecay, false); + $this->flowIntoBlock($this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z + 1), $adjacentDecay, false); } } } @@ -343,10 +343,10 @@ abstract class Liquid extends Transparent{ $ev->call(); if(!$ev->isCancelled()){ if($block->getId() > 0){ - $this->pos->getWorldNonNull()->useBreakOn($block->pos); + $this->pos->getWorld()->useBreakOn($block->pos); } - $this->pos->getWorldNonNull()->setBlock($block->pos, $ev->getNewState()); + $this->pos->getWorld()->setBlock($block->pos, $ev->getNewState()); } } } @@ -374,10 +374,10 @@ abstract class Liquid extends Transparent{ } if(!isset($this->flowCostVisited[$hash = World::blockHash($x, $y, $z)])){ - $blockSide = $this->pos->getWorldNonNull()->getBlockAt($x, $y, $z); + $blockSide = $this->pos->getWorld()->getBlockAt($x, $y, $z); if(!$this->canFlowInto($blockSide)){ $this->flowCostVisited[$hash] = self::BLOCKED; - }elseif($this->pos->getWorldNonNull()->getBlockAt($x, $y - 1, $z)->canBeFlowedInto()){ + }elseif($this->pos->getWorld()->getBlockAt($x, $y - 1, $z)->canBeFlowedInto()){ $this->flowCostVisited[$hash] = self::CAN_FLOW_DOWN; }else{ $this->flowCostVisited[$hash] = self::CAN_FLOW; @@ -426,12 +426,12 @@ abstract class Liquid extends Transparent{ }elseif($j === 3){ ++$z; } - $block = $this->pos->getWorldNonNull()->getBlockAt($x, $y, $z); + $block = $this->pos->getWorld()->getBlockAt($x, $y, $z); if(!$this->canFlowInto($block)){ $this->flowCostVisited[World::blockHash($x, $y, $z)] = self::BLOCKED; continue; - }elseif($this->pos->getWorldNonNull()->getBlockAt($x, $y - 1, $z)->canBeFlowedInto()){ + }elseif($this->pos->getWorld()->getBlockAt($x, $y - 1, $z)->canBeFlowedInto()){ $this->flowCostVisited[World::blockHash($x, $y, $z)] = self::CAN_FLOW_DOWN; $flowCost[$j] = $maxCost = 0; }elseif($maxCost > 0){ @@ -478,13 +478,13 @@ abstract class Liquid extends Transparent{ $ev = new BlockFormEvent($this, $result); $ev->call(); if(!$ev->isCancelled()){ - $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)); + $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)); } return true; } protected function canFlowInto(Block $block) : bool{ - 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 + 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 } } diff --git a/src/block/Mycelium.php b/src/block/Mycelium.php index d3dce32f9..8308875ef 100644 --- a/src/block/Mycelium.php +++ b/src/block/Mycelium.php @@ -53,13 +53,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->getWorldNonNull()->getBlockAt($x, $y, $z); + $block = $this->pos->getWorld()->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->getWorldNonNull()->setBlock($block->pos, $ev->getNewState()); + $this->pos->getWorld()->setBlock($block->pos, $ev->getNewState()); } } } diff --git a/src/block/NetherWartPlant.php b/src/block/NetherWartPlant.php index da44b7bde..7ca38d72f 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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); } } @@ -79,7 +79,7 @@ class NetherWartPlant extends Flowable{ $ev = new BlockGrowEvent($this, $block); $ev->call(); if(!$ev->isCancelled()){ - $this->pos->getWorldNonNull()->setBlock($this->pos, $ev->getNewState()); + $this->pos->getWorld()->setBlock($this->pos, $ev->getNewState()); } } } diff --git a/src/block/Note.php b/src/block/Note.php index 54fcf7a1d..3e027c220 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->getWorldNonNull()->getTile($this->pos); + $tile = $this->pos->getWorld()->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->getWorldNonNull()->getTile($this->pos); + $tile = $this->pos->getWorld()->getTile($this->pos); assert($tile instanceof TileNote); $tile->setPitch($this->pitch); } diff --git a/src/block/RedMushroom.php b/src/block/RedMushroom.php index c5e643f21..72d3bb5ec 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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); } } diff --git a/src/block/RedstoneComparator.php b/src/block/RedstoneComparator.php index cae56d03f..7372ab99a 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->getWorldNonNull()->getTile($this->pos); + $tile = $this->pos->getWorld()->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->getWorldNonNull()->getTile($this->pos); + $tile = $this->pos->getWorld()->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->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorld()->setBlock($this->pos, $this); return true; } public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->isTransparent()){ - $this->pos->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); } } diff --git a/src/block/RedstoneOre.php b/src/block/RedstoneOre.php index 5981b19ad..9cfb07da5 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->getWorldNonNull()->setBlock($this->pos, $this); //no return here - this shouldn't prevent block placement + $this->pos->getWorld()->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->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorld()->setBlock($this->pos, $this); } } @@ -87,7 +87,7 @@ class RedstoneOre extends Opaque{ public function onRandomTick() : void{ if($this->lit){ $this->lit = false; - $this->pos->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorld()->setBlock($this->pos, $this); } } diff --git a/src/block/RedstoneRepeater.php b/src/block/RedstoneRepeater.php index af15cc322..82af3f53d 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->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorld()->setBlock($this->pos, $this); return true; } public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->isTransparent()){ - $this->pos->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); } } diff --git a/src/block/Sapling.php b/src/block/Sapling.php index c6e8a227f..8b0e74f54 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->getWorldNonNull(), $this->pos->x, $this->pos->y, $this->pos->z, new Random(mt_rand()), $this->treeType); + Tree::growTree($this->pos->getWorld(), $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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); } } @@ -90,12 +90,12 @@ class Sapling extends Flowable{ } public function onRandomTick() : void{ - if($this->pos->getWorldNonNull()->getFullLightAt($this->pos->x, $this->pos->y, $this->pos->z) >= 8 and mt_rand(1, 7) === 1){ + if($this->pos->getWorld()->getFullLightAt($this->pos->x, $this->pos->y, $this->pos->z) >= 8 and mt_rand(1, 7) === 1){ if($this->ready){ - Tree::growTree($this->pos->getWorldNonNull(), $this->pos->x, $this->pos->y, $this->pos->z, new Random(mt_rand()), $this->treeType); + Tree::growTree($this->pos->getWorld(), $this->pos->x, $this->pos->y, $this->pos->z, new Random(mt_rand()), $this->treeType); }else{ $this->ready = true; - $this->pos->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorld()->setBlock($this->pos, $this); } } } diff --git a/src/block/Sign.php b/src/block/Sign.php index 6c137a222..17bad1f3a 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->getWorldNonNull()->getTile($this->pos); + $tile = $this->pos->getWorld()->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->getWorldNonNull()->getTile($this->pos); + $tile = $this->pos->getWorld()->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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); } } @@ -161,7 +161,7 @@ class Sign extends Transparent{ $ev->call(); if(!$ev->isCancelled()){ $this->text = clone $ev->getNewText(); - $this->pos->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorld()->setBlock($this->pos, $this); return true; } diff --git a/src/block/Skull.php b/src/block/Skull.php index 1aaeda4e0..8b60f5dea 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->getWorldNonNull()->getTile($this->pos); + $tile = $this->pos->getWorld()->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->getWorldNonNull()->getTile($this->pos); + $tile = $this->pos->getWorld()->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 fb225f491..228ebb5f0 100644 --- a/src/block/SnowLayer.php +++ b/src/block/SnowLayer.php @@ -94,8 +94,8 @@ class SnowLayer extends Flowable implements Fallable{ } public function onRandomTick() : void{ - if($this->pos->getWorldNonNull()->getBlockLightAt($this->pos->x, $this->pos->y, $this->pos->z) >= 12){ - $this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::AIR(), false); + if($this->pos->getWorld()->getBlockLightAt($this->pos->x, $this->pos->y, $this->pos->z) >= 12){ + $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::AIR(), false); } } diff --git a/src/block/Stem.php b/src/block/Stem.php index 66a9e6268..6ef52f165 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->getWorldNonNull()->setBlock($this->pos, $ev->getNewState()); + $this->pos->getWorld()->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->getWorldNonNull()->setBlock($side->pos, $ev->getNewState()); + $this->pos->getWorld()->setBlock($side->pos, $ev->getNewState()); } } } diff --git a/src/block/Sugarcane.php b/src/block/Sugarcane.php index bc90d89ae..d3444052f 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->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y + $y, $this->pos->z); + $b = $this->pos->getWorld()->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->getWorldNonNull()->setBlock($b->pos, $ev->getNewState()); + $this->pos->getWorld()->setBlock($b->pos, $ev->getNewState()); }else{ break; } } $this->age = 0; - $this->pos->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorld()->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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->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->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y + $y, $this->pos->z); + $b = $this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y + $y, $this->pos->z); if($b->getId() === BlockLegacyIds::AIR){ - $this->pos->getWorldNonNull()->setBlock($b->pos, VanillaBlocks::SUGARCANE()); + $this->pos->getWorld()->setBlock($b->pos, VanillaBlocks::SUGARCANE()); break; } } $this->age = 0; - $this->pos->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorld()->setBlock($this->pos, $this); }else{ ++$this->age; - $this->pos->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorld()->setBlock($this->pos, $this); } } } diff --git a/src/block/TNT.php b/src/block/TNT.php index a07634d54..201b5c5dc 100644 --- a/src/block/TNT.php +++ b/src/block/TNT.php @@ -90,11 +90,11 @@ class TNT extends Opaque{ } public function ignite(int $fuse = 80) : void{ - $this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::AIR()); + $this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::AIR()); $mot = (new Random())->nextSignedFloat() * M_PI * 2; - $tnt = new PrimedTNT(Location::fromObject($this->pos->add(0.5, 0, 0.5), $this->pos->getWorldNonNull())); + $tnt = new PrimedTNT(Location::fromObject($this->pos->add(0.5, 0, 0.5), $this->pos->getWorld())); $tnt->setFuse($fuse); $tnt->setMotion(new Vector3(-sin($mot) * 0.02, 0.2, -cos($mot) * 0.02)); diff --git a/src/block/TallGrass.php b/src/block/TallGrass.php index 99880c446..88b3ac6ce 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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); } } diff --git a/src/block/Torch.php b/src/block/Torch.php index f97ef7d2c..001fbba6f 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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); } } diff --git a/src/block/Trapdoor.php b/src/block/Trapdoor.php index b0205dadb..ab1d75f53 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->getWorldNonNull()->setBlock($this->pos, $this); - $this->pos->getWorldNonNull()->addSound($this->pos, new DoorSound()); + $this->pos->getWorld()->setBlock($this->pos, $this); + $this->pos->getWorld()->addSound($this->pos, new DoorSound()); return true; } } diff --git a/src/block/Vine.php b/src/block/Vine.php index 9af86636b..b590c740d 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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); }else{ - $this->pos->getWorldNonNull()->setBlock($this->pos, $this); + $this->pos->getWorld()->setBlock($this->pos, $this); } } } diff --git a/src/block/WaterLily.php b/src/block/WaterLily.php index 87abbc5e5..e4648d378 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->getWorldNonNull()->useBreakOn($this->pos); + $this->pos->getWorld()->useBreakOn($this->pos); } } } diff --git a/src/block/inventory/ChestInventory.php b/src/block/inventory/ChestInventory.php index 377703ebd..5675f28b7 100644 --- a/src/block/inventory/ChestInventory.php +++ b/src/block/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()->getWorldNonNull()->addSound($this->getHolder()->add(0.5, 0.5, 0.5), $this->getOpenSound()); + $this->getHolder()->getWorld()->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()->getWorldNonNull()->addSound($this->getHolder()->add(0.5, 0.5, 0.5), $this->getCloseSound()); + $this->getHolder()->getWorld()->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->getWorldNonNull()->broadcastPacketToViewers($holder, BlockEventPacket::create(1, $isOpen ? 1 : 0, $holder->asVector3())); + $holder->getWorld()->broadcastPacketToViewers($holder, BlockEventPacket::create(1, $isOpen ? 1 : 0, $holder->asVector3())); } } diff --git a/src/block/tile/BrewingStand.php b/src/block/tile/BrewingStand.php index d6571f630..8977d36b1 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->getListeners()->add(CallbackInventoryListener::onAnyChange(function(Inventory $unused) : void{ - $this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, 1); + $this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, 1); })); } diff --git a/src/block/tile/Chest.php b/src/block/tile/Chest.php index e197685e4..896cafead 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->getWorldNonNull()->isChunkLoaded($this->pairX >> 4, $this->pairZ >> 4)){ + if($this->isPaired() and $this->pos->getWorld()->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->getWorldNonNull()->isInLoadedTerrain(new Vector3($this->pairX, $this->pos->y, $this->pairZ))){ + if($this->isPaired() and !$this->pos->getWorld()->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->getWorldNonNull()->getTileAt($this->pairX, $this->pos->y, $this->pairZ); + $tile = $this->pos->getWorld()->getTileAt($this->pairX, $this->pos->y, $this->pairZ); if($tile instanceof Chest){ return $tile; } diff --git a/src/block/tile/ContainerTrait.php b/src/block/tile/ContainerTrait.php index b23c944eb..2968c5490 100644 --- a/src/block/tile/ContainerTrait.php +++ b/src/block/tile/ContainerTrait.php @@ -94,7 +94,7 @@ trait ContainerTrait{ $pos = $this->getPos(); foreach($inv->getContents() as $k => $item){ - $pos->getWorldNonNull()->dropItem($pos->add(0.5, 0.5, 0.5), $item); + $pos->getWorld()->dropItem($pos->add(0.5, 0.5, 0.5), $item); } $inv->clearAll(); } diff --git a/src/block/tile/Furnace.php b/src/block/tile/Furnace.php index d80809b75..7f2ec36c4 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->getListeners()->add(CallbackInventoryListener::onAnyChange( function(Inventory $unused) : void{ - $this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, 1); + $this->pos->getWorld()->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->getWorldNonNull()->setBlock($block->getPos(), $block); + $this->pos->getWorld()->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->getWorldNonNull()->getServer()->getCraftingManager()->getFurnaceRecipeManager()->match($raw); + $smelt = $this->pos->getWorld()->getServer()->getCraftingManager()->getFurnaceRecipeManager()->match($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->getWorldNonNull()->setBlock($block->getPos(), $block); + $this->pos->getWorld()->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 5fb12b184..dac763570 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->getWorldNonNull()->getBlock($this->pos); + return $this->pos->getWorld()->getBlock($this->pos); } public function getPos() : Position{ @@ -130,7 +130,7 @@ abstract class Tile{ $this->closed = true; if($this->pos->isValid()){ - $this->pos->getWorldNonNull()->removeTile($this); + $this->pos->getWorld()->removeTile($this); } $this->pos = null; } diff --git a/src/block/utils/FallableTrait.php b/src/block/utils/FallableTrait.php index be51117a0..c0d276057 100644 --- a/src/block/utils/FallableTrait.php +++ b/src/block/utils/FallableTrait.php @@ -49,14 +49,14 @@ trait FallableTrait{ public function onNearbyBlockChange() : void{ $pos = $this->getPos(); - $down = $pos->getWorldNonNull()->getBlock($pos->getSide(Facing::DOWN)); + $down = $pos->getWorld()->getBlock($pos->getSide(Facing::DOWN)); if($down->getId() === BlockLegacyIds::AIR or $down instanceof Liquid or $down instanceof Fire){ - $pos->getWorldNonNull()->setBlock($pos, VanillaBlocks::AIR()); + $pos->getWorld()->setBlock($pos, VanillaBlocks::AIR()); $block = $this; if(!($block instanceof Block)) throw new AssumptionFailedError(__TRAIT__ . " should only be used by Blocks"); - $fall = new FallingBlock(Location::fromObject($pos->add(0.5, 0, 0.5), $pos->getWorldNonNull()), $block); + $fall = new FallingBlock(Location::fromObject($pos->add(0.5, 0, 0.5), $pos->getWorld()), $block); $fall->spawnToAll(); } } diff --git a/src/command/defaults/ParticleCommand.php b/src/command/defaults/ParticleCommand.php index 7b617f15a..a9c580645 100644 --- a/src/command/defaults/ParticleCommand.php +++ b/src/command/defaults/ParticleCommand.php @@ -94,7 +94,7 @@ class ParticleCommand extends VanillaCommand{ if($sender instanceof Player){ $senderPos = $sender->getPosition(); - $world = $senderPos->getWorldNonNull(); + $world = $senderPos->getWorld(); $pos = new Vector3( $this->getRelativeDouble($senderPos->getX(), $sender, $args[1]), $this->getRelativeDouble($senderPos->getY(), $sender, $args[2], 0, World::Y_MAX), diff --git a/src/command/defaults/SeedCommand.php b/src/command/defaults/SeedCommand.php index 4f92150bb..29017edb5 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()->getWorldNonNull()->getSeed(); + $seed = $sender->getPosition()->getWorld()->getSeed(); }else{ $seed = $sender->getServer()->getWorldManager()->getDefaultWorld()->getSeed(); } diff --git a/src/command/defaults/SetWorldSpawnCommand.php b/src/command/defaults/SetWorldSpawnCommand.php index 36241ea8a..45534184a 100644 --- a/src/command/defaults/SetWorldSpawnCommand.php +++ b/src/command/defaults/SetWorldSpawnCommand.php @@ -52,7 +52,7 @@ class SetWorldSpawnCommand extends VanillaCommand{ if(count($args) === 0){ if($sender instanceof Player){ $location = $sender->getPosition(); - $world = $location->getWorldNonNull(); + $world = $location->getWorld(); $pos = $location->asVector3()->round(); }else{ $sender->sendMessage(TextFormat::RED . "You can only perform this command as a player"); diff --git a/src/command/defaults/SpawnpointCommand.php b/src/command/defaults/SpawnpointCommand.php index 3879ced83..91813c24c 100644 --- a/src/command/defaults/SpawnpointCommand.php +++ b/src/command/defaults/SpawnpointCommand.php @@ -83,7 +83,7 @@ class SpawnpointCommand extends VanillaCommand{ }elseif(count($args) <= 1){ if($sender instanceof Player){ $cpos = $sender->getPosition(); - $pos = Position::fromObject($cpos->floor(), $cpos->getWorldNonNull()); + $pos = Position::fromObject($cpos->floor(), $cpos->getWorld()); $target->setSpawn($pos); Command::broadcastCommandMessage($sender, new TranslationContainer("commands.spawnpoint.success", [$target->getName(), round($pos->x, 2), round($pos->y, 2), round($pos->z, 2)])); diff --git a/src/command/defaults/TeleportCommand.php b/src/command/defaults/TeleportCommand.php index ed86dd413..ff302bd8c 100644 --- a/src/command/defaults/TeleportCommand.php +++ b/src/command/defaults/TeleportCommand.php @@ -112,7 +112,7 @@ class TeleportCommand extends VanillaCommand{ $x = $this->getRelativeDouble($base->x, $sender, $targetArgs[0]); $y = $this->getRelativeDouble($base->y, $sender, $targetArgs[1], 0, 256); $z = $this->getRelativeDouble($base->z, $sender, $targetArgs[2]); - $targetLocation = new Location($x, $y, $z, $yaw, $pitch, $base->getWorldNonNull()); + $targetLocation = new Location($x, $y, $z, $yaw, $pitch, $base->getWorld()); $subject->teleport($targetLocation); Command::broadcastCommandMessage($sender, new TranslationContainer("commands.tp.success.coordinates", [ diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 878e6c9ed..cd5f42a07 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -223,7 +223,7 @@ abstract class Entity{ } $this->id = self::nextRuntimeId(); - $this->server = $location->getWorldNonNull()->getServer(); + $this->server = $location->getWorld()->getServer(); $this->location = $location->asLocation(); assert( @@ -1289,7 +1289,7 @@ abstract class Entity{ } public function getWorld() : World{ - return $this->location->getWorldNonNull(); + return $this->location->getWorld(); } protected function setPosition(Vector3 $pos) : bool{ @@ -1297,8 +1297,8 @@ abstract class Entity{ return false; } - if($pos instanceof Position and $pos->isValid() and $pos->getWorldNonNull() !== $this->getWorld()){ - if(!$this->switchWorld($pos->getWorldNonNull())){ + if($pos instanceof Position and $pos->isValid() and $pos->getWorld() !== $this->getWorld()){ + if(!$this->switchWorld($pos->getWorld())){ return false; } } @@ -1410,7 +1410,7 @@ abstract class Entity{ $pitch = $pitch ?? $pos->pitch; } $from = $this->location->asPosition(); - $to = Position::fromObject($pos, $pos instanceof Position ? $pos->getWorldNonNull() : $this->getWorld()); + $to = Position::fromObject($pos, $pos instanceof Position ? $pos->getWorld() : $this->getWorld()); $ev = new EntityTeleportEvent($this, $from, $to); $ev->call(); if($ev->isCancelled()){ diff --git a/src/entity/Location.php b/src/entity/Location.php index 2ff9171ac..2ff7f3b07 100644 --- a/src/entity/Location.php +++ b/src/entity/Location.php @@ -63,7 +63,7 @@ class Location extends Position{ } public function __toString(){ - return "Location (world=" . ($this->isValid() ? $this->getWorldNonNull()->getDisplayName() : "null") . ", x=$this->x, y=$this->y, z=$this->z, yaw=$this->yaw, pitch=$this->pitch)"; + return "Location (world=" . ($this->isValid() ? $this->getWorld()->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/item/Bow.php b/src/item/Bow.php index 0f68e1410..2dcbb5b01 100644 --- a/src/item/Bow.php +++ b/src/item/Bow.php @@ -103,7 +103,7 @@ class Bow extends Tool{ } $ev->getProjectile()->spawnToAll(); - $location->getWorldNonNull()->addSound($location, new BowShootSound()); + $location->getWorld()->addSound($location, new BowShootSound()); }else{ $entity->spawnToAll(); } diff --git a/src/item/PaintingItem.php b/src/item/PaintingItem.php index 6c6b1f25e..114a94b1c 100644 --- a/src/item/PaintingItem.php +++ b/src/item/PaintingItem.php @@ -75,7 +75,7 @@ class PaintingItem extends Item{ $replacePos = $blockReplace->getPos(); $clickedPos = $blockClicked->getPos(); - $entity = new Painting(Location::fromObject($replacePos, $replacePos->getWorldNonNull()), $clickedPos, $face, $motive); + $entity = new Painting(Location::fromObject($replacePos, $replacePos->getWorld()), $clickedPos, $face, $motive); $this->pop(); $entity->spawnToAll(); diff --git a/src/item/ProjectileItem.php b/src/item/ProjectileItem.php index 8ac5fedc1..f8fb55673 100644 --- a/src/item/ProjectileItem.php +++ b/src/item/ProjectileItem.php @@ -51,7 +51,7 @@ abstract class ProjectileItem extends Item{ $projectile->spawnToAll(); - $location->getWorldNonNull()->addSound($location, new ThrowSound()); + $location->getWorld()->addSound($location, new ThrowSound()); $this->pop(); diff --git a/src/network/mcpe/NetworkSession.php b/src/network/mcpe/NetworkSession.php index b1d09ea51..0f9bfad87 100644 --- a/src/network/mcpe/NetworkSession.php +++ b/src/network/mcpe/NetworkSession.php @@ -822,7 +822,7 @@ class NetworkSession{ public function startUsingChunk(int $chunkX, int $chunkZ, \Closure $onCompletion) : void{ Utils::validateCallableSignature(function(int $chunkX, int $chunkZ) : void{}, $onCompletion); - $world = $this->player->getLocation()->getWorldNonNull(); + $world = $this->player->getLocation()->getWorld(); ChunkCache::getInstance($world, $this->compressor)->request($chunkX, $chunkZ)->onResolve( //this callback may be called synchronously or asynchronously, depending on whether the promise is resolved yet @@ -830,7 +830,7 @@ class NetworkSession{ if(!$this->isConnected()){ return; } - $currentWorld = $this->player->getLocation()->getWorldNonNull(); + $currentWorld = $this->player->getLocation()->getWorld(); if($world !== $currentWorld or !$this->player->isUsingChunk($chunkX, $chunkZ)){ $this->logger->debug("Tried to send no-longer-active chunk $chunkX $chunkZ in world " . $world->getFolderName()); return; diff --git a/src/network/mcpe/handler/InGamePacketHandler.php b/src/network/mcpe/handler/InGamePacketHandler.php index 9e34ef057..30a599583 100644 --- a/src/network/mcpe/handler/InGamePacketHandler.php +++ b/src/network/mcpe/handler/InGamePacketHandler.php @@ -359,7 +359,7 @@ class InGamePacketHandler extends PacketHandler{ }else{ $blocks[] = $blockPos; } - $this->player->getLocation()->getWorldNonNull()->sendBlocks([$this->player], $blocks); + $this->player->getLocation()->getWorld()->sendBlocks([$this->player], $blocks); } } @@ -563,7 +563,7 @@ class InGamePacketHandler extends PacketHandler{ return false; } - $block = $this->player->getLocation()->getWorldNonNull()->getBlock($pos); + $block = $this->player->getLocation()->getWorld()->getBlock($pos); $nbt = $packet->namedtag->getRoot(); if(!($nbt instanceof CompoundTag)) throw new AssumptionFailedError("PHPStan should ensure this is a CompoundTag"); //for phpstorm's benefit diff --git a/src/network/mcpe/handler/PreSpawnPacketHandler.php b/src/network/mcpe/handler/PreSpawnPacketHandler.php index 4371dc853..560fbf544 100644 --- a/src/network/mcpe/handler/PreSpawnPacketHandler.php +++ b/src/network/mcpe/handler/PreSpawnPacketHandler.php @@ -68,12 +68,12 @@ class PreSpawnPacketHandler extends PacketHandler{ $pk->seed = -1; $pk->spawnSettings = new SpawnSettings(SpawnSettings::BIOME_TYPE_DEFAULT, "", DimensionIds::OVERWORLD); //TODO: implement this properly $pk->worldGamemode = TypeConverter::getInstance()->coreGameModeToProtocol($this->server->getGamemode()); - $pk->difficulty = $location->getWorldNonNull()->getDifficulty(); + $pk->difficulty = $location->getWorld()->getDifficulty(); $pk->spawnX = $spawnPosition->getFloorX(); $pk->spawnY = $spawnPosition->getFloorY(); $pk->spawnZ = $spawnPosition->getFloorZ(); $pk->hasAchievementsDisabled = true; - $pk->time = $location->getWorldNonNull()->getTime(); + $pk->time = $location->getWorld()->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 df03dc55d..a13ed87d6 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -713,7 +713,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, } protected function switchWorld(World $targetWorld) : bool{ - $oldWorld = $this->location->isValid() ? $this->location->getWorldNonNull() : null; + $oldWorld = $this->location->isValid() ? $this->location->getWorld() : null; if(parent::switchWorld($targetWorld)){ if($oldWorld !== null){ foreach($this->usedChunks as $index => $status){ @@ -959,7 +959,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, if(!($pos instanceof Position)){ $world = $this->getWorld(); }else{ - $world = $pos->getWorldNonNull(); + $world = $pos->getWorld(); } $this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $world); $this->networkSession->syncPlayerSpawnPoint($this->spawnPosition); @@ -2082,7 +2082,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, } if($this->hasValidSpawnPosition()){ - $nbt->setString("SpawnLevel", $this->spawnPosition->getWorldNonNull()->getFolderName()); + $nbt->setString("SpawnLevel", $this->spawnPosition->getWorld()->getFolderName()); $nbt->setInt("SpawnX", $this->spawnPosition->getFloorX()); $nbt->setInt("SpawnY", $this->spawnPosition->getFloorY()); $nbt->setInt("SpawnZ", $this->spawnPosition->getFloorZ()); @@ -2152,7 +2152,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()->getWorldNonNull()); + $realSpawn = Position::fromObject($ev->getRespawnPosition()->add(0.5, 0, 0.5), $ev->getRespawnPosition()->getWorld()); $this->teleport($realSpawn); $this->setSprinting(false); diff --git a/src/world/Explosion.php b/src/world/Explosion.php index db17c93d0..a409f00ab 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -73,7 +73,7 @@ class Explosion{ throw new \InvalidArgumentException("Position does not have a valid world"); } $this->source = $center; - $this->world = $center->getWorldNonNull(); + $this->world = $center->getWorld(); 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 0d8c4914c..9d2f36299 100644 --- a/src/world/Position.php +++ b/src/world/Position.php @@ -61,32 +61,16 @@ class Position extends Vector3{ } /** - * Returns the target world, or null if the target is not valid. - * If a reference exists to a world which is closed, the reference will be destroyed and null will be returned. - * - * @return World|null - */ - public function getWorld(){ - if($this->world !== null and $this->world->isClosed()){ - \GlobalLogger::get()->debug("Position was holding a reference to an unloaded world"); - $this->world = null; - } - - return $this->world; - } - - /** - * Returns the position's world if valid. Throws an error if the world is unexpectedly null. + * Returns the position's world if valid. Throws an error if the world is unexpectedly invalid. * * @throws AssumptionFailedError */ - public function getWorldNonNull() : World{ - $world = $this->getWorld(); - if($world === null){ - throw new AssumptionFailedError("Position world is null"); + public function getWorld() : World{ + if($this->world === null || $this->world->isClosed()){ + throw new AssumptionFailedError("Position world is null or has been unloaded"); } - return $world; + return $this->world; } /** @@ -114,7 +98,7 @@ class Position extends Vector3{ } public function __toString(){ - return "Position(level=" . ($this->isValid() ? $this->getWorldNonNull()->getDisplayName() : "null") . ",x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")"; + return "Position(level=" . ($this->isValid() ? $this->getWorld()->getDisplayName() : "null") . ",x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")"; } public function equals(Vector3 $v) : bool{ diff --git a/src/world/World.php b/src/world/World.php index 31f129841..bd1c6530b 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -2043,7 +2043,7 @@ class World implements ChunkManager{ throw new \InvalidArgumentException("Attempted to add a garbage closed Tile to world"); } $pos = $tile->getPos(); - if(!$pos->isValid() || $pos->getWorldNonNull() !== $this){ + if(!$pos->isValid() || $pos->getWorld() !== $this){ throw new \InvalidArgumentException("Invalid Tile world"); } @@ -2065,7 +2065,7 @@ class World implements ChunkManager{ */ public function removeTile(Tile $tile) : void{ $pos = $tile->getPos(); - if(!$pos->isValid() || $pos->getWorldNonNull() !== $this){ + if(!$pos->isValid() || $pos->getWorld() !== $this){ throw new \InvalidArgumentException("Invalid Tile world"); }