Replace disallowed operators in src/world/

This commit is contained in:
Dylan K. Taylor 2022-01-20 19:05:23 +00:00
parent 282b430b1f
commit aae5962f6a
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
30 changed files with 102 additions and 102 deletions

View File

@ -102,7 +102,7 @@ class Explosion{
for($i = 0; $i < $this->rays; ++$i){ for($i = 0; $i < $this->rays; ++$i){
for($j = 0; $j < $this->rays; ++$j){ for($j = 0; $j < $this->rays; ++$j){
for($k = 0; $k < $this->rays; ++$k){ 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 //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]; [$shiftX, $shiftY, $shiftZ] = [$i / $mRays * 2 - 1, $j / $mRays * 2 - 1, $k / $mRays * 2 - 1];
$len = sqrt($shiftX ** 2 + $shiftY ** 2 + $shiftZ ** 2); $len = sqrt($shiftX ** 2 + $shiftY ** 2 + $shiftZ ** 2);

View File

@ -39,7 +39,7 @@ class Position extends Vector3{
*/ */
public function __construct($x, $y, $z, ?World $world){ public function __construct($x, $y, $z, ?World $world){
parent::__construct($x, $y, $z); 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"); 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 * Checks if this object has a valid reference to a loaded world
*/ */
public function isValid() : bool{ public function isValid() : bool{
if($this->world !== null and !$this->world->isLoaded()){ if($this->world !== null && !$this->world->isLoaded()){
$this->world = null; $this->world = null;
return false; return false;
@ -103,7 +103,7 @@ class Position extends Vector3{
public function equals(Vector3 $v) : bool{ public function equals(Vector3 $v) : bool{
if($v instanceof Position){ 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); return parent::equals($v);
} }

View File

@ -81,9 +81,9 @@ class SimpleChunkManager implements ChunkManager{
public function isInWorld(int $x, int $y, int $z) : bool{ public function isInWorld(int $x, int $y, int $z) : bool{
return ( return (
$x <= Limits::INT32_MAX and $x >= Limits::INT32_MIN and $x <= Limits::INT32_MAX && $x >= Limits::INT32_MIN &&
$y < $this->maxY and $y >= $this->minY and $y < $this->maxY && $y >= $this->minY &&
$z <= Limits::INT32_MAX and $z >= Limits::INT32_MIN $z <= Limits::INT32_MAX && $z >= Limits::INT32_MIN
); );
} }
} }

View File

@ -839,7 +839,7 @@ class World implements ChunkManager{
$this->timings->scheduledBlockUpdates->startTiming(); $this->timings->scheduledBlockUpdates->startTiming();
//Delayed updates //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 */ /** @var Vector3 $vec */
$vec = $this->scheduledBlockUpdateQueue->extract()["data"]; $vec = $this->scheduledBlockUpdateQueue->extract()["data"];
unset($this->scheduledBlockUpdateQueueIndex[World::blockHash($vec->x, $vec->y, $vec->z)]); unset($this->scheduledBlockUpdateQueueIndex[World::blockHash($vec->x, $vec->y, $vec->z)]);
@ -878,7 +878,7 @@ class World implements ChunkManager{
//Update entities that need update //Update entities that need update
Timings::$tickEntity->startTiming(); Timings::$tickEntity->startTiming();
foreach($this->updateEntities as $id => $entity){ 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]); unset($this->updateEntities[$id]);
} }
if($entity->isFlaggedForDespawn()){ 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(); $this->checkSleep();
} }
@ -949,7 +949,7 @@ class World implements ChunkManager{
if($resetTime){ if($resetTime){
$time = $this->getTimeOfDay(); $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); $this->setTime($this->getTime() + World::TIME_FULL - $time);
foreach($this->getPlayers() as $p){ foreach($this->getPlayers() as $p){
@ -1028,7 +1028,7 @@ class World implements ChunkManager{
} }
private function tickChunks() : void{ private function tickChunks() : void{
if($this->chunksPerTick <= 0 or count($this->tickingLoaders) === 0){ if($this->chunksPerTick <= 0 || count($this->tickingLoaders) === 0){
return; return;
} }
@ -1049,7 +1049,7 @@ class World implements ChunkManager{
$dx = mt_rand(-$randRange, $randRange); $dx = mt_rand(-$randRange, $randRange);
$dz = mt_rand(-$randRange, $randRange); $dz = mt_rand(-$randRange, $randRange);
$hash = World::chunkHash($dx + $chunkX, $dz + $chunkZ); $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; $chunkTickList[$hash] = true;
} }
} }
@ -1164,7 +1164,7 @@ class World implements ChunkManager{
public function save(bool $force = false) : bool{ public function save(bool $force = false) : bool{
if(!$this->getAutoSave() and !$force){ if(!$this->getAutoSave() && !$force){
return false; return false;
} }
@ -1200,8 +1200,8 @@ class World implements ChunkManager{
*/ */
public function scheduleDelayedBlockUpdate(Vector3 $pos, int $delay) : void{ public function scheduleDelayedBlockUpdate(Vector3 $pos, int $delay) : void{
if( if(
!$this->isInWorld($pos->x, $pos->y, $pos->z) or !$this->isInWorld($pos->x, $pos->y, $pos->z) ||
(isset($this->scheduledBlockUpdateQueueIndex[$index = World::blockHash($pos->x, $pos->y, $pos->z)]) and $this->scheduledBlockUpdateQueueIndex[$index] <= $delay) (isset($this->scheduledBlockUpdateQueueIndex[$index = World::blockHash($pos->x, $pos->y, $pos->z)]) && $this->scheduledBlockUpdateQueueIndex[$index] <= $delay)
){ ){
return; return;
} }
@ -1520,9 +1520,9 @@ class World implements ChunkManager{
public function isInWorld(int $x, int $y, int $z) : bool{ public function isInWorld(int $x, int $y, int $z) : bool{
return ( return (
$x <= Limits::INT32_MAX and $x >= Limits::INT32_MIN and $x <= Limits::INT32_MAX && $x >= Limits::INT32_MIN &&
$y < $this->maxY and $y >= $this->minY and $y < $this->maxY && $y >= $this->minY &&
$z <= Limits::INT32_MAX and $z >= Limits::INT32_MIN $z <= Limits::INT32_MAX && $z >= Limits::INT32_MIN
); );
} }
@ -1556,7 +1556,7 @@ class World implements ChunkManager{
if($this->isInWorld($x, $y, $z)){ if($this->isInWorld($x, $y, $z)){
$relativeBlockHash = World::chunkBlockHash($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]; return $this->blockCache[$chunkHash][$relativeBlockHash];
} }
@ -1586,7 +1586,7 @@ class World implements ChunkManager{
$dynamicStateRead = false; $dynamicStateRead = false;
} }
if($addToCache and $relativeBlockHash !== null){ if($addToCache && $relativeBlockHash !== null){
$this->blockCache[$chunkHash][$relativeBlockHash] = $block; $this->blockCache[$chunkHash][$relativeBlockHash] = $block;
} }
@ -1713,23 +1713,23 @@ class World implements ChunkManager{
} }
$drops = []; $drops = [];
if($player === null or $player->hasFiniteResources()){ if($player === null || $player->hasFiniteResources()){
$drops = array_merge(...array_map(fn(Block $block) => $block->getDrops($item), $affectedBlocks)); $drops = array_merge(...array_map(fn(Block $block) => $block->getDrops($item), $affectedBlocks));
} }
$xpDrop = 0; $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)); $xpDrop = array_sum(array_map(fn(Block $block) => $block->getXpDropForTool($item), $affectedBlocks));
} }
if($player !== null){ if($player !== null){
$ev = new BlockBreakEvent($player, $target, $item, $player->isCreative(), $drops, $xpDrop); $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(); $ev->cancel();
} }
if($player->isAdventure(true) and !$ev->isCancelled()){ if($player->isAdventure(true) && !$ev->isCancelled()){
$canBreak = false; $canBreak = false;
$itemParser = LegacyStringToItemParser::getInstance(); $itemParser = LegacyStringToItemParser::getInstance();
foreach($item->getCanDestroy() as $v){ foreach($item->getCanDestroy() as $v){
@ -1828,7 +1828,7 @@ class World implements ChunkManager{
$ev->call(); $ev->call();
if(!$ev->isCancelled()){ 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; return true;
} }
@ -1843,7 +1843,7 @@ class World implements ChunkManager{
return true; return true;
} }
if($item->isNull() or !$item->canBePlaced()){ if($item->isNull() || !$item->canBePlaced()){
return false; return false;
} }
$hand = $item->getBlock($face); $hand = $item->getBlock($face);
@ -1876,7 +1876,7 @@ class World implements ChunkManager{
$ev->cancel(); $ev->cancel();
} }
if($player->isAdventure(true) and !$ev->isCancelled()){ if($player->isAdventure(true) && !$ev->isCancelled()){
$canPlace = false; $canPlace = false;
$itemParser = LegacyStringToItemParser::getInstance(); $itemParser = LegacyStringToItemParser::getInstance();
foreach($item->getCanPlaceOn() as $v){ foreach($item->getCanPlaceOn() as $v){
@ -1941,9 +1941,9 @@ class World implements ChunkManager{
public function getCollidingEntities(AxisAlignedBB $bb, ?Entity $entity = null) : array{ public function getCollidingEntities(AxisAlignedBB $bb, ?Entity $entity = null) : array{
$nearby = []; $nearby = [];
if($entity === null or $entity->canCollide){ if($entity === null || $entity->canCollide){
foreach($this->getNearbyEntities($bb, $entity) as $ent){ 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; $nearby[] = $ent;
} }
} }
@ -1971,7 +1971,7 @@ class World implements ChunkManager{
continue; continue;
} }
foreach($this->getChunkEntities($x, $z) as $ent){ foreach($this->getChunkEntities($x, $z) as $ent){
if($ent !== $entity and $ent->boundingBox->intersectsWith($bb)){ if($ent !== $entity && $ent->boundingBox->intersectsWith($bb)){
$nearby[] = $ent; $nearby[] = $ent;
} }
} }
@ -2014,7 +2014,7 @@ class World implements ChunkManager{
continue; continue;
} }
foreach($this->getChunkEntities($x, $z) as $entity){ 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; continue;
} }
$distSq = $entity->getPosition()->distanceSquared($pos); $distSq = $entity->getPosition()->distanceSquared($pos);
@ -2173,7 +2173,7 @@ class World implements ChunkManager{
public function setChunk(int $chunkX, int $chunkZ, Chunk $chunk) : void{ public function setChunk(int $chunkX, int $chunkZ, Chunk $chunk) : void{
$chunkHash = World::chunkHash($chunkX, $chunkZ); $chunkHash = World::chunkHash($chunkX, $chunkZ);
$oldChunk = $this->loadChunk($chunkX, $chunkZ); $oldChunk = $this->loadChunk($chunkX, $chunkZ);
if($oldChunk !== null and $oldChunk !== $chunk){ if($oldChunk !== null && $oldChunk !== $chunk){
$deletedTiles = 0; $deletedTiles = 0;
$transferredTiles = 0; $transferredTiles = 0;
foreach($oldChunk->getTiles() as $oldTile){ foreach($oldChunk->getTiles() as $oldTile){
@ -2439,7 +2439,7 @@ class World implements ChunkManager{
} }
public function isChunkInUse(int $x, int $z) : bool{ 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{ 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; return false;
} }
@ -2596,7 +2596,7 @@ class World implements ChunkManager{
} }
public function unloadChunk(int $x, int $z, bool $safe = true, bool $trySave = true) : bool{ 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; return false;
} }
@ -2619,7 +2619,7 @@ class World implements ChunkManager{
return false; return false;
} }
if($trySave and $this->getAutoSave()){ if($trySave && $this->getAutoSave()){
$this->timings->syncChunkSave->startTiming(); $this->timings->syncChunkSave->startTiming();
try{ try{
$this->provider->saveChunk($x, $z, new ChunkData( $this->provider->saveChunk($x, $z, new ChunkData(
@ -2668,14 +2668,14 @@ class World implements ChunkManager{
$spawnX = $spawn->x >> Chunk::COORD_BIT_SIZE; $spawnX = $spawn->x >> Chunk::COORD_BIT_SIZE;
$spawnZ = $spawn->z >> 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 * @throws WorldException if the terrain is not generated
*/ */
public function getSafeSpawn(?Vector3 $spawn = null) : Position{ 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(); $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 + 1, $z)->isFullCube()){
if(!$this->getBlockAt($x, $y, $z)->isFullCube()){ if(!$this->getBlockAt($x, $y, $z)->isFullCube()){
return new Position($spawn->x, $y === (int) $spawn->y ? $spawn->y : $y, $spawn->z, $this); 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{ public function setDifficulty(int $difficulty) : void{
if($difficulty < 0 or $difficulty > 3){ if($difficulty < 0 || $difficulty > 3){
throw new \InvalidArgumentException("Invalid difficulty level $difficulty"); throw new \InvalidArgumentException("Invalid difficulty level $difficulty");
} }
$this->provider->getWorldData()->setDifficulty($difficulty); $this->provider->getWorldData()->setDifficulty($difficulty);
@ -3013,7 +3013,7 @@ class World implements ChunkManager{
$this->setChunk($x + $relativeX, $z + $relativeZ, $adjacentChunk); $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(); (new ChunkPopulateEvent($this, $x, $z, $chunk))->call();
foreach($this->getChunkListeners($x, $z) as $listener){ foreach($this->getChunkListeners($x, $z) as $listener){

View File

@ -104,7 +104,7 @@ class WorldManager{
* it only affects the server on runtime * it only affects the server on runtime
*/ */
public function setDefaultWorld(?World $world) : void{ 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; $this->defaultWorld = $world;
} }
} }
@ -134,7 +134,7 @@ class WorldManager{
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
public function unloadWorld(World $world, bool $forceUnload = false) : bool{ 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."); throw new \InvalidArgumentException("The default world cannot be unloaded while running, please switch worlds.");
} }
if($world->isDoingTick()){ if($world->isDoingTick()){
@ -142,13 +142,13 @@ class WorldManager{
} }
$ev = new WorldUnloadEvent($world); $ev = new WorldUnloadEvent($world);
if($world === $this->defaultWorld and !$forceUnload){ if($world === $this->defaultWorld && !$forceUnload){
$ev->cancel(); $ev->cancel();
} }
$ev->call(); $ev->call();
if(!$forceUnload and $ev->isCancelled()){ if(!$forceUnload && $ev->isCancelled()){
return false; return false;
} }
@ -159,7 +159,7 @@ class WorldManager{
$safeSpawn = null; $safeSpawn = null;
} }
foreach($world->getPlayers() as $player){ foreach($world->getPlayers() as $player){
if($world === $this->defaultWorld or $safeSpawn === null){ if($world === $this->defaultWorld || $safeSpawn === null){
$player->disconnect("Forced default world unload"); $player->disconnect("Forced default world unload");
}else{ }else{
$player->teleport($safeSpawn); $player->teleport($safeSpawn);
@ -271,7 +271,7 @@ class WorldManager{
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
public function generateWorld(string $name, WorldCreationOptions $options, bool $backgroundGeneration = true) : bool{ 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; 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->autoSaveTicker = 0;
$this->server->getLogger()->debug("[Auto Save] Saving worlds..."); $this->server->getLogger()->debug("[Auto Save] Saving worlds...");
$start = microtime(true); $start = microtime(true);

View File

@ -48,7 +48,7 @@ final class BiomeArray{
} }
private static function idx(int $x, int $z) : int{ 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"); throw new \InvalidArgumentException("x and z must be in the range 0-15");
} }
return ($z << 4) | $x; return ($z << 4) | $x;
@ -59,7 +59,7 @@ final class BiomeArray{
} }
public function set(int $x, int $z, int $biomeId) : void{ 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"); throw new \InvalidArgumentException("Biome ID must be in the range 0-255");
} }
$this->payload[self::idx($x, $z)] = chr($biomeId); $this->payload[self::idx($x, $z)] = chr($biomeId);

View File

@ -197,7 +197,7 @@ class Chunk{
} }
$pos = $tile->getPosition(); $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"); throw new \InvalidArgumentException("Another tile is already at this location");
} }
$this->tiles[$index] = $tile; $this->tiles[$index] = $tile;
@ -292,7 +292,7 @@ class Chunk{
* Sets a subchunk in the chunk index * Sets a subchunk in the chunk index
*/ */
public function setSubChunk(int $y, ?SubChunk $subChunk) : void{ 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"); throw new \InvalidArgumentException("Invalid subchunk Y coordinate $y");
} }

View File

@ -50,7 +50,7 @@ final class HeightArray{
} }
private static function idx(int $x, int $z) : int{ 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"); throw new \InvalidArgumentException("x and z must be in the range 0-15");
} }
return ($z << 4) | $x; return ($z << 4) | $x;

View File

@ -63,7 +63,7 @@ final class WorldProviderManager{
public function addProvider(WorldProviderManagerEntry $providerEntry, string $name, bool $overwrite = false) : void{ public function addProvider(WorldProviderManagerEntry $providerEntry, string $name, bool $overwrite = false) : void{
$name = strtolower($name); $name = strtolower($name);
if(!$overwrite and isset($this->providers[$name])){ if(!$overwrite && isset($this->providers[$name])){
throw new \InvalidArgumentException("Alias \"$name\" is already assigned"); throw new \InvalidArgumentException("Alias \"$name\" is already assigned");
} }

View File

@ -144,7 +144,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
} }
public static function isValid(string $path) : bool{ 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{ public static function generate(string $path, string $name, WorldCreationOptions $options) : void{
@ -207,7 +207,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
* @return PalettedBlockArray[] * @return PalettedBlockArray[]
*/ */
protected function deserializeLegacyExtraData(string $index, int $chunkVersion) : array{ 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 []; return [];
} }
@ -391,7 +391,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
/** @var CompoundTag[] $entities */ /** @var CompoundTag[] $entities */
$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{ try{
$entities = array_map(fn(TreeRoot $root) => $root->mustGetCompoundTag(), $nbt->readMultiple($entityData)); $entities = array_map(fn(TreeRoot $root) => $root->mustGetCompoundTag(), $nbt->readMultiple($entityData));
}catch(NbtDataException $e){ }catch(NbtDataException $e){
@ -401,7 +401,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
/** @var CompoundTag[] $tiles */ /** @var CompoundTag[] $tiles */
$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{ try{
$tiles = array_map(fn(TreeRoot $root) => $root->mustGetCompoundTag(), $nbt->readMultiple($tileData)); $tiles = array_map(fn(TreeRoot $root) => $root->mustGetCompoundTag(), $nbt->readMultiple($tileData));
}catch(NbtDataException $e){ }catch(NbtDataException $e){
@ -527,7 +527,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
public function getAllChunks(bool $skipCorrupted = false, ?\Logger $logger = null) : \Generator{ public function getAllChunks(bool $skipCorrupted = false, ?\Logger $logger = null) : \Generator{
foreach($this->db->getIterator() as $key => $_){ 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)); $chunkX = Binary::readLInt(substr($key, 0, 4));
$chunkZ = Binary::readLInt(substr($key, 4, 4)); $chunkZ = Binary::readLInt(substr($key, 4, 4));
try{ try{
@ -549,7 +549,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
public function calculateChunkCount() : int{ public function calculateChunkCount() : int{
$count = 0; $count = 0;
foreach($this->db->getIterator() as $key => $_){ 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++; $count++;
} }
} }

View File

@ -95,7 +95,7 @@ final class RegionGarbageMap{
/** @var int|null $prevIndex */ /** @var int|null $prevIndex */
$prevIndex = null; $prevIndex = null;
foreach($this->entries as $k => $entry){ 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 SHOULD overwrite the previous index and not appear at the end
$this->entries[$prevIndex] = new RegionLocationTableEntry( $this->entries[$prevIndex] = new RegionLocationTableEntry(
$this->entries[$prevIndex]->getFirstSector(), $this->entries[$prevIndex]->getFirstSector(),

View File

@ -169,7 +169,7 @@ class RegionLoader{
} }
$compression = $stream->getByte(); $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 . ")"); 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(); $endGarbage = $this->garbageTable->end();
$nextSector = $this->nextSector; $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(); $nextSector = $endGarbage->getFirstSector();
$this->garbageTable->remove($endGarbage); $this->garbageTable->remove($endGarbage);
} }
@ -267,7 +267,7 @@ class RegionLoader{
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
protected static function getChunkOffset(int $x, int $z) : int{ 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"); throw new \InvalidArgumentException("Invalid chunk position in region, expected x/z in range 0-31, got x=$x, z=$z");
} }
return $x | ($z << 5); return $x | ($z << 5);
@ -298,7 +298,7 @@ class RegionLoader{
fseek($this->filePointer, 0); fseek($this->filePointer, 0);
$headerRaw = fread($this->filePointer, self::REGION_HEADER_LENGTH); $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)"); throw new CorruptedRegionException("Corrupted region header (unexpected end of file)");
} }
@ -311,7 +311,7 @@ class RegionLoader{
$sectorCount = $index & 0xff; $sectorCount = $index & 0xff;
$timestamp = $data[$i + 1025]; $timestamp = $data[$i + 1025];
if($offset === 0 or $sectorCount === 0){ if($offset === 0 || $sectorCount === 0){
$this->locationTable[$i] = null; $this->locationTable[$i] = null;
}elseif($offset >= self::FIRST_SECTOR){ }elseif($offset >= self::FIRST_SECTOR){
$this->bumpNextFreeSector($this->locationTable[$i] = new RegionLocationTableEntry($offset, $sectorCount, $timestamp)); $this->bumpNextFreeSector($this->locationTable[$i] = new RegionLocationTableEntry($offset, $sectorCount, $timestamp));

View File

@ -38,7 +38,7 @@ class RegionLocationTableEntry{
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
public function __construct(int $firstSector, int $sectorCount, int $timestamp){ 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"); throw new \InvalidArgumentException("Start sector must be positive, got $firstSector");
} }
$this->firstSector = $firstSector; $this->firstSector = $firstSector;
@ -79,10 +79,10 @@ class RegionLocationTableEntry{
$entry2Last = $entry2->getLastSector(); $entry2Last = $entry2->getLastSector();
return ( return (
($entry2->firstSector >= $entry1->firstSector and $entry2->firstSector <= $entry1Last) or ($entry2->firstSector >= $entry1->firstSector && $entry2->firstSector <= $entry1Last) ||
($entry2Last >= $entry1->firstSector and $entry2Last <= $entry1Last) ($entry2Last >= $entry1->firstSector && $entry2Last <= $entry1Last)
); );
}; };
return $overlapCheck($this, $other) or $overlapCheck($other, $this); return $overlapCheck($this, $other) || $overlapCheck($other, $this);
} }
} }

View File

@ -59,7 +59,7 @@ abstract class RegionWorldProvider extends BaseWorldProvider{
abstract protected static function getPcWorldFormatVersion() : int; abstract protected static function getPcWorldFormatVersion() : int;
public static function isValid(string $path) : bool{ 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){ foreach(scandir($regionPath, SCANDIR_SORT_NONE) as $file){
$extPos = strrpos($file, "."); $extPos = strrpos($file, ".");
if($extPos !== false && substr($file, $extPos + 1) === static::getRegionFileExtension()){ 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{ public function loadChunk(int $chunkX, int $chunkZ) : ?ChunkData{
$regionX = $regionZ = null; $regionX = $regionZ = null;
self::getRegionIndex($chunkX, $chunkZ, $regionX, $regionZ); 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))){ if(!file_exists($this->pathToRegion($regionX, $regionZ))){
return null; return null;

View File

@ -75,7 +75,7 @@ class Flat extends Generator{
$count = count($structure); $count = count($structure);
for($sy = 0; $sy < $count; $sy += SubChunk::EDGE_LENGTH){ for($sy = 0; $sy < $count; $sy += SubChunk::EDGE_LENGTH){
$subchunk = $this->chunk->getSubChunk($sy >> SubChunk::COORD_BIT_SIZE); $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]; $id = $structure[$y | $sy];
for($Z = 0; $Z < SubChunk::EDGE_LENGTH; ++$Z){ for($Z = 0; $Z < SubChunk::EDGE_LENGTH; ++$Z){

View File

@ -73,7 +73,7 @@ final class GeneratorManager{
Utils::testValidInstance($class, Generator::class); Utils::testValidInstance($class, Generator::class);
$name = strtolower($name); $name = strtolower($name);
if(!$overwrite and isset($this->list[$name])){ if(!$overwrite && isset($this->list[$name])){
throw new \InvalidArgumentException("Alias \"$name\" is already assigned"); throw new \InvalidArgumentException("Alias \"$name\" is already assigned");
} }

View File

@ -86,7 +86,7 @@ class Nether extends Generator{
$chunk->setBiomeId($x, $z, BiomeIds::HELL); $chunk->setBiomeId($x, $z, BiomeIds::HELL);
for($y = 0; $y < 128; ++$y){ for($y = 0; $y < 128; ++$y){
if($y === 0 or $y === 127){ if($y === 0 || $y === 127){
$chunk->setFullBlock($x, $y, $z, $bedrock); $chunk->setFullBlock($x, $y, $z, $bedrock);
continue; continue;
} }

View File

@ -256,7 +256,7 @@ abstract class Noise{
} }
for($zz = 0; $zz < $zSize; ++$zz){ 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; $nx = (int) ($xx / $samplingRate) * $samplingRate;
$nz = (int) ($zz / $samplingRate) * $samplingRate; $nz = (int) ($zz / $samplingRate) * $samplingRate;
$noiseArray[$xx][$zz] = Noise::bilinearLerp( $noiseArray[$xx][$zz] = Noise::bilinearLerp(
@ -320,7 +320,7 @@ abstract class Noise{
$dz2 = ($zz - $nz) / ($nnz - $nz); $dz2 = ($zz - $nz) / ($nnz - $nz);
for($yy = 0; $yy < $ySize; ++$yy){ 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; $ny = (int) ($yy / $ySamplingRate) * $ySamplingRate;
$nny = $ny + $ySamplingRate; $nny = $ny + $ySamplingRate;

View File

@ -173,7 +173,7 @@ class Normal extends Generator{
$weight = $this->gaussian->kernel[$sx + $this->gaussian->smoothSize][$sz + $this->gaussian->smoothSize]; $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; $adjacent = $biome;
}else{ }else{
$index = World::chunkHash($absoluteX + $sx, $absoluteZ + $sz); $index = World::chunkHash($absoluteX + $sx, $absoluteZ + $sz);

View File

@ -80,12 +80,12 @@ class Ore{
$sizeY = ($yy + 0.5 - $seedY) / $size; $sizeY = ($yy + 0.5 - $seedY) / $size;
$sizeY *= $sizeY; $sizeY *= $sizeY;
if($yy > 0 and ($sizeX + $sizeY) < 1){ if($yy > 0 && ($sizeX + $sizeY) < 1){
for($zz = $startZ; $zz <= $endZ; ++$zz){ for($zz = $startZ; $zz <= $endZ; ++$zz){
$sizeZ = ($zz + 0.5 - $seedZ) / $size; $sizeZ = ($zz + 0.5 - $seedZ) / $size;
$sizeZ *= $sizeZ; $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); $world->setBlockAt($xx, $yy, $zz, $this->type->material);
} }
} }

View File

@ -58,7 +58,7 @@ class SpruceTree extends Tree{
$xOff = abs($xx - $x); $xOff = abs($xx - $x);
for($zz = $z - $radius; $zz <= $z + $radius; ++$zz){ for($zz = $z - $radius; $zz <= $z + $radius; ++$zz){
$zOff = abs($zz - $z); $zOff = abs($zz - $z);
if($xOff === $radius and $zOff === $radius and $radius > 0){ if($xOff === $radius && $zOff === $radius && $radius > 0){
continue; continue;
} }

View File

@ -47,7 +47,7 @@ class TallGrass{
for($c = 0; $c < $count; ++$c){ for($c = 0; $c < $count; ++$c){
$x = $random->nextRange($pos->x - $radius, $pos->x + $radius); $x = $random->nextRange($pos->x - $radius, $pos->x + $radius);
$z = $random->nextRange($pos->z - $radius, $pos->z + $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)]); $world->setBlockAt($x, $pos->y + 1, $z, $arr[$random->nextRange(0, $arrC)]);
} }
} }

View File

@ -51,7 +51,7 @@ abstract class Tree{
public function canPlaceObject(ChunkManager $world, int $x, int $y, int $z, Random $random) : bool{ public function canPlaceObject(ChunkManager $world, int $x, int $y, int $z, Random $random) : bool{
$radiusToCheck = 0; $radiusToCheck = 0;
for($yy = 0; $yy < $this->treeHeight + 3; ++$yy){ for($yy = 0; $yy < $this->treeHeight + 3; ++$yy){
if($yy === 1 or $yy === $this->treeHeight){ if($yy === 1 || $yy === $this->treeHeight){
++$radiusToCheck; ++$radiusToCheck;
} }
for($xx = -$radiusToCheck; $xx < ($radiusToCheck + 1); ++$xx){ for($xx = -$radiusToCheck; $xx < ($radiusToCheck + 1); ++$xx){
@ -105,7 +105,7 @@ abstract class Tree{
$xOff = abs($xx - $x); $xOff = abs($xx - $x);
for($zz = $z - $mid; $zz <= $z + $mid; ++$zz){ for($zz = $z - $mid; $zz <= $z + $mid; ++$zz){
$zOff = abs($zz - $z); $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; continue;
} }
if(!$transaction->fetchBlockAt($xx, $yy, $zz)->isSolid()){ if(!$transaction->fetchBlockAt($xx, $yy, $zz)->isSolid()){
@ -117,6 +117,6 @@ abstract class Tree{
} }
protected function canOverride(Block $block) : bool{ 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;
} }
} }

View File

@ -57,13 +57,13 @@ class GroundCover implements Populator{
} }
$startY = min(127, $startY + $diffY); $startY = min(127, $startY + $diffY);
$endY = $startY - count($cover); $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]; $b = $cover[$startY - $y];
$id = $factory->fromFullBlock($chunk->getFullBlock($x, $y, $z)); $id = $factory->fromFullBlock($chunk->getFullBlock($x, $y, $z));
if($id->getId() === BlockLegacyIds::AIR and $b->isSolid()){ if($id->getId() === BlockLegacyIds::AIR && $b->isSolid()){
break; break;
} }
if($b->canBeFlowedInto() and $id instanceof Liquid){ if($b->canBeFlowedInto() && $id instanceof Liquid){
continue; continue;
} }

View File

@ -52,7 +52,7 @@ class TallGrass implements Populator{
$z = $random->nextRange($chunkZ * Chunk::EDGE_LENGTH, $chunkZ * Chunk::EDGE_LENGTH + (Chunk::EDGE_LENGTH - 1)); $z = $random->nextRange($chunkZ * Chunk::EDGE_LENGTH, $chunkZ * Chunk::EDGE_LENGTH + (Chunk::EDGE_LENGTH - 1));
$y = $this->getHighestWorkableBlock($world, $x, $z); $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); $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{ private function canTallGrassStay(ChunkManager $world, int $x, int $y, int $z) : bool{
$b = $world->getBlockAt($x, $y, $z)->getId(); $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{ private function getHighestWorkableBlock(ChunkManager $world, int $x, int $z) : int{
for($y = 127; $y >= 0; --$y){ for($y = 127; $y >= 0; --$y){
$b = $world->getBlockAt($x, $y, $z)->getId(); $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; return $y + 1;
} }
} }

View File

@ -72,9 +72,9 @@ class Tree implements Populator{
private function getHighestWorkableBlock(ChunkManager $world, int $x, int $z) : int{ private function getHighestWorkableBlock(ChunkManager $world, int $x, int $z) : int{
for($y = 127; $y >= 0; --$y){ for($y = 127; $y >= 0; --$y){
$b = $world->getBlockAt($x, $y, $z)->getId(); $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; return $y + 1;
}elseif($b !== BlockLegacyIds::AIR and $b !== BlockLegacyIds::SNOW_LAYER){ }elseif($b !== BlockLegacyIds::AIR && $b !== BlockLegacyIds::SNOW_LAYER){
return -1; return -1;
} }
} }

View File

@ -134,7 +134,7 @@ abstract class LightUpdate{
if($this->subChunkExplorer->moveTo($cx, $cy, $cz) !== SubChunkExplorerStatus::INVALID){ if($this->subChunkExplorer->moveTo($cx, $cy, $cz) !== SubChunkExplorerStatus::INVALID){
$this->computeRemoveLight($cx, $cy, $cz, $oldAdjacentLight, $context); $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->spreadVisited[$index] = true;
$context->spreadQueue->enqueue([$cx, $cy, $cz]); $context->spreadQueue->enqueue([$cx, $cy, $cz]);
} }
@ -173,7 +173,7 @@ abstract class LightUpdate{
$lz = $z & SubChunk::COORD_MASK; $lz = $z & SubChunk::COORD_MASK;
$current = $lightArray->get($lx, $ly, $lz); $current = $lightArray->get($lx, $ly, $lz);
if($current !== 0 and $current < $oldAdjacentLevel){ if($current !== 0 && $current < $oldAdjacentLevel){
$lightArray->set($lx, $ly, $lz, 0); $lightArray->set($lx, $ly, $lz, 0);
if(!isset($context->removalVisited[$index = World::blockHash($x, $y, $z)])){ if(!isset($context->removalVisited[$index = World::blockHash($x, $y, $z)])){
@ -201,7 +201,7 @@ abstract class LightUpdate{
if($current < $potentialLight){ if($current < $potentialLight){
$lightArray->set($lx, $ly, $lz, $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->spreadVisited[$index] = true;
$context->spreadQueue->enqueue([$x, $y, $z]); $context->spreadQueue->enqueue([$x, $y, $z]);
} }

View File

@ -44,7 +44,7 @@ class DragonEggTeleportParticle implements Particle{
} }
private static function boundOrThrow(int $v) : int{ 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"); throw new \InvalidArgumentException("Value must be between -255 and 255");
} }
return $v; return $v;

View File

@ -35,7 +35,7 @@ class NoteSound implements Sound{
private $note; private $note;
public function __construct(NoteInstrument $instrument, int $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"); throw new \InvalidArgumentException("Note $note is outside accepted range");
} }
$this->instrument = $instrument; $this->instrument = $instrument;

View File

@ -53,7 +53,7 @@ class SubChunkExplorer{
public function moveTo(int $x, int $y, int $z) : int{ public function moveTo(int $x, int $y, int $z) : int{
$newChunkX = $x >> SubChunk::COORD_BIT_SIZE; $newChunkX = $x >> SubChunk::COORD_BIT_SIZE;
$newChunkZ = $z >> 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->currentX = $newChunkX;
$this->currentZ = $newChunkZ; $this->currentZ = $newChunkZ;
$this->currentSubChunk = null; $this->currentSubChunk = null;
@ -65,10 +65,10 @@ class SubChunkExplorer{
} }
$newChunkY = $y >> SubChunk::COORD_BIT_SIZE; $newChunkY = $y >> SubChunk::COORD_BIT_SIZE;
if($this->currentSubChunk === null or $this->currentY !== $newChunkY){ if($this->currentSubChunk === null || $this->currentY !== $newChunkY){
$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; $this->currentSubChunk = null;
return SubChunkExplorerStatus::INVALID; return SubChunkExplorerStatus::INVALID;
} }