From aae5962f6a3deea7218dcac57fdf4d5e77728533 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 20 Jan 2022 19:05:23 +0000 Subject: [PATCH] Replace disallowed operators in src/world/ --- src/world/Explosion.php | 2 +- src/world/Position.php | 6 +- src/world/SimpleChunkManager.php | 6 +- src/world/World.php | 70 +++++++++---------- src/world/WorldManager.php | 14 ++-- src/world/format/BiomeArray.php | 4 +- src/world/format/Chunk.php | 4 +- src/world/format/HeightArray.php | 2 +- src/world/format/io/WorldProviderManager.php | 2 +- src/world/format/io/leveldb/LevelDB.php | 12 ++-- .../format/io/region/RegionGarbageMap.php | 2 +- src/world/format/io/region/RegionLoader.php | 10 +-- .../io/region/RegionLocationTableEntry.php | 8 +-- .../format/io/region/RegionWorldProvider.php | 4 +- src/world/generator/Flat.php | 2 +- src/world/generator/GeneratorManager.php | 2 +- src/world/generator/hell/Nether.php | 2 +- src/world/generator/noise/Noise.php | 4 +- src/world/generator/normal/Normal.php | 2 +- src/world/generator/object/Ore.php | 4 +- src/world/generator/object/SpruceTree.php | 2 +- src/world/generator/object/TallGrass.php | 2 +- src/world/generator/object/Tree.php | 6 +- src/world/generator/populator/GroundCover.php | 6 +- src/world/generator/populator/TallGrass.php | 6 +- src/world/generator/populator/Tree.php | 4 +- src/world/light/LightUpdate.php | 6 +- .../particle/DragonEggTeleportParticle.php | 2 +- src/world/sound/NoteSound.php | 2 +- src/world/utils/SubChunkExplorer.php | 6 +- 30 files changed, 102 insertions(+), 102 deletions(-) diff --git a/src/world/Explosion.php b/src/world/Explosion.php index b02964dd6e..f67d9034f5 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -102,7 +102,7 @@ class Explosion{ for($i = 0; $i < $this->rays; ++$i){ for($j = 0; $j < $this->rays; ++$j){ for($k = 0; $k < $this->rays; ++$k){ - if($i === 0 or $i === $mRays or $j === 0 or $j === $mRays or $k === 0 or $k === $mRays){ + if($i === 0 || $i === $mRays || $j === 0 || $j === $mRays || $k === 0 || $k === $mRays){ //this could be written as new Vector3(...)->normalize()->multiply(stepLen), but we're avoiding Vector3 for performance here [$shiftX, $shiftY, $shiftZ] = [$i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1]; $len = sqrt($shiftX ** 2 + $shiftY ** 2 + $shiftZ ** 2); diff --git a/src/world/Position.php b/src/world/Position.php index f3fe84caaf..5339adbec9 100644 --- a/src/world/Position.php +++ b/src/world/Position.php @@ -39,7 +39,7 @@ class Position extends Vector3{ */ public function __construct($x, $y, $z, ?World $world){ parent::__construct($x, $y, $z); - if($world !== null and !$world->isLoaded()){ + if($world !== null && !$world->isLoaded()){ throw new \InvalidArgumentException("Specified world has been unloaded and cannot be used"); } @@ -77,7 +77,7 @@ class Position extends Vector3{ * Checks if this object has a valid reference to a loaded world */ public function isValid() : bool{ - if($this->world !== null and !$this->world->isLoaded()){ + if($this->world !== null && !$this->world->isLoaded()){ $this->world = null; return false; @@ -103,7 +103,7 @@ class Position extends Vector3{ public function equals(Vector3 $v) : bool{ if($v instanceof Position){ - return parent::equals($v) and $v->world === $this->world; + return parent::equals($v) && $v->world === $this->world; } return parent::equals($v); } diff --git a/src/world/SimpleChunkManager.php b/src/world/SimpleChunkManager.php index 105412bb50..1b2605f334 100644 --- a/src/world/SimpleChunkManager.php +++ b/src/world/SimpleChunkManager.php @@ -81,9 +81,9 @@ class SimpleChunkManager implements ChunkManager{ public function isInWorld(int $x, int $y, int $z) : bool{ return ( - $x <= Limits::INT32_MAX and $x >= Limits::INT32_MIN and - $y < $this->maxY and $y >= $this->minY and - $z <= Limits::INT32_MAX and $z >= Limits::INT32_MIN + $x <= Limits::INT32_MAX && $x >= Limits::INT32_MIN && + $y < $this->maxY && $y >= $this->minY && + $z <= Limits::INT32_MAX && $z >= Limits::INT32_MIN ); } } diff --git a/src/world/World.php b/src/world/World.php index 8806ffef86..65ded6fa47 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -839,7 +839,7 @@ class World implements ChunkManager{ $this->timings->scheduledBlockUpdates->startTiming(); //Delayed updates - while($this->scheduledBlockUpdateQueue->count() > 0 and $this->scheduledBlockUpdateQueue->current()["priority"] <= $currentTick){ + while($this->scheduledBlockUpdateQueue->count() > 0 && $this->scheduledBlockUpdateQueue->current()["priority"] <= $currentTick){ /** @var Vector3 $vec */ $vec = $this->scheduledBlockUpdateQueue->extract()["data"]; unset($this->scheduledBlockUpdateQueueIndex[World::blockHash($vec->x, $vec->y, $vec->z)]); @@ -878,7 +878,7 @@ class World implements ChunkManager{ //Update entities that need update Timings::$tickEntity->startTiming(); foreach($this->updateEntities as $id => $entity){ - if($entity->isClosed() or $entity->isFlaggedForDespawn() or !$entity->onUpdate($currentTick)){ + if($entity->isClosed() || $entity->isFlaggedForDespawn() || !$entity->onUpdate($currentTick)){ unset($this->updateEntities[$id]); } if($entity->isFlaggedForDespawn()){ @@ -918,7 +918,7 @@ class World implements ChunkManager{ } - if($this->sleepTicks > 0 and --$this->sleepTicks <= 0){ + if($this->sleepTicks > 0 && --$this->sleepTicks <= 0){ $this->checkSleep(); } @@ -949,7 +949,7 @@ class World implements ChunkManager{ if($resetTime){ $time = $this->getTimeOfDay(); - if($time >= World::TIME_NIGHT and $time < World::TIME_SUNRISE){ + if($time >= World::TIME_NIGHT && $time < World::TIME_SUNRISE){ $this->setTime($this->getTime() + World::TIME_FULL - $time); foreach($this->getPlayers() as $p){ @@ -1028,7 +1028,7 @@ class World implements ChunkManager{ } private function tickChunks() : void{ - if($this->chunksPerTick <= 0 or count($this->tickingLoaders) === 0){ + if($this->chunksPerTick <= 0 || count($this->tickingLoaders) === 0){ return; } @@ -1049,7 +1049,7 @@ class World implements ChunkManager{ $dx = mt_rand(-$randRange, $randRange); $dz = mt_rand(-$randRange, $randRange); $hash = World::chunkHash($dx + $chunkX, $dz + $chunkZ); - if(!isset($chunkTickList[$hash]) and isset($this->chunks[$hash]) and $this->isChunkTickable($dx + $chunkX, $dz + $chunkZ)){ + if(!isset($chunkTickList[$hash]) && isset($this->chunks[$hash]) && $this->isChunkTickable($dx + $chunkX, $dz + $chunkZ)){ $chunkTickList[$hash] = true; } } @@ -1164,7 +1164,7 @@ class World implements ChunkManager{ public function save(bool $force = false) : bool{ - if(!$this->getAutoSave() and !$force){ + if(!$this->getAutoSave() && !$force){ return false; } @@ -1200,8 +1200,8 @@ class World implements ChunkManager{ */ public function scheduleDelayedBlockUpdate(Vector3 $pos, int $delay) : void{ if( - !$this->isInWorld($pos->x, $pos->y, $pos->z) or - (isset($this->scheduledBlockUpdateQueueIndex[$index = World::blockHash($pos->x, $pos->y, $pos->z)]) and $this->scheduledBlockUpdateQueueIndex[$index] <= $delay) + !$this->isInWorld($pos->x, $pos->y, $pos->z) || + (isset($this->scheduledBlockUpdateQueueIndex[$index = World::blockHash($pos->x, $pos->y, $pos->z)]) && $this->scheduledBlockUpdateQueueIndex[$index] <= $delay) ){ return; } @@ -1520,9 +1520,9 @@ class World implements ChunkManager{ public function isInWorld(int $x, int $y, int $z) : bool{ return ( - $x <= Limits::INT32_MAX and $x >= Limits::INT32_MIN and - $y < $this->maxY and $y >= $this->minY and - $z <= Limits::INT32_MAX and $z >= Limits::INT32_MIN + $x <= Limits::INT32_MAX && $x >= Limits::INT32_MIN && + $y < $this->maxY && $y >= $this->minY && + $z <= Limits::INT32_MAX && $z >= Limits::INT32_MIN ); } @@ -1556,7 +1556,7 @@ class World implements ChunkManager{ if($this->isInWorld($x, $y, $z)){ $relativeBlockHash = World::chunkBlockHash($x, $y, $z); - if($cached and isset($this->blockCache[$chunkHash][$relativeBlockHash])){ + if($cached && isset($this->blockCache[$chunkHash][$relativeBlockHash])){ return $this->blockCache[$chunkHash][$relativeBlockHash]; } @@ -1586,7 +1586,7 @@ class World implements ChunkManager{ $dynamicStateRead = false; } - if($addToCache and $relativeBlockHash !== null){ + if($addToCache && $relativeBlockHash !== null){ $this->blockCache[$chunkHash][$relativeBlockHash] = $block; } @@ -1713,23 +1713,23 @@ class World implements ChunkManager{ } $drops = []; - if($player === null or $player->hasFiniteResources()){ + if($player === null || $player->hasFiniteResources()){ $drops = array_merge(...array_map(fn(Block $block) => $block->getDrops($item), $affectedBlocks)); } $xpDrop = 0; - if($player !== null and $player->hasFiniteResources()){ + if($player !== null && $player->hasFiniteResources()){ $xpDrop = array_sum(array_map(fn(Block $block) => $block->getXpDropForTool($item), $affectedBlocks)); } if($player !== null){ $ev = new BlockBreakEvent($player, $target, $item, $player->isCreative(), $drops, $xpDrop); - if($target instanceof Air or ($player->isSurvival() and !$target->getBreakInfo()->isBreakable()) or $player->isSpectator()){ + if($target instanceof Air || ($player->isSurvival() && !$target->getBreakInfo()->isBreakable()) || $player->isSpectator()){ $ev->cancel(); } - if($player->isAdventure(true) and !$ev->isCancelled()){ + if($player->isAdventure(true) && !$ev->isCancelled()){ $canBreak = false; $itemParser = LegacyStringToItemParser::getInstance(); foreach($item->getCanDestroy() as $v){ @@ -1828,7 +1828,7 @@ class World implements ChunkManager{ $ev->call(); if(!$ev->isCancelled()){ - if((!$player->isSneaking() or $item->isNull()) and $blockClicked->onInteract($item, $face, $clickVector, $player)){ + if((!$player->isSneaking() || $item->isNull()) && $blockClicked->onInteract($item, $face, $clickVector, $player)){ return true; } @@ -1843,7 +1843,7 @@ class World implements ChunkManager{ return true; } - if($item->isNull() or !$item->canBePlaced()){ + if($item->isNull() || !$item->canBePlaced()){ return false; } $hand = $item->getBlock($face); @@ -1876,7 +1876,7 @@ class World implements ChunkManager{ $ev->cancel(); } - if($player->isAdventure(true) and !$ev->isCancelled()){ + if($player->isAdventure(true) && !$ev->isCancelled()){ $canPlace = false; $itemParser = LegacyStringToItemParser::getInstance(); foreach($item->getCanPlaceOn() as $v){ @@ -1941,9 +1941,9 @@ class World implements ChunkManager{ public function getCollidingEntities(AxisAlignedBB $bb, ?Entity $entity = null) : array{ $nearby = []; - if($entity === null or $entity->canCollide){ + if($entity === null || $entity->canCollide){ foreach($this->getNearbyEntities($bb, $entity) as $ent){ - if($ent->canBeCollidedWith() and ($entity === null or $entity->canCollideWith($ent))){ + if($ent->canBeCollidedWith() && ($entity === null || $entity->canCollideWith($ent))){ $nearby[] = $ent; } } @@ -1971,7 +1971,7 @@ class World implements ChunkManager{ continue; } foreach($this->getChunkEntities($x, $z) as $ent){ - if($ent !== $entity and $ent->boundingBox->intersectsWith($bb)){ + if($ent !== $entity && $ent->boundingBox->intersectsWith($bb)){ $nearby[] = $ent; } } @@ -2014,7 +2014,7 @@ class World implements ChunkManager{ continue; } foreach($this->getChunkEntities($x, $z) as $entity){ - if(!($entity instanceof $entityType) or $entity->isFlaggedForDespawn() or (!$includeDead and !$entity->isAlive())){ + if(!($entity instanceof $entityType) || $entity->isFlaggedForDespawn() || (!$includeDead && !$entity->isAlive())){ continue; } $distSq = $entity->getPosition()->distanceSquared($pos); @@ -2173,7 +2173,7 @@ class World implements ChunkManager{ public function setChunk(int $chunkX, int $chunkZ, Chunk $chunk) : void{ $chunkHash = World::chunkHash($chunkX, $chunkZ); $oldChunk = $this->loadChunk($chunkX, $chunkZ); - if($oldChunk !== null and $oldChunk !== $chunk){ + if($oldChunk !== null && $oldChunk !== $chunk){ $deletedTiles = 0; $transferredTiles = 0; foreach($oldChunk->getTiles() as $oldTile){ @@ -2439,7 +2439,7 @@ class World implements ChunkManager{ } public function isChunkInUse(int $x, int $z) : bool{ - return isset($this->chunkLoaders[$index = World::chunkHash($x, $z)]) and count($this->chunkLoaders[$index]) > 0; + return isset($this->chunkLoaders[$index = World::chunkHash($x, $z)]) && count($this->chunkLoaders[$index]) > 0; } /** @@ -2582,7 +2582,7 @@ class World implements ChunkManager{ } public function unloadChunkRequest(int $x, int $z, bool $safe = true) : bool{ - if(($safe and $this->isChunkInUse($x, $z)) or $this->isSpawnChunk($x, $z)){ + if(($safe && $this->isChunkInUse($x, $z)) || $this->isSpawnChunk($x, $z)){ return false; } @@ -2596,7 +2596,7 @@ class World implements ChunkManager{ } public function unloadChunk(int $x, int $z, bool $safe = true, bool $trySave = true) : bool{ - if($safe and $this->isChunkInUse($x, $z)){ + if($safe && $this->isChunkInUse($x, $z)){ return false; } @@ -2619,7 +2619,7 @@ class World implements ChunkManager{ return false; } - if($trySave and $this->getAutoSave()){ + if($trySave && $this->getAutoSave()){ $this->timings->syncChunkSave->startTiming(); try{ $this->provider->saveChunk($x, $z, new ChunkData( @@ -2668,14 +2668,14 @@ class World implements ChunkManager{ $spawnX = $spawn->x >> Chunk::COORD_BIT_SIZE; $spawnZ = $spawn->z >> Chunk::COORD_BIT_SIZE; - return abs($X - $spawnX) <= 1 and abs($Z - $spawnZ) <= 1; + return abs($X - $spawnX) <= 1 && abs($Z - $spawnZ) <= 1; } /** * @throws WorldException if the terrain is not generated */ public function getSafeSpawn(?Vector3 $spawn = null) : Position{ - if(!($spawn instanceof Vector3) or $spawn->y < 1){ + if(!($spawn instanceof Vector3) || $spawn->y < 1){ $spawn = $this->getSpawnLocation(); } @@ -2700,7 +2700,7 @@ class World implements ChunkManager{ } } - for(; $y >= $this->minY and $y < $max; ++$y){ + for(; $y >= $this->minY && $y < $max; ++$y){ if(!$this->getBlockAt($x, $y + 1, $z)->isFullCube()){ if(!$this->getBlockAt($x, $y, $z)->isFullCube()){ return new Position($spawn->x, $y === (int) $spawn->y ? $spawn->y : $y, $spawn->z, $this); @@ -2786,7 +2786,7 @@ class World implements ChunkManager{ } public function setDifficulty(int $difficulty) : void{ - if($difficulty < 0 or $difficulty > 3){ + if($difficulty < 0 || $difficulty > 3){ throw new \InvalidArgumentException("Invalid difficulty level $difficulty"); } $this->provider->getWorldData()->setDifficulty($difficulty); @@ -3013,7 +3013,7 @@ class World implements ChunkManager{ $this->setChunk($x + $relativeX, $z + $relativeZ, $adjacentChunk); } - if(($oldChunk === null or !$oldChunk->isPopulated()) and $chunk->isPopulated()){ + if(($oldChunk === null || !$oldChunk->isPopulated()) && $chunk->isPopulated()){ (new ChunkPopulateEvent($this, $x, $z, $chunk))->call(); foreach($this->getChunkListeners($x, $z) as $listener){ diff --git a/src/world/WorldManager.php b/src/world/WorldManager.php index aa906e4ab4..65fe547264 100644 --- a/src/world/WorldManager.php +++ b/src/world/WorldManager.php @@ -104,7 +104,7 @@ class WorldManager{ * it only affects the server on runtime */ public function setDefaultWorld(?World $world) : void{ - if($world === null or ($this->isWorldLoaded($world->getFolderName()) and $world !== $this->defaultWorld)){ + if($world === null || ($this->isWorldLoaded($world->getFolderName()) && $world !== $this->defaultWorld)){ $this->defaultWorld = $world; } } @@ -134,7 +134,7 @@ class WorldManager{ * @throws \InvalidArgumentException */ public function unloadWorld(World $world, bool $forceUnload = false) : bool{ - if($world === $this->getDefaultWorld() and !$forceUnload){ + if($world === $this->getDefaultWorld() && !$forceUnload){ throw new \InvalidArgumentException("The default world cannot be unloaded while running, please switch worlds."); } if($world->isDoingTick()){ @@ -142,13 +142,13 @@ class WorldManager{ } $ev = new WorldUnloadEvent($world); - if($world === $this->defaultWorld and !$forceUnload){ + if($world === $this->defaultWorld && !$forceUnload){ $ev->cancel(); } $ev->call(); - if(!$forceUnload and $ev->isCancelled()){ + if(!$forceUnload && $ev->isCancelled()){ return false; } @@ -159,7 +159,7 @@ class WorldManager{ $safeSpawn = null; } foreach($world->getPlayers() as $player){ - if($world === $this->defaultWorld or $safeSpawn === null){ + if($world === $this->defaultWorld || $safeSpawn === null){ $player->disconnect("Forced default world unload"); }else{ $player->teleport($safeSpawn); @@ -271,7 +271,7 @@ class WorldManager{ * @throws \InvalidArgumentException */ public function generateWorld(string $name, WorldCreationOptions $options, bool $backgroundGeneration = true) : bool{ - if(trim($name) === "" or $this->isWorldGenerated($name)){ + if(trim($name) === "" || $this->isWorldGenerated($name)){ return false; } @@ -365,7 +365,7 @@ class WorldManager{ } } - if($this->autoSave and ++$this->autoSaveTicker >= $this->autoSaveTicks){ + if($this->autoSave && ++$this->autoSaveTicker >= $this->autoSaveTicks){ $this->autoSaveTicker = 0; $this->server->getLogger()->debug("[Auto Save] Saving worlds..."); $start = microtime(true); diff --git a/src/world/format/BiomeArray.php b/src/world/format/BiomeArray.php index 30a5d2cb0f..ed45e88fcd 100644 --- a/src/world/format/BiomeArray.php +++ b/src/world/format/BiomeArray.php @@ -48,7 +48,7 @@ final class BiomeArray{ } private static function idx(int $x, int $z) : int{ - if($x < 0 or $x >= 16 or $z < 0 or $z >= 16){ + if($x < 0 || $x >= 16 || $z < 0 || $z >= 16){ throw new \InvalidArgumentException("x and z must be in the range 0-15"); } return ($z << 4) | $x; @@ -59,7 +59,7 @@ final class BiomeArray{ } public function set(int $x, int $z, int $biomeId) : void{ - if($biomeId < 0 or $biomeId >= 256){ + if($biomeId < 0 || $biomeId >= 256){ throw new \InvalidArgumentException("Biome ID must be in the range 0-255"); } $this->payload[self::idx($x, $z)] = chr($biomeId); diff --git a/src/world/format/Chunk.php b/src/world/format/Chunk.php index 8bb5eed9f2..6a8dad59c8 100644 --- a/src/world/format/Chunk.php +++ b/src/world/format/Chunk.php @@ -197,7 +197,7 @@ class Chunk{ } $pos = $tile->getPosition(); - if(isset($this->tiles[$index = Chunk::blockHash($pos->x, $pos->y, $pos->z)]) and $this->tiles[$index] !== $tile){ + if(isset($this->tiles[$index = Chunk::blockHash($pos->x, $pos->y, $pos->z)]) && $this->tiles[$index] !== $tile){ throw new \InvalidArgumentException("Another tile is already at this location"); } $this->tiles[$index] = $tile; @@ -292,7 +292,7 @@ class Chunk{ * Sets a subchunk in the chunk index */ public function setSubChunk(int $y, ?SubChunk $subChunk) : void{ - if($y < self::MIN_SUBCHUNK_INDEX or $y > self::MAX_SUBCHUNK_INDEX){ + if($y < self::MIN_SUBCHUNK_INDEX || $y > self::MAX_SUBCHUNK_INDEX){ throw new \InvalidArgumentException("Invalid subchunk Y coordinate $y"); } diff --git a/src/world/format/HeightArray.php b/src/world/format/HeightArray.php index 54c8e19f33..88df7299b2 100644 --- a/src/world/format/HeightArray.php +++ b/src/world/format/HeightArray.php @@ -50,7 +50,7 @@ final class HeightArray{ } private static function idx(int $x, int $z) : int{ - if($x < 0 or $x >= 16 or $z < 0 or $z >= 16){ + if($x < 0 || $x >= 16 || $z < 0 || $z >= 16){ throw new \InvalidArgumentException("x and z must be in the range 0-15"); } return ($z << 4) | $x; diff --git a/src/world/format/io/WorldProviderManager.php b/src/world/format/io/WorldProviderManager.php index 64dad08168..db67c62216 100644 --- a/src/world/format/io/WorldProviderManager.php +++ b/src/world/format/io/WorldProviderManager.php @@ -63,7 +63,7 @@ final class WorldProviderManager{ public function addProvider(WorldProviderManagerEntry $providerEntry, string $name, bool $overwrite = false) : void{ $name = strtolower($name); - if(!$overwrite and isset($this->providers[$name])){ + if(!$overwrite && isset($this->providers[$name])){ throw new \InvalidArgumentException("Alias \"$name\" is already assigned"); } diff --git a/src/world/format/io/leveldb/LevelDB.php b/src/world/format/io/leveldb/LevelDB.php index acd8ffed4a..91d367fb01 100644 --- a/src/world/format/io/leveldb/LevelDB.php +++ b/src/world/format/io/leveldb/LevelDB.php @@ -144,7 +144,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{ } public static function isValid(string $path) : bool{ - return file_exists(Path::join($path, "level.dat")) and is_dir(Path::join($path, "db")); + return file_exists(Path::join($path, "level.dat")) && is_dir(Path::join($path, "db")); } public static function generate(string $path, string $name, WorldCreationOptions $options) : void{ @@ -207,7 +207,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{ * @return PalettedBlockArray[] */ protected function deserializeLegacyExtraData(string $index, int $chunkVersion) : array{ - if(($extraRawData = $this->db->get($index . self::TAG_BLOCK_EXTRA_DATA)) === false or $extraRawData === ""){ + if(($extraRawData = $this->db->get($index . self::TAG_BLOCK_EXTRA_DATA)) === false || $extraRawData === ""){ return []; } @@ -391,7 +391,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{ /** @var CompoundTag[] $entities */ $entities = []; - if(($entityData = $this->db->get($index . self::TAG_ENTITY)) !== false and $entityData !== ""){ + if(($entityData = $this->db->get($index . self::TAG_ENTITY)) !== false && $entityData !== ""){ try{ $entities = array_map(fn(TreeRoot $root) => $root->mustGetCompoundTag(), $nbt->readMultiple($entityData)); }catch(NbtDataException $e){ @@ -401,7 +401,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{ /** @var CompoundTag[] $tiles */ $tiles = []; - if(($tileData = $this->db->get($index . self::TAG_BLOCK_ENTITY)) !== false and $tileData !== ""){ + if(($tileData = $this->db->get($index . self::TAG_BLOCK_ENTITY)) !== false && $tileData !== ""){ try{ $tiles = array_map(fn(TreeRoot $root) => $root->mustGetCompoundTag(), $nbt->readMultiple($tileData)); }catch(NbtDataException $e){ @@ -527,7 +527,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{ public function getAllChunks(bool $skipCorrupted = false, ?\Logger $logger = null) : \Generator{ foreach($this->db->getIterator() as $key => $_){ - if(strlen($key) === 9 and substr($key, -1) === self::TAG_VERSION){ + if(strlen($key) === 9 && substr($key, -1) === self::TAG_VERSION){ $chunkX = Binary::readLInt(substr($key, 0, 4)); $chunkZ = Binary::readLInt(substr($key, 4, 4)); try{ @@ -549,7 +549,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{ public function calculateChunkCount() : int{ $count = 0; foreach($this->db->getIterator() as $key => $_){ - if(strlen($key) === 9 and substr($key, -1) === self::TAG_VERSION){ + if(strlen($key) === 9 && substr($key, -1) === self::TAG_VERSION){ $count++; } } diff --git a/src/world/format/io/region/RegionGarbageMap.php b/src/world/format/io/region/RegionGarbageMap.php index a3dd8e5426..9b03734496 100644 --- a/src/world/format/io/region/RegionGarbageMap.php +++ b/src/world/format/io/region/RegionGarbageMap.php @@ -95,7 +95,7 @@ final class RegionGarbageMap{ /** @var int|null $prevIndex */ $prevIndex = null; foreach($this->entries as $k => $entry){ - if($prevIndex !== null and $this->entries[$prevIndex]->getLastSector() + 1 === $entry->getFirstSector()){ + if($prevIndex !== null && $this->entries[$prevIndex]->getLastSector() + 1 === $entry->getFirstSector()){ //this SHOULD overwrite the previous index and not appear at the end $this->entries[$prevIndex] = new RegionLocationTableEntry( $this->entries[$prevIndex]->getFirstSector(), diff --git a/src/world/format/io/region/RegionLoader.php b/src/world/format/io/region/RegionLoader.php index dd50f6c38d..4490524541 100644 --- a/src/world/format/io/region/RegionLoader.php +++ b/src/world/format/io/region/RegionLoader.php @@ -169,7 +169,7 @@ class RegionLoader{ } $compression = $stream->getByte(); - if($compression !== self::COMPRESSION_ZLIB and $compression !== self::COMPRESSION_GZIP){ + if($compression !== self::COMPRESSION_ZLIB && $compression !== self::COMPRESSION_GZIP){ throw new CorruptedChunkException("Invalid compression type (got $compression, expected " . self::COMPRESSION_ZLIB . " or " . self::COMPRESSION_GZIP . ")"); } @@ -192,7 +192,7 @@ class RegionLoader{ $endGarbage = $this->garbageTable->end(); $nextSector = $this->nextSector; - for(; $endGarbage !== null and $endGarbage->getLastSector() + 1 === $nextSector; $endGarbage = $this->garbageTable->end()){ + for(; $endGarbage !== null && $endGarbage->getLastSector() + 1 === $nextSector; $endGarbage = $this->garbageTable->end()){ $nextSector = $endGarbage->getFirstSector(); $this->garbageTable->remove($endGarbage); } @@ -267,7 +267,7 @@ class RegionLoader{ * @throws \InvalidArgumentException */ protected static function getChunkOffset(int $x, int $z) : int{ - if($x < 0 or $x > 31 or $z < 0 or $z > 31){ + if($x < 0 || $x > 31 || $z < 0 || $z > 31){ throw new \InvalidArgumentException("Invalid chunk position in region, expected x/z in range 0-31, got x=$x, z=$z"); } return $x | ($z << 5); @@ -298,7 +298,7 @@ class RegionLoader{ fseek($this->filePointer, 0); $headerRaw = fread($this->filePointer, self::REGION_HEADER_LENGTH); - if($headerRaw === false or strlen($headerRaw) !== self::REGION_HEADER_LENGTH){ + if($headerRaw === false || strlen($headerRaw) !== self::REGION_HEADER_LENGTH){ throw new CorruptedRegionException("Corrupted region header (unexpected end of file)"); } @@ -311,7 +311,7 @@ class RegionLoader{ $sectorCount = $index & 0xff; $timestamp = $data[$i + 1025]; - if($offset === 0 or $sectorCount === 0){ + if($offset === 0 || $sectorCount === 0){ $this->locationTable[$i] = null; }elseif($offset >= self::FIRST_SECTOR){ $this->bumpNextFreeSector($this->locationTable[$i] = new RegionLocationTableEntry($offset, $sectorCount, $timestamp)); diff --git a/src/world/format/io/region/RegionLocationTableEntry.php b/src/world/format/io/region/RegionLocationTableEntry.php index 8a7fdfaeb1..c3c68be875 100644 --- a/src/world/format/io/region/RegionLocationTableEntry.php +++ b/src/world/format/io/region/RegionLocationTableEntry.php @@ -38,7 +38,7 @@ class RegionLocationTableEntry{ * @throws \InvalidArgumentException */ public function __construct(int $firstSector, int $sectorCount, int $timestamp){ - if($firstSector < 0 or $firstSector >= 2 ** 24){ + if($firstSector < 0 || $firstSector >= 2 ** 24){ throw new \InvalidArgumentException("Start sector must be positive, got $firstSector"); } $this->firstSector = $firstSector; @@ -79,10 +79,10 @@ class RegionLocationTableEntry{ $entry2Last = $entry2->getLastSector(); return ( - ($entry2->firstSector >= $entry1->firstSector and $entry2->firstSector <= $entry1Last) or - ($entry2Last >= $entry1->firstSector and $entry2Last <= $entry1Last) + ($entry2->firstSector >= $entry1->firstSector && $entry2->firstSector <= $entry1Last) || + ($entry2Last >= $entry1->firstSector && $entry2Last <= $entry1Last) ); }; - return $overlapCheck($this, $other) or $overlapCheck($other, $this); + return $overlapCheck($this, $other) || $overlapCheck($other, $this); } } diff --git a/src/world/format/io/region/RegionWorldProvider.php b/src/world/format/io/region/RegionWorldProvider.php index 1fe62912c7..25fcf65b37 100644 --- a/src/world/format/io/region/RegionWorldProvider.php +++ b/src/world/format/io/region/RegionWorldProvider.php @@ -59,7 +59,7 @@ abstract class RegionWorldProvider extends BaseWorldProvider{ abstract protected static function getPcWorldFormatVersion() : int; public static function isValid(string $path) : bool{ - if(file_exists(Path::join($path, "level.dat")) and is_dir($regionPath = Path::join($path, "region"))){ + if(file_exists(Path::join($path, "level.dat")) && is_dir($regionPath = Path::join($path, "region"))){ foreach(scandir($regionPath, SCANDIR_SORT_NONE) as $file){ $extPos = strrpos($file, "."); if($extPos !== false && substr($file, $extPos + 1) === static::getRegionFileExtension()){ @@ -191,7 +191,7 @@ abstract class RegionWorldProvider extends BaseWorldProvider{ public function loadChunk(int $chunkX, int $chunkZ) : ?ChunkData{ $regionX = $regionZ = null; self::getRegionIndex($chunkX, $chunkZ, $regionX, $regionZ); - assert(is_int($regionX) and is_int($regionZ)); + assert(is_int($regionX) && is_int($regionZ)); if(!file_exists($this->pathToRegion($regionX, $regionZ))){ return null; diff --git a/src/world/generator/Flat.php b/src/world/generator/Flat.php index 26a658b6d6..06dadc517b 100644 --- a/src/world/generator/Flat.php +++ b/src/world/generator/Flat.php @@ -75,7 +75,7 @@ class Flat extends Generator{ $count = count($structure); for($sy = 0; $sy < $count; $sy += SubChunk::EDGE_LENGTH){ $subchunk = $this->chunk->getSubChunk($sy >> SubChunk::COORD_BIT_SIZE); - for($y = 0; $y < SubChunk::EDGE_LENGTH and isset($structure[$y | $sy]); ++$y){ + for($y = 0; $y < SubChunk::EDGE_LENGTH && isset($structure[$y | $sy]); ++$y){ $id = $structure[$y | $sy]; for($Z = 0; $Z < SubChunk::EDGE_LENGTH; ++$Z){ diff --git a/src/world/generator/GeneratorManager.php b/src/world/generator/GeneratorManager.php index f90c6ae4ab..76bda57b6a 100644 --- a/src/world/generator/GeneratorManager.php +++ b/src/world/generator/GeneratorManager.php @@ -73,7 +73,7 @@ final class GeneratorManager{ Utils::testValidInstance($class, Generator::class); $name = strtolower($name); - if(!$overwrite and isset($this->list[$name])){ + if(!$overwrite && isset($this->list[$name])){ throw new \InvalidArgumentException("Alias \"$name\" is already assigned"); } diff --git a/src/world/generator/hell/Nether.php b/src/world/generator/hell/Nether.php index 8657e25808..5440c6d043 100644 --- a/src/world/generator/hell/Nether.php +++ b/src/world/generator/hell/Nether.php @@ -86,7 +86,7 @@ class Nether extends Generator{ $chunk->setBiomeId($x, $z, BiomeIds::HELL); for($y = 0; $y < 128; ++$y){ - if($y === 0 or $y === 127){ + if($y === 0 || $y === 127){ $chunk->setFullBlock($x, $y, $z, $bedrock); continue; } diff --git a/src/world/generator/noise/Noise.php b/src/world/generator/noise/Noise.php index fde81d10b1..1d0b7b3b10 100644 --- a/src/world/generator/noise/Noise.php +++ b/src/world/generator/noise/Noise.php @@ -256,7 +256,7 @@ abstract class Noise{ } for($zz = 0; $zz < $zSize; ++$zz){ - if($xx % $samplingRate !== 0 or $zz % $samplingRate !== 0){ + if($xx % $samplingRate !== 0 || $zz % $samplingRate !== 0){ $nx = (int) ($xx / $samplingRate) * $samplingRate; $nz = (int) ($zz / $samplingRate) * $samplingRate; $noiseArray[$xx][$zz] = Noise::bilinearLerp( @@ -320,7 +320,7 @@ abstract class Noise{ $dz2 = ($zz - $nz) / ($nnz - $nz); for($yy = 0; $yy < $ySize; ++$yy){ - if($xx % $xSamplingRate !== 0 or $zz % $zSamplingRate !== 0 or $yy % $ySamplingRate !== 0){ + if($xx % $xSamplingRate !== 0 || $zz % $zSamplingRate !== 0 || $yy % $ySamplingRate !== 0){ $ny = (int) ($yy / $ySamplingRate) * $ySamplingRate; $nny = $ny + $ySamplingRate; diff --git a/src/world/generator/normal/Normal.php b/src/world/generator/normal/Normal.php index f8a006663c..a1aebfc1bd 100644 --- a/src/world/generator/normal/Normal.php +++ b/src/world/generator/normal/Normal.php @@ -173,7 +173,7 @@ class Normal extends Generator{ $weight = $this->gaussian->kernel[$sx + $this->gaussian->smoothSize][$sz + $this->gaussian->smoothSize]; - if($sx === 0 and $sz === 0){ + if($sx === 0 && $sz === 0){ $adjacent = $biome; }else{ $index = World::chunkHash($absoluteX + $sx, $absoluteZ + $sz); diff --git a/src/world/generator/object/Ore.php b/src/world/generator/object/Ore.php index aad9cc0349..5a3066030e 100644 --- a/src/world/generator/object/Ore.php +++ b/src/world/generator/object/Ore.php @@ -80,12 +80,12 @@ class Ore{ $sizeY = ($yy + 0.5 - $seedY) / $size; $sizeY *= $sizeY; - if($yy > 0 and ($sizeX + $sizeY) < 1){ + if($yy > 0 && ($sizeX + $sizeY) < 1){ for($zz = $startZ; $zz <= $endZ; ++$zz){ $sizeZ = ($zz + 0.5 - $seedZ) / $size; $sizeZ *= $sizeZ; - if(($sizeX + $sizeY + $sizeZ) < 1 and $world->getBlockAt($xx, $yy, $zz)->isSameType($this->type->replaces)){ + if(($sizeX + $sizeY + $sizeZ) < 1 && $world->getBlockAt($xx, $yy, $zz)->isSameType($this->type->replaces)){ $world->setBlockAt($xx, $yy, $zz, $this->type->material); } } diff --git a/src/world/generator/object/SpruceTree.php b/src/world/generator/object/SpruceTree.php index 3439b03d4d..acac1210a6 100644 --- a/src/world/generator/object/SpruceTree.php +++ b/src/world/generator/object/SpruceTree.php @@ -58,7 +58,7 @@ class SpruceTree extends Tree{ $xOff = abs($xx - $x); for($zz = $z - $radius; $zz <= $z + $radius; ++$zz){ $zOff = abs($zz - $z); - if($xOff === $radius and $zOff === $radius and $radius > 0){ + if($xOff === $radius && $zOff === $radius && $radius > 0){ continue; } diff --git a/src/world/generator/object/TallGrass.php b/src/world/generator/object/TallGrass.php index 80e75e5a1d..8fe70e0c80 100644 --- a/src/world/generator/object/TallGrass.php +++ b/src/world/generator/object/TallGrass.php @@ -47,7 +47,7 @@ class TallGrass{ for($c = 0; $c < $count; ++$c){ $x = $random->nextRange($pos->x - $radius, $pos->x + $radius); $z = $random->nextRange($pos->z - $radius, $pos->z + $radius); - if($world->getBlockAt($x, $pos->y + 1, $z)->getId() === BlockLegacyIds::AIR and $world->getBlockAt($x, $pos->y, $z)->getId() === BlockLegacyIds::GRASS){ + if($world->getBlockAt($x, $pos->y + 1, $z)->getId() === BlockLegacyIds::AIR && $world->getBlockAt($x, $pos->y, $z)->getId() === BlockLegacyIds::GRASS){ $world->setBlockAt($x, $pos->y + 1, $z, $arr[$random->nextRange(0, $arrC)]); } } diff --git a/src/world/generator/object/Tree.php b/src/world/generator/object/Tree.php index 90eef6c3ab..9b032ad957 100644 --- a/src/world/generator/object/Tree.php +++ b/src/world/generator/object/Tree.php @@ -51,7 +51,7 @@ abstract class Tree{ public function canPlaceObject(ChunkManager $world, int $x, int $y, int $z, Random $random) : bool{ $radiusToCheck = 0; for($yy = 0; $yy < $this->treeHeight + 3; ++$yy){ - if($yy === 1 or $yy === $this->treeHeight){ + if($yy === 1 || $yy === $this->treeHeight){ ++$radiusToCheck; } for($xx = -$radiusToCheck; $xx < ($radiusToCheck + 1); ++$xx){ @@ -105,7 +105,7 @@ abstract class Tree{ $xOff = abs($xx - $x); for($zz = $z - $mid; $zz <= $z + $mid; ++$zz){ $zOff = abs($zz - $z); - if($xOff === $mid and $zOff === $mid and ($yOff === 0 or $random->nextBoundedInt(2) === 0)){ + if($xOff === $mid && $zOff === $mid && ($yOff === 0 || $random->nextBoundedInt(2) === 0)){ continue; } if(!$transaction->fetchBlockAt($xx, $yy, $zz)->isSolid()){ @@ -117,6 +117,6 @@ abstract class Tree{ } protected function canOverride(Block $block) : bool{ - return $block->canBeReplaced() or $block instanceof Sapling or $block instanceof Leaves; + return $block->canBeReplaced() || $block instanceof Sapling || $block instanceof Leaves; } } diff --git a/src/world/generator/populator/GroundCover.php b/src/world/generator/populator/GroundCover.php index da5a336a3e..7a72e021c6 100644 --- a/src/world/generator/populator/GroundCover.php +++ b/src/world/generator/populator/GroundCover.php @@ -57,13 +57,13 @@ class GroundCover implements Populator{ } $startY = min(127, $startY + $diffY); $endY = $startY - count($cover); - for($y = $startY; $y > $endY and $y >= 0; --$y){ + for($y = $startY; $y > $endY && $y >= 0; --$y){ $b = $cover[$startY - $y]; $id = $factory->fromFullBlock($chunk->getFullBlock($x, $y, $z)); - if($id->getId() === BlockLegacyIds::AIR and $b->isSolid()){ + if($id->getId() === BlockLegacyIds::AIR && $b->isSolid()){ break; } - if($b->canBeFlowedInto() and $id instanceof Liquid){ + if($b->canBeFlowedInto() && $id instanceof Liquid){ continue; } diff --git a/src/world/generator/populator/TallGrass.php b/src/world/generator/populator/TallGrass.php index 6783e6537a..10e3d53c55 100644 --- a/src/world/generator/populator/TallGrass.php +++ b/src/world/generator/populator/TallGrass.php @@ -52,7 +52,7 @@ class TallGrass implements Populator{ $z = $random->nextRange($chunkZ * Chunk::EDGE_LENGTH, $chunkZ * Chunk::EDGE_LENGTH + (Chunk::EDGE_LENGTH - 1)); $y = $this->getHighestWorkableBlock($world, $x, $z); - if($y !== -1 and $this->canTallGrassStay($world, $x, $y, $z)){ + if($y !== -1 && $this->canTallGrassStay($world, $x, $y, $z)){ $world->setBlockAt($x, $y, $z, $block); } } @@ -60,13 +60,13 @@ class TallGrass implements Populator{ private function canTallGrassStay(ChunkManager $world, int $x, int $y, int $z) : bool{ $b = $world->getBlockAt($x, $y, $z)->getId(); - return ($b === BlockLegacyIds::AIR or $b === BlockLegacyIds::SNOW_LAYER) and $world->getBlockAt($x, $y - 1, $z)->getId() === BlockLegacyIds::GRASS; + return ($b === BlockLegacyIds::AIR || $b === BlockLegacyIds::SNOW_LAYER) && $world->getBlockAt($x, $y - 1, $z)->getId() === BlockLegacyIds::GRASS; } private function getHighestWorkableBlock(ChunkManager $world, int $x, int $z) : int{ for($y = 127; $y >= 0; --$y){ $b = $world->getBlockAt($x, $y, $z)->getId(); - if($b !== BlockLegacyIds::AIR and $b !== BlockLegacyIds::LEAVES and $b !== BlockLegacyIds::LEAVES2 and $b !== BlockLegacyIds::SNOW_LAYER){ + if($b !== BlockLegacyIds::AIR && $b !== BlockLegacyIds::LEAVES && $b !== BlockLegacyIds::LEAVES2 && $b !== BlockLegacyIds::SNOW_LAYER){ return $y + 1; } } diff --git a/src/world/generator/populator/Tree.php b/src/world/generator/populator/Tree.php index 45eb64835c..ba4e7d0aee 100644 --- a/src/world/generator/populator/Tree.php +++ b/src/world/generator/populator/Tree.php @@ -72,9 +72,9 @@ class Tree implements Populator{ private function getHighestWorkableBlock(ChunkManager $world, int $x, int $z) : int{ for($y = 127; $y >= 0; --$y){ $b = $world->getBlockAt($x, $y, $z)->getId(); - if($b === BlockLegacyIds::DIRT or $b === BlockLegacyIds::GRASS){ + if($b === BlockLegacyIds::DIRT || $b === BlockLegacyIds::GRASS){ return $y + 1; - }elseif($b !== BlockLegacyIds::AIR and $b !== BlockLegacyIds::SNOW_LAYER){ + }elseif($b !== BlockLegacyIds::AIR && $b !== BlockLegacyIds::SNOW_LAYER){ return -1; } } diff --git a/src/world/light/LightUpdate.php b/src/world/light/LightUpdate.php index a8b196a520..45fa19df3d 100644 --- a/src/world/light/LightUpdate.php +++ b/src/world/light/LightUpdate.php @@ -134,7 +134,7 @@ abstract class LightUpdate{ if($this->subChunkExplorer->moveTo($cx, $cy, $cz) !== SubChunkExplorerStatus::INVALID){ $this->computeRemoveLight($cx, $cy, $cz, $oldAdjacentLight, $context); - }elseif($this->getEffectiveLight($cx, $cy, $cz) > 0 and !isset($context->spreadVisited[$index = World::blockHash($cx, $cy, $cz)])){ + }elseif($this->getEffectiveLight($cx, $cy, $cz) > 0 && !isset($context->spreadVisited[$index = World::blockHash($cx, $cy, $cz)])){ $context->spreadVisited[$index] = true; $context->spreadQueue->enqueue([$cx, $cy, $cz]); } @@ -173,7 +173,7 @@ abstract class LightUpdate{ $lz = $z & SubChunk::COORD_MASK; $current = $lightArray->get($lx, $ly, $lz); - if($current !== 0 and $current < $oldAdjacentLevel){ + if($current !== 0 && $current < $oldAdjacentLevel){ $lightArray->set($lx, $ly, $lz, 0); if(!isset($context->removalVisited[$index = World::blockHash($x, $y, $z)])){ @@ -201,7 +201,7 @@ abstract class LightUpdate{ if($current < $potentialLight){ $lightArray->set($lx, $ly, $lz, $potentialLight); - if(!isset($context->spreadVisited[$index = World::blockHash($x, $y, $z)]) and $potentialLight > 1){ + if(!isset($context->spreadVisited[$index = World::blockHash($x, $y, $z)]) && $potentialLight > 1){ $context->spreadVisited[$index] = true; $context->spreadQueue->enqueue([$x, $y, $z]); } diff --git a/src/world/particle/DragonEggTeleportParticle.php b/src/world/particle/DragonEggTeleportParticle.php index a2f2ae3ac2..924fba112d 100644 --- a/src/world/particle/DragonEggTeleportParticle.php +++ b/src/world/particle/DragonEggTeleportParticle.php @@ -44,7 +44,7 @@ class DragonEggTeleportParticle implements Particle{ } private static function boundOrThrow(int $v) : int{ - if($v < -255 or $v > 255){ + if($v < -255 || $v > 255){ throw new \InvalidArgumentException("Value must be between -255 and 255"); } return $v; diff --git a/src/world/sound/NoteSound.php b/src/world/sound/NoteSound.php index 00101b8d77..c8822a1a9a 100644 --- a/src/world/sound/NoteSound.php +++ b/src/world/sound/NoteSound.php @@ -35,7 +35,7 @@ class NoteSound implements Sound{ private $note; public function __construct(NoteInstrument $instrument, int $note){ - if($note < 0 or $note > 255){ + if($note < 0 || $note > 255){ throw new \InvalidArgumentException("Note $note is outside accepted range"); } $this->instrument = $instrument; diff --git a/src/world/utils/SubChunkExplorer.php b/src/world/utils/SubChunkExplorer.php index 69bdb44e10..1a52dd9cbb 100644 --- a/src/world/utils/SubChunkExplorer.php +++ b/src/world/utils/SubChunkExplorer.php @@ -53,7 +53,7 @@ class SubChunkExplorer{ public function moveTo(int $x, int $y, int $z) : int{ $newChunkX = $x >> SubChunk::COORD_BIT_SIZE; $newChunkZ = $z >> SubChunk::COORD_BIT_SIZE; - if($this->currentChunk === null or $this->currentX !== $newChunkX or $this->currentZ !== $newChunkZ){ + if($this->currentChunk === null || $this->currentX !== $newChunkX || $this->currentZ !== $newChunkZ){ $this->currentX = $newChunkX; $this->currentZ = $newChunkZ; $this->currentSubChunk = null; @@ -65,10 +65,10 @@ class SubChunkExplorer{ } $newChunkY = $y >> SubChunk::COORD_BIT_SIZE; - if($this->currentSubChunk === null or $this->currentY !== $newChunkY){ + if($this->currentSubChunk === null || $this->currentY !== $newChunkY){ $this->currentY = $newChunkY; - if($this->currentY < Chunk::MIN_SUBCHUNK_INDEX or $this->currentY > Chunk::MAX_SUBCHUNK_INDEX){ + if($this->currentY < Chunk::MIN_SUBCHUNK_INDEX || $this->currentY > Chunk::MAX_SUBCHUNK_INDEX){ $this->currentSubChunk = null; return SubChunkExplorerStatus::INVALID; }