diff --git a/.travis.yml b/.travis.yml index b86d5c9b9..79aab7836 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ before_script: - cd .. - git clone https://github.com/pmmp/ext-chunkutils2.git chunkutils - cd chunkutils - - git checkout 5c96eeea7667ef15aa684b6a455a2a46699aff37 + - git checkout d8d762a597ac0da6f333f862096d6af0e6286b75 - phpize - ./configure && make && make install - cd .. diff --git a/src/pocketmine/MemoryManager.php b/src/pocketmine/MemoryManager.php index 530dd3bcf..79c31a95d 100644 --- a/src/pocketmine/MemoryManager.php +++ b/src/pocketmine/MemoryManager.php @@ -214,14 +214,14 @@ class MemoryManager{ $this->server->getLogger()->debug(sprintf("[Memory Manager] %sLow memory triggered, limit %gMB, using %gMB", $global ? "Global " : "", round(($limit / 1024) / 1024, 2), round(($memory / 1024) / 1024, 2))); if($this->lowMemClearWorldCache){ - foreach($this->server->getLevelManager()->getLevels() as $level){ - $level->clearCache(true); + foreach($this->server->getWorldManager()->getWorlds() as $world){ + $world->clearCache(true); } } if($this->lowMemChunkGC){ - foreach($this->server->getLevelManager()->getLevels() as $level){ - $level->doChunkGarbageCollection(); + foreach($this->server->getWorldManager()->getWorlds() as $world){ + $world->doChunkGarbageCollection(); } } diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 13738689f..a470e2180 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -84,11 +84,6 @@ use pocketmine\item\WritableBook; use pocketmine\item\WrittenBook; use pocketmine\lang\TextContainer; use pocketmine\lang\TranslationContainer; -use pocketmine\level\ChunkListener; -use pocketmine\level\ChunkLoader; -use pocketmine\level\format\Chunk; -use pocketmine\level\Level; -use pocketmine\level\Position; use pocketmine\math\Vector3; use pocketmine\metadata\MetadataValue; use pocketmine\nbt\tag\ByteTag; @@ -116,6 +111,11 @@ use pocketmine\tile\Tile; use pocketmine\timings\Timings; use pocketmine\utils\TextFormat; use pocketmine\utils\UUID; +use pocketmine\world\ChunkListener; +use pocketmine\world\ChunkLoader; +use pocketmine\world\format\Chunk; +use pocketmine\world\Position; +use pocketmine\world\World; use function abs; use function array_merge; use function assert; @@ -305,22 +305,22 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $spawnReset = false; - if($namedtag !== null and ($level = $this->server->getLevelManager()->getLevelByName($namedtag->getString("Level", "", true))) !== null){ + if($namedtag !== null and ($world = $this->server->getWorldManager()->getWorldByName($namedtag->getString("Level", "", true))) !== null){ /** @var float[] $pos */ $pos = $namedtag->getListTag("Pos")->getAllValues(); $spawn = new Vector3($pos[0], $pos[1], $pos[2]); }else{ - $level = $this->server->getLevelManager()->getDefaultLevel(); //TODO: default level might be null - $spawn = $level->getSpawnLocation(); + $world = $this->server->getWorldManager()->getDefaultWorld(); //TODO: default world might be null + $spawn = $world->getSpawnLocation(); $spawnReset = true; } //load the spawn chunk so we can see the terrain - $level->registerChunkLoader($this, $spawn->getFloorX() >> 4, $spawn->getFloorZ() >> 4, true); - $level->registerChunkListener($this, $spawn->getFloorX() >> 4, $spawn->getFloorZ() >> 4); - $this->usedChunks[Level::chunkHash($spawn->getFloorX() >> 4, $spawn->getFloorZ() >> 4)] = false; + $world->registerChunkLoader($this, $spawn->getFloorX() >> 4, $spawn->getFloorZ() >> 4, true); + $world->registerChunkListener($this, $spawn->getFloorX() >> 4, $spawn->getFloorZ() >> 4); + $this->usedChunks[World::chunkHash($spawn->getFloorX() >> 4, $spawn->getFloorZ() >> 4)] = false; if($spawnReset){ - $spawn = $level->getSafeSpawn($spawn); + $spawn = $world->getSafeSpawn($spawn); } if($namedtag === null){ @@ -337,7 +337,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, ])); } - parent::__construct($level, $namedtag); + parent::__construct($world, $namedtag); $ev = new PlayerLoginEvent($this, "Plugin reason"); $ev->call(); @@ -352,7 +352,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $this->networkSession->getIp(), $this->networkSession->getPort(), $this->id, - $this->level->getDisplayName(), + $this->world->getDisplayName(), round($this->x, 4), round($this->y, 4), round($this->z, 4) @@ -398,10 +398,10 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, } if(!$this->hasValidSpawnPosition()){ - if(($level = $this->server->getLevelManager()->getLevelByName($nbt->getString("SpawnLevel", ""))) instanceof Level){ - $this->spawnPosition = new Position($nbt->getInt("SpawnX"), $nbt->getInt("SpawnY"), $nbt->getInt("SpawnZ"), $level); + if(($world = $this->server->getWorldManager()->getWorldByName($nbt->getString("SpawnLevel", ""))) instanceof World){ + $this->spawnPosition = new Position($nbt->getInt("SpawnX"), $nbt->getInt("SpawnY"), $nbt->getInt("SpawnZ"), $world); }else{ - $this->spawnPosition = $this->level->getSafeSpawn(); + $this->spawnPosition = $this->world->getSafeSpawn(); } } } @@ -555,7 +555,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, * @param Player $player */ public function spawnTo(Player $player) : void{ - if($this->isAlive() and $player->isAlive() and $player->getLevel() === $this->level and $player->canSee($this) and !$this->isSpectator()){ + if($this->isAlive() and $player->isAlive() and $player->getWorld() === $this->world and $player->canSee($this) and !$this->isSpectator()){ parent::spawnTo($player); } } @@ -931,20 +931,20 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, } } - protected function switchLevel(Level $targetLevel) : bool{ - $oldLevel = $this->level; - if(parent::switchLevel($targetLevel)){ - if($oldLevel !== null){ + protected function switchWorld(World $targetWorld) : bool{ + $oldWorld = $this->world; + if(parent::switchWorld($targetWorld)){ + if($oldWorld !== null){ foreach($this->usedChunks as $index => $d){ - Level::getXZ($index, $X, $Z); - $this->unloadChunk($X, $Z, $oldLevel); + World::getXZ($index, $X, $Z); + $this->unloadChunk($X, $Z, $oldWorld); } } $this->usedChunks = []; $this->loadQueue = []; - $this->level->sendTime($this); - $this->level->sendDifficulty($this); + $this->world->sendTime($this); + $this->world->sendDifficulty($this); return true; } @@ -952,15 +952,15 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, return false; } - protected function unloadChunk(int $x, int $z, ?Level $level = null){ - $level = $level ?? $this->level; - $index = Level::chunkHash($x, $z); + protected function unloadChunk(int $x, int $z, ?World $world = null){ + $world = $world ?? $this->world; + $index = World::chunkHash($x, $z); if(isset($this->usedChunks[$index])){ $this->networkSession->stopUsingChunk($x, $z); unset($this->usedChunks[$index]); } - $level->unregisterChunkLoader($this, $x, $z); - $level->unregisterChunkListener($this, $x, $z); + $world->unregisterChunkLoader($this, $x, $z); + $world->unregisterChunkListener($this, $x, $z); unset($this->loadQueue[$index]); } @@ -969,8 +969,8 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, return; } - assert(isset($this->usedChunks[Level::chunkHash($x, $z)])); - $this->usedChunks[Level::chunkHash($x, $z)] = true; + assert(isset($this->usedChunks[World::chunkHash($x, $z)])); + $this->usedChunks[World::chunkHash($x, $z)] = true; $spawn = $this->spawnChunkLoadCount++ === $this->spawnThreshold; $this->networkSession->startUsingChunk($x, $z, $spawn); @@ -996,21 +996,21 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $X = null; $Z = null; - Level::getXZ($index, $X, $Z); + World::getXZ($index, $X, $Z); assert(is_int($X) and is_int($Z)); ++$count; $this->usedChunks[$index] = false; - $this->level->registerChunkLoader($this, $X, $Z, true); - $this->level->registerChunkListener($this, $X, $Z); + $this->world->registerChunkLoader($this, $X, $Z, true); + $this->world->registerChunkListener($this, $X, $Z); - if(!$this->level->populateChunk($X, $Z)){ + if(!$this->world->populateChunk($X, $Z)){ continue; } unset($this->loadQueue[$index]); - $this->level->requestChunk($X, $Z, $this); + $this->world->requestChunk($X, $Z, $this); } Timings::$playerChunkSendTimer->stopTiming(); @@ -1065,23 +1065,23 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, //If the chunk is in the radius, others at the same offsets in different quadrants are also guaranteed to be. /* Top right quadrant */ - yield Level::chunkHash($centerX + $x, $centerZ + $z); + yield World::chunkHash($centerX + $x, $centerZ + $z); /* Top left quadrant */ - yield Level::chunkHash($centerX - $x - 1, $centerZ + $z); + yield World::chunkHash($centerX - $x - 1, $centerZ + $z); /* Bottom right quadrant */ - yield Level::chunkHash($centerX + $x, $centerZ - $z - 1); + yield World::chunkHash($centerX + $x, $centerZ - $z - 1); /* Bottom left quadrant */ - yield Level::chunkHash($centerX - $x - 1, $centerZ - $z - 1); + yield World::chunkHash($centerX - $x - 1, $centerZ - $z - 1); if($x !== $z){ /* Top right quadrant mirror */ - yield Level::chunkHash($centerX + $z, $centerZ + $x); + yield World::chunkHash($centerX + $z, $centerZ + $x); /* Top left quadrant mirror */ - yield Level::chunkHash($centerX - $z - 1, $centerZ + $x); + yield World::chunkHash($centerX - $z - 1, $centerZ + $x); /* Bottom right quadrant mirror */ - yield Level::chunkHash($centerX + $z, $centerZ - $x - 1); + yield World::chunkHash($centerX + $z, $centerZ - $x - 1); /* Bottom left quadrant mirror */ - yield Level::chunkHash($centerX - $z - 1, $centerZ - $x - 1); + yield World::chunkHash($centerX - $z - 1, $centerZ - $x - 1); } } } @@ -1105,7 +1105,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, } foreach($unloadChunks as $index => $bool){ - Level::getXZ($index, $X, $Z); + World::getXZ($index, $X, $Z); $this->unloadChunk($X, $Z); } @@ -1139,9 +1139,9 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, if($this->hasValidSpawnPosition()){ return $this->spawnPosition; }else{ - $level = $this->server->getLevelManager()->getDefaultLevel(); + $world = $this->server->getWorldManager()->getDefaultWorld(); - return $level->getSafeSpawn(); + return $world->getSafeSpawn(); } } @@ -1160,11 +1160,11 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, */ public function setSpawn(Vector3 $pos){ if(!($pos instanceof Position)){ - $level = $this->level; + $world = $this->world; }else{ - $level = $pos->getLevel(); + $world = $pos->getWorld(); } - $this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $level); + $this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $world); $this->networkSession->syncPlayerSpawnPoint($this->spawnPosition); } @@ -1186,7 +1186,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, } $pos = $pos->floor(); - $b = $this->level->getBlock($pos); + $b = $this->world->getBlock($pos); $ev = new PlayerBedEnterEvent($this, $b); $ev->call(); @@ -1205,14 +1205,14 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $this->setSpawn($pos); - $this->level->setSleepTicks(60); + $this->world->setSleepTicks(60); return true; } public function stopSleep(){ if($this->sleeping instanceof Vector3){ - $b = $this->level->getBlock($this->sleeping); + $b = $this->world->getBlock($this->sleeping); if($b instanceof Bed){ $b->setOccupied(false); } @@ -1222,7 +1222,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $this->propertyManager->setBlockPos(EntityMetadataProperties::PLAYER_BED_POSITION, null); $this->setPlayerFlag(PlayerMetadataFlags::SLEEP, false); - $this->level->setSleepTicks(0); + $this->world->setSleepTicks(0); $this->broadcastAnimation([$this], AnimatePacket::ACTION_STOP_SLEEP); } @@ -1410,7 +1410,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $bb->minY = $this->y - 0.2; $bb->maxY = $this->y + 0.2; - $this->onGround = $this->isCollided = count($this->level->getCollisionBlocks($bb, true)) > 0; + $this->onGround = $this->isCollided = count($this->world->getCollisionBlocks($bb, true)) > 0; } public function canBeMovedByCurrents() : bool{ @@ -1418,7 +1418,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, } protected function checkNearEntities(){ - foreach($this->level->getNearbyEntities($this->boundingBox->expandedCopy(1, 0.5, 1), $this) as $entity){ + foreach($this->world->getNearbyEntities($this->boundingBox->expandedCopy(1, 0.5, 1), $this) as $entity){ $entity->scheduleUpdate(); if(!$entity->isAlive() or $entity->isFlaggedForDespawn()){ @@ -1500,7 +1500,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $this->server->getLogger()->warning($this->getName() . " moved too fast, reverting movement"); $this->server->getLogger()->debug("Old position: " . $this->asVector3() . ", new position: " . $this->newPosition); $revert = true; - }elseif(!$this->level->isInLoadedTerrain($newPos) or !$this->level->isChunkGenerated($newPos->getFloorX() >> 4, $newPos->getFloorZ() >> 4)){ + }elseif(!$this->world->isInLoadedTerrain($newPos) or !$this->world->isChunkGenerated($newPos->getFloorX() >> 4, $newPos->getFloorZ() >> 4)){ $revert = true; $this->nextChunkOrderRun = 0; } @@ -1864,14 +1864,14 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, } public function pickBlock(Vector3 $pos, bool $addTileNBT) : bool{ - $block = $this->level->getBlock($pos); + $block = $this->world->getBlock($pos); if($block instanceof UnknownBlock){ return true; } $item = $block->getPickedItem(); if($addTileNBT){ - $tile = $this->getLevel()->getTile($block); + $tile = $this->getWorld()->getTile($block); if($tile instanceof Tile){ $nbt = $tile->getCleanedNBT(); if($nbt instanceof CompoundTag){ @@ -1922,12 +1922,12 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, return false; //TODO: maybe this should throw an exception instead? } - $target = $this->level->getBlock($pos); + $target = $this->world->getBlock($pos); $ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $target, null, $face, PlayerInteractEvent::LEFT_CLICK_BLOCK); $ev->call(); if($ev->isCancelled()){ - $this->level->sendBlocks([$this], [$target]); + $this->world->sendBlocks([$this], [$target]); $this->inventory->sendHeldItem($this); return true; } @@ -1937,7 +1937,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $block = $target->getSide($face); if($block->getId() === BlockLegacyIds::FIRE){ - $this->level->setBlock($block, BlockFactory::get(BlockLegacyIds::AIR)); + $this->world->setBlock($block, BlockFactory::get(BlockLegacyIds::AIR)); return true; } @@ -1945,7 +1945,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, //TODO: improve this to take stuff like swimming, ladders, enchanted tools into account, fix wrong tool break time calculations for bad tools (pmmp/PocketMine-MP#211) $breakTime = ceil($target->getBreakTime($this->inventory->getItemInHand()) * 20); if($breakTime > 0){ - $this->level->broadcastLevelEvent($pos, LevelEventPacket::EVENT_BLOCK_START_BREAK, (int) (65535 / $breakTime)); + $this->world->broadcastLevelEvent($pos, LevelEventPacket::EVENT_BLOCK_START_BREAK, (int) (65535 / $breakTime)); } } @@ -1953,8 +1953,8 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, } public function continueBreakBlock(Vector3 $pos, int $face) : void{ - $block = $this->level->getBlock($pos); - $this->level->broadcastLevelEvent( + $block = $this->world->getBlock($pos); + $this->world->broadcastLevelEvent( $pos, LevelEventPacket::EVENT_PARTICLE_PUNCH_BLOCK, $block->getRuntimeId() | ($face << 24) @@ -1964,7 +1964,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, } public function stopBreakBlock(Vector3 $pos) : void{ - $this->level->broadcastLevelEvent($pos, LevelEventPacket::EVENT_BLOCK_STOP_BREAK); + $this->world->broadcastLevelEvent($pos, LevelEventPacket::EVENT_BLOCK_STOP_BREAK); } /** @@ -1980,7 +1980,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, if($this->canInteract($pos->add(0.5, 0.5, 0.5), $this->isCreative() ? 13 : 7) and !$this->isSpectator()){ $item = $this->inventory->getItemInHand(); $oldItem = clone $item; - if($this->level->useBreakOn($pos, $item, $this, true)){ + if($this->world->useBreakOn($pos, $item, $this, true)){ if($this->hasFiniteResources() and !$item->equalsExact($oldItem)){ $this->inventory->setItemInHand($item); } @@ -1992,12 +1992,12 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $this->inventory->sendContents($this); $this->inventory->sendHeldItem($this); - $target = $this->level->getBlock($pos); + $target = $this->world->getBlock($pos); /** @var Block[] $blocks */ $blocks = $target->getAllSides(); $blocks[] = $target; - $this->level->sendBlocks([$this], $blocks); + $this->world->sendBlocks([$this], $blocks); return false; } @@ -2017,7 +2017,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, if($this->canInteract($pos->add(0.5, 0.5, 0.5), 13) and !$this->isSpectator()){ $item = $this->inventory->getItemInHand(); //this is a copy of the real item $oldItem = clone $item; - if($this->level->useItemOn($pos, $item, $face, $clickOffset, $this, true)){ + if($this->world->useItemOn($pos, $item, $face, $clickOffset, $this, true)){ if($this->hasFiniteResources() and !$item->equalsExact($oldItem)){ $this->inventory->setItemInHand($item); } @@ -2031,13 +2031,13 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, return true; } - $target = $this->level->getBlock($pos); + $target = $this->world->getBlock($pos); $block = $target->getSide($face); /** @var Block[] $blocks */ $blocks = array_merge($target->getAllSides(), $block->getAllSides()); //getAllSides() on each of these will include $target and $block because they are next to each other - $this->level->sendBlocks([$this], $blocks); + $this->world->sendBlocks([$this], $blocks); return false; } @@ -2178,7 +2178,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, * @param Item $item */ public function dropItem(Item $item) : void{ - $this->level->dropItem($this->add(0, 1.3, 0), $item, $this->getDirectionVector()->multiply(0.4), 40); + $this->world->dropItem($this->add(0, 1.3, 0), $item, $this->getDirectionVector()->multiply(0.4), 40); } public function handleBookEdit(BookEditPacket $packet) : bool{ @@ -2564,10 +2564,10 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, if($this->isValid()){ foreach($this->usedChunks as $index => $d){ - Level::getXZ($index, $chunkX, $chunkZ); - $this->level->unregisterChunkLoader($this, $chunkX, $chunkZ); - $this->level->unregisterChunkListener($this, $chunkX, $chunkZ); - foreach($this->level->getChunkEntities($chunkX, $chunkZ) as $entity){ + World::getXZ($index, $chunkX, $chunkZ); + $this->world->unregisterChunkLoader($this, $chunkX, $chunkZ); + $this->world->unregisterChunkListener($this, $chunkX, $chunkZ); + foreach($this->world->getChunkEntities($chunkX, $chunkZ) as $entity){ $entity->despawnFrom($this); } unset($this->usedChunks[$index]); @@ -2626,11 +2626,11 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $nbt = $this->saveNBT(); if($this->isValid()){ - $nbt->setString("Level", $this->level->getFolderName()); + $nbt->setString("Level", $this->world->getFolderName()); } if($this->hasValidSpawnPosition()){ - $nbt->setString("SpawnLevel", $this->spawnPosition->getLevel()->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()); @@ -2671,7 +2671,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, if(!$ev->getKeepInventory()){ foreach($ev->getDrops() as $item){ - $this->level->dropItem($this, $item); + $this->world->dropItem($this, $item); } if($this->inventory !== null){ @@ -2683,7 +2683,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, } } - $this->level->dropExperience($this, $ev->getXpDropAmount()); + $this->world->dropExperience($this, $ev->getXpDropAmount()); $this->setXpAndProgress(0, 0); if($ev->getDeathMessage() != ""){ @@ -2709,7 +2709,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()->getLevel()); + $realSpawn = Position::fromObject($ev->getRespawnPosition()->add(0.5, 0, 0.5), $ev->getRespawnPosition()->getWorld()); $this->teleport($realSpawn); $this->setSprinting(false); @@ -3038,7 +3038,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, } public function onChunkChanged(Chunk $chunk) : void{ - if(isset($this->usedChunks[$hash = Level::chunkHash($chunk->getX(), $chunk->getZ())])){ + if(isset($this->usedChunks[$hash = World::chunkHash($chunk->getX(), $chunk->getZ())])){ $this->usedChunks[$hash] = false; $this->nextChunkOrderRun = 0; } diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 346e79dbf..6a41f1fde 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -47,17 +47,9 @@ use pocketmine\item\ItemFactory; use pocketmine\lang\Language; use pocketmine\lang\LanguageNotFoundException; use pocketmine\lang\TextContainer; -use pocketmine\level\biome\Biome; -use pocketmine\level\format\io\LevelProviderManager; -use pocketmine\level\format\io\WritableLevelProvider; -use pocketmine\level\generator\Generator; -use pocketmine\level\generator\GeneratorManager; -use pocketmine\level\generator\normal\Normal; -use pocketmine\level\Level; -use pocketmine\level\LevelManager; use pocketmine\metadata\EntityMetadataStore; -use pocketmine\metadata\LevelMetadataStore; use pocketmine\metadata\PlayerMetadataStore; +use pocketmine\metadata\WorldMetadataStore; use pocketmine\nbt\BigEndianNbtSerializer; use pocketmine\nbt\NbtDataException; use pocketmine\nbt\tag\CompoundTag; @@ -102,6 +94,14 @@ use pocketmine\utils\Terminal; use pocketmine\utils\TextFormat; use pocketmine\utils\Utils; use pocketmine\utils\UUID; +use pocketmine\world\biome\Biome; +use pocketmine\world\format\io\WorldProviderManager; +use pocketmine\world\format\io\WritableWorldProvider; +use pocketmine\world\generator\Generator; +use pocketmine\world\generator\GeneratorManager; +use pocketmine\world\generator\normal\Normal; +use pocketmine\world\World; +use pocketmine\world\WorldManager; use function array_key_exists; use function array_shift; use function array_sum; @@ -238,8 +238,8 @@ class Server{ /** @var ResourcePackManager */ private $resourceManager; - /** @var LevelManager */ - private $levelManager; + /** @var WorldManager */ + private $worldManager; /** @var int */ private $maxPlayers; @@ -253,8 +253,8 @@ class Server{ /** @var PlayerMetadataStore */ private $playerMetadata; - /** @var LevelMetadataStore */ - private $levelMetadata; + /** @var WorldMetadataStore */ + private $worldMetadata; /** @var Network */ private $network; @@ -436,7 +436,7 @@ class Server{ } /** - * Returns Server global difficulty. Note that this may be overridden in individual Levels. + * Returns Server global difficulty. Note that this may be overridden in individual worlds. * @return int */ public function getDifficulty() : int{ @@ -493,10 +493,10 @@ class Server{ } /** - * @return LevelMetadataStore + * @return WorldMetadataStore */ - public function getLevelMetadata(){ - return $this->levelMetadata; + public function getWorldMetadata(){ + return $this->worldMetadata; } /** @@ -528,10 +528,10 @@ class Server{ } /** - * @return LevelManager + * @return WorldManager */ - public function getLevelManager() : LevelManager{ - return $this->levelManager; + public function getWorldManager() : WorldManager{ + return $this->worldManager; } public function getAsyncPool() : AsyncPool{ @@ -1130,7 +1130,7 @@ class Server{ $this->entityMetadata = new EntityMetadataStore(); $this->playerMetadata = new PlayerMetadataStore(); - $this->levelMetadata = new LevelMetadataStore(); + $this->worldMetadata = new WorldMetadataStore(); $this->operators = new Config($this->dataPath . "ops.txt", Config::ENUM); $this->whitelist = new Config($this->dataPath . "white-list.txt", Config::ENUM); @@ -1156,8 +1156,8 @@ class Server{ $this->logger->warning($this->getLanguage()->translateString("pocketmine.server.authProperty.disabled")); } - if($this->getConfigBool("hardcore", false) and $this->getDifficulty() < Level::DIFFICULTY_HARD){ - $this->setConfigInt("difficulty", Level::DIFFICULTY_HARD); + if($this->getConfigBool("hardcore", false) and $this->getDifficulty() < World::DIFFICULTY_HARD){ + $this->setConfigInt("difficulty", World::DIFFICULTY_HARD); } if(\pocketmine\DEBUG >= 0){ @@ -1213,18 +1213,18 @@ class Server{ $this->pluginManager->registerInterface(new PharPluginLoader($this->autoloader)); $this->pluginManager->registerInterface(new ScriptPluginLoader()); - LevelProviderManager::init(); + WorldProviderManager::init(); if( - ($format = LevelProviderManager::getProviderByName($formatName = (string) $this->getProperty("level-settings.default-format"))) !== null and - is_a($format, WritableLevelProvider::class, true) + ($format = WorldProviderManager::getProviderByName($formatName = (string) $this->getProperty("level-settings.default-format"))) !== null and + is_a($format, WritableWorldProvider::class, true) ){ - LevelProviderManager::setDefault($format); + WorldProviderManager::setDefault($format); }elseif($formatName !== ""){ $this->logger->warning($this->language->translateString("pocketmine.level.badDefaultFormat", [$formatName])); } GeneratorManager::registerDefaultGenerators(); - $this->levelManager = new LevelManager($this); + $this->worldManager = new WorldManager($this); $this->updater = new AutoUpdater($this, $this->getProperty("auto-updater.host", "update.pmmp.io")); @@ -1241,7 +1241,7 @@ class Server{ }elseif(!is_array($options)){ continue; } - if(!$this->levelManager->loadLevel($name, true)){ + if(!$this->worldManager->loadWorld($name, true)){ if(isset($options["generator"])){ $generatorOptions = explode(":", $options["generator"]); $generator = GeneratorManager::getGenerator(array_shift($generatorOptions)); @@ -1252,19 +1252,19 @@ class Server{ $generator = Normal::class; } - $this->levelManager->generateLevel($name, Generator::convertSeed((string) ($options["seed"] ?? "")), $generator, $options); + $this->worldManager->generateWorld($name, Generator::convertSeed((string) ($options["seed"] ?? "")), $generator, $options); } } - if($this->levelManager->getDefaultLevel() === null){ + if($this->worldManager->getDefaultWorld() === null){ $default = $this->getConfigString("level-name", "world"); if(trim($default) == ""){ $this->getLogger()->warning("level-name cannot be null, using default"); $default = "world"; $this->setConfigString("level-name", "world"); } - if(!$this->levelManager->loadLevel($default, true)){ - $this->levelManager->generateLevel( + if(!$this->worldManager->loadWorld($default, true)){ + $this->worldManager->generateWorld( $default, Generator::convertSeed($this->getConfigString("level-seed")), GeneratorManager::getGenerator($this->getConfigString("level-type")), @@ -1272,14 +1272,14 @@ class Server{ ); } - $level = $this->levelManager->getLevelByName($default); - if($level === null){ + $world = $this->worldManager->getWorldByName($default); + if($world === null){ $this->getLogger()->emergency($this->getLanguage()->translateString("pocketmine.level.defaultError")); $this->forceShutdown(); return; } - $this->levelManager->setDefaultLevel($level); + $this->worldManager->setDefaultWorld($world); } $this->enablePlugins(PluginLoadOrder::POSTWORLD()); @@ -1628,10 +1628,10 @@ class Server{ $this->network->getSessionManager()->close($this->getProperty("settings.shutdown-message", "Server closed")); } - if($this->levelManager instanceof LevelManager){ + if($this->worldManager instanceof WorldManager){ $this->getLogger()->debug("Unloading all worlds"); - foreach($this->levelManager->getLevels() as $level){ - $this->levelManager->unloadLevel($level, true); + foreach($this->worldManager->getWorlds() as $world){ + $this->worldManager->unloadWorld($world, true); } } @@ -1951,7 +1951,7 @@ class Server{ $this->asyncPool->collectTasks(); Timings::$schedulerAsyncTimer->stopTiming(); - $this->levelManager->tick($this->tickCounter); + $this->worldManager->tick($this->tickCounter); Timings::$connectionTimer->startTiming(); $this->network->tick(); @@ -1978,8 +1978,8 @@ class Server{ } if(($this->tickCounter % 100) === 0){ - foreach($this->levelManager->getLevels() as $level){ - $level->clearCache(); + foreach($this->worldManager->getWorlds() as $world){ + $world->clearCache(); } if($this->getTicksPerSecondAverage() < 12){ diff --git a/src/pocketmine/block/Banner.php b/src/pocketmine/block/Banner.php index fac53405b..9d6b9998f 100644 --- a/src/pocketmine/block/Banner.php +++ b/src/pocketmine/block/Banner.php @@ -92,7 +92,7 @@ class Banner extends Transparent{ public function readStateFromWorld() : void{ parent::readStateFromWorld(); - $tile = $this->level->getTile($this); + $tile = $this->world->getTile($this); if($tile instanceof TileBanner){ $this->baseColor = $tile->getBaseColor(); $this->setPatterns($tile->getPatterns()); @@ -101,7 +101,7 @@ class Banner extends Transparent{ public function writeStateToWorld() : void{ parent::writeStateToWorld(); - $tile = $this->level->getTile($this); + $tile = $this->world->getTile($this); assert($tile instanceof TileBanner); $tile->setBaseColor($this->baseColor); $tile->setPatterns($this->patterns); @@ -164,7 +164,7 @@ class Banner extends Transparent{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::opposite($this->facing))->getId() === BlockLegacyIds::AIR){ - $this->getLevel()->useBreakOn($this); + $this->getWorld()->useBreakOn($this); } } diff --git a/src/pocketmine/block/BaseRail.php b/src/pocketmine/block/BaseRail.php index 3dfb543ed..1d894108a 100644 --- a/src/pocketmine/block/BaseRail.php +++ b/src/pocketmine/block/BaseRail.php @@ -247,7 +247,7 @@ abstract class BaseRail extends Flowable{ if(isset($otherPossible[$otherSide])){ $otherConnections[] = $otherSide; $other->setConnections($otherConnections); - $other->level->setBlock($other, $other); + $other->world->setBlock($other, $other); $changed = true; $thisConnections[] = $thisSide; @@ -275,11 +275,11 @@ abstract class BaseRail extends Flowable{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->isTransparent()){ - $this->level->useBreakOn($this); + $this->world->useBreakOn($this); }else{ foreach($this->connections as $connection){ if(($connection & self::FLAG_ASCEND) !== 0 and $this->getSide($connection & ~self::FLAG_ASCEND)->isTransparent()){ - $this->level->useBreakOn($this); + $this->world->useBreakOn($this); break; } } diff --git a/src/pocketmine/block/Bed.php b/src/pocketmine/block/Bed.php index a82e3ecdb..841589b53 100644 --- a/src/pocketmine/block/Bed.php +++ b/src/pocketmine/block/Bed.php @@ -29,7 +29,6 @@ use pocketmine\item\Bed as ItemBed; use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\lang\TranslationContainer; -use pocketmine\level\Level; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Bearing; use pocketmine\math\Facing; @@ -37,6 +36,7 @@ use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\tile\Bed as TileBed; use pocketmine\utils\TextFormat; +use pocketmine\world\World; class Bed extends Transparent{ private const BITFLAG_OCCUPIED = 0x04; @@ -75,7 +75,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->level->getTile($this); + $tile = $this->world->getTile($this); if($tile instanceof TileBed){ $this->color = $tile->getColor(); } @@ -84,7 +84,7 @@ class Bed extends Transparent{ public function writeStateToWorld() : void{ parent::writeStateToWorld(); //extra block properties storage hack - $tile = $this->level->getTile($this); + $tile = $this->world->getTile($this); if($tile instanceof TileBed){ $tile->setColor($this->color); } @@ -111,11 +111,11 @@ class Bed extends Transparent{ public function setOccupied(bool $occupied = true) : void{ $this->occupied = $occupied; - $this->level->setBlock($this, $this, false); + $this->world->setBlock($this, $this, false); if(($other = $this->getOtherHalf()) !== null){ $other->occupied = $occupied; - $this->level->setBlock($other, $other, false); + $this->world->setBlock($other, $other, false); } } @@ -150,9 +150,9 @@ class Bed extends Transparent{ return true; } - $time = $this->getLevel()->getTime() % Level::TIME_FULL; + $time = $this->getWorld()->getTime() % World::TIME_FULL; - $isNight = ($time >= Level::TIME_NIGHT and $time < Level::TIME_SUNRISE); + $isNight = ($time >= World::TIME_NIGHT and $time < World::TIME_SUNRISE); if(!$isNight){ $player->sendMessage(new TranslationContainer(TextFormat::GRAY . "%tile.bed.noSleep")); @@ -188,7 +188,7 @@ class Bed extends Transparent{ parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); $nextState = clone $this; $nextState->head = true; - $this->getLevel()->setBlock($next, $nextState); + $this->getWorld()->setBlock($next, $nextState); return true; } diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 0eb7f1efc..bd573b15b 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -31,8 +31,6 @@ use pocketmine\entity\Entity; use pocketmine\item\enchantment\Enchantment; use pocketmine\item\Item; use pocketmine\item\ItemFactory; -use pocketmine\level\Level; -use pocketmine\level\Position; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; use pocketmine\math\RayTraceResult; @@ -43,6 +41,8 @@ use pocketmine\network\mcpe\protocol\types\RuntimeBlockMapping; use pocketmine\Player; use pocketmine\plugin\Plugin; use pocketmine\tile\TileFactory; +use pocketmine\world\Position; +use pocketmine\world\World; use function array_merge; use function assert; use function dechex; @@ -174,16 +174,16 @@ class Block extends Position implements BlockLegacyIds, Metadatable{ } public function writeStateToWorld() : void{ - $this->level->getChunkAtPosition($this)->setFullBlock($this->x & 0xf, $this->y, $this->z & 0xf, $this->getFullId()); + $this->world->getChunkAtPosition($this)->setFullBlock($this->x & 0xf, $this->y, $this->z & 0xf, $this->getFullId()); $tileType = $this->idInfo->getTileClass(); - $oldTile = $this->level->getTile($this); + $oldTile = $this->world->getTile($this); if($oldTile !== null and ($tileType === null or !($oldTile instanceof $tileType))){ $oldTile->close(); $oldTile = null; } if($oldTile === null and $tileType !== null){ - $this->level->addTile(TileFactory::create($tileType, $this->level, $this->asVector3())); + $this->world->addTile(TileFactory::create($tileType, $this->world, $this->asVector3())); } } @@ -244,7 +244,7 @@ class Block extends Position implements BlockLegacyIds, Metadatable{ * @return bool */ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - return $this->getLevel()->setBlock($blockReplace, $this); + return $this->getWorld()->setBlock($blockReplace, $this); } /** @@ -312,10 +312,10 @@ class Block extends Position implements BlockLegacyIds, Metadatable{ * @return bool */ public function onBreak(Item $item, ?Player $player = null) : bool{ - if(($t = $this->level->getTile($this)) !== null){ + if(($t = $this->world->getTile($this)) !== null){ $t->onBlockDestroyed(); } - return $this->getLevel()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR)); + return $this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR)); } @@ -370,7 +370,7 @@ class Block extends Position implements BlockLegacyIds, Metadatable{ } /** - * Called when this block is updated by the delayed blockupdate scheduler in the level. + * Called when this block is updated by the delayed blockupdate scheduler in the world. */ public function onScheduledUpdate() : void{ @@ -494,18 +494,19 @@ class Block extends Position implements BlockLegacyIds, Metadatable{ } /** - * @internal - * - * @param Level $level + * @param World $world * @param int $x * @param int $y * @param int $z + * + *@internal + * */ - final public function position(Level $level, int $x, int $y, int $z) : void{ + final public function position(World $world, int $x, int $y, int $z) : void{ $this->x = $x; $this->y = $y; $this->z = $z; - $this->level = $level; + $this->world = $world; } /** @@ -653,7 +654,7 @@ class Block extends Position implements BlockLegacyIds, Metadatable{ */ public function getSide(int $side, int $step = 1){ if($this->isValid()){ - return $this->getLevel()->getBlock(Vector3::getSide($side, $step)); + return $this->getWorld()->getBlock(Vector3::getSide($side, $step)); } return BlockFactory::get(BlockLegacyIds::AIR, 0, Position::fromObject(Vector3::getSide($side, $step))); @@ -812,13 +813,13 @@ class Block extends Position implements BlockLegacyIds, Metadatable{ public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue) : void{ if($this->isValid()){ - $this->level->getBlockMetadata()->setMetadata($this, $metadataKey, $newMetadataValue); + $this->world->getBlockMetadata()->setMetadata($this, $metadataKey, $newMetadataValue); } } public function getMetadata(string $metadataKey){ if($this->isValid()){ - return $this->level->getBlockMetadata()->getMetadata($this, $metadataKey); + return $this->world->getBlockMetadata()->getMetadata($this, $metadataKey); } return null; @@ -826,7 +827,7 @@ class Block extends Position implements BlockLegacyIds, Metadatable{ public function hasMetadata(string $metadataKey) : bool{ if($this->isValid()){ - return $this->level->getBlockMetadata()->hasMetadata($this, $metadataKey); + return $this->world->getBlockMetadata()->hasMetadata($this, $metadataKey); } return false; @@ -834,7 +835,7 @@ class Block extends Position implements BlockLegacyIds, Metadatable{ public function removeMetadata(string $metadataKey, Plugin $owningPlugin) : void{ if($this->isValid()){ - $this->level->getBlockMetadata()->removeMetadata($this, $metadataKey, $owningPlugin); + $this->world->getBlockMetadata()->removeMetadata($this, $metadataKey, $owningPlugin); } } } diff --git a/src/pocketmine/block/BlockFactory.php b/src/pocketmine/block/BlockFactory.php index 691e11a2c..217f06e2d 100644 --- a/src/pocketmine/block/BlockFactory.php +++ b/src/pocketmine/block/BlockFactory.php @@ -31,7 +31,7 @@ use pocketmine\block\utils\TreeType; use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\item\ItemIds; -use pocketmine\level\Position; +use pocketmine\world\Position; use pocketmine\tile\Comparator; use function array_fill; use function array_filter; @@ -645,7 +645,7 @@ class BlockFactory{ } if($pos !== null){ - $block->position($pos->getLevel(), $pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ()); + $block->position($pos->getWorld(), $pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ()); } return $block; diff --git a/src/pocketmine/block/Button.php b/src/pocketmine/block/Button.php index da13e9aee..87247a960 100644 --- a/src/pocketmine/block/Button.php +++ b/src/pocketmine/block/Button.php @@ -25,11 +25,11 @@ namespace pocketmine\block; use pocketmine\block\utils\BlockDataValidator; use pocketmine\item\Item; -use pocketmine\level\sound\RedstonePowerOffSound; -use pocketmine\level\sound\RedstonePowerOnSound; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; +use pocketmine\world\sound\RedstonePowerOffSound; +use pocketmine\world\sound\RedstonePowerOnSound; abstract class Button extends Flowable{ @@ -63,9 +63,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->level->setBlock($this, $this); - $this->level->scheduleDelayedBlockUpdate($this, $this->getActivationTime()); - $this->level->addSound($this->add(0.5, 0.5, 0.5), new RedstonePowerOnSound()); + $this->world->setBlock($this, $this); + $this->world->scheduleDelayedBlockUpdate($this, $this->getActivationTime()); + $this->world->addSound($this->add(0.5, 0.5, 0.5), new RedstonePowerOnSound()); } return true; @@ -74,8 +74,8 @@ abstract class Button extends Flowable{ public function onScheduledUpdate() : void{ if($this->powered){ $this->powered = false; - $this->level->setBlock($this, $this); - $this->level->addSound($this->add(0.5, 0.5, 0.5), new RedstonePowerOffSound()); + $this->world->setBlock($this, $this); + $this->world->addSound($this->add(0.5, 0.5, 0.5), new RedstonePowerOffSound()); } } } diff --git a/src/pocketmine/block/Cactus.php b/src/pocketmine/block/Cactus.php index f52a149fd..9a8c76235 100644 --- a/src/pocketmine/block/Cactus.php +++ b/src/pocketmine/block/Cactus.php @@ -72,12 +72,12 @@ class Cactus extends Transparent{ public function onNearbyBlockChange() : void{ $down = $this->getSide(Facing::DOWN); if($down->getId() !== BlockLegacyIds::SAND and $down->getId() !== BlockLegacyIds::CACTUS){ - $this->getLevel()->useBreakOn($this); + $this->getWorld()->useBreakOn($this); }else{ foreach(Facing::HORIZONTAL as $side){ $b = $this->getSide($side); if($b->isSolid()){ - $this->getLevel()->useBreakOn($this); + $this->getWorld()->useBreakOn($this); break; } } @@ -92,23 +92,23 @@ class Cactus extends Transparent{ if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::CACTUS){ if($this->age === 15){ for($y = 1; $y < 3; ++$y){ - $b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z); + $b = $this->getWorld()->getBlockAt($this->x, $this->y + $y, $this->z); if($b->getId() === BlockLegacyIds::AIR){ $ev = new BlockGrowEvent($b, BlockFactory::get(BlockLegacyIds::CACTUS)); $ev->call(); if($ev->isCancelled()){ break; } - $this->getLevel()->setBlock($b, $ev->getNewState()); + $this->getWorld()->setBlock($b, $ev->getNewState()); }else{ break; } } $this->age = 0; - $this->getLevel()->setBlock($this, $this); + $this->getWorld()->setBlock($this, $this); }else{ ++$this->age; - $this->getLevel()->setBlock($this, $this); + $this->getWorld()->setBlock($this, $this); } } } diff --git a/src/pocketmine/block/Cake.php b/src/pocketmine/block/Cake.php index 6410a5cd9..d121490ed 100644 --- a/src/pocketmine/block/Cake.php +++ b/src/pocketmine/block/Cake.php @@ -72,7 +72,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->getLevel()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR)); + $this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR)); } } @@ -125,6 +125,6 @@ class Cake extends Transparent implements FoodSource{ } public function onConsume(Living $consumer) : void{ - $this->level->setBlock($this, $this->getResidue()); + $this->world->setBlock($this, $this->getResidue()); } } diff --git a/src/pocketmine/block/Carpet.php b/src/pocketmine/block/Carpet.php index 8a11ea2ed..2397145d8 100644 --- a/src/pocketmine/block/Carpet.php +++ b/src/pocketmine/block/Carpet.php @@ -54,7 +54,7 @@ class Carpet extends Flowable{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->getId() === BlockLegacyIds::AIR){ - $this->getLevel()->useBreakOn($this); + $this->getWorld()->useBreakOn($this); } } diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index 678564d4a..993b004d6 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -67,7 +67,7 @@ class Chest extends Transparent{ } if(parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){ - $tile = $this->level->getTile($this); + $tile = $this->world->getTile($this); if($tile instanceof TileChest){ foreach([ Facing::rotateY($this->facing, true), @@ -75,7 +75,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->level->getTile($c); + $pair = $this->world->getTile($c); if($pair instanceof TileChest and !$pair->isPaired()){ $pair->pairWith($tile); $tile->pairWith($pair); @@ -94,7 +94,7 @@ class Chest extends Transparent{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player instanceof Player){ - $chest = $this->getLevel()->getTile($this); + $chest = $this->getWorld()->getTile($this); if($chest instanceof TileChest){ if( !$this->getSide(Facing::UP)->isTransparent() or diff --git a/src/pocketmine/block/CoarseDirt.php b/src/pocketmine/block/CoarseDirt.php index 90ff2ef9d..ac26869a5 100644 --- a/src/pocketmine/block/CoarseDirt.php +++ b/src/pocketmine/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->getLevel()->setBlock($this, BlockFactory::get(BlockLegacyIds::DIRT)); + $this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::DIRT)); return true; } diff --git a/src/pocketmine/block/CocoaBlock.php b/src/pocketmine/block/CocoaBlock.php index 1c74c16e8..e56c15720 100644 --- a/src/pocketmine/block/CocoaBlock.php +++ b/src/pocketmine/block/CocoaBlock.php @@ -88,7 +88,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->level->setBlock($this, $this); + $this->world->setBlock($this, $this); $item->pop(); @@ -101,7 +101,7 @@ class CocoaBlock extends Transparent{ public function onNearbyBlockChange() : void{ $side = $this->getSide(Facing::opposite($this->facing)); if(!($side instanceof Wood) or $side->getTreeType() !== TreeType::JUNGLE()){ - $this->level->useBreakOn($this); + $this->world->useBreakOn($this); } } @@ -112,7 +112,7 @@ class CocoaBlock extends Transparent{ public function onRandomTick() : void{ if($this->age < 2 and mt_rand(1, 5) === 1){ $this->age++; - $this->level->setBlock($this, $this); + $this->world->setBlock($this, $this); } } diff --git a/src/pocketmine/block/ConcretePowder.php b/src/pocketmine/block/ConcretePowder.php index fae849dac..ee3baed92 100644 --- a/src/pocketmine/block/ConcretePowder.php +++ b/src/pocketmine/block/ConcretePowder.php @@ -42,7 +42,7 @@ class ConcretePowder extends Solid implements Fallable{ public function onNearbyBlockChange() : void{ if(($block = $this->checkAdjacentWater()) !== null){ - $this->level->setBlock($this, $block); + $this->world->setBlock($this, $block); }else{ $this->startFalling(); } diff --git a/src/pocketmine/block/Crops.php b/src/pocketmine/block/Crops.php index 9f39280d3..4c6e84536 100644 --- a/src/pocketmine/block/Crops.php +++ b/src/pocketmine/block/Crops.php @@ -68,7 +68,7 @@ abstract class Crops extends Flowable{ $ev = new BlockGrowEvent($this, $block); $ev->call(); if(!$ev->isCancelled()){ - $this->getLevel()->setBlock($this, $ev->getNewState()); + $this->getWorld()->setBlock($this, $ev->getNewState()); } $item->pop(); @@ -81,7 +81,7 @@ abstract class Crops extends Flowable{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::FARMLAND){ - $this->getLevel()->useBreakOn($this); + $this->getWorld()->useBreakOn($this); } } @@ -96,7 +96,7 @@ abstract class Crops extends Flowable{ $ev = new BlockGrowEvent($this, $block); $ev->call(); if(!$ev->isCancelled()){ - $this->getLevel()->setBlock($this, $ev->getNewState()); + $this->getWorld()->setBlock($this, $ev->getNewState()); } } } diff --git a/src/pocketmine/block/Dandelion.php b/src/pocketmine/block/Dandelion.php index dda14ad05..b80b8d8b7 100644 --- a/src/pocketmine/block/Dandelion.php +++ b/src/pocketmine/block/Dandelion.php @@ -42,7 +42,7 @@ class Dandelion extends Flowable{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->isTransparent()){ - $this->getLevel()->useBreakOn($this); + $this->getWorld()->useBreakOn($this); } } diff --git a/src/pocketmine/block/DaylightSensor.php b/src/pocketmine/block/DaylightSensor.php index 41e53794a..a471d013d 100644 --- a/src/pocketmine/block/DaylightSensor.php +++ b/src/pocketmine/block/DaylightSensor.php @@ -93,7 +93,7 @@ class DaylightSensor extends Transparent{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->inverted = !$this->inverted; - $this->level->setBlock($this, $this); + $this->world->setBlock($this, $this); return true; } diff --git a/src/pocketmine/block/DeadBush.php b/src/pocketmine/block/DeadBush.php index 0ca036fcd..9c43fbb50 100644 --- a/src/pocketmine/block/DeadBush.php +++ b/src/pocketmine/block/DeadBush.php @@ -42,7 +42,7 @@ class DeadBush extends Flowable{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->isTransparent()){ - $this->getLevel()->useBreakOn($this); + $this->getWorld()->useBreakOn($this); } } diff --git a/src/pocketmine/block/Dirt.php b/src/pocketmine/block/Dirt.php index 663544e52..feb23e7ae 100644 --- a/src/pocketmine/block/Dirt.php +++ b/src/pocketmine/block/Dirt.php @@ -44,7 +44,7 @@ class Dirt extends Solid{ 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->getLevel()->setBlock($this, BlockFactory::get(BlockLegacyIds::FARMLAND)); + $this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::FARMLAND)); return true; } diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index 314b8d0f9..4654b787d 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -25,13 +25,13 @@ namespace pocketmine\block; use pocketmine\block\utils\BlockDataValidator; use pocketmine\item\Item; -use pocketmine\level\BlockTransaction; -use pocketmine\level\sound\DoorSound; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Bearing; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; +use pocketmine\world\BlockTransaction; +use pocketmine\world\sound\DoorSound; abstract class Door extends Transparent{ @@ -99,7 +99,7 @@ abstract class Door extends Transparent{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->getId() === BlockLegacyIds::AIR){ //Replace with common break method - $this->getLevel()->useBreakOn($this); //this will delete both halves if they exist + $this->getWorld()->useBreakOn($this); //this will delete both halves if they exist } } @@ -125,7 +125,7 @@ abstract class Door extends Transparent{ $topHalf = clone $this; $topHalf->top = true; - $transaction = new BlockTransaction($this->level); + $transaction = new BlockTransaction($this->world); $transaction->addBlock($blockReplace, $this)->addBlock($blockUp, $topHalf); return $transaction->apply(); @@ -140,11 +140,11 @@ abstract 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->level->setBlock($other, $other); + $this->world->setBlock($other, $other); } - $this->level->setBlock($this, $this); - $this->level->addSound($this, new DoorSound()); + $this->world->setBlock($this, $this); + $this->world->addSound($this, new DoorSound()); return true; } diff --git a/src/pocketmine/block/DoublePlant.php b/src/pocketmine/block/DoublePlant.php index 60c1f6c3d..c58abbab0 100644 --- a/src/pocketmine/block/DoublePlant.php +++ b/src/pocketmine/block/DoublePlant.php @@ -24,10 +24,10 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\item\Item; -use pocketmine\level\BlockTransaction; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; +use pocketmine\world\BlockTransaction; class DoublePlant extends Flowable{ private const BITFLAG_TOP = 0x08; @@ -53,7 +53,7 @@ class DoublePlant extends Flowable{ $top = clone $this; $top->top = true; - $transaction = new BlockTransaction($this->level); + $transaction = new BlockTransaction($this->world); $transaction->addBlock($blockReplace, $this)->addBlock($blockReplace->getSide(Facing::UP), $top); return $transaction->apply(); } @@ -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->getLevel()->useBreakOn($this); + $this->getWorld()->useBreakOn($this); } } diff --git a/src/pocketmine/block/DragonEgg.php b/src/pocketmine/block/DragonEgg.php index e91f7eb58..27de6cc9d 100644 --- a/src/pocketmine/block/DragonEgg.php +++ b/src/pocketmine/block/DragonEgg.php @@ -28,10 +28,10 @@ use pocketmine\block\utils\FallableTrait; use pocketmine\event\block\BlockTeleportEvent; use pocketmine\item\Item; use pocketmine\item\TieredTool; -use pocketmine\level\Level; -use pocketmine\level\particle\DragonEggTeleportParticle; use pocketmine\math\Vector3; use pocketmine\Player; +use pocketmine\world\particle\DragonEggTeleportParticle; +use pocketmine\world\World; use function max; use function min; use function mt_rand; @@ -71,9 +71,9 @@ class DragonEgg extends Transparent implements Fallable{ protected function teleport() : void{ for($tries = 0; $tries < 16; ++$tries){ - $block = $this->level->getBlockAt( + $block = $this->world->getBlockAt( $this->x + mt_rand(-16, 16), - max(0, min(Level::Y_MAX - 1, $this->y + mt_rand(-8, 8))), + max(0, min(World::Y_MAX - 1, $this->y + mt_rand(-8, 8))), $this->z + mt_rand(-16, 16) ); if($block instanceof Air){ @@ -84,9 +84,9 @@ class DragonEgg extends Transparent implements Fallable{ }else{ $block = $ev->getTo(); } - $this->level->addParticle($this, new DragonEggTeleportParticle($this->x - $block->x, $this->y - $block->y, $this->z - $block->z)); - $this->level->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR)); - $this->level->setBlock($block, $this); + $this->world->addParticle($this, new DragonEggTeleportParticle($this->x - $block->x, $this->y - $block->y, $this->z - $block->z)); + $this->world->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR)); + $this->world->setBlock($block, $this); break; } } diff --git a/src/pocketmine/block/EnderChest.php b/src/pocketmine/block/EnderChest.php index 4235fa984..7e934e84e 100644 --- a/src/pocketmine/block/EnderChest.php +++ b/src/pocketmine/block/EnderChest.php @@ -84,7 +84,7 @@ class EnderChest extends Transparent{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player instanceof Player){ - $enderChest = $this->getLevel()->getTile($this); + $enderChest = $this->getWorld()->getTile($this); if($enderChest instanceof TileEnderChest and $this->getSide(Facing::UP)->isTransparent()){ $player->getEnderChestInventory()->setHolderPosition($enderChest); $player->addWindow($player->getEnderChestInventory()); diff --git a/src/pocketmine/block/Farmland.php b/src/pocketmine/block/Farmland.php index b762e6aa2..9bbc2bd0d 100644 --- a/src/pocketmine/block/Farmland.php +++ b/src/pocketmine/block/Farmland.php @@ -60,7 +60,7 @@ class Farmland extends Transparent{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::UP)->isSolid()){ - $this->level->setBlock($this, BlockFactory::get(BlockLegacyIds::DIRT)); + $this->world->setBlock($this, BlockFactory::get(BlockLegacyIds::DIRT)); } } @@ -72,13 +72,13 @@ class Farmland extends Transparent{ if(!$this->canHydrate()){ if($this->wetness > 0){ $this->wetness--; - $this->level->setBlock($this, $this, false); + $this->world->setBlock($this, $this, false); }else{ - $this->level->setBlock($this, BlockFactory::get(BlockLegacyIds::DIRT)); + $this->world->setBlock($this, BlockFactory::get(BlockLegacyIds::DIRT)); } }elseif($this->wetness < 7){ $this->wetness = 7; - $this->level->setBlock($this, $this, false); + $this->world->setBlock($this, $this, false); } } @@ -89,7 +89,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->level->getBlockAt($x, $y, $z) instanceof Water){ + if($this->world->getBlockAt($x, $y, $z) instanceof Water){ return true; } } diff --git a/src/pocketmine/block/FenceGate.php b/src/pocketmine/block/FenceGate.php index a338f8bf4..c27ed843c 100644 --- a/src/pocketmine/block/FenceGate.php +++ b/src/pocketmine/block/FenceGate.php @@ -25,12 +25,12 @@ namespace pocketmine\block; use pocketmine\block\utils\BlockDataValidator; use pocketmine\item\Item; -use pocketmine\level\sound\DoorSound; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Bearing; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; +use pocketmine\world\sound\DoorSound; class FenceGate extends Transparent{ /** @var bool */ @@ -92,7 +92,7 @@ class FenceGate extends Transparent{ $inWall = $this->checkInWall(); if($inWall !== $this->inWall){ $this->inWall = $inWall; - $this->level->setBlock($this, $this); + $this->world->setBlock($this, $this); } } @@ -105,8 +105,8 @@ class FenceGate extends Transparent{ } } - $this->getLevel()->setBlock($this, $this); - $this->level->addSound($this, new DoorSound()); + $this->getWorld()->setBlock($this, $this); + $this->world->addSound($this, new DoorSound()); return true; } diff --git a/src/pocketmine/block/Fire.php b/src/pocketmine/block/Fire.php index dd739f50b..298a1bf5a 100644 --- a/src/pocketmine/block/Fire.php +++ b/src/pocketmine/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->getLevel()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR)); + $this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR)); }else{ - $this->level->scheduleDelayedBlockUpdate($this, mt_rand(30, 40)); + $this->world->scheduleDelayedBlockUpdate($this, mt_rand(30, 40)); } } @@ -124,10 +124,10 @@ class Fire extends Flowable{ } if($result !== null){ - $this->level->setBlock($this, $result); + $this->world->setBlock($this, $result); } - $this->level->scheduleDelayedBlockUpdate($this, mt_rand(30, 40)); + $this->world->scheduleDelayedBlockUpdate($this, 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->level->setBlock($block, $fire); + $this->world->setBlock($block, $fire); }else{ - $this->level->setBlock($block, BlockFactory::get(BlockLegacyIds::AIR)); + $this->world->setBlock($block, BlockFactory::get(BlockLegacyIds::AIR)); } } } diff --git a/src/pocketmine/block/Flower.php b/src/pocketmine/block/Flower.php index d4d2949ac..165abadfe 100644 --- a/src/pocketmine/block/Flower.php +++ b/src/pocketmine/block/Flower.php @@ -52,7 +52,7 @@ class Flower extends Flowable{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->isTransparent()){ - $this->getLevel()->useBreakOn($this); + $this->getWorld()->useBreakOn($this); } } diff --git a/src/pocketmine/block/FlowerPot.php b/src/pocketmine/block/FlowerPot.php index d7505029a..1c2644c9b 100644 --- a/src/pocketmine/block/FlowerPot.php +++ b/src/pocketmine/block/FlowerPot.php @@ -56,7 +56,7 @@ class FlowerPot extends Flowable{ public function readStateFromWorld() : void{ parent::readStateFromWorld(); - $tile = $this->level->getTile($this); + $tile = $this->world->getTile($this); if($tile instanceof TileFlowerPot){ $this->setPlant($tile->getPlant()); }else{ @@ -67,7 +67,7 @@ class FlowerPot extends Flowable{ public function writeStateToWorld() : void{ parent::writeStateToWorld(); - $tile = $this->level->getTile($this); + $tile = $this->world->getTile($this); assert($tile instanceof TileFlowerPot); $tile->setPlant($this->plant); } @@ -121,7 +121,7 @@ class FlowerPot extends Flowable{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->isTransparent()){ - $this->getLevel()->useBreakOn($this); + $this->getWorld()->useBreakOn($this); } } @@ -133,7 +133,7 @@ class FlowerPot extends Flowable{ $this->setPlant($plant); $item->pop(); - $this->level->setBlock($this, $this); + $this->world->setBlock($this, $this); return true; } diff --git a/src/pocketmine/block/FrostedIce.php b/src/pocketmine/block/FrostedIce.php index aaae97160..5a1446db1 100644 --- a/src/pocketmine/block/FrostedIce.php +++ b/src/pocketmine/block/FrostedIce.php @@ -50,17 +50,17 @@ class FrostedIce extends Ice{ public function onNearbyBlockChange() : void{ if(!$this->checkAdjacentBlocks(2)){ - $this->level->useBreakOn($this); + $this->world->useBreakOn($this); }else{ - $this->level->scheduleDelayedBlockUpdate($this, mt_rand(20, 40)); + $this->world->scheduleDelayedBlockUpdate($this, mt_rand(20, 40)); } } public function onRandomTick() : void{ if((!$this->checkAdjacentBlocks(4) or mt_rand(0, 2) === 0) and - max( //TODO: move this to Level - $this->level->getHighestAdjacentBlockLight($this->x, $this->y, $this->z), - $this->level->getHighestAdjacentBlockSkyLight($this->x, $this->y, $this->z) - $this->level->getSkyLightReduction() + max( //TODO: move this to World + $this->world->getHighestAdjacentBlockLight($this->x, $this->y, $this->z), + $this->world->getHighestAdjacentBlockSkyLight($this->x, $this->y, $this->z) - $this->world->getSkyLightReduction() ) >= 12 - $this->age){ if($this->tryMelt()){ foreach($this->getAllSides() as $block){ @@ -70,7 +70,7 @@ class FrostedIce extends Ice{ } } }else{ - $this->level->scheduleDelayedBlockUpdate($this, mt_rand(20, 40)); + $this->world->scheduleDelayedBlockUpdate($this, mt_rand(20, 40)); } } @@ -86,7 +86,7 @@ class FrostedIce extends Ice{ continue; } if( - $this->level->getBlockAt($this->x + $x, $this->y, $this->z + $z) instanceof FrostedIce and + $this->world->getBlockAt($this->x + $x, $this->y, $this->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->level->useBreakOn($this); + $this->world->useBreakOn($this); return true; } $this->age++; - $this->level->setBlock($this, $this); - $this->level->scheduleDelayedBlockUpdate($this, mt_rand(20, 40)); + $this->world->setBlock($this, $this); + $this->world->scheduleDelayedBlockUpdate($this, mt_rand(20, 40)); return false; } } diff --git a/src/pocketmine/block/Furnace.php b/src/pocketmine/block/Furnace.php index c5921cb03..87fe90717 100644 --- a/src/pocketmine/block/Furnace.php +++ b/src/pocketmine/block/Furnace.php @@ -97,7 +97,7 @@ class Furnace extends Solid{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($player instanceof Player){ - $furnace = $this->getLevel()->getTile($this); + $furnace = $this->getWorld()->getTile($this); if($furnace instanceof TileFurnace and $furnace->canOpenWith($item->getCustomName())){ $player->addWindow($furnace->getInventory()); } diff --git a/src/pocketmine/block/Grass.php b/src/pocketmine/block/Grass.php index ec7325053..8fe2c0979 100644 --- a/src/pocketmine/block/Grass.php +++ b/src/pocketmine/block/Grass.php @@ -29,11 +29,11 @@ use pocketmine\item\Hoe; use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\item\Shovel; -use pocketmine\level\generator\object\TallGrass as TallGrassObject; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\utils\Random; +use pocketmine\world\generator\object\TallGrass as TallGrassObject; use function mt_rand; class Grass extends Solid{ @@ -57,13 +57,13 @@ class Grass extends Solid{ } public function onRandomTick() : void{ - $lightAbove = $this->level->getFullLightAt($this->x, $this->y + 1, $this->z); - if($lightAbove < 4 and $this->level->getBlockAt($this->x, $this->y + 1, $this->z)->getLightFilter() >= 2){ + $lightAbove = $this->world->getFullLightAt($this->x, $this->y + 1, $this->z); + if($lightAbove < 4 and $this->world->getBlockAt($this->x, $this->y + 1, $this->z)->getLightFilter() >= 2){ //grass dies $ev = new BlockSpreadEvent($this, $this, BlockFactory::get(BlockLegacyIds::DIRT)); $ev->call(); if(!$ev->isCancelled()){ - $this->level->setBlock($this, $ev->getNewState(), false); + $this->world->setBlock($this, $ev->getNewState(), false); } }elseif($lightAbove >= 9){ //try grass spread @@ -72,12 +72,12 @@ class Grass extends Solid{ $y = mt_rand($this->y - 3, $this->y + 1); $z = mt_rand($this->z - 1, $this->z + 1); - $b = $this->level->getBlockAt($x, $y, $z); + $b = $this->world->getBlockAt($x, $y, $z); if( !($b instanceof Dirt) or $b instanceof CoarseDirt or - $this->level->getFullLightAt($x, $y + 1, $z) < 4 or - $this->level->getBlockAt($x, $y + 1, $z)->getLightFilter() >= 2 + $this->world->getFullLightAt($x, $y + 1, $z) < 4 or + $this->world->getBlockAt($x, $y + 1, $z)->getLightFilter() >= 2 ){ continue; } @@ -85,7 +85,7 @@ class Grass extends Solid{ $ev = new BlockSpreadEvent($b, $this, BlockFactory::get(BlockLegacyIds::GRASS)); $ev->call(); if(!$ev->isCancelled()){ - $this->level->setBlock($b, $ev->getNewState(), false); + $this->world->setBlock($b, $ev->getNewState(), false); } } } @@ -97,17 +97,17 @@ class Grass extends Solid{ } if($item instanceof Fertilizer){ $item->pop(); - TallGrassObject::growGrass($this->getLevel(), $this, new Random(mt_rand()), 8, 2); + TallGrassObject::growGrass($this->getWorld(), $this, new Random(mt_rand()), 8, 2); return true; }elseif($item instanceof Hoe){ $item->applyDamage(1); - $this->getLevel()->setBlock($this, BlockFactory::get(BlockLegacyIds::FARMLAND)); + $this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::FARMLAND)); return true; }elseif($item instanceof Shovel and $this->getSide(Facing::UP)->getId() === BlockLegacyIds::AIR){ $item->applyDamage(1); - $this->getLevel()->setBlock($this, BlockFactory::get(BlockLegacyIds::GRASS_PATH)); + $this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::GRASS_PATH)); return true; } diff --git a/src/pocketmine/block/GrassPath.php b/src/pocketmine/block/GrassPath.php index 74b426a3d..9c7fb29cf 100644 --- a/src/pocketmine/block/GrassPath.php +++ b/src/pocketmine/block/GrassPath.php @@ -44,7 +44,7 @@ class GrassPath extends Transparent{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::UP)->isSolid()){ - $this->level->setBlock($this, BlockFactory::get(BlockLegacyIds::DIRT)); + $this->world->setBlock($this, BlockFactory::get(BlockLegacyIds::DIRT)); } } diff --git a/src/pocketmine/block/Ice.php b/src/pocketmine/block/Ice.php index 2427fc00c..0a3265134 100644 --- a/src/pocketmine/block/Ice.php +++ b/src/pocketmine/block/Ice.php @@ -47,7 +47,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())){ - return $this->getLevel()->setBlock($this, BlockFactory::get(BlockLegacyIds::WATER)); + return $this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::WATER)); } return parent::onBreak($item, $player); } @@ -57,8 +57,8 @@ class Ice extends Transparent{ } public function onRandomTick() : void{ - if($this->level->getHighestAdjacentBlockLight($this->x, $this->y, $this->z) >= 12){ - $this->level->useBreakOn($this); + if($this->world->getHighestAdjacentBlockLight($this->x, $this->y, $this->z) >= 12){ + $this->world->useBreakOn($this); } } diff --git a/src/pocketmine/block/ItemFrame.php b/src/pocketmine/block/ItemFrame.php index 264914fe0..ffc8d5bc1 100644 --- a/src/pocketmine/block/ItemFrame.php +++ b/src/pocketmine/block/ItemFrame.php @@ -56,7 +56,7 @@ class ItemFrame extends Flowable{ public function readStateFromWorld() : void{ parent::readStateFromWorld(); - $tile = $this->level->getTile($this); + $tile = $this->world->getTile($this); if($tile instanceof TileItemFrame){ $this->framedItem = $tile->getItem(); if($this->framedItem->isNull()){ @@ -69,7 +69,7 @@ class ItemFrame extends Flowable{ public function writeStateToWorld() : void{ parent::writeStateToWorld(); - $tile = $this->level->getTile($this); + $tile = $this->world->getTile($this); if($tile instanceof TileItemFrame){ $tile->setItem($this->framedItem); $tile->setItemRotation($this->itemRotation); @@ -151,7 +151,7 @@ class ItemFrame extends Flowable{ return true; } - $this->level->setBlock($this, $this); + $this->world->setBlock($this, $this); return true; } @@ -161,16 +161,16 @@ class ItemFrame extends Flowable{ return false; } if(lcg_value() <= $this->itemDropChance){ - $this->level->dropItem($this->add(0.5, 0.5, 0.5), $this->getFramedItem()); + $this->world->dropItem($this->add(0.5, 0.5, 0.5), $this->getFramedItem()); } $this->setFramedItem(null); - $this->level->setBlock($this, $this); + $this->world->setBlock($this, $this); return true; } public function onNearbyBlockChange() : void{ if(!$this->getSide(Facing::opposite($this->facing))->isSolid()){ - $this->level->useBreakOn($this); + $this->world->useBreakOn($this); } } diff --git a/src/pocketmine/block/Ladder.php b/src/pocketmine/block/Ladder.php index 35df7a25f..2c8023a53 100644 --- a/src/pocketmine/block/Ladder.php +++ b/src/pocketmine/block/Ladder.php @@ -87,7 +87,7 @@ class Ladder extends Transparent{ public function onNearbyBlockChange() : void{ if(!$this->getSide(Facing::opposite($this->facing))->isSolid()){ //Replace with common break method - $this->level->useBreakOn($this); + $this->world->useBreakOn($this); } } diff --git a/src/pocketmine/block/Lava.php b/src/pocketmine/block/Lava.php index 388d441d8..7b3a2a074 100644 --- a/src/pocketmine/block/Lava.php +++ b/src/pocketmine/block/Lava.php @@ -27,9 +27,9 @@ use pocketmine\entity\Entity; use pocketmine\event\entity\EntityCombustByBlockEvent; use pocketmine\event\entity\EntityDamageByBlockEvent; use pocketmine\event\entity\EntityDamageEvent; -use pocketmine\level\sound\BucketEmptyLavaSound; -use pocketmine\level\sound\BucketFillLavaSound; -use pocketmine\level\sound\Sound; +use pocketmine\world\sound\BucketEmptyLavaSound; +use pocketmine\world\sound\BucketFillLavaSound; +use pocketmine\world\sound\Sound; use pocketmine\math\Facing; class Lava extends Liquid{ diff --git a/src/pocketmine/block/Leaves.php b/src/pocketmine/block/Leaves.php index e96f16b04..e594171b7 100644 --- a/src/pocketmine/block/Leaves.php +++ b/src/pocketmine/block/Leaves.php @@ -27,10 +27,10 @@ use pocketmine\block\utils\TreeType; use pocketmine\event\block\LeavesDecayEvent; use pocketmine\item\Item; use pocketmine\item\ItemFactory; -use pocketmine\level\Level; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; +use pocketmine\world\World; use function mt_rand; class Leaves extends Transparent{ @@ -74,7 +74,7 @@ class Leaves extends Transparent{ protected function findLog(Block $pos, array &$visited = [], int $distance = 0) : bool{ - $index = Level::blockHash($pos->x, $pos->y, $pos->z); + $index = World::blockHash($pos->x, $pos->y, $pos->z); if(isset($visited[$index])){ return false; } @@ -98,7 +98,7 @@ class Leaves extends Transparent{ public function onNearbyBlockChange() : void{ if(!$this->noDecay and !$this->checkDecay){ $this->checkDecay = true; - $this->getLevel()->setBlock($this, $this, false); + $this->getWorld()->setBlock($this, $this, false); } } @@ -112,9 +112,9 @@ class Leaves extends Transparent{ $ev->call(); if($ev->isCancelled() or $this->findLog($this)){ $this->checkDecay = false; - $this->getLevel()->setBlock($this, $this, false); + $this->getWorld()->setBlock($this, $this, false); }else{ - $this->getLevel()->useBreakOn($this); + $this->getWorld()->useBreakOn($this); } } } diff --git a/src/pocketmine/block/Lever.php b/src/pocketmine/block/Lever.php index 98d63e299..4c925ac6b 100644 --- a/src/pocketmine/block/Lever.php +++ b/src/pocketmine/block/Lever.php @@ -25,11 +25,11 @@ namespace pocketmine\block; use pocketmine\block\utils\BlockDataValidator; use pocketmine\item\Item; -use pocketmine\level\sound\RedstonePowerOffSound; -use pocketmine\level\sound\RedstonePowerOnSound; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; +use pocketmine\world\sound\RedstonePowerOffSound; +use pocketmine\world\sound\RedstonePowerOnSound; class Lever extends Flowable{ protected const BOTTOM = 0; @@ -106,14 +106,14 @@ class Lever extends Flowable{ } if(!$this->getSide($face)->isSolid()){ - $this->level->useBreakOn($this); + $this->world->useBreakOn($this); } } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->powered = !$this->powered; - $this->level->setBlock($this, $this); - $this->level->addSound( + $this->world->setBlock($this, $this); + $this->world->addSound( $this->add(0.5, 0.5, 0.5), $this->powered ? new RedstonePowerOnSound() : new RedstonePowerOffSound() ); diff --git a/src/pocketmine/block/Liquid.php b/src/pocketmine/block/Liquid.php index c983267bf..29a5dd22f 100644 --- a/src/pocketmine/block/Liquid.php +++ b/src/pocketmine/block/Liquid.php @@ -28,11 +28,11 @@ use pocketmine\entity\Entity; use pocketmine\event\block\BlockFormEvent; use pocketmine\event\block\BlockSpreadEvent; use pocketmine\item\Item; -use pocketmine\level\Level; -use pocketmine\level\sound\FizzSound; -use pocketmine\level\sound\Sound; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Vector3; +use pocketmine\world\sound\FizzSound; +use pocketmine\world\sound\Sound; +use pocketmine\world\World; use function array_fill; use function lcg_value; use function min; @@ -189,7 +189,7 @@ abstract class Liquid extends Transparent{ }elseif($j === 3){ ++$z; } - $sideBlock = $this->level->getBlockAt($x, $y, $z); + $sideBlock = $this->world->getBlockAt($x, $y, $z); $blockDecay = $this->getEffectiveFlowDecay($sideBlock); if($blockDecay < 0){ @@ -197,7 +197,7 @@ abstract class Liquid extends Transparent{ continue; } - $blockDecay = $this->getEffectiveFlowDecay($this->level->getBlockAt($x, $y - 1, $z)); + $blockDecay = $this->getEffectiveFlowDecay($this->world->getBlockAt($x, $y - 1, $z)); if($blockDecay >= 0){ $realDecay = $blockDecay - ($decay - 8); @@ -217,14 +217,14 @@ abstract class Liquid extends Transparent{ if($this->falling){ if( - !$this->canFlowInto($this->level->getBlockAt($this->x, $this->y, $this->z - 1)) or - !$this->canFlowInto($this->level->getBlockAt($this->x, $this->y, $this->z + 1)) or - !$this->canFlowInto($this->level->getBlockAt($this->x - 1, $this->y, $this->z)) or - !$this->canFlowInto($this->level->getBlockAt($this->x + 1, $this->y, $this->z)) or - !$this->canFlowInto($this->level->getBlockAt($this->x, $this->y + 1, $this->z - 1)) or - !$this->canFlowInto($this->level->getBlockAt($this->x, $this->y + 1, $this->z + 1)) or - !$this->canFlowInto($this->level->getBlockAt($this->x - 1, $this->y + 1, $this->z)) or - !$this->canFlowInto($this->level->getBlockAt($this->x + 1, $this->y + 1, $this->z)) + !$this->canFlowInto($this->world->getBlockAt($this->x, $this->y, $this->z - 1)) or + !$this->canFlowInto($this->world->getBlockAt($this->x, $this->y, $this->z + 1)) or + !$this->canFlowInto($this->world->getBlockAt($this->x - 1, $this->y, $this->z)) or + !$this->canFlowInto($this->world->getBlockAt($this->x + 1, $this->y, $this->z)) or + !$this->canFlowInto($this->world->getBlockAt($this->x, $this->y + 1, $this->z - 1)) or + !$this->canFlowInto($this->world->getBlockAt($this->x, $this->y + 1, $this->z + 1)) or + !$this->canFlowInto($this->world->getBlockAt($this->x - 1, $this->y + 1, $this->z)) or + !$this->canFlowInto($this->world->getBlockAt($this->x + 1, $this->y + 1, $this->z)) ){ $vector = $vector->normalize()->add(0, -6, 0); } @@ -255,7 +255,7 @@ abstract class Liquid extends Transparent{ public function onNearbyBlockChange() : void{ $this->checkForHarden(); - $this->level->scheduleDelayedBlockUpdate($this, $this->tickRate()); + $this->world->scheduleDelayedBlockUpdate($this, $this->tickRate()); } public function onScheduledUpdate() : void{ @@ -264,10 +264,10 @@ abstract class Liquid extends Transparent{ if(!$this->isSource()){ $smallestFlowDecay = -100; $this->adjacentSources = 0; - $smallestFlowDecay = $this->getSmallestFlowDecay($this->level->getBlockAt($this->x, $this->y, $this->z - 1), $smallestFlowDecay); - $smallestFlowDecay = $this->getSmallestFlowDecay($this->level->getBlockAt($this->x, $this->y, $this->z + 1), $smallestFlowDecay); - $smallestFlowDecay = $this->getSmallestFlowDecay($this->level->getBlockAt($this->x - 1, $this->y, $this->z), $smallestFlowDecay); - $smallestFlowDecay = $this->getSmallestFlowDecay($this->level->getBlockAt($this->x + 1, $this->y, $this->z), $smallestFlowDecay); + $smallestFlowDecay = $this->getSmallestFlowDecay($this->world->getBlockAt($this->x, $this->y, $this->z - 1), $smallestFlowDecay); + $smallestFlowDecay = $this->getSmallestFlowDecay($this->world->getBlockAt($this->x, $this->y, $this->z + 1), $smallestFlowDecay); + $smallestFlowDecay = $this->getSmallestFlowDecay($this->world->getBlockAt($this->x - 1, $this->y, $this->z), $smallestFlowDecay); + $smallestFlowDecay = $this->getSmallestFlowDecay($this->world->getBlockAt($this->x + 1, $this->y, $this->z), $smallestFlowDecay); $newDecay = $smallestFlowDecay + $multiplier; $falling = false; @@ -276,12 +276,12 @@ abstract class Liquid extends Transparent{ $newDecay = -1; } - if($this->getEffectiveFlowDecay($this->level->getBlockAt($this->x, $this->y + 1, $this->z)) >= 0){ + if($this->getEffectiveFlowDecay($this->world->getBlockAt($this->x, $this->y + 1, $this->z)) >= 0){ $falling = true; } if($this->adjacentSources >= 2 and $this instanceof Water){ - $bottomBlock = $this->level->getBlockAt($this->x, $this->y - 1, $this->z); + $bottomBlock = $this->world->getBlockAt($this->x, $this->y - 1, $this->z); if($bottomBlock->isSolid() or ($bottomBlock instanceof Water and $bottomBlock->isSource())){ $newDecay = 0; $falling = false; @@ -290,17 +290,17 @@ abstract class Liquid extends Transparent{ if($falling !== $this->falling or (!$falling and $newDecay !== $this->decay)){ if(!$falling and $newDecay < 0){ - $this->level->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR)); + $this->world->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR)); return; } $this->falling = $falling; $this->decay = $falling ? 0 : $newDecay; - $this->level->setBlock($this, $this); //local block update will cause an update to be scheduled + $this->world->setBlock($this, $this); //local block update will cause an update to be scheduled } } - $bottomBlock = $this->level->getBlockAt($this->x, $this->y - 1, $this->z); + $bottomBlock = $this->world->getBlockAt($this->x, $this->y - 1, $this->z); $this->flowIntoBlock($bottomBlock, 0, true); @@ -315,19 +315,19 @@ abstract class Liquid extends Transparent{ $flags = $this->getOptimalFlowDirections(); if($flags[0]){ - $this->flowIntoBlock($this->level->getBlockAt($this->x - 1, $this->y, $this->z), $adjacentDecay, false); + $this->flowIntoBlock($this->world->getBlockAt($this->x - 1, $this->y, $this->z), $adjacentDecay, false); } if($flags[1]){ - $this->flowIntoBlock($this->level->getBlockAt($this->x + 1, $this->y, $this->z), $adjacentDecay, false); + $this->flowIntoBlock($this->world->getBlockAt($this->x + 1, $this->y, $this->z), $adjacentDecay, false); } if($flags[2]){ - $this->flowIntoBlock($this->level->getBlockAt($this->x, $this->y, $this->z - 1), $adjacentDecay, false); + $this->flowIntoBlock($this->world->getBlockAt($this->x, $this->y, $this->z - 1), $adjacentDecay, false); } if($flags[3]){ - $this->flowIntoBlock($this->level->getBlockAt($this->x, $this->y, $this->z + 1), $adjacentDecay, false); + $this->flowIntoBlock($this->world->getBlockAt($this->x, $this->y, $this->z + 1), $adjacentDecay, false); } } } @@ -345,10 +345,10 @@ abstract class Liquid extends Transparent{ $ev->call(); if(!$ev->isCancelled()){ if($block->getId() > 0){ - $this->level->useBreakOn($block); + $this->world->useBreakOn($block); } - $this->level->setBlock($block, $ev->getNewState()); + $this->world->setBlock($block, $ev->getNewState()); } } } @@ -375,11 +375,11 @@ abstract class Liquid extends Transparent{ ++$z; } - if(!isset($this->flowCostVisited[$hash = Level::blockHash($x, $y, $z)])){ - $blockSide = $this->level->getBlockAt($x, $y, $z); + if(!isset($this->flowCostVisited[$hash = World::blockHash($x, $y, $z)])){ + $blockSide = $this->world->getBlockAt($x, $y, $z); if(!$this->canFlowInto($blockSide)){ $this->flowCostVisited[$hash] = self::BLOCKED; - }elseif($this->level->getBlockAt($x, $y - 1, $z)->canBeFlowedInto()){ + }elseif($this->world->getBlockAt($x, $y - 1, $z)->canBeFlowedInto()){ $this->flowCostVisited[$hash] = self::CAN_FLOW_DOWN; }else{ $this->flowCostVisited[$hash] = self::CAN_FLOW; @@ -428,16 +428,16 @@ abstract class Liquid extends Transparent{ }elseif($j === 3){ ++$z; } - $block = $this->level->getBlockAt($x, $y, $z); + $block = $this->world->getBlockAt($x, $y, $z); if(!$this->canFlowInto($block)){ - $this->flowCostVisited[Level::blockHash($x, $y, $z)] = self::BLOCKED; + $this->flowCostVisited[World::blockHash($x, $y, $z)] = self::BLOCKED; continue; - }elseif($this->level->getBlockAt($x, $y - 1, $z)->canBeFlowedInto()){ - $this->flowCostVisited[Level::blockHash($x, $y, $z)] = self::CAN_FLOW_DOWN; + }elseif($this->world->getBlockAt($x, $y - 1, $z)->canBeFlowedInto()){ + $this->flowCostVisited[World::blockHash($x, $y, $z)] = self::CAN_FLOW_DOWN; $flowCost[$j] = $maxCost = 0; }elseif($maxCost > 0){ - $this->flowCostVisited[Level::blockHash($x, $y, $z)] = self::CAN_FLOW; + $this->flowCostVisited[World::blockHash($x, $y, $z)] = self::CAN_FLOW; $flowCost[$j] = $this->calculateFlowCost($x, $y, $z, 1, $maxCost, $j ^ 0x01, $j ^ 0x01); $maxCost = min($maxCost, $flowCost[$j]); } @@ -480,13 +480,13 @@ abstract class Liquid extends Transparent{ $ev = new BlockFormEvent($this, $result); $ev->call(); if(!$ev->isCancelled()){ - $this->level->setBlock($this, $ev->getNewState()); - $this->level->addSound($this->add(0.5, 0.5, 0.5), new FizzSound(2.6 + (lcg_value() - lcg_value()) * 0.8)); + $this->world->setBlock($this, $ev->getNewState()); + $this->world->addSound($this->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->level->isInWorld($block->x, $block->y, $block->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->world->isInWorld($block->x, $block->y, $block->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/pocketmine/block/Mycelium.php b/src/pocketmine/block/Mycelium.php index 5870822c2..1271f0785 100644 --- a/src/pocketmine/block/Mycelium.php +++ b/src/pocketmine/block/Mycelium.php @@ -54,13 +54,13 @@ class Mycelium extends Solid{ $x = mt_rand($this->x - 1, $this->x + 1); $y = mt_rand($this->y - 2, $this->y + 2); $z = mt_rand($this->z - 1, $this->z + 1); - $block = $this->getLevel()->getBlockAt($x, $y, $z); + $block = $this->getWorld()->getBlockAt($x, $y, $z); if($block->getId() === BlockLegacyIds::DIRT){ if($block->getSide(Facing::UP) instanceof Transparent){ $ev = new BlockSpreadEvent($block, $this, BlockFactory::get(BlockLegacyIds::MYCELIUM)); $ev->call(); if(!$ev->isCancelled()){ - $this->getLevel()->setBlock($block, $ev->getNewState()); + $this->getWorld()->setBlock($block, $ev->getNewState()); } } } diff --git a/src/pocketmine/block/NetherWartPlant.php b/src/pocketmine/block/NetherWartPlant.php index b1c8661ed..6d14c1c43 100644 --- a/src/pocketmine/block/NetherWartPlant.php +++ b/src/pocketmine/block/NetherWartPlant.php @@ -60,7 +60,7 @@ class NetherWartPlant extends Flowable{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::SOUL_SAND){ - $this->getLevel()->useBreakOn($this); + $this->getWorld()->useBreakOn($this); } } @@ -75,7 +75,7 @@ class NetherWartPlant extends Flowable{ $ev = new BlockGrowEvent($this, $block); $ev->call(); if(!$ev->isCancelled()){ - $this->getLevel()->setBlock($this, $ev->getNewState()); + $this->getWorld()->setBlock($this, $ev->getNewState()); } } } diff --git a/src/pocketmine/block/RedMushroom.php b/src/pocketmine/block/RedMushroom.php index 35f832da6..1f6a98bad 100644 --- a/src/pocketmine/block/RedMushroom.php +++ b/src/pocketmine/block/RedMushroom.php @@ -36,7 +36,7 @@ class RedMushroom extends Flowable{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->isTransparent()){ - $this->getLevel()->useBreakOn($this); + $this->getWorld()->useBreakOn($this); } } diff --git a/src/pocketmine/block/RedstoneComparator.php b/src/pocketmine/block/RedstoneComparator.php index 2b8121fd4..aea91205c 100644 --- a/src/pocketmine/block/RedstoneComparator.php +++ b/src/pocketmine/block/RedstoneComparator.php @@ -70,7 +70,7 @@ class RedstoneComparator extends Flowable{ public function readStateFromWorld() : void{ parent::readStateFromWorld(); - $tile = $this->level->getTile($this); + $tile = $this->world->getTile($this); if($tile instanceof Comparator){ $this->signalStrength = $tile->getSignalStrength(); } @@ -78,7 +78,7 @@ class RedstoneComparator extends Flowable{ public function writeStateToWorld() : void{ parent::writeStateToWorld(); - $tile = $this->level->getTile($this); + $tile = $this->world->getTile($this); assert($tile instanceof Comparator); $tile->setSignalStrength($this->signalStrength); } @@ -158,13 +158,13 @@ class RedstoneComparator extends Flowable{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->isSubtractMode = !$this->isSubtractMode; - $this->level->setBlock($this, $this); + $this->world->setBlock($this, $this); return true; } public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->isTransparent()){ - $this->level->useBreakOn($this); + $this->world->useBreakOn($this); } } diff --git a/src/pocketmine/block/RedstoneOre.php b/src/pocketmine/block/RedstoneOre.php index 66c2f085e..33f8ffb3a 100644 --- a/src/pocketmine/block/RedstoneOre.php +++ b/src/pocketmine/block/RedstoneOre.php @@ -72,13 +72,13 @@ class RedstoneOre extends Solid{ } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - return $this->getLevel()->setBlock($this, $this, false); + return $this->getWorld()->setBlock($this, $this, false); } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if(!$this->lit){ $this->lit = true; - $this->getLevel()->setBlock($this, $this); //no return here - this shouldn't prevent block placement + $this->getWorld()->setBlock($this, $this); //no return here - this shouldn't prevent block placement } return false; } @@ -86,7 +86,7 @@ class RedstoneOre extends Solid{ public function onNearbyBlockChange() : void{ if(!$this->lit){ $this->lit = true; - $this->getLevel()->setBlock($this, $this); + $this->getWorld()->setBlock($this, $this); } } @@ -97,7 +97,7 @@ class RedstoneOre extends Solid{ public function onRandomTick() : void{ if($this->lit){ $this->lit = false; - $this->level->setBlock($this, $this); + $this->world->setBlock($this, $this); } } diff --git a/src/pocketmine/block/RedstoneRepeater.php b/src/pocketmine/block/RedstoneRepeater.php index 651607d0e..6f7a4070f 100644 --- a/src/pocketmine/block/RedstoneRepeater.php +++ b/src/pocketmine/block/RedstoneRepeater.php @@ -98,13 +98,13 @@ class RedstoneRepeater extends Flowable{ if(++$this->delay > 4){ $this->delay = 1; } - $this->level->setBlock($this, $this); + $this->world->setBlock($this, $this); return true; } public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->isTransparent()){ - $this->level->useBreakOn($this); + $this->world->useBreakOn($this); } } diff --git a/src/pocketmine/block/Sapling.php b/src/pocketmine/block/Sapling.php index 86d9c5497..06a164e11 100644 --- a/src/pocketmine/block/Sapling.php +++ b/src/pocketmine/block/Sapling.php @@ -26,11 +26,11 @@ namespace pocketmine\block; use pocketmine\block\utils\TreeType; use pocketmine\item\Fertilizer; use pocketmine\item\Item; -use pocketmine\level\generator\object\Tree; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\utils\Random; +use pocketmine\world\generator\object\Tree; use function mt_rand; class Sapling extends Flowable{ @@ -68,7 +68,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->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->treeType); + Tree::growTree($this->getWorld(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->treeType); $item->pop(); @@ -80,7 +80,7 @@ class Sapling extends Flowable{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->isTransparent()){ - $this->getLevel()->useBreakOn($this); + $this->getWorld()->useBreakOn($this); } } @@ -89,12 +89,12 @@ class Sapling extends Flowable{ } public function onRandomTick() : void{ - if($this->level->getFullLightAt($this->x, $this->y, $this->z) >= 8 and mt_rand(1, 7) === 1){ + if($this->world->getFullLightAt($this->x, $this->y, $this->z) >= 8 and mt_rand(1, 7) === 1){ if($this->ready){ - Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->treeType); + Tree::growTree($this->getWorld(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->treeType); }else{ $this->ready = true; - $this->getLevel()->setBlock($this, $this); + $this->getWorld()->setBlock($this, $this); } } } diff --git a/src/pocketmine/block/Sign.php b/src/pocketmine/block/Sign.php index 0b1a9e416..4a51f3fda 100644 --- a/src/pocketmine/block/Sign.php +++ b/src/pocketmine/block/Sign.php @@ -84,7 +84,7 @@ class Sign extends Transparent{ public function readStateFromWorld() : void{ parent::readStateFromWorld(); - $tile = $this->level->getTile($this); + $tile = $this->world->getTile($this); if($tile instanceof TileSign){ $this->text = $tile->getText(); } @@ -92,7 +92,7 @@ class Sign extends Transparent{ public function writeStateToWorld() : void{ parent::writeStateToWorld(); - $tile = $this->level->getTile($this); + $tile = $this->world->getTile($this); assert($tile instanceof TileSign); $tile->setText($this->text); } @@ -128,7 +128,7 @@ class Sign extends Transparent{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::opposite($this->facing))->getId() === BlockLegacyIds::AIR){ - $this->getLevel()->useBreakOn($this); + $this->getWorld()->useBreakOn($this); } } @@ -169,7 +169,7 @@ class Sign extends Transparent{ $ev->call(); if(!$ev->isCancelled()){ $this->text = clone $ev->getNewText(); - $this->level->setBlock($this, $this); + $this->world->setBlock($this, $this); return true; } diff --git a/src/pocketmine/block/Skull.php b/src/pocketmine/block/Skull.php index 68e564a82..99c6b9359 100644 --- a/src/pocketmine/block/Skull.php +++ b/src/pocketmine/block/Skull.php @@ -65,7 +65,7 @@ class Skull extends Flowable{ public function readStateFromWorld() : void{ parent::readStateFromWorld(); - $tile = $this->level->getTile($this); + $tile = $this->world->getTile($this); if($tile instanceof TileSkull){ $this->skullType = $tile->getSkullType(); $this->rotation = $tile->getRotation(); @@ -75,7 +75,7 @@ class Skull extends Flowable{ public function writeStateToWorld() : void{ parent::writeStateToWorld(); //extra block properties storage hack - $tile = $this->level->getTile($this); + $tile = $this->world->getTile($this); assert($tile instanceof TileSkull); $tile->setRotation($this->rotation); $tile->setSkullType($this->skullType); diff --git a/src/pocketmine/block/SnowLayer.php b/src/pocketmine/block/SnowLayer.php index f7a4a2bee..6fa335de9 100644 --- a/src/pocketmine/block/SnowLayer.php +++ b/src/pocketmine/block/SnowLayer.php @@ -95,8 +95,8 @@ class SnowLayer extends Flowable implements Fallable{ } public function onRandomTick() : void{ - if($this->level->getBlockLightAt($this->x, $this->y, $this->z) >= 12){ - $this->getLevel()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR), false); + if($this->world->getBlockLightAt($this->x, $this->y, $this->z) >= 12){ + $this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR), false); } } diff --git a/src/pocketmine/block/Stem.php b/src/pocketmine/block/Stem.php index 397bcd8e5..0bc2b478b 100644 --- a/src/pocketmine/block/Stem.php +++ b/src/pocketmine/block/Stem.php @@ -41,7 +41,7 @@ abstract class Stem extends Crops{ $ev = new BlockGrowEvent($this, $block); $ev->call(); if(!$ev->isCancelled()){ - $this->getLevel()->setBlock($this, $ev->getNewState()); + $this->getWorld()->setBlock($this, $ev->getNewState()); } }else{ $grow = $this->getPlant(); @@ -57,7 +57,7 @@ abstract class Stem extends Crops{ $ev = new BlockGrowEvent($side, $grow); $ev->call(); if(!$ev->isCancelled()){ - $this->getLevel()->setBlock($side, $ev->getNewState()); + $this->getWorld()->setBlock($side, $ev->getNewState()); } } } diff --git a/src/pocketmine/block/Sugarcane.php b/src/pocketmine/block/Sugarcane.php index 6823a8eb9..9c2abd907 100644 --- a/src/pocketmine/block/Sugarcane.php +++ b/src/pocketmine/block/Sugarcane.php @@ -52,20 +52,20 @@ class Sugarcane extends Flowable{ if($item instanceof Fertilizer){ if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::SUGARCANE_BLOCK){ for($y = 1; $y < 3; ++$y){ - $b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z); + $b = $this->getWorld()->getBlockAt($this->x, $this->y + $y, $this->z); if($b->getId() === BlockLegacyIds::AIR){ $ev = new BlockGrowEvent($b, BlockFactory::get(BlockLegacyIds::SUGARCANE_BLOCK)); $ev->call(); if($ev->isCancelled()){ break; } - $this->getLevel()->setBlock($b, $ev->getNewState()); + $this->getWorld()->setBlock($b, $ev->getNewState()); }else{ break; } } $this->age = 0; - $this->getLevel()->setBlock($this, $this); + $this->getWorld()->setBlock($this, $this); } $item->pop(); @@ -79,7 +79,7 @@ class Sugarcane extends Flowable{ public function onNearbyBlockChange() : void{ $down = $this->getSide(Facing::DOWN); if($down->isTransparent() and $down->getId() !== BlockLegacyIds::SUGARCANE_BLOCK){ - $this->getLevel()->useBreakOn($this); + $this->getWorld()->useBreakOn($this); } } @@ -91,17 +91,17 @@ class Sugarcane extends Flowable{ if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::SUGARCANE_BLOCK){ if($this->age === 15){ for($y = 1; $y < 3; ++$y){ - $b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z); + $b = $this->getWorld()->getBlockAt($this->x, $this->y + $y, $this->z); if($b->getId() === BlockLegacyIds::AIR){ - $this->getLevel()->setBlock($b, BlockFactory::get(BlockLegacyIds::SUGARCANE_BLOCK)); + $this->getWorld()->setBlock($b, BlockFactory::get(BlockLegacyIds::SUGARCANE_BLOCK)); break; } } $this->age = 0; - $this->getLevel()->setBlock($this, $this); + $this->getWorld()->setBlock($this, $this); }else{ ++$this->age; - $this->getLevel()->setBlock($this, $this); + $this->getWorld()->setBlock($this, $this); } } } diff --git a/src/pocketmine/block/TNT.php b/src/pocketmine/block/TNT.php index 226eff137..c968e6a50 100644 --- a/src/pocketmine/block/TNT.php +++ b/src/pocketmine/block/TNT.php @@ -90,14 +90,14 @@ class TNT extends Solid{ } public function ignite(int $fuse = 80) : void{ - $this->getLevel()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR)); + $this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR)); $mot = (new Random())->nextSignedFloat() * M_PI * 2; $nbt = EntityFactory::createBaseNBT($this->add(0.5, 0, 0.5), new Vector3(-sin($mot) * 0.02, 0.2, -cos($mot) * 0.02)); $nbt->setShort("Fuse", $fuse); /** @var PrimedTNT $tnt */ - $tnt = EntityFactory::create(PrimedTNT::class, $this->getLevel(), $nbt); + $tnt = EntityFactory::create(PrimedTNT::class, $this->getWorld(), $nbt); $tnt->spawnToAll(); } diff --git a/src/pocketmine/block/TallGrass.php b/src/pocketmine/block/TallGrass.php index eaf36f9b4..41a67eb11 100644 --- a/src/pocketmine/block/TallGrass.php +++ b/src/pocketmine/block/TallGrass.php @@ -47,7 +47,7 @@ class TallGrass extends Flowable{ public function onNearbyBlockChange() : void{ if($this->getSide(Facing::DOWN)->isTransparent()){ //Replace with common break method - $this->level->useBreakOn($this); + $this->world->useBreakOn($this); } } diff --git a/src/pocketmine/block/Torch.php b/src/pocketmine/block/Torch.php index 4a45c706f..e5a5533b6 100644 --- a/src/pocketmine/block/Torch.php +++ b/src/pocketmine/block/Torch.php @@ -55,7 +55,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->getLevel()->useBreakOn($this); + $this->getWorld()->useBreakOn($this); } } diff --git a/src/pocketmine/block/Trapdoor.php b/src/pocketmine/block/Trapdoor.php index c815b85ee..0c063eae1 100644 --- a/src/pocketmine/block/Trapdoor.php +++ b/src/pocketmine/block/Trapdoor.php @@ -25,11 +25,11 @@ namespace pocketmine\block; use pocketmine\block\utils\BlockDataValidator; use pocketmine\item\Item; -use pocketmine\level\sound\DoorSound; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; +use pocketmine\world\sound\DoorSound; class Trapdoor extends Transparent{ private const MASK_UPPER = 0x04; @@ -79,8 +79,8 @@ class Trapdoor extends Transparent{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->open = !$this->open; - $this->level->setBlock($this, $this); - $this->level->addSound($this, new DoorSound()); + $this->world->setBlock($this, $this); + $this->world->addSound($this, new DoorSound()); return true; } diff --git a/src/pocketmine/block/Vine.php b/src/pocketmine/block/Vine.php index 27b59636a..1fa2112b2 100644 --- a/src/pocketmine/block/Vine.php +++ b/src/pocketmine/block/Vine.php @@ -170,9 +170,9 @@ class Vine extends Flowable{ if($changed){ if(empty($this->faces)){ - $this->level->useBreakOn($this); + $this->world->useBreakOn($this); }else{ - $this->level->setBlock($this, $this); + $this->world->setBlock($this, $this); } } } diff --git a/src/pocketmine/block/Water.php b/src/pocketmine/block/Water.php index 5423847bc..c4d9762a2 100644 --- a/src/pocketmine/block/Water.php +++ b/src/pocketmine/block/Water.php @@ -24,9 +24,9 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\entity\Entity; -use pocketmine\level\sound\BucketEmptyWaterSound; -use pocketmine\level\sound\BucketFillWaterSound; -use pocketmine\level\sound\Sound; +use pocketmine\world\sound\BucketEmptyWaterSound; +use pocketmine\world\sound\BucketFillWaterSound; +use pocketmine\world\sound\Sound; class Water extends Liquid{ diff --git a/src/pocketmine/block/WaterLily.php b/src/pocketmine/block/WaterLily.php index 9719427b2..00eb99f51 100644 --- a/src/pocketmine/block/WaterLily.php +++ b/src/pocketmine/block/WaterLily.php @@ -52,7 +52,7 @@ class WaterLily extends Flowable{ public function onNearbyBlockChange() : void{ if(!($this->getSide(Facing::DOWN) instanceof Water)){ - $this->getLevel()->useBreakOn($this); + $this->getWorld()->useBreakOn($this); } } } diff --git a/src/pocketmine/block/utils/FallableTrait.php b/src/pocketmine/block/utils/FallableTrait.php index 451af2221..86b9bfee4 100644 --- a/src/pocketmine/block/utils/FallableTrait.php +++ b/src/pocketmine/block/utils/FallableTrait.php @@ -29,8 +29,8 @@ use pocketmine\block\Fire; use pocketmine\block\Liquid; use pocketmine\entity\EntityFactory; use pocketmine\entity\object\FallingBlock; -use pocketmine\level\Position; use pocketmine\math\Facing; +use pocketmine\world\Position; /** * This trait handles falling behaviour for blocks that need them. @@ -47,16 +47,16 @@ trait FallableTrait{ public function onNearbyBlockChange() : void{ $pos = $this->asPosition(); - $down = $pos->level->getBlock($pos->getSide(Facing::DOWN)); + $down = $pos->world->getBlock($pos->getSide(Facing::DOWN)); if($down->getId() === BlockLegacyIds::AIR or $down instanceof Liquid or $down instanceof Fire){ - $pos->level->setBlock($pos, BlockFactory::get(BlockLegacyIds::AIR)); + $pos->world->setBlock($pos, BlockFactory::get(BlockLegacyIds::AIR)); $nbt = EntityFactory::createBaseNBT($pos->add(0.5, 0, 0.5)); $nbt->setInt("TileID", $this->getId()); $nbt->setByte("Data", $this->getMeta()); /** @var FallingBlock $fall */ - $fall = EntityFactory::create(FallingBlock::class, $pos->getLevel(), $nbt); + $fall = EntityFactory::create(FallingBlock::class, $pos->getWorld(), $nbt); $fall->spawnToAll(); } } diff --git a/src/pocketmine/command/defaults/DifficultyCommand.php b/src/pocketmine/command/defaults/DifficultyCommand.php index 8addfb0a8..9b2bbd602 100644 --- a/src/pocketmine/command/defaults/DifficultyCommand.php +++ b/src/pocketmine/command/defaults/DifficultyCommand.php @@ -27,7 +27,7 @@ use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\command\utils\InvalidCommandSyntaxException; use pocketmine\lang\TranslationContainer; -use pocketmine\level\Level; +use pocketmine\world\World; use function count; class DifficultyCommand extends VanillaCommand{ @@ -50,18 +50,18 @@ class DifficultyCommand extends VanillaCommand{ throw new InvalidCommandSyntaxException(); } - $difficulty = Level::getDifficultyFromString($args[0]); + $difficulty = World::getDifficultyFromString($args[0]); if($sender->getServer()->isHardcore()){ - $difficulty = Level::DIFFICULTY_HARD; + $difficulty = World::DIFFICULTY_HARD; } if($difficulty !== -1){ $sender->getServer()->setConfigInt("difficulty", $difficulty); //TODO: add per-world support - foreach($sender->getServer()->getLevelManager()->getLevels() as $level){ - $level->setDifficulty($difficulty); + foreach($sender->getServer()->getWorldManager()->getWorlds() as $world){ + $world->setDifficulty($difficulty); } Command::broadcastCommandMessage($sender, new TranslationContainer("commands.difficulty.success", [$difficulty])); diff --git a/src/pocketmine/command/defaults/GarbageCollectorCommand.php b/src/pocketmine/command/defaults/GarbageCollectorCommand.php index 6058f160c..1fc6b7f73 100644 --- a/src/pocketmine/command/defaults/GarbageCollectorCommand.php +++ b/src/pocketmine/command/defaults/GarbageCollectorCommand.php @@ -51,13 +51,13 @@ class GarbageCollectorCommand extends VanillaCommand{ $memory = memory_get_usage(); - foreach($sender->getServer()->getLevelManager()->getLevels() as $level){ - $diff = [count($level->getChunks()), count($level->getEntities())]; - $level->doChunkGarbageCollection(); - $level->unloadChunks(true); - $chunksCollected += $diff[0] - count($level->getChunks()); - $entitiesCollected += $diff[1] - count($level->getEntities()); - $level->clearCache(true); + foreach($sender->getServer()->getWorldManager()->getWorlds() as $world){ + $diff = [count($world->getChunks()), count($world->getEntities())]; + $world->doChunkGarbageCollection(); + $world->unloadChunks(true); + $chunksCollected += $diff[0] - count($world->getChunks()); + $entitiesCollected += $diff[1] - count($world->getEntities()); + $world->clearCache(true); } $cyclesCollected = $sender->getServer()->getMemoryManager()->triggerGarbageCollector(); diff --git a/src/pocketmine/command/defaults/ParticleCommand.php b/src/pocketmine/command/defaults/ParticleCommand.php index 9b4d57b7e..ddec2514b 100644 --- a/src/pocketmine/command/defaults/ParticleCommand.php +++ b/src/pocketmine/command/defaults/ParticleCommand.php @@ -29,39 +29,39 @@ use pocketmine\command\utils\InvalidCommandSyntaxException; use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\lang\TranslationContainer; -use pocketmine\level\Level; -use pocketmine\level\particle\AngryVillagerParticle; -use pocketmine\level\particle\BlockForceFieldParticle; -use pocketmine\level\particle\BubbleParticle; -use pocketmine\level\particle\CriticalParticle; -use pocketmine\level\particle\DustParticle; -use pocketmine\level\particle\EnchantmentTableParticle; -use pocketmine\level\particle\EnchantParticle; -use pocketmine\level\particle\ExplodeParticle; -use pocketmine\level\particle\FlameParticle; -use pocketmine\level\particle\HappyVillagerParticle; -use pocketmine\level\particle\HeartParticle; -use pocketmine\level\particle\HugeExplodeParticle; -use pocketmine\level\particle\HugeExplodeSeedParticle; -use pocketmine\level\particle\InkParticle; -use pocketmine\level\particle\InstantEnchantParticle; -use pocketmine\level\particle\ItemBreakParticle; -use pocketmine\level\particle\LavaDripParticle; -use pocketmine\level\particle\LavaParticle; -use pocketmine\level\particle\Particle; -use pocketmine\level\particle\PortalParticle; -use pocketmine\level\particle\RainSplashParticle; -use pocketmine\level\particle\RedstoneParticle; -use pocketmine\level\particle\SmokeParticle; -use pocketmine\level\particle\SplashParticle; -use pocketmine\level\particle\SporeParticle; -use pocketmine\level\particle\TerrainParticle; -use pocketmine\level\particle\WaterDripParticle; -use pocketmine\level\particle\WaterParticle; use pocketmine\math\Vector3; use pocketmine\Player; use pocketmine\utils\Random; use pocketmine\utils\TextFormat; +use pocketmine\world\particle\AngryVillagerParticle; +use pocketmine\world\particle\BlockForceFieldParticle; +use pocketmine\world\particle\BubbleParticle; +use pocketmine\world\particle\CriticalParticle; +use pocketmine\world\particle\DustParticle; +use pocketmine\world\particle\EnchantmentTableParticle; +use pocketmine\world\particle\EnchantParticle; +use pocketmine\world\particle\ExplodeParticle; +use pocketmine\world\particle\FlameParticle; +use pocketmine\world\particle\HappyVillagerParticle; +use pocketmine\world\particle\HeartParticle; +use pocketmine\world\particle\HugeExplodeParticle; +use pocketmine\world\particle\HugeExplodeSeedParticle; +use pocketmine\world\particle\InkParticle; +use pocketmine\world\particle\InstantEnchantParticle; +use pocketmine\world\particle\ItemBreakParticle; +use pocketmine\world\particle\LavaDripParticle; +use pocketmine\world\particle\LavaParticle; +use pocketmine\world\particle\Particle; +use pocketmine\world\particle\PortalParticle; +use pocketmine\world\particle\RainSplashParticle; +use pocketmine\world\particle\RedstoneParticle; +use pocketmine\world\particle\SmokeParticle; +use pocketmine\world\particle\SplashParticle; +use pocketmine\world\particle\SporeParticle; +use pocketmine\world\particle\TerrainParticle; +use pocketmine\world\particle\WaterDripParticle; +use pocketmine\world\particle\WaterParticle; +use pocketmine\world\World; use function count; use function explode; use function max; @@ -91,14 +91,14 @@ class ParticleCommand extends VanillaCommand{ } if($sender instanceof Player){ - $level = $sender->getLevel(); + $world = $sender->getWorld(); $pos = new Vector3( $this->getRelativeDouble($sender->getX(), $sender, $args[1]), - $this->getRelativeDouble($sender->getY(), $sender, $args[2], 0, Level::Y_MAX), + $this->getRelativeDouble($sender->getY(), $sender, $args[2], 0, World::Y_MAX), $this->getRelativeDouble($sender->getZ(), $sender, $args[3]) ); }else{ - $level = $sender->getServer()->getLevelManager()->getDefaultLevel(); + $world = $sender->getServer()->getWorldManager()->getDefaultWorld(); $pos = new Vector3((float) $args[1], (float) $args[2], (float) $args[3]); } @@ -125,7 +125,7 @@ class ParticleCommand extends VanillaCommand{ $random = new Random((int) (microtime(true) * 1000) + mt_rand()); for($i = 0; $i < $count; ++$i){ - $level->addParticle($pos->add( + $world->addParticle($pos->add( $random->nextSignedFloat() * $xd, $random->nextSignedFloat() * $yd, $random->nextSignedFloat() * $zd diff --git a/src/pocketmine/command/defaults/SaveCommand.php b/src/pocketmine/command/defaults/SaveCommand.php index 5ed458296..1949baa30 100644 --- a/src/pocketmine/command/defaults/SaveCommand.php +++ b/src/pocketmine/command/defaults/SaveCommand.php @@ -52,8 +52,8 @@ class SaveCommand extends VanillaCommand{ $player->save(); } - foreach($sender->getServer()->getLevelManager()->getLevels() as $level){ - $level->save(true); + foreach($sender->getServer()->getWorldManager()->getWorlds() as $world){ + $world->save(true); } Command::broadcastCommandMessage($sender, new TranslationContainer("pocketmine.save.success", [round(microtime(true) - $start, 3)])); diff --git a/src/pocketmine/command/defaults/SaveOffCommand.php b/src/pocketmine/command/defaults/SaveOffCommand.php index e5b8d79e3..82687867a 100644 --- a/src/pocketmine/command/defaults/SaveOffCommand.php +++ b/src/pocketmine/command/defaults/SaveOffCommand.php @@ -43,7 +43,7 @@ class SaveOffCommand extends VanillaCommand{ return true; } - $sender->getServer()->getLevelManager()->setAutoSave(false); + $sender->getServer()->getWorldManager()->setAutoSave(false); Command::broadcastCommandMessage($sender, new TranslationContainer("commands.save.disabled")); diff --git a/src/pocketmine/command/defaults/SaveOnCommand.php b/src/pocketmine/command/defaults/SaveOnCommand.php index d79f03be5..3df4808bd 100644 --- a/src/pocketmine/command/defaults/SaveOnCommand.php +++ b/src/pocketmine/command/defaults/SaveOnCommand.php @@ -43,7 +43,7 @@ class SaveOnCommand extends VanillaCommand{ return true; } - $sender->getServer()->getLevelManager()->setAutoSave(true); + $sender->getServer()->getWorldManager()->setAutoSave(true); Command::broadcastCommandMessage($sender, new TranslationContainer("commands.save.enabled")); diff --git a/src/pocketmine/command/defaults/SeedCommand.php b/src/pocketmine/command/defaults/SeedCommand.php index 5fdaa50b9..9ea9fb26f 100644 --- a/src/pocketmine/command/defaults/SeedCommand.php +++ b/src/pocketmine/command/defaults/SeedCommand.php @@ -44,9 +44,9 @@ class SeedCommand extends VanillaCommand{ } if($sender instanceof Player){ - $seed = $sender->getLevel()->getSeed(); + $seed = $sender->getWorld()->getSeed(); }else{ - $seed = $sender->getServer()->getLevelManager()->getDefaultLevel()->getSeed(); + $seed = $sender->getServer()->getWorldManager()->getDefaultWorld()->getSeed(); } $sender->sendMessage(new TranslationContainer("commands.seed.success", [$seed])); diff --git a/src/pocketmine/command/defaults/SetWorldSpawnCommand.php b/src/pocketmine/command/defaults/SetWorldSpawnCommand.php index fe50ec205..f406b6a46 100644 --- a/src/pocketmine/command/defaults/SetWorldSpawnCommand.php +++ b/src/pocketmine/command/defaults/SetWorldSpawnCommand.php @@ -51,7 +51,7 @@ class SetWorldSpawnCommand extends VanillaCommand{ if(count($args) === 0){ if($sender instanceof Player){ - $level = $sender->getLevel(); + $world = $sender->getWorld(); $pos = (new Vector3($sender->x, $sender->y, $sender->z))->round(); }else{ $sender->sendMessage(TextFormat::RED . "You can only perform this command as a player"); @@ -59,13 +59,13 @@ class SetWorldSpawnCommand extends VanillaCommand{ return true; } }elseif(count($args) === 3){ - $level = $sender->getServer()->getLevelManager()->getDefaultLevel(); + $world = $sender->getServer()->getWorldManager()->getDefaultWorld(); $pos = new Vector3($this->getInteger($sender, $args[0]), $this->getInteger($sender, $args[1]), $this->getInteger($sender, $args[2])); }else{ throw new InvalidCommandSyntaxException(); } - $level->setSpawnLocation($pos); + $world->setSpawnLocation($pos); Command::broadcastCommandMessage($sender, new TranslationContainer("commands.setworldspawn.success", [round($pos->x, 2), round($pos->y, 2), round($pos->z, 2)])); diff --git a/src/pocketmine/command/defaults/SpawnpointCommand.php b/src/pocketmine/command/defaults/SpawnpointCommand.php index 775e896f5..eac5caafa 100644 --- a/src/pocketmine/command/defaults/SpawnpointCommand.php +++ b/src/pocketmine/command/defaults/SpawnpointCommand.php @@ -27,10 +27,10 @@ use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\command\utils\InvalidCommandSyntaxException; use pocketmine\lang\TranslationContainer; -use pocketmine\level\Level; -use pocketmine\level\Position; use pocketmine\Player; use pocketmine\utils\TextFormat; +use pocketmine\world\Position; +use pocketmine\world\World; use function count; use function round; @@ -71,12 +71,12 @@ class SpawnpointCommand extends VanillaCommand{ if(count($args) === 4){ if($target->isValid()){ - $level = $target->getLevel(); - $pos = $sender instanceof Player ? $sender->getPosition() : $level->getSpawnLocation(); + $world = $target->getWorld(); + $pos = $sender instanceof Player ? $sender->getPosition() : $world->getSpawnLocation(); $x = $this->getRelativeDouble($pos->x, $sender, $args[1]); - $y = $this->getRelativeDouble($pos->y, $sender, $args[2], 0, Level::Y_MAX); + $y = $this->getRelativeDouble($pos->y, $sender, $args[2], 0, World::Y_MAX); $z = $this->getRelativeDouble($pos->z, $sender, $args[3]); - $target->setSpawn(new Position($x, $y, $z, $level)); + $target->setSpawn(new Position($x, $y, $z, $world)); Command::broadcastCommandMessage($sender, new TranslationContainer("commands.spawnpoint.success", [$target->getName(), round($x, 2), round($y, 2), round($z, 2)])); @@ -84,7 +84,7 @@ class SpawnpointCommand extends VanillaCommand{ } }elseif(count($args) <= 1){ if($sender instanceof Player){ - $pos = new Position($sender->getFloorX(), $sender->getFloorY(), $sender->getFloorZ(), $sender->getLevel()); + $pos = new Position($sender->getFloorX(), $sender->getFloorY(), $sender->getFloorZ(), $sender->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/pocketmine/command/defaults/StatusCommand.php b/src/pocketmine/command/defaults/StatusCommand.php index d937f75e0..74d22076e 100644 --- a/src/pocketmine/command/defaults/StatusCommand.php +++ b/src/pocketmine/command/defaults/StatusCommand.php @@ -107,13 +107,13 @@ class StatusCommand extends VanillaCommand{ $sender->sendMessage(TextFormat::GOLD . "Maximum memory (manager): " . TextFormat::RED . number_format(round($globalLimit, 2), 2) . " MB."); } - foreach($server->getLevelManager()->getLevels() as $level){ - $levelName = $level->getFolderName() !== $level->getDisplayName() ? " (" . $level->getDisplayName() . ")" : ""; - $timeColor = $level->getTickRateTime() > 40 ? TextFormat::RED : TextFormat::YELLOW; - $sender->sendMessage(TextFormat::GOLD . "World \"{$level->getFolderName()}\"$levelName: " . - TextFormat::RED . number_format(count($level->getChunks())) . TextFormat::GREEN . " chunks, " . - TextFormat::RED . number_format(count($level->getEntities())) . TextFormat::GREEN . " entities. " . - "Time $timeColor" . round($level->getTickRateTime(), 2) . "ms" + foreach($server->getWorldManager()->getWorlds() as $world){ + $worldName = $world->getFolderName() !== $world->getDisplayName() ? " (" . $world->getDisplayName() . ")" : ""; + $timeColor = $world->getTickRateTime() > 40 ? TextFormat::RED : TextFormat::YELLOW; + $sender->sendMessage(TextFormat::GOLD . "World \"{$world->getFolderName()}\"$worldName: " . + TextFormat::RED . number_format(count($world->getChunks())) . TextFormat::GREEN . " chunks, " . + TextFormat::RED . number_format(count($world->getEntities())) . TextFormat::GREEN . " entities. " . + "Time $timeColor" . round($world->getTickRateTime(), 2) . "ms" ); } diff --git a/src/pocketmine/command/defaults/TimeCommand.php b/src/pocketmine/command/defaults/TimeCommand.php index 0ca094c9c..ce12e7986 100644 --- a/src/pocketmine/command/defaults/TimeCommand.php +++ b/src/pocketmine/command/defaults/TimeCommand.php @@ -27,9 +27,9 @@ use pocketmine\command\Command; use pocketmine\command\CommandSender; use pocketmine\command\utils\InvalidCommandSyntaxException; use pocketmine\lang\TranslationContainer; -use pocketmine\level\Level; use pocketmine\Player; use pocketmine\utils\TextFormat; +use pocketmine\world\World; use function count; class TimeCommand extends VanillaCommand{ @@ -54,8 +54,8 @@ class TimeCommand extends VanillaCommand{ return true; } - foreach($sender->getServer()->getLevelManager()->getLevels() as $level){ - $level->startTime(); + foreach($sender->getServer()->getWorldManager()->getWorlds() as $world){ + $world->startTime(); } Command::broadcastCommandMessage($sender, "Restarted the time"); return true; @@ -65,8 +65,8 @@ class TimeCommand extends VanillaCommand{ return true; } - foreach($sender->getServer()->getLevelManager()->getLevels() as $level){ - $level->stopTime(); + foreach($sender->getServer()->getWorldManager()->getWorlds() as $world){ + $world->stopTime(); } Command::broadcastCommandMessage($sender, "Stopped the time"); return true; @@ -77,11 +77,11 @@ class TimeCommand extends VanillaCommand{ return true; } if($sender instanceof Player){ - $level = $sender->getLevel(); + $world = $sender->getWorld(); }else{ - $level = $sender->getServer()->getLevelManager()->getDefaultLevel(); + $world = $sender->getServer()->getWorldManager()->getDefaultWorld(); } - $sender->sendMessage(new TranslationContainer("commands.time.query", [$level->getTime()])); + $sender->sendMessage(new TranslationContainer("commands.time.query", [$world->getTime()])); return true; } @@ -98,15 +98,15 @@ class TimeCommand extends VanillaCommand{ } if($args[1] === "day"){ - $value = Level::TIME_DAY; + $value = World::TIME_DAY; }elseif($args[1] === "night"){ - $value = Level::TIME_NIGHT; + $value = World::TIME_NIGHT; }else{ $value = $this->getInteger($sender, $args[1], 0); } - foreach($sender->getServer()->getLevelManager()->getLevels() as $level){ - $level->setTime($value); + foreach($sender->getServer()->getWorldManager()->getWorlds() as $world){ + $world->setTime($value); } Command::broadcastCommandMessage($sender, new TranslationContainer("commands.time.set", [$value])); }elseif($args[0] === "add"){ @@ -117,8 +117,8 @@ class TimeCommand extends VanillaCommand{ } $value = $this->getInteger($sender, $args[1], 0); - foreach($sender->getServer()->getLevelManager()->getLevels() as $level){ - $level->setTime($level->getTime() + $value); + foreach($sender->getServer()->getWorldManager()->getWorlds() as $world){ + $world->setTime($world->getTime() + $value); } Command::broadcastCommandMessage($sender, new TranslationContainer("commands.time.added", [$value])); }else{ diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index ab29ea83f..71c8f5e70 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -30,15 +30,11 @@ use pocketmine\block\Block; use pocketmine\block\Water; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityDespawnEvent; -use pocketmine\event\entity\EntityLevelChangeEvent; use pocketmine\event\entity\EntityMotionEvent; use pocketmine\event\entity\EntityRegainHealthEvent; use pocketmine\event\entity\EntitySpawnEvent; use pocketmine\event\entity\EntityTeleportEvent; -use pocketmine\level\format\Chunk; -use pocketmine\level\Level; -use pocketmine\level\Location; -use pocketmine\level\Position; +use pocketmine\event\entity\EntityWorldChangeEvent; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Bearing; use pocketmine\math\Facing; @@ -67,6 +63,10 @@ use pocketmine\plugin\Plugin; use pocketmine\Server; use pocketmine\timings\Timings; use pocketmine\timings\TimingsHandler; +use pocketmine\world\format\Chunk; +use pocketmine\world\Location; +use pocketmine\world\Position; +use pocketmine\world\World; use function abs; use function assert; use function cos; @@ -199,7 +199,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ /** @var TimingsHandler */ protected $timings; - public function __construct(Level $level, CompoundTag $nbt){ + public function __construct(World $world, CompoundTag $nbt){ $this->timings = Timings::getEntityTimings($this); $this->temporalVector = new Vector3(); @@ -209,20 +209,20 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ } $this->id = EntityFactory::nextRuntimeId(); - $this->server = $level->getServer(); + $this->server = $world->getServer(); /** @var float[] $pos */ $pos = $nbt->getListTag("Pos")->getAllValues(); /** @var float[] $rotation */ $rotation = $nbt->getListTag("Rotation")->getAllValues(); - parent::__construct($pos[0], $pos[1], $pos[2], $rotation[0], $rotation[1], $level); + parent::__construct($pos[0], $pos[1], $pos[2], $rotation[0], $rotation[1], $world); assert(!is_nan($this->x) and !is_infinite($this->x) and !is_nan($this->y) and !is_infinite($this->y) and !is_nan($this->z) and !is_infinite($this->z)); $this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0); $this->recalculateBoundingBox(); - $this->chunk = $this->level->getChunkAtPosition($this, false); + $this->chunk = $this->world->getChunkAtPosition($this, false); if($this->chunk === null){ throw new \InvalidStateException("Cannot create entities in unloaded chunks"); } @@ -256,7 +256,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ $this->propertyManager->clearDirtyProperties(); //Prevents resending properties that were set during construction $this->chunk->addEntity($this); - $this->level->addEntity($this); + $this->world->addEntity($this); $this->lastUpdate = $this->server->getTick(); (new EntitySpawnEvent($this))->call(); @@ -450,7 +450,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ public function getOwningEntity() : ?Entity{ $eid = $this->getOwningEntityId(); if($eid !== null){ - return $this->server->getLevelManager()->findEntity($eid); + return $this->server->getWorldManager()->findEntity($eid); } return null; @@ -490,7 +490,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ public function getTargetEntity() : ?Entity{ $eid = $this->getTargetEntityId(); if($eid !== null){ - return $this->server->getLevelManager()->findEntity($eid); + return $this->server->getWorldManager()->findEntity($eid); } return null; @@ -871,7 +871,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ $pk->flags |= MoveEntityAbsolutePacket::FLAG_TELEPORT; } - $this->level->broadcastPacketToViewers($this, $pk); + $this->world->broadcastPacketToViewers($this, $pk); } protected function broadcastMotion() : void{ @@ -879,7 +879,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ $pk->entityRuntimeId = $this->id; $pk->motion = $this->getMotion(); - $this->level->broadcastPacketToViewers($this, $pk); + $this->world->broadcastPacketToViewers($this, $pk); } public function hasGravity() : bool{ @@ -914,7 +914,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ } if($this->onGround){ - $friction *= $this->level->getBlockAt((int) floor($this->x), (int) floor($this->y - 1), (int) floor($this->z))->getFrictionFactor(); + $friction *= $this->world->getBlockAt((int) floor($this->x), (int) floor($this->y - 1), (int) floor($this->z))->getFrictionFactor(); } $this->motion->x *= $friction; @@ -922,7 +922,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ } protected function checkObstruction(float $x, float $y, float $z) : bool{ - if(count($this->level->getCollisionBoxes($this, $this->getBoundingBox(), false)) === 0){ + if(count($this->world->getCollisionBoxes($this, $this->getBoundingBox(), false)) === 0){ return false; } @@ -934,13 +934,13 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ $diffY = $y - $floorY; $diffZ = $z - $floorZ; - if($this->level->getBlockAt($floorX, $floorY, $floorZ)->isSolid()){ - $westNonSolid = !$this->level->getBlockAt($floorX - 1, $floorY, $floorZ)->isSolid(); - $eastNonSolid = !$this->level->getBlockAt($floorX + 1, $floorY, $floorZ)->isSolid(); - $downNonSolid = !$this->level->getBlockAt($floorX, $floorY - 1, $floorZ)->isSolid(); - $upNonSolid = !$this->level->getBlockAt($floorX, $floorY + 1, $floorZ)->isSolid(); - $northNonSolid = !$this->level->getBlockAt($floorX, $floorY, $floorZ - 1)->isSolid(); - $southNonSolid = !$this->level->getBlockAt($floorX, $floorY, $floorZ + 1)->isSolid(); + if($this->world->getBlockAt($floorX, $floorY, $floorZ)->isSolid()){ + $westNonSolid = !$this->world->getBlockAt($floorX - 1, $floorY, $floorZ)->isSolid(); + $eastNonSolid = !$this->world->getBlockAt($floorX + 1, $floorY, $floorZ)->isSolid(); + $downNonSolid = !$this->world->getBlockAt($floorX, $floorY - 1, $floorZ)->isSolid(); + $upNonSolid = !$this->world->getBlockAt($floorX, $floorY + 1, $floorZ)->isSolid(); + $northNonSolid = !$this->world->getBlockAt($floorX, $floorY, $floorZ - 1)->isSolid(); + $southNonSolid = !$this->world->getBlockAt($floorX, $floorY, $floorZ + 1)->isSolid(); $direction = -1; $limit = 9999; @@ -1105,7 +1105,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ if($this->closed){ throw new \InvalidStateException("Cannot schedule update on garbage entity " . get_class($this)); } - $this->level->updateEntities[$this->id] = $this; + $this->world->updateEntities[$this->id] = $this; } public function onNearbyBlockChange() : void{ @@ -1176,7 +1176,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ } public function isUnderwater() : bool{ - $block = $this->level->getBlockAt((int) floor($this->x), (int) floor($y = ($this->y + $this->getEyeHeight())), (int) floor($this->z)); + $block = $this->world->getBlockAt((int) floor($this->x), (int) floor($y = ($this->y + $this->getEyeHeight())), (int) floor($this->z)); if($block instanceof Water){ $f = ($block->y + 1) - ($block->getFluidHeightPercent() - 0.1111111); @@ -1187,7 +1187,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ } public function isInsideOfSolid() : bool{ - $block = $this->level->getBlockAt((int) floor($this->x), (int) floor($y = ($this->y + $this->getEyeHeight())), (int) floor($this->z)); + $block = $this->world->getBlockAt((int) floor($this->x), (int) floor($y = ($this->y + $this->getEyeHeight())), (int) floor($this->z)); return $block->isSolid() and !$block->isTransparent() and $block->collidesWithBB($this->getBoundingBox()); } @@ -1223,7 +1223,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ /*$sneakFlag = $this->onGround and $this instanceof Player; if($sneakFlag){ - for($mov = 0.05; $dx != 0.0 and count($this->level->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($dx, -1, 0))) === 0; $movX = $dx){ + for($mov = 0.05; $dx != 0.0 and count($this->world->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($dx, -1, 0))) === 0; $movX = $dx){ if($dx < $mov and $dx >= -$mov){ $dx = 0; }elseif($dx > 0){ @@ -1233,7 +1233,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ } } - for(; $dz != 0.0 and count($this->level->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox(0, -1, $dz))) === 0; $movZ = $dz){ + for(; $dz != 0.0 and count($this->world->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox(0, -1, $dz))) === 0; $movZ = $dz){ if($dz < $mov and $dz >= -$mov){ $dz = 0; }elseif($dz > 0){ @@ -1249,7 +1249,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ assert(abs($dx) <= 20 and abs($dy) <= 20 and abs($dz) <= 20, "Movement distance is excessive: dx=$dx, dy=$dy, dz=$dz"); //TODO: bad hack here will cause unexpected behaviour under heavy lag - $list = $this->level->getCollisionBoxes($this, $this->level->getTickRateTime() > 50 ? $this->boundingBox->offsetCopy($dx, $dy, $dz) : $this->boundingBox->addCoord($dx, $dy, $dz), false); + $list = $this->world->getCollisionBoxes($this, $this->world->getTickRateTime() > 50 ? $this->boundingBox->offsetCopy($dx, $dy, $dz) : $this->boundingBox->addCoord($dx, $dy, $dz), false); foreach($list as $bb){ $dy = $bb->calculateYOffset($this->boundingBox, $dy); @@ -1284,7 +1284,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ $this->boundingBox->setBB($axisalignedbb); - $list = $this->level->getCollisionBoxes($this, $this->boundingBox->addCoord($dx, $dy, $dz), false); + $list = $this->world->getCollisionBoxes($this, $this->boundingBox->addCoord($dx, $dy, $dz), false); foreach($list as $bb){ $dy = $bb->calculateYOffset($this->boundingBox, $dy); @@ -1367,7 +1367,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ for($z = $minZ; $z <= $maxZ; ++$z){ for($x = $minX; $x <= $maxX; ++$x){ for($y = $minY; $y <= $maxY; ++$y){ - $block = $this->level->getBlockAt($x, $y, $z); + $block = $this->world->getBlockAt($x, $y, $z); if($block->hasEntityCollision()){ $this->blocksAround[] = $block; } @@ -1418,8 +1418,8 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ return false; } - if($pos instanceof Position and $pos->level !== null and $pos->level !== $this->level){ - if(!$this->switchLevel($pos->getLevel())){ + if($pos instanceof Position and $pos->world !== null and $pos->world !== $this->world){ + if(!$this->switchWorld($pos->getWorld())){ return false; } } @@ -1460,10 +1460,10 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ if($this->chunk !== null){ $this->chunk->removeEntity($this); } - $this->chunk = $this->level->getChunk($chunkX, $chunkZ, true); + $this->chunk = $this->world->getChunk($chunkX, $chunkZ, true); if(!$this->justCreated){ - $newChunk = $this->level->getViewersForPosition($this); + $newChunk = $this->world->getViewersForPosition($this); foreach($this->hasSpawned as $player){ if(!isset($newChunk[spl_object_id($player)])){ $this->despawnFrom($player); @@ -1540,8 +1540,8 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ $yaw = $yaw ?? $pos->yaw; $pitch = $pitch ?? $pos->pitch; } - $from = Position::fromObject($this, $this->level); - $to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevel() : $this->level); + $from = Position::fromObject($this, $this->world); + $to = Position::fromObject($pos, $pos instanceof Position ? $pos->getWorld() : $this->world); $ev = new EntityTeleportEvent($this, $from, $to); $ev->call(); if($ev->isCancelled()){ @@ -1563,27 +1563,27 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ return false; } - protected function switchLevel(Level $targetLevel) : bool{ + protected function switchWorld(World $targetWorld) : bool{ if($this->closed){ return false; } if($this->isValid()){ - $ev = new EntityLevelChangeEvent($this, $this->level, $targetLevel); + $ev = new EntityWorldChangeEvent($this, $this->world, $targetWorld); $ev->call(); if($ev->isCancelled()){ return false; } - $this->level->removeEntity($this); + $this->world->removeEntity($this); if($this->chunk !== null){ $this->chunk->removeEntity($this); } $this->despawnFromAll(); } - $this->setLevel($targetLevel); - $this->level->addEntity($this); + $this->setWorld($targetWorld); + $this->world->addEntity($this); $this->chunk = null; return true; @@ -1636,7 +1636,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ if($this->chunk === null or $this->closed){ return; } - foreach($this->level->getViewersForPosition($this) as $player){ + foreach($this->world->getViewersForPosition($this) as $player){ if($player->isOnline()){ $this->spawnTo($player); } @@ -1717,7 +1717,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ $this->chunk->removeEntity($this); } if($this->isValid()){ - $this->level->removeEntity($this); + $this->world->removeEntity($this); } } @@ -1729,7 +1729,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ */ protected function destroyCycles() : void{ $this->chunk = null; - $this->setLevel(null); + $this->setWorld(null); $this->lastDamageCause = null; } diff --git a/src/pocketmine/entity/EntityFactory.php b/src/pocketmine/entity/EntityFactory.php index 467bc3625..d14632908 100644 --- a/src/pocketmine/entity/EntityFactory.php +++ b/src/pocketmine/entity/EntityFactory.php @@ -36,7 +36,6 @@ use pocketmine\entity\projectile\EnderPearl; use pocketmine\entity\projectile\ExperienceBottle; use pocketmine\entity\projectile\Snowball; use pocketmine\entity\projectile\SplashPotion; -use pocketmine\level\Level; use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\DoubleTag; @@ -45,6 +44,7 @@ use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\StringTag; use pocketmine\utils\Utils; +use pocketmine\world\World; use function array_keys; use function assert; use function in_array; @@ -174,20 +174,20 @@ final class EntityFactory{ } /** - * Creates an entity with the specified type, level and NBT, with optional additional arguments to pass to the + * Creates an entity with the specified type, world and NBT, with optional additional arguments to pass to the * entity's constructor. * * TODO: make this NBT-independent * * @param string $baseClass - * @param Level $level + * @param World $world * @param CompoundTag $nbt * @param mixed ...$args * * @return Entity instanceof $baseClass * @throws \InvalidArgumentException if the class doesn't exist or is not registered */ - public static function create(string $baseClass, Level $level, CompoundTag $nbt, ...$args) : Entity{ + public static function create(string $baseClass, World $world, CompoundTag $nbt, ...$args) : Entity{ if(isset(self::$classMapping[$baseClass])){ $class = self::$classMapping[$baseClass]; assert(is_a($class, $baseClass, true)); @@ -195,7 +195,7 @@ final class EntityFactory{ * @var Entity $entity * @see Entity::__construct() */ - $entity = new $class($level, $nbt, ...$args); + $entity = new $class($world, $nbt, ...$args); return $entity; } @@ -205,15 +205,16 @@ final class EntityFactory{ /** * Creates an entity from data stored on a chunk. - * @internal * - * @param Level $level + * @param World $world * @param CompoundTag $nbt * * @return Entity|null * @throws \RuntimeException + *@internal + * */ - public static function createFromData(Level $level, CompoundTag $nbt) : ?Entity{ + public static function createFromData(World $world, CompoundTag $nbt) : ?Entity{ $saveId = $nbt->getTag("id") ?? $nbt->getTag("identifier"); $baseClass = null; if($saveId instanceof StringTag){ @@ -230,7 +231,7 @@ final class EntityFactory{ * @var Entity $entity * @see Entity::__construct() */ - $entity = new $class($level, $nbt); + $entity = new $class($world, $nbt); return $entity; } diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index f497ac6a3..e4f8725d0 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -42,10 +42,6 @@ use pocketmine\item\enchantment\Enchantment; use pocketmine\item\FoodSource; use pocketmine\item\Item; use pocketmine\item\Totem; -use pocketmine\level\Level; -use pocketmine\level\sound\TotemUseSound; -use pocketmine\level\sound\XpCollectSound; -use pocketmine\level\sound\XpLevelUpSound; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\ByteArrayTag; use pocketmine\nbt\tag\CompoundTag; @@ -62,6 +58,10 @@ use pocketmine\network\mcpe\protocol\types\PlayerListEntry; use pocketmine\network\mcpe\protocol\types\PlayerMetadataFlags; use pocketmine\Player; use pocketmine\utils\UUID; +use pocketmine\world\sound\TotemUseSound; +use pocketmine\world\sound\XpCollectSound; +use pocketmine\world\sound\XpLevelUpSound; +use pocketmine\world\World; use function array_filter; use function array_merge; use function array_rand; @@ -101,7 +101,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ protected $baseOffset = 1.62; - public function __construct(Level $level, CompoundTag $nbt){ + public function __construct(World $world, CompoundTag $nbt){ if($this->skin === null){ $skinTag = $nbt->getCompoundTag("Skin"); if($skinTag === null or !self::isValidSkin($skinTag->hasTag("Data", ByteArrayTag::class) ? @@ -112,7 +112,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ } } - parent::__construct($level, $nbt); + parent::__construct($world, $nbt); } /** @@ -350,7 +350,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ if($playSound){ $newLevel = $this->getXpLevel(); if((int) ($newLevel / 5) > (int) ($oldLevel / 5)){ - $this->level->addSound($this, new XpLevelUpSound($newLevel)); + $this->world->addSound($this, new XpLevelUpSound($newLevel)); } } @@ -442,9 +442,9 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ if($playSound){ $newLevel = $this->getXpLevel(); if((int) ($newLevel / 5) > (int) ($oldLevel / 5)){ - $this->level->addSound($this, new XpLevelUpSound($newLevel)); + $this->world->addSound($this, new XpLevelUpSound($newLevel)); }elseif($this->getCurrentTotalXp() > $oldTotal){ - $this->level->addSound($this, new XpCollectSound()); + $this->world->addSound($this, new XpCollectSound()); } } @@ -696,14 +696,14 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ if($this->isAlive()){ $food = $this->getFood(); $health = $this->getHealth(); - $difficulty = $this->level->getDifficulty(); + $difficulty = $this->world->getDifficulty(); $this->foodTickTimer += $tickDiff; if($this->foodTickTimer >= 80){ $this->foodTickTimer = 0; } - if($difficulty === Level::DIFFICULTY_PEACEFUL and $this->foodTickTimer % 10 === 0){ + if($difficulty === World::DIFFICULTY_PEACEFUL and $this->foodTickTimer % 10 === 0){ if($food < $this->getMaxFood()){ $this->addFood(1.0); $food = $this->getFood(); @@ -720,7 +720,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ $this->exhaust(3.0, PlayerExhaustEvent::CAUSE_HEALTH_REGEN); } }elseif($food <= 0){ - if(($difficulty === Level::DIFFICULTY_EASY and $health > 10) or ($difficulty === Level::DIFFICULTY_NORMAL and $health > 1) or $difficulty === Level::DIFFICULTY_HARD){ + if(($difficulty === World::DIFFICULTY_EASY and $health > 10) or ($difficulty === World::DIFFICULTY_NORMAL and $health > 1) or $difficulty === World::DIFFICULTY_HARD){ $this->attack(new EntityDamageEvent($this, EntityDamageEvent::CAUSE_STARVATION, 1)); } } @@ -761,7 +761,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ $this->addEffect(new EffectInstance(Effect::ABSORPTION(), 5 * 20, 1)); $this->broadcastEntityEvent(EntityEventPacket::CONSUME_TOTEM); - $this->level->addSound($this->add(0, $this->eyeHeight, 0), new TotemUseSound()); + $this->world->addSound($this->add(0, $this->eyeHeight, 0), new TotemUseSound()); $hand = $this->inventory->getItemInHand(); if($hand instanceof Totem){ diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index 197dc6840..6605bca06 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -40,7 +40,6 @@ use pocketmine\item\Consumable; use pocketmine\item\Durable; use pocketmine\item\enchantment\Enchantment; use pocketmine\item\Item; -use pocketmine\level\sound\ItemBreakSound; use pocketmine\math\Vector3; use pocketmine\math\VoxelRayTrace; use pocketmine\nbt\tag\CompoundTag; @@ -54,6 +53,7 @@ use pocketmine\Player; use pocketmine\timings\Timings; use pocketmine\utils\Binary; use pocketmine\utils\Color; +use pocketmine\world\sound\ItemBreakSound; use function abs; use function array_shift; use function atan2; @@ -546,7 +546,7 @@ abstract class Living extends Entity implements Damageable{ private function damageItem(Durable $item, int $durabilityRemoved) : void{ $item->applyDamage($durabilityRemoved); if($item->isBroken()){ - $this->level->addSound($this, new ItemBreakSound()); + $this->world->addSound($this, new ItemBreakSound()); } } @@ -598,7 +598,7 @@ abstract class Living extends Entity implements Damageable{ $source->getCause() === EntityDamageEvent::CAUSE_PROJECTILE or $source->getCause() === EntityDamageEvent::CAUSE_ENTITY_ATTACK ) and $e->isOnFire()){ - $this->setOnFire(2 * $this->level->getDifficulty()); + $this->setOnFire(2 * $this->world->getDifficulty()); } $deltaX = $this->x - $e->x; @@ -646,11 +646,11 @@ abstract class Living extends Entity implements Damageable{ $ev = new EntityDeathEvent($this, $this->getDrops(), $this->getXpDropAmount()); $ev->call(); foreach($ev->getDrops() as $item){ - $this->getLevel()->dropItem($this, $item); + $this->getWorld()->dropItem($this, $item); } //TODO: check death conditions (must have been damaged by player < 5 seconds from death) - $this->level->dropExperience($this, $ev->getXpDropAmount()); + $this->world->dropExperience($this, $ev->getXpDropAmount()); $this->startDeathAnimation(); } @@ -864,7 +864,7 @@ abstract class Living extends Entity implements Damageable{ $nextIndex = 0; foreach(VoxelRayTrace::inDirection($this->add(0, $this->eyeHeight, 0), $this->getDirectionVector(), $maxDistance) as $vector3){ - $block = $this->level->getBlockAt($vector3->x, $vector3->y, $vector3->z); + $block = $this->world->getBlockAt($vector3->x, $vector3->y, $vector3->z); $blocks[$nextIndex++] = $block; if($maxLength !== 0 and count($blocks) > $maxLength){ diff --git a/src/pocketmine/entity/object/ExperienceOrb.php b/src/pocketmine/entity/object/ExperienceOrb.php index c0141bae2..612f055f5 100644 --- a/src/pocketmine/entity/object/ExperienceOrb.php +++ b/src/pocketmine/entity/object/ExperienceOrb.php @@ -152,7 +152,7 @@ class ExperienceOrb extends Entity{ return null; } - $entity = $this->level->getEntity($this->targetPlayerRuntimeId); + $entity = $this->world->getEntity($this->targetPlayerRuntimeId); if($entity instanceof Human){ return $entity; } @@ -180,7 +180,7 @@ class ExperienceOrb extends Entity{ if($this->lookForTargetTime >= 20){ if($currentTarget === null){ - $newTarget = $this->level->getNearestEntity($this, self::MAX_TARGET_DISTANCE, Human::class); + $newTarget = $this->world->getNearestEntity($this, self::MAX_TARGET_DISTANCE, Human::class); if($newTarget instanceof Human and !($newTarget instanceof Player and $newTarget->isSpectator())){ $currentTarget = $newTarget; diff --git a/src/pocketmine/entity/object/FallingBlock.php b/src/pocketmine/entity/object/FallingBlock.php index c22e84908..c563b486e 100644 --- a/src/pocketmine/entity/object/FallingBlock.php +++ b/src/pocketmine/entity/object/FallingBlock.php @@ -98,7 +98,7 @@ class FallingBlock extends Entity{ if(!$this->isFlaggedForDespawn()){ $pos = $this->add(-$this->width / 2, $this->height, -$this->width / 2)->floor(); - $this->block->position($this->level, $pos->x, $pos->y, $pos->z); + $this->block->position($this->world, $pos->x, $pos->y, $pos->z); $blockTarget = null; if($this->block instanceof Fallable){ @@ -108,15 +108,15 @@ class FallingBlock extends Entity{ if($this->onGround or $blockTarget !== null){ $this->flagForDespawn(); - $block = $this->level->getBlock($pos); + $block = $this->world->getBlock($pos); if($block->getId() > 0 and $block->isTransparent() and !$block->canBeReplaced()){ //FIXME: anvils are supposed to destroy torches - $this->getLevel()->dropItem($this, $this->block->asItem()); + $this->getWorld()->dropItem($this, $this->block->asItem()); }else{ $ev = new EntityBlockChangeEvent($this, $block, $blockTarget ?? $this->block); $ev->call(); if(!$ev->isCancelled()){ - $this->getLevel()->setBlock($pos, $ev->getTo()); + $this->getWorld()->setBlock($pos, $ev->getTo()); } } $hasUpdate = true; diff --git a/src/pocketmine/entity/object/Painting.php b/src/pocketmine/entity/object/Painting.php index e5ea041cd..44f545f89 100644 --- a/src/pocketmine/entity/object/Painting.php +++ b/src/pocketmine/entity/object/Painting.php @@ -29,8 +29,6 @@ use pocketmine\entity\Entity; use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\item\Item; use pocketmine\item\ItemFactory; -use pocketmine\level\Level; -use pocketmine\level\particle\DestroyBlockParticle; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Bearing; use pocketmine\math\Facing; @@ -39,6 +37,8 @@ use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\CompoundTag; use pocketmine\network\mcpe\protocol\AddPaintingPacket; use pocketmine\Player; +use pocketmine\world\particle\DestroyBlockParticle; +use pocketmine\world\World; use function ceil; class Painting extends Entity{ @@ -62,7 +62,7 @@ class Painting extends Entity{ /** @var string */ protected $motive; - public function __construct(Level $level, CompoundTag $nbt){ + public function __construct(World $world, CompoundTag $nbt){ $this->motive = $nbt->getString("Motive"); $this->blockIn = new Vector3($nbt->getInt("TileX"), $nbt->getInt("TileY"), $nbt->getInt("TileZ")); if($nbt->hasTag("Direction", ByteTag::class)){ @@ -70,7 +70,7 @@ class Painting extends Entity{ }elseif($nbt->hasTag("Facing", ByteTag::class)){ $this->direction = $nbt->getByte("Facing"); } - parent::__construct($level, $nbt); + parent::__construct($world, $nbt); } protected function initEntity(CompoundTag $nbt) : void{ @@ -107,9 +107,9 @@ class Painting extends Entity{ if($drops){ //non-living entities don't have a way to create drops generically yet - $this->level->dropItem($this, ItemFactory::get(Item::PAINTING)); + $this->world->dropItem($this, ItemFactory::get(Item::PAINTING)); } - $this->level->addParticle($this->add(0.5, 0.5, 0.5), new DestroyBlockParticle(BlockFactory::get(BlockLegacyIds::PLANKS))); + $this->world->addParticle($this->add(0.5, 0.5, 0.5), new DestroyBlockParticle(BlockFactory::get(BlockLegacyIds::PLANKS))); } protected function recalculateBoundingBox() : void{ @@ -121,7 +121,7 @@ class Painting extends Entity{ parent::onNearbyBlockChange(); $face = Bearing::toFacing($this->direction); - if(!self::canFit($this->level, $this->blockIn->getSide($face), $face, false, $this->getMotive())){ + if(!self::canFit($this->world, $this->blockIn->getSide($face), $face, false, $this->getMotive())){ $this->kill(); } } @@ -226,7 +226,7 @@ class Painting extends Entity{ /** * Returns whether a painting with the specified motive can be placed at the given position. * - * @param Level $level + * @param World $world * @param Vector3 $blockIn * @param int $facing * @param bool $checkOverlap @@ -234,7 +234,7 @@ class Painting extends Entity{ * * @return bool */ - public static function canFit(Level $level, Vector3 $blockIn, int $facing, bool $checkOverlap, PaintingMotive $motive) : bool{ + public static function canFit(World $world, Vector3 $blockIn, int $facing, bool $checkOverlap, PaintingMotive $motive) : bool{ $width = $motive->getWidth(); $height = $motive->getHeight(); @@ -251,7 +251,7 @@ class Painting extends Entity{ for($h = 0; $h < $height; ++$h){ $pos = $startPos->getSide($rotatedFace, $w)->getSide(Facing::UP, $h); - $block = $level->getBlockAt($pos->x, $pos->y, $pos->z); + $block = $world->getBlockAt($pos->x, $pos->y, $pos->z); if($block->isSolid() or !$block->getSide($oppositeSide)->isSolid()){ return false; } @@ -261,7 +261,7 @@ class Painting extends Entity{ if($checkOverlap){ $bb = self::getPaintingBB($blockIn, $facing, $motive); - foreach($level->getNearbyEntities($bb) as $entity){ + foreach($world->getNearbyEntities($bb) as $entity){ if($entity instanceof self){ return false; } diff --git a/src/pocketmine/entity/object/PrimedTNT.php b/src/pocketmine/entity/object/PrimedTNT.php index 92fc9870b..58406b2aa 100644 --- a/src/pocketmine/entity/object/PrimedTNT.php +++ b/src/pocketmine/entity/object/PrimedTNT.php @@ -27,12 +27,12 @@ use pocketmine\entity\Entity; use pocketmine\entity\Explosive; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\ExplosionPrimeEvent; -use pocketmine\level\Explosion; -use pocketmine\level\sound\IgniteSound; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\ShortTag; use pocketmine\network\mcpe\protocol\types\EntityMetadataFlags; use pocketmine\network\mcpe\protocol\types\EntityMetadataProperties; +use pocketmine\world\Explosion; +use pocketmine\world\sound\IgniteSound; class PrimedTNT extends Entity implements Explosive{ public const NETWORK_ID = self::TNT; @@ -68,7 +68,7 @@ class PrimedTNT extends Entity implements Explosive{ $this->setGenericFlag(EntityMetadataFlags::IGNITED, true); $this->propertyManager->setInt(EntityMetadataProperties::FUSE_LENGTH, $this->fuse); - $this->level->addSound($this, new IgniteSound()); + $this->world->addSound($this, new IgniteSound()); } diff --git a/src/pocketmine/entity/projectile/Arrow.php b/src/pocketmine/entity/projectile/Arrow.php index e20c679a6..0dde2ed11 100644 --- a/src/pocketmine/entity/projectile/Arrow.php +++ b/src/pocketmine/entity/projectile/Arrow.php @@ -29,14 +29,14 @@ use pocketmine\event\entity\ProjectileHitEvent; use pocketmine\event\inventory\InventoryPickupArrowEvent; use pocketmine\item\Item; use pocketmine\item\ItemFactory; -use pocketmine\level\Level; -use pocketmine\level\sound\ArrowHitSound; use pocketmine\math\RayTraceResult; use pocketmine\nbt\tag\CompoundTag; use pocketmine\network\mcpe\protocol\EntityEventPacket; use pocketmine\network\mcpe\protocol\TakeItemEntityPacket; use pocketmine\network\mcpe\protocol\types\EntityMetadataFlags; use pocketmine\Player; +use pocketmine\world\sound\ArrowHitSound; +use pocketmine\world\World; use function mt_rand; use function sqrt; @@ -67,8 +67,8 @@ class Arrow extends Projectile{ /** @var int */ protected $collideTicks = 0; - public function __construct(Level $level, CompoundTag $nbt, ?Entity $shootingEntity = null, bool $critical = false){ - parent::__construct($level, $nbt, $shootingEntity); + public function __construct(World $world, CompoundTag $nbt, ?Entity $shootingEntity = null, bool $critical = false){ + parent::__construct($world, $nbt, $shootingEntity); $this->setCritical($critical); } @@ -139,7 +139,7 @@ class Arrow extends Projectile{ protected function onHit(ProjectileHitEvent $event) : void{ $this->setCritical(false); - $this->level->addSound($this, new ArrowHitSound()); + $this->world->addSound($this, new ArrowHitSound()); } protected function onHitBlock(Block $blockHit, RayTraceResult $hitResult) : void{ diff --git a/src/pocketmine/entity/projectile/Egg.php b/src/pocketmine/entity/projectile/Egg.php index 70a160554..f643220b2 100644 --- a/src/pocketmine/entity/projectile/Egg.php +++ b/src/pocketmine/entity/projectile/Egg.php @@ -26,7 +26,7 @@ namespace pocketmine\entity\projectile; use pocketmine\event\entity\ProjectileHitEvent; use pocketmine\item\Item; use pocketmine\item\ItemFactory; -use pocketmine\level\particle\ItemBreakParticle; +use pocketmine\world\particle\ItemBreakParticle; class Egg extends Throwable{ public const NETWORK_ID = self::EGG; @@ -35,7 +35,7 @@ class Egg extends Throwable{ protected function onHit(ProjectileHitEvent $event) : void{ for($i = 0; $i < 6; ++$i){ - $this->level->addParticle($this, new ItemBreakParticle(ItemFactory::get(Item::EGG))); + $this->world->addParticle($this, new ItemBreakParticle(ItemFactory::get(Item::EGG))); } } } diff --git a/src/pocketmine/entity/projectile/EnderPearl.php b/src/pocketmine/entity/projectile/EnderPearl.php index 2d102909c..9293219ba 100644 --- a/src/pocketmine/entity/projectile/EnderPearl.php +++ b/src/pocketmine/entity/projectile/EnderPearl.php @@ -27,11 +27,11 @@ use pocketmine\block\Block; use pocketmine\block\BlockLegacyIds; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\ProjectileHitEvent; -use pocketmine\level\particle\EndermanTeleportParticle; -use pocketmine\level\sound\EndermanTeleportSound; use pocketmine\math\AxisAlignedBB; use pocketmine\math\RayTraceResult; use pocketmine\math\Vector3; +use pocketmine\world\particle\EndermanTeleportParticle; +use pocketmine\world\sound\EndermanTeleportSound; class EnderPearl extends Throwable{ public const NETWORK_ID = self::ENDER_PEARL; @@ -51,10 +51,10 @@ class EnderPearl extends Throwable{ //TODO: check end gateways (when they are added) //TODO: spawn endermites at origin - $this->level->addParticle($owner, new EndermanTeleportParticle()); - $this->level->addSound($owner, new EndermanTeleportSound()); + $this->world->addParticle($owner, new EndermanTeleportParticle()); + $this->world->addSound($owner, new EndermanTeleportSound()); $owner->teleport($target = $event->getRayTraceResult()->getHitVector()); - $this->level->addSound($target, new EndermanTeleportSound()); + $this->world->addSound($target, new EndermanTeleportSound()); $owner->attack(new EntityDamageEvent($owner, EntityDamageEvent::CAUSE_FALL, 5)); } diff --git a/src/pocketmine/entity/projectile/ExperienceBottle.php b/src/pocketmine/entity/projectile/ExperienceBottle.php index 2a32aa647..103ce1c03 100644 --- a/src/pocketmine/entity/projectile/ExperienceBottle.php +++ b/src/pocketmine/entity/projectile/ExperienceBottle.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\entity\projectile; use pocketmine\event\entity\ProjectileHitEvent; -use pocketmine\level\particle\PotionSplashParticle; -use pocketmine\level\sound\PotionSplashSound; +use pocketmine\world\particle\PotionSplashParticle; +use pocketmine\world\sound\PotionSplashSound; use function mt_rand; class ExperienceBottle extends Throwable{ @@ -38,9 +38,9 @@ class ExperienceBottle extends Throwable{ } public function onHit(ProjectileHitEvent $event) : void{ - $this->level->addParticle($this, new PotionSplashParticle(PotionSplashParticle::DEFAULT_COLOR())); - $this->level->addSound($this, new PotionSplashSound()); + $this->world->addParticle($this, new PotionSplashParticle(PotionSplashParticle::DEFAULT_COLOR())); + $this->world->addSound($this, new PotionSplashSound()); - $this->level->dropExperience($this, mt_rand(3, 11)); + $this->world->dropExperience($this, mt_rand(3, 11)); } } diff --git a/src/pocketmine/entity/projectile/Projectile.php b/src/pocketmine/entity/projectile/Projectile.php index ee29edf4e..1079046af 100644 --- a/src/pocketmine/entity/projectile/Projectile.php +++ b/src/pocketmine/entity/projectile/Projectile.php @@ -34,8 +34,6 @@ use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\ProjectileHitBlockEvent; use pocketmine\event\entity\ProjectileHitEntityEvent; use pocketmine\event\entity\ProjectileHitEvent; -use pocketmine\level\Level; -use pocketmine\level\Position; use pocketmine\math\RayTraceResult; use pocketmine\math\Vector3; use pocketmine\math\VoxelRayTrace; @@ -43,6 +41,8 @@ use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; use pocketmine\timings\Timings; +use pocketmine\world\Position; +use pocketmine\world\World; use function assert; use function atan2; use function ceil; @@ -58,8 +58,8 @@ abstract class Projectile extends Entity{ /** @var Block|null */ protected $blockHit; - public function __construct(Level $level, CompoundTag $nbt, ?Entity $shootingEntity = null){ - parent::__construct($level, $nbt); + public function __construct(World $world, CompoundTag $nbt, ?Entity $shootingEntity = null){ + parent::__construct($world, $nbt); if($shootingEntity !== null){ $this->setOwningEntity($shootingEntity); } @@ -84,7 +84,7 @@ abstract class Projectile extends Entity{ $blockData = null; if($nbt->hasTag("tileX", IntTag::class) and $nbt->hasTag("tileY", IntTag::class) and $nbt->hasTag("tileZ", IntTag::class)){ - $blockPos = new Position($nbt->getInt("tileX"), $nbt->getInt("tileY"), $nbt->getInt("tileZ"), $this->level); + $blockPos = new Position($nbt->getInt("tileX"), $nbt->getInt("tileY"), $nbt->getInt("tileZ"), $this->world); }else{ break; } @@ -163,7 +163,7 @@ abstract class Projectile extends Entity{ } public function onNearbyBlockChange() : void{ - if($this->blockHit !== null and $this->level->isInLoadedTerrain($this->blockHit) and !$this->blockHit->isSameState($this->level->getBlock($this->blockHit))){ + if($this->blockHit !== null and $this->world->isInLoadedTerrain($this->blockHit) and !$this->blockHit->isSameState($this->world->getBlock($this->blockHit))){ $this->blockHit = null; } @@ -187,7 +187,7 @@ abstract class Projectile extends Entity{ $hitResult = null; foreach(VoxelRayTrace::betweenPoints($start, $end) as $vector3){ - $block = $this->level->getBlockAt($vector3->x, $vector3->y, $vector3->z); + $block = $this->world->getBlockAt($vector3->x, $vector3->y, $vector3->z); $blockHitResult = $this->calculateInterceptWithBlock($block, $start, $end); if($blockHitResult !== null){ @@ -201,7 +201,7 @@ abstract class Projectile extends Entity{ $entityDistance = PHP_INT_MAX; $newDiff = $end->subtract($start); - foreach($this->level->getCollidingEntities($this->boundingBox->addCoord($newDiff->x, $newDiff->y, $newDiff->z)->expand(1, 1, 1), $this) as $entity){ + foreach($this->world->getCollidingEntities($this->boundingBox->addCoord($newDiff->x, $newDiff->y, $newDiff->z)->expand(1, 1, 1), $this) as $entity){ if($entity->getId() === $this->getOwningEntityId() and $this->ticksLived < 5){ continue; } diff --git a/src/pocketmine/entity/projectile/Snowball.php b/src/pocketmine/entity/projectile/Snowball.php index 587d98048..1ff3fc2f6 100644 --- a/src/pocketmine/entity/projectile/Snowball.php +++ b/src/pocketmine/entity/projectile/Snowball.php @@ -24,14 +24,14 @@ declare(strict_types=1); namespace pocketmine\entity\projectile; use pocketmine\event\entity\ProjectileHitEvent; -use pocketmine\level\particle\SnowballPoofParticle; +use pocketmine\world\particle\SnowballPoofParticle; class Snowball extends Throwable{ public const NETWORK_ID = self::SNOWBALL; protected function onHit(ProjectileHitEvent $event) : void{ for($i = 0; $i < 6; ++$i){ - $this->level->addParticle($this, new SnowballPoofParticle()); + $this->world->addParticle($this, new SnowballPoofParticle()); } } } diff --git a/src/pocketmine/entity/projectile/SplashPotion.php b/src/pocketmine/entity/projectile/SplashPotion.php index 5c74c7569..40c8ef0ba 100644 --- a/src/pocketmine/entity/projectile/SplashPotion.php +++ b/src/pocketmine/entity/projectile/SplashPotion.php @@ -32,12 +32,12 @@ use pocketmine\event\entity\ProjectileHitBlockEvent; use pocketmine\event\entity\ProjectileHitEntityEvent; use pocketmine\event\entity\ProjectileHitEvent; use pocketmine\item\Potion; -use pocketmine\level\particle\PotionSplashParticle; -use pocketmine\level\sound\PotionSplashSound; use pocketmine\nbt\tag\CompoundTag; use pocketmine\network\mcpe\protocol\types\EntityMetadataFlags; use pocketmine\network\mcpe\protocol\types\EntityMetadataProperties; use pocketmine\utils\Color; +use pocketmine\world\particle\PotionSplashParticle; +use pocketmine\world\sound\PotionSplashSound; use function round; use function sqrt; @@ -83,12 +83,12 @@ class SplashPotion extends Throwable{ $particle = new PotionSplashParticle(Color::mix(...$colors)); } - $this->level->addParticle($this, $particle); - $this->level->addSound($this, new PotionSplashSound()); + $this->world->addParticle($this, $particle); + $this->world->addSound($this, new PotionSplashSound()); if($hasEffects){ if(!$this->willLinger()){ - foreach($this->level->getNearbyEntities($this->boundingBox->expandedCopy(4.125, 2.125, 4.125), $this) as $entity){ + foreach($this->world->getNearbyEntities($this->boundingBox->expandedCopy(4.125, 2.125, 4.125), $this) as $entity){ if($entity instanceof Living and $entity->isAlive()){ $distanceSquared = $entity->add(0, $entity->getEyeHeight(), 0)->distanceSquared($this); if($distanceSquared > 16){ //4 blocks @@ -123,11 +123,11 @@ class SplashPotion extends Throwable{ $blockIn = $event->getBlockHit()->getSide($event->getRayTraceResult()->getHitFace()); if($blockIn->getId() === BlockLegacyIds::FIRE){ - $this->level->setBlock($blockIn, BlockFactory::get(BlockLegacyIds::AIR)); + $this->world->setBlock($blockIn, BlockFactory::get(BlockLegacyIds::AIR)); } foreach($blockIn->getHorizontalSides() as $horizontalSide){ if($horizontalSide->getId() === BlockLegacyIds::FIRE){ - $this->level->setBlock($horizontalSide, BlockFactory::get(BlockLegacyIds::AIR)); + $this->world->setBlock($horizontalSide, BlockFactory::get(BlockLegacyIds::AIR)); } } } diff --git a/src/pocketmine/event/entity/EntityDamageByChildEntityEvent.php b/src/pocketmine/event/entity/EntityDamageByChildEntityEvent.php index e10e062ba..ab994ad63 100644 --- a/src/pocketmine/event/entity/EntityDamageByChildEntityEvent.php +++ b/src/pocketmine/event/entity/EntityDamageByChildEntityEvent.php @@ -51,6 +51,6 @@ class EntityDamageByChildEntityEvent extends EntityDamageByEntityEvent{ * @return Entity|null */ public function getChild() : ?Entity{ - return $this->getEntity()->getLevel()->getServer()->getLevelManager()->findEntity($this->childEntityEid); + return $this->getEntity()->getWorld()->getServer()->getWorldManager()->findEntity($this->childEntityEid); } } diff --git a/src/pocketmine/event/entity/EntityDamageByEntityEvent.php b/src/pocketmine/event/entity/EntityDamageByEntityEvent.php index 893c2672e..ab0fdf8d7 100644 --- a/src/pocketmine/event/entity/EntityDamageByEntityEvent.php +++ b/src/pocketmine/event/entity/EntityDamageByEntityEvent.php @@ -69,7 +69,7 @@ class EntityDamageByEntityEvent extends EntityDamageEvent{ * @return Entity|null */ public function getDamager() : ?Entity{ - return $this->getEntity()->getLevel()->getServer()->getLevelManager()->findEntity($this->damagerEntityId); + return $this->getEntity()->getWorld()->getServer()->getWorldManager()->findEntity($this->damagerEntityId); } /** diff --git a/src/pocketmine/event/entity/EntityExplodeEvent.php b/src/pocketmine/event/entity/EntityExplodeEvent.php index f3aa1c98f..106a6f679 100644 --- a/src/pocketmine/event/entity/EntityExplodeEvent.php +++ b/src/pocketmine/event/entity/EntityExplodeEvent.php @@ -27,7 +27,7 @@ use pocketmine\block\Block; use pocketmine\entity\Entity; use pocketmine\event\Cancellable; use pocketmine\event\CancellableTrait; -use pocketmine\level\Position; +use pocketmine\world\Position; /** * Called when a entity explodes diff --git a/src/pocketmine/event/entity/EntityTeleportEvent.php b/src/pocketmine/event/entity/EntityTeleportEvent.php index 3c5c5dc57..160b5f9b7 100644 --- a/src/pocketmine/event/entity/EntityTeleportEvent.php +++ b/src/pocketmine/event/entity/EntityTeleportEvent.php @@ -26,7 +26,7 @@ namespace pocketmine\event\entity; use pocketmine\entity\Entity; use pocketmine\event\Cancellable; use pocketmine\event\CancellableTrait; -use pocketmine\level\Position; +use pocketmine\world\Position; class EntityTeleportEvent extends EntityEvent implements Cancellable{ use CancellableTrait; diff --git a/src/pocketmine/event/entity/EntityLevelChangeEvent.php b/src/pocketmine/event/entity/EntityWorldChangeEvent.php similarity index 66% rename from src/pocketmine/event/entity/EntityLevelChangeEvent.php rename to src/pocketmine/event/entity/EntityWorldChangeEvent.php index cb792115e..fc020a7a4 100644 --- a/src/pocketmine/event/entity/EntityLevelChangeEvent.php +++ b/src/pocketmine/event/entity/EntityWorldChangeEvent.php @@ -26,27 +26,27 @@ namespace pocketmine\event\entity; use pocketmine\entity\Entity; use pocketmine\event\Cancellable; use pocketmine\event\CancellableTrait; -use pocketmine\level\Level; +use pocketmine\world\World; -class EntityLevelChangeEvent extends EntityEvent implements Cancellable{ +class EntityWorldChangeEvent extends EntityEvent implements Cancellable{ use CancellableTrait; - /** @var Level */ - private $originLevel; - /** @var Level */ - private $targetLevel; + /** @var World */ + private $originWorld; + /** @var World */ + private $targetWorld; - public function __construct(Entity $entity, Level $originLevel, Level $targetLevel){ + public function __construct(Entity $entity, World $originWorld, World $targetWorld){ $this->entity = $entity; - $this->originLevel = $originLevel; - $this->targetLevel = $targetLevel; + $this->originWorld = $originWorld; + $this->targetWorld = $targetWorld; } - public function getOrigin() : Level{ - return $this->originLevel; + public function getOrigin() : World{ + return $this->originWorld; } - public function getTarget() : Level{ - return $this->targetLevel; + public function getTarget() : World{ + return $this->targetWorld; } } diff --git a/src/pocketmine/event/player/PlayerMoveEvent.php b/src/pocketmine/event/player/PlayerMoveEvent.php index 720a98b95..f949abd67 100644 --- a/src/pocketmine/event/player/PlayerMoveEvent.php +++ b/src/pocketmine/event/player/PlayerMoveEvent.php @@ -25,7 +25,7 @@ namespace pocketmine\event\player; use pocketmine\event\Cancellable; use pocketmine\event\CancellableTrait; -use pocketmine\level\Location; +use pocketmine\world\Location; use pocketmine\Player; class PlayerMoveEvent extends PlayerEvent implements Cancellable{ diff --git a/src/pocketmine/event/player/PlayerRespawnEvent.php b/src/pocketmine/event/player/PlayerRespawnEvent.php index 9a9380f2f..1df9eac36 100644 --- a/src/pocketmine/event/player/PlayerRespawnEvent.php +++ b/src/pocketmine/event/player/PlayerRespawnEvent.php @@ -23,7 +23,7 @@ declare(strict_types=1); namespace pocketmine\event\player; -use pocketmine\level\Position; +use pocketmine\world\Position; use pocketmine\Player; /** diff --git a/src/pocketmine/event/server/QueryRegenerateEvent.php b/src/pocketmine/event/server/QueryRegenerateEvent.php index c4effc1f9..0550de332 100644 --- a/src/pocketmine/event/server/QueryRegenerateEvent.php +++ b/src/pocketmine/event/server/QueryRegenerateEvent.php @@ -89,8 +89,8 @@ class QueryRegenerateEvent extends ServerEvent{ $this->gametype = ($server->getGamemode()->getMagicNumber() & 0x01) === 0 ? "SMP" : "CMP"; $this->version = $server->getVersion(); $this->server_engine = $server->getName() . " " . $server->getPocketMineVersion(); - $level = $server->getLevelManager()->getDefaultLevel(); - $this->map = $level === null ? "unknown" : $level->getDisplayName(); + $world = $server->getWorldManager()->getDefaultWorld(); + $this->map = $world === null ? "unknown" : $world->getDisplayName(); $this->numPlayers = count($this->players); $this->maxPlayers = $server->getMaxPlayers(); $this->whitelist = $server->hasWhitelist() ? "on" : "off"; diff --git a/src/pocketmine/event/level/ChunkEvent.php b/src/pocketmine/event/world/ChunkEvent.php similarity index 78% rename from src/pocketmine/event/level/ChunkEvent.php rename to src/pocketmine/event/world/ChunkEvent.php index b155a14a1..993e77d25 100644 --- a/src/pocketmine/event/level/ChunkEvent.php +++ b/src/pocketmine/event/world/ChunkEvent.php @@ -22,24 +22,24 @@ declare(strict_types=1); -namespace pocketmine\event\level; +namespace pocketmine\event\world; -use pocketmine\level\format\Chunk; -use pocketmine\level\Level; +use pocketmine\world\format\Chunk; +use pocketmine\world\World; /** * Chunk-related events */ -abstract class ChunkEvent extends LevelEvent{ +abstract class ChunkEvent extends WorldEvent{ /** @var Chunk */ private $chunk; /** - * @param Level $level + * @param World $world * @param Chunk $chunk */ - public function __construct(Level $level, Chunk $chunk){ - parent::__construct($level); + public function __construct(World $world, Chunk $chunk){ + parent::__construct($world); $this->chunk = $chunk; } diff --git a/src/pocketmine/event/level/ChunkLoadEvent.php b/src/pocketmine/event/world/ChunkLoadEvent.php similarity index 83% rename from src/pocketmine/event/level/ChunkLoadEvent.php rename to src/pocketmine/event/world/ChunkLoadEvent.php index 660248d7f..575bf74cf 100644 --- a/src/pocketmine/event/level/ChunkLoadEvent.php +++ b/src/pocketmine/event/world/ChunkLoadEvent.php @@ -22,10 +22,10 @@ declare(strict_types=1); -namespace pocketmine\event\level; +namespace pocketmine\event\world; -use pocketmine\level\format\Chunk; -use pocketmine\level\Level; +use pocketmine\world\format\Chunk; +use pocketmine\world\World; /** * Called when a Chunk is loaded @@ -34,8 +34,8 @@ class ChunkLoadEvent extends ChunkEvent{ /** @var bool */ private $newChunk; - public function __construct(Level $level, Chunk $chunk, bool $newChunk){ - parent::__construct($level, $chunk); + public function __construct(World $world, Chunk $chunk, bool $newChunk){ + parent::__construct($world, $chunk); $this->newChunk = $newChunk; } diff --git a/src/pocketmine/event/level/ChunkPopulateEvent.php b/src/pocketmine/event/world/ChunkPopulateEvent.php similarity index 96% rename from src/pocketmine/event/level/ChunkPopulateEvent.php rename to src/pocketmine/event/world/ChunkPopulateEvent.php index 76c6abb8d..3797bb58b 100644 --- a/src/pocketmine/event/level/ChunkPopulateEvent.php +++ b/src/pocketmine/event/world/ChunkPopulateEvent.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\event\level; +namespace pocketmine\event\world; /** * Called when a Chunk is populated (after receiving it on the main thread) diff --git a/src/pocketmine/event/level/ChunkUnloadEvent.php b/src/pocketmine/event/world/ChunkUnloadEvent.php similarity index 96% rename from src/pocketmine/event/level/ChunkUnloadEvent.php rename to src/pocketmine/event/world/ChunkUnloadEvent.php index e37df56cd..89b58b6d4 100644 --- a/src/pocketmine/event/level/ChunkUnloadEvent.php +++ b/src/pocketmine/event/world/ChunkUnloadEvent.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\event\level; +namespace pocketmine\event\world; use pocketmine\event\Cancellable; use pocketmine\event\CancellableTrait; diff --git a/src/pocketmine/event/level/SpawnChangeEvent.php b/src/pocketmine/event/world/SpawnChangeEvent.php similarity index 76% rename from src/pocketmine/event/level/SpawnChangeEvent.php rename to src/pocketmine/event/world/SpawnChangeEvent.php index 5c6476fe6..208856859 100644 --- a/src/pocketmine/event/level/SpawnChangeEvent.php +++ b/src/pocketmine/event/world/SpawnChangeEvent.php @@ -21,25 +21,25 @@ declare(strict_types=1); -namespace pocketmine\event\level; +namespace pocketmine\event\world; -use pocketmine\level\Level; -use pocketmine\level\Position; +use pocketmine\world\Position; +use pocketmine\world\World; /** - * An event that is called when a level spawn changes. + * An event that is called when a world spawn changes. * The previous spawn is included */ -class SpawnChangeEvent extends LevelEvent{ +class SpawnChangeEvent extends WorldEvent{ /** @var Position */ private $previousSpawn; /** - * @param Level $level + * @param World $world * @param Position $previousSpawn */ - public function __construct(Level $level, Position $previousSpawn){ - parent::__construct($level); + public function __construct(World $world, Position $previousSpawn){ + parent::__construct($world); $this->previousSpawn = $previousSpawn; } diff --git a/src/pocketmine/event/level/LevelEvent.php b/src/pocketmine/event/world/WorldEvent.php similarity index 70% rename from src/pocketmine/event/level/LevelEvent.php rename to src/pocketmine/event/world/WorldEvent.php index 7e24f5d28..193a0d8e1 100644 --- a/src/pocketmine/event/level/LevelEvent.php +++ b/src/pocketmine/event/world/WorldEvent.php @@ -22,28 +22,28 @@ declare(strict_types=1); /** - * Level related events + * World related events */ -namespace pocketmine\event\level; +namespace pocketmine\event\world; use pocketmine\event\Event; -use pocketmine\level\Level; +use pocketmine\world\World; -abstract class LevelEvent extends Event{ - /** @var Level */ - private $level; +abstract class WorldEvent extends Event{ + /** @var World */ + private $world; /** - * @param Level $level + * @param World $world */ - public function __construct(Level $level){ - $this->level = $level; + public function __construct(World $world){ + $this->world = $world; } /** - * @return Level + * @return World */ - public function getLevel() : Level{ - return $this->level; + public function getWorld() : World{ + return $this->world; } } diff --git a/src/pocketmine/event/level/LevelInitEvent.php b/src/pocketmine/event/world/WorldInitEvent.php similarity index 86% rename from src/pocketmine/event/level/LevelInitEvent.php rename to src/pocketmine/event/world/WorldInitEvent.php index 7bf1b4c25..4b85571ed 100644 --- a/src/pocketmine/event/level/LevelInitEvent.php +++ b/src/pocketmine/event/world/WorldInitEvent.php @@ -21,11 +21,11 @@ declare(strict_types=1); -namespace pocketmine\event\level; +namespace pocketmine\event\world; /** - * Called when a Level is initializing + * Called when a World is initializing */ -class LevelInitEvent extends LevelEvent{ +class WorldInitEvent extends WorldEvent{ } diff --git a/src/pocketmine/event/level/LevelLoadEvent.php b/src/pocketmine/event/world/WorldLoadEvent.php similarity index 87% rename from src/pocketmine/event/level/LevelLoadEvent.php rename to src/pocketmine/event/world/WorldLoadEvent.php index 32e58bbc3..18235c29b 100644 --- a/src/pocketmine/event/level/LevelLoadEvent.php +++ b/src/pocketmine/event/world/WorldLoadEvent.php @@ -21,11 +21,11 @@ declare(strict_types=1); -namespace pocketmine\event\level; +namespace pocketmine\event\world; /** - * Called when a Level is loaded + * Called when a World is loaded */ -class LevelLoadEvent extends LevelEvent{ +class WorldLoadEvent extends WorldEvent{ } diff --git a/src/pocketmine/event/level/LevelSaveEvent.php b/src/pocketmine/event/world/WorldSaveEvent.php similarity index 87% rename from src/pocketmine/event/level/LevelSaveEvent.php rename to src/pocketmine/event/world/WorldSaveEvent.php index 5e077f343..e43894791 100644 --- a/src/pocketmine/event/level/LevelSaveEvent.php +++ b/src/pocketmine/event/world/WorldSaveEvent.php @@ -21,11 +21,11 @@ declare(strict_types=1); -namespace pocketmine\event\level; +namespace pocketmine\event\world; /** - * Called when a Level is saved + * Called when a World is saved */ -class LevelSaveEvent extends LevelEvent{ +class WorldSaveEvent extends WorldEvent{ } diff --git a/src/pocketmine/event/level/LevelUnloadEvent.php b/src/pocketmine/event/world/WorldUnloadEvent.php similarity index 86% rename from src/pocketmine/event/level/LevelUnloadEvent.php rename to src/pocketmine/event/world/WorldUnloadEvent.php index 14b950396..7f5b3ff8b 100644 --- a/src/pocketmine/event/level/LevelUnloadEvent.php +++ b/src/pocketmine/event/world/WorldUnloadEvent.php @@ -21,14 +21,14 @@ declare(strict_types=1); -namespace pocketmine\event\level; +namespace pocketmine\event\world; use pocketmine\event\Cancellable; use pocketmine\event\CancellableTrait; /** - * Called when a Level is unloaded + * Called when a World is unloaded */ -class LevelUnloadEvent extends LevelEvent implements Cancellable{ +class WorldUnloadEvent extends WorldEvent implements Cancellable{ use CancellableTrait; } diff --git a/src/pocketmine/inventory/AnvilInventory.php b/src/pocketmine/inventory/AnvilInventory.php index f22b56674..b1891531b 100644 --- a/src/pocketmine/inventory/AnvilInventory.php +++ b/src/pocketmine/inventory/AnvilInventory.php @@ -23,7 +23,7 @@ declare(strict_types=1); namespace pocketmine\inventory; -use pocketmine\level\Position; +use pocketmine\world\Position; use pocketmine\network\mcpe\protocol\types\WindowTypes; use pocketmine\Player; diff --git a/src/pocketmine/inventory/ArmorInventory.php b/src/pocketmine/inventory/ArmorInventory.php index 39700c51d..744ccde8b 100644 --- a/src/pocketmine/inventory/ArmorInventory.php +++ b/src/pocketmine/inventory/ArmorInventory.php @@ -101,7 +101,7 @@ class ArmorInventory extends BaseInventory{ $pk = new MobArmorEquipmentPacket(); $pk->entityRuntimeId = $this->getHolder()->getId(); $pk->slots = $this->getContents(true); - $this->holder->getLevel()->getServer()->broadcastPacket($target, $pk); + $this->holder->getWorld()->getServer()->broadcastPacket($target, $pk); } } @@ -123,7 +123,7 @@ class ArmorInventory extends BaseInventory{ $pk = new MobArmorEquipmentPacket(); $pk->entityRuntimeId = $this->getHolder()->getId(); $pk->slots = $armor; - $this->holder->getLevel()->getServer()->broadcastPacket($target, $pk); + $this->holder->getWorld()->getServer()->broadcastPacket($target, $pk); } } diff --git a/src/pocketmine/inventory/ChestInventory.php b/src/pocketmine/inventory/ChestInventory.php index 0b5f269b7..f9da8aea5 100644 --- a/src/pocketmine/inventory/ChestInventory.php +++ b/src/pocketmine/inventory/ChestInventory.php @@ -23,9 +23,9 @@ declare(strict_types=1); namespace pocketmine\inventory; -use pocketmine\level\sound\ChestCloseSound; -use pocketmine\level\sound\ChestOpenSound; -use pocketmine\level\sound\Sound; +use pocketmine\world\sound\ChestCloseSound; +use pocketmine\world\sound\ChestOpenSound; +use pocketmine\world\sound\Sound; use pocketmine\network\mcpe\protocol\BlockEventPacket; use pocketmine\network\mcpe\protocol\types\WindowTypes; use pocketmine\Player; @@ -70,7 +70,7 @@ class ChestInventory extends ContainerInventory{ 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()->getLevel()->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()); } } @@ -78,7 +78,7 @@ class ChestInventory extends ContainerInventory{ 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()->getLevel()->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); } @@ -92,6 +92,6 @@ class ChestInventory extends ContainerInventory{ $pk->z = (int) $holder->z; $pk->eventType = 1; //it's always 1 for a chest $pk->eventData = $isOpen ? 1 : 0; - $holder->getLevel()->broadcastPacketToViewers($holder, $pk); + $holder->getWorld()->broadcastPacketToViewers($holder, $pk); } } diff --git a/src/pocketmine/inventory/EnchantInventory.php b/src/pocketmine/inventory/EnchantInventory.php index 4d3a6b97f..d3e41cf43 100644 --- a/src/pocketmine/inventory/EnchantInventory.php +++ b/src/pocketmine/inventory/EnchantInventory.php @@ -23,7 +23,7 @@ declare(strict_types=1); namespace pocketmine\inventory; -use pocketmine\level\Position; +use pocketmine\world\Position; use pocketmine\network\mcpe\protocol\types\WindowTypes; use pocketmine\Player; diff --git a/src/pocketmine/inventory/EnderChestInventory.php b/src/pocketmine/inventory/EnderChestInventory.php index 7523b8702..6395f4d30 100644 --- a/src/pocketmine/inventory/EnderChestInventory.php +++ b/src/pocketmine/inventory/EnderChestInventory.php @@ -23,12 +23,12 @@ declare(strict_types=1); namespace pocketmine\inventory; -use pocketmine\level\Position; -use pocketmine\level\sound\EnderChestCloseSound; -use pocketmine\level\sound\EnderChestOpenSound; -use pocketmine\level\sound\Sound; use pocketmine\network\mcpe\protocol\types\WindowTypes; use pocketmine\tile\EnderChest; +use pocketmine\world\Position; +use pocketmine\world\sound\EnderChestCloseSound; +use pocketmine\world\sound\EnderChestOpenSound; +use pocketmine\world\sound\Sound; class EnderChestInventory extends ChestInventory{ @@ -50,7 +50,7 @@ class EnderChestInventory extends ChestInventory{ */ public function setHolderPosition(EnderChest $enderChest) : void{ $this->holder->setComponents($enderChest->getFloorX(), $enderChest->getFloorY(), $enderChest->getFloorZ()); - $this->holder->setLevel($enderChest->getLevel()); + $this->holder->setWorld($enderChest->getWorld()); } protected function getOpenSound() : Sound{ diff --git a/src/pocketmine/inventory/PlayerInventory.php b/src/pocketmine/inventory/PlayerInventory.php index df0fedcc2..e6b93a44c 100644 --- a/src/pocketmine/inventory/PlayerInventory.php +++ b/src/pocketmine/inventory/PlayerInventory.php @@ -151,7 +151,7 @@ class PlayerInventory extends BaseInventory{ $this->sendSlot($this->getHeldItemIndex(), $target); } }else{ - $this->getHolder()->getLevel()->getServer()->broadcastPacket($target, $pk); + $this->getHolder()->getWorld()->getServer()->broadcastPacket($target, $pk); if(in_array($this->getHolder(), $target, true)){ $this->sendSlot($this->getHeldItemIndex(), $this->getHolder()); } diff --git a/src/pocketmine/item/Bow.php b/src/pocketmine/item/Bow.php index 74d3f41bd..290a220d4 100644 --- a/src/pocketmine/item/Bow.php +++ b/src/pocketmine/item/Bow.php @@ -29,7 +29,7 @@ use pocketmine\entity\projectile\Projectile; use pocketmine\event\entity\EntityShootBowEvent; use pocketmine\event\entity\ProjectileLaunchEvent; use pocketmine\item\enchantment\Enchantment; -use pocketmine\level\sound\BowShootSound; +use pocketmine\world\sound\BowShootSound; use pocketmine\Player; use function intdiv; use function min; @@ -65,7 +65,7 @@ class Bow extends Tool{ $baseForce = min((($p ** 2) + $p * 2) / 3, 1); /** @var ArrowEntity $entity */ - $entity = EntityFactory::create(ArrowEntity::class, $player->getLevel(), $nbt, $player, $baseForce >= 1); + $entity = EntityFactory::create(ArrowEntity::class, $player->getWorld(), $nbt, $player, $baseForce >= 1); $infinity = $this->hasEnchantment(Enchantment::INFINITY()); if($infinity){ @@ -106,7 +106,7 @@ class Bow extends Tool{ } $ev->getProjectile()->spawnToAll(); - $player->getLevel()->addSound($player, new BowShootSound()); + $player->getWorld()->addSound($player, new BowShootSound()); }else{ $entity->spawnToAll(); } diff --git a/src/pocketmine/item/Bucket.php b/src/pocketmine/item/Bucket.php index 4af42b9ac..095ae7fd9 100644 --- a/src/pocketmine/item/Bucket.php +++ b/src/pocketmine/item/Bucket.php @@ -47,8 +47,8 @@ class Bucket extends Item{ $ev = new PlayerBucketFillEvent($player, $blockReplace, $face, $this, $resultItem); $ev->call(); if(!$ev->isCancelled()){ - $player->getLevel()->setBlock($blockClicked, BlockFactory::get(BlockLegacyIds::AIR)); - $player->getLevel()->addSound($blockClicked->add(0.5, 0.5, 0.5), $blockClicked->getBucketFillSound()); + $player->getWorld()->setBlock($blockClicked, BlockFactory::get(BlockLegacyIds::AIR)); + $player->getWorld()->addSound($blockClicked->add(0.5, 0.5, 0.5), $blockClicked->getBucketFillSound()); if($player->hasFiniteResources()){ if($stack->getCount() === 0){ $player->getInventory()->setItemInHand($ev->getItem()); diff --git a/src/pocketmine/item/ChorusFruit.php b/src/pocketmine/item/ChorusFruit.php index 757fd126b..5bbb9dd10 100644 --- a/src/pocketmine/item/ChorusFruit.php +++ b/src/pocketmine/item/ChorusFruit.php @@ -25,8 +25,8 @@ namespace pocketmine\item; use pocketmine\block\Liquid; use pocketmine\entity\Living; -use pocketmine\level\sound\EndermanTeleportSound; use pocketmine\math\Vector3; +use pocketmine\world\sound\EndermanTeleportSound; use function assert; use function min; use function mt_rand; @@ -50,11 +50,11 @@ class ChorusFruit extends Food{ } public function onConsume(Living $consumer) : void{ - $level = $consumer->getLevel(); - assert($level !== null); + $world = $consumer->getWorld(); + assert($world !== null); $minX = $consumer->getFloorX() - 8; - $minY = min($consumer->getFloorY(), $consumer->getLevel()->getWorldHeight()) - 8; + $minY = min($consumer->getFloorY(), $consumer->getWorld()->getWorldHeight()) - 8; $minZ = $consumer->getFloorZ() - 8; $maxX = $minX + 16; @@ -66,23 +66,23 @@ class ChorusFruit extends Food{ $y = mt_rand($minY, $maxY); $z = mt_rand($minZ, $maxZ); - while($y >= 0 and !$level->getBlockAt($x, $y, $z)->isSolid()){ + while($y >= 0 and !$world->getBlockAt($x, $y, $z)->isSolid()){ $y--; } if($y < 0){ continue; } - $blockUp = $level->getBlockAt($x, $y + 1, $z); - $blockUp2 = $level->getBlockAt($x, $y + 2, $z); + $blockUp = $world->getBlockAt($x, $y + 1, $z); + $blockUp2 = $world->getBlockAt($x, $y + 2, $z); if($blockUp->isSolid() or $blockUp instanceof Liquid or $blockUp2->isSolid() or $blockUp2 instanceof Liquid){ continue; } //Sounds are broadcasted at both source and destination - $level->addSound($consumer->asVector3(), new EndermanTeleportSound()); + $world->addSound($consumer->asVector3(), new EndermanTeleportSound()); $consumer->teleport($target = new Vector3($x + 0.5, $y + 1, $z + 0.5)); - $level->addSound($target, new EndermanTeleportSound()); + $world->addSound($target, new EndermanTeleportSound()); break; } diff --git a/src/pocketmine/item/FlintSteel.php b/src/pocketmine/item/FlintSteel.php index 241d4f5af..e69df4d41 100644 --- a/src/pocketmine/item/FlintSteel.php +++ b/src/pocketmine/item/FlintSteel.php @@ -26,9 +26,9 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\block\BlockFactory; use pocketmine\block\BlockLegacyIds; -use pocketmine\level\sound\FlintSteelSound; use pocketmine\math\Vector3; use pocketmine\Player; +use pocketmine\world\sound\FlintSteelSound; use function assert; class FlintSteel extends Tool{ @@ -38,10 +38,10 @@ class FlintSteel extends Tool{ public function onActivate(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector) : ItemUseResult{ if($blockReplace->getId() === BlockLegacyIds::AIR){ - $level = $player->getLevel(); - assert($level !== null); - $level->setBlock($blockReplace, BlockFactory::get(BlockLegacyIds::FIRE)); - $level->addSound($blockReplace->add(0.5, 0.5, 0.5), new FlintSteelSound()); + $world = $player->getWorld(); + assert($world !== null); + $world->setBlock($blockReplace, BlockFactory::get(BlockLegacyIds::FIRE)); + $world->addSound($blockReplace->add(0.5, 0.5, 0.5), new FlintSteelSound()); $this->applyDamage(1); diff --git a/src/pocketmine/item/LiquidBucket.php b/src/pocketmine/item/LiquidBucket.php index 4ef4cdcd1..5ec0efe31 100644 --- a/src/pocketmine/item/LiquidBucket.php +++ b/src/pocketmine/item/LiquidBucket.php @@ -63,8 +63,8 @@ class LiquidBucket extends Item{ $ev = new PlayerBucketEmptyEvent($player, $blockReplace, $face, $this, ItemFactory::get(Item::BUCKET)); $ev->call(); if(!$ev->isCancelled()){ - $player->getLevel()->setBlock($blockReplace, $resultBlock->getFlowingForm()); - $player->getLevel()->addSound($blockClicked->add(0.5, 0.5, 0.5), $resultBlock->getBucketEmptySound()); + $player->getWorld()->setBlock($blockReplace, $resultBlock->getFlowingForm()); + $player->getWorld()->addSound($blockClicked->add(0.5, 0.5, 0.5), $resultBlock->getBucketEmptySound()); if($player->hasFiniteResources()){ $player->getInventory()->setItemInHand($ev->getItem()); diff --git a/src/pocketmine/item/PaintingItem.php b/src/pocketmine/item/PaintingItem.php index e577d9b49..8d9642c49 100644 --- a/src/pocketmine/item/PaintingItem.php +++ b/src/pocketmine/item/PaintingItem.php @@ -52,7 +52,7 @@ class PaintingItem extends Item{ continue; } - if(Painting::canFit($player->getLevel(), $blockReplace, $face, true, $motive)){ + if(Painting::canFit($player->getWorld(), $blockReplace, $face, true, $motive)){ if($currentTotalDimension > $totalDimension){ $totalDimension = $currentTotalDimension; /* @@ -94,11 +94,11 @@ class PaintingItem extends Item{ $nbt->setInt("TileZ", $blockClicked->getFloorZ()); /** @var Painting $entity */ - $entity = EntityFactory::create(Painting::class, $blockReplace->getLevel(), $nbt); + $entity = EntityFactory::create(Painting::class, $blockReplace->getWorld(), $nbt); $this->pop(); $entity->spawnToAll(); - $player->getLevel()->broadcastLevelEvent($blockReplace->add(0.5, 0.5, 0.5), LevelEventPacket::EVENT_SOUND_ITEMFRAME_PLACE); //item frame and painting have the same sound + $player->getWorld()->broadcastLevelEvent($blockReplace->add(0.5, 0.5, 0.5), LevelEventPacket::EVENT_SOUND_ITEMFRAME_PLACE); //item frame and painting have the same sound return ItemUseResult::SUCCESS(); } } diff --git a/src/pocketmine/item/ProjectileItem.php b/src/pocketmine/item/ProjectileItem.php index f633057fe..66adef0b0 100644 --- a/src/pocketmine/item/ProjectileItem.php +++ b/src/pocketmine/item/ProjectileItem.php @@ -26,7 +26,7 @@ namespace pocketmine\item; use pocketmine\entity\EntityFactory; use pocketmine\entity\projectile\Throwable; use pocketmine\event\entity\ProjectileLaunchEvent; -use pocketmine\level\sound\ThrowSound; +use pocketmine\world\sound\ThrowSound; use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; use pocketmine\Player; @@ -60,7 +60,7 @@ abstract class ProjectileItem extends Item{ Utils::testValidInstance($class, Throwable::class); /** @var Throwable $projectile */ - $projectile = EntityFactory::create($class, $player->getLevel(), $nbt, $player); + $projectile = EntityFactory::create($class, $player->getWorld(), $nbt, $player); $projectile->setMotion($projectile->getMotion()->multiply($this->getThrowForce())); $projectileEv = new ProjectileLaunchEvent($projectile); @@ -72,7 +72,7 @@ abstract class ProjectileItem extends Item{ $projectile->spawnToAll(); - $player->getLevel()->addSound($player, new ThrowSound()); + $player->getWorld()->addSound($player, new ThrowSound()); $this->pop(); diff --git a/src/pocketmine/item/SpawnEgg.php b/src/pocketmine/item/SpawnEgg.php index 6fd053a1f..de42271d8 100644 --- a/src/pocketmine/item/SpawnEgg.php +++ b/src/pocketmine/item/SpawnEgg.php @@ -57,7 +57,7 @@ class SpawnEgg extends Item{ $nbt->setString("CustomName", $this->getCustomName()); } - $entity = EntityFactory::create($this->entityClass, $player->getLevel(), $nbt); + $entity = EntityFactory::create($this->entityClass, $player->getWorld(), $nbt); $this->pop(); $entity->spawnToAll(); //TODO: what if the entity was marked for deletion? diff --git a/src/pocketmine/metadata/BlockMetadataStore.php b/src/pocketmine/metadata/BlockMetadataStore.php index b8968e1d7..87cfd85f9 100644 --- a/src/pocketmine/metadata/BlockMetadataStore.php +++ b/src/pocketmine/metadata/BlockMetadataStore.php @@ -24,19 +24,19 @@ declare(strict_types=1); namespace pocketmine\metadata; use pocketmine\block\Block; -use pocketmine\level\Level; use pocketmine\plugin\Plugin; +use pocketmine\world\World; class BlockMetadataStore extends MetadataStore{ - /** @var Level */ + /** @var World */ private $owningLevel; - public function __construct(Level $owningLevel){ + public function __construct(World $owningLevel){ $this->owningLevel = $owningLevel; } private function disambiguate(Block $block, string $metadataKey) : string{ - if($block->getLevel() !== $this->owningLevel){ + if($block->getWorld() !== $this->owningLevel){ throw new \InvalidStateException("Block does not belong to world " . $this->owningLevel->getDisplayName()); } return $block->x . ":" . $block->y . ":" . $block->z . ":" . $metadataKey; diff --git a/src/pocketmine/metadata/LevelMetadataStore.php b/src/pocketmine/metadata/WorldMetadataStore.php similarity index 73% rename from src/pocketmine/metadata/LevelMetadataStore.php rename to src/pocketmine/metadata/WorldMetadataStore.php index 259d7fbc8..7893ba19a 100644 --- a/src/pocketmine/metadata/LevelMetadataStore.php +++ b/src/pocketmine/metadata/WorldMetadataStore.php @@ -23,29 +23,29 @@ declare(strict_types=1); namespace pocketmine\metadata; -use pocketmine\level\Level; use pocketmine\plugin\Plugin; +use pocketmine\world\World; use function strtolower; -class LevelMetadataStore extends MetadataStore{ +class WorldMetadataStore extends MetadataStore{ - private function disambiguate(Level $level, string $metadataKey) : string{ - return strtolower($level->getFolderName()) . ":" . $metadataKey; + private function disambiguate(World $world, string $metadataKey) : string{ + return strtolower($world->getFolderName()) . ":" . $metadataKey; } - public function getMetadata(Level $subject, string $metadataKey){ + public function getMetadata(World $subject, string $metadataKey){ return $this->getMetadataInternal($this->disambiguate($subject, $metadataKey)); } - public function hasMetadata(Level $subject, string $metadataKey) : bool{ + public function hasMetadata(World $subject, string $metadataKey) : bool{ return $this->hasMetadataInternal($this->disambiguate($subject, $metadataKey)); } - public function removeMetadata(Level $subject, string $metadataKey, Plugin $owningPlugin) : void{ + public function removeMetadata(World $subject, string $metadataKey, Plugin $owningPlugin) : void{ $this->removeMetadataInternal($this->disambiguate($subject, $metadataKey), $owningPlugin); } - public function setMetadata(Level $subject, string $metadataKey, MetadataValue $newMetadataValue) : void{ + public function setMetadata(World $subject, string $metadataKey, MetadataValue $newMetadataValue) : void{ $this->setMetadataInternal($this->disambiguate($subject, $metadataKey), $newMetadataValue); } } diff --git a/src/pocketmine/network/mcpe/ChunkCache.php b/src/pocketmine/network/mcpe/ChunkCache.php index dcadd609d..52134e5d0 100644 --- a/src/pocketmine/network/mcpe/ChunkCache.php +++ b/src/pocketmine/network/mcpe/ChunkCache.php @@ -23,10 +23,10 @@ declare(strict_types=1); namespace pocketmine\network\mcpe; -use pocketmine\level\ChunkListener; -use pocketmine\level\format\Chunk; -use pocketmine\level\Level; use pocketmine\math\Vector3; +use pocketmine\world\ChunkListener; +use pocketmine\world\format\Chunk; +use pocketmine\world\World; use function spl_object_id; use function strlen; @@ -43,15 +43,15 @@ class ChunkCache implements ChunkListener{ /** * Fetches the ChunkCache instance for the given world. This lazily creates cache systems as needed. * - * @param Level $world + * @param World $world * * @return ChunkCache */ - public static function getInstance(Level $world) : self{ + public static function getInstance(World $world) : self{ return self::$instances[spl_object_id($world)] ?? (self::$instances[spl_object_id($world)] = new self($world)); } - /** @var Level */ + /** @var World */ private $world; /** @var CompressBatchPromise[] */ @@ -63,9 +63,9 @@ class ChunkCache implements ChunkListener{ private $misses = 0; /** - * @param Level $world + * @param World $world */ - private function __construct(Level $world){ + private function __construct(World $world){ $this->world = $world; } @@ -79,7 +79,7 @@ class ChunkCache implements ChunkListener{ */ public function request(int $chunkX, int $chunkZ) : CompressBatchPromise{ $this->world->registerChunkListener($this, $chunkX, $chunkZ); - $chunkHash = Level::chunkHash($chunkX, $chunkZ); + $chunkHash = World::chunkHash($chunkX, $chunkZ); if(isset($this->caches[$chunkHash])){ ++$this->hits; @@ -113,7 +113,7 @@ class ChunkCache implements ChunkListener{ } private function destroy(int $chunkX, int $chunkZ) : bool{ - $chunkHash = Level::chunkHash($chunkX, $chunkZ); + $chunkHash = World::chunkHash($chunkX, $chunkZ); $existing = $this->caches[$chunkHash] ?? null; unset($this->caches[$chunkHash]); @@ -129,7 +129,7 @@ class ChunkCache implements ChunkListener{ * @throws \InvalidArgumentException */ private function restartPendingRequest(int $chunkX, int $chunkZ) : void{ - $chunkHash = Level::chunkHash($chunkX, $chunkZ); + $chunkHash = World::chunkHash($chunkX, $chunkZ); $existing = $this->caches[$chunkHash]; if($existing === null or $existing->hasResult()){ throw new \InvalidArgumentException("Restart can only be applied to unresolved promises"); @@ -147,7 +147,7 @@ class ChunkCache implements ChunkListener{ * @throws \InvalidArgumentException */ private function destroyOrRestart(int $chunkX, int $chunkZ) : void{ - $cache = $this->caches[Level::chunkHash($chunkX, $chunkZ)] ?? null; + $cache = $this->caches[World::chunkHash($chunkX, $chunkZ)] ?? null; if($cache !== null){ if(!$cache->hasResult()){ //some requesters are waiting for this chunk, so their request needs to be fulfilled diff --git a/src/pocketmine/network/mcpe/ChunkRequestTask.php b/src/pocketmine/network/mcpe/ChunkRequestTask.php index 30d2725c1..635348367 100644 --- a/src/pocketmine/network/mcpe/ChunkRequestTask.php +++ b/src/pocketmine/network/mcpe/ChunkRequestTask.php @@ -23,7 +23,7 @@ declare(strict_types=1); namespace pocketmine\network\mcpe; -use pocketmine\level\format\Chunk; +use pocketmine\world\format\Chunk; use pocketmine\network\mcpe\protocol\FullChunkDataPacket; use pocketmine\scheduler\AsyncTask; diff --git a/src/pocketmine/network/mcpe/NetworkSession.php b/src/pocketmine/network/mcpe/NetworkSession.php index d12347a75..f28d3b44a 100644 --- a/src/pocketmine/network/mcpe/NetworkSession.php +++ b/src/pocketmine/network/mcpe/NetworkSession.php @@ -30,7 +30,6 @@ use pocketmine\event\server\DataPacketReceiveEvent; use pocketmine\event\server\DataPacketSendEvent; use pocketmine\form\Form; use pocketmine\GameMode; -use pocketmine\level\Position; use pocketmine\math\Vector3; use pocketmine\network\BadPacketException; use pocketmine\network\mcpe\handler\DeathSessionHandler; @@ -70,6 +69,7 @@ use pocketmine\PlayerInfo; use pocketmine\Server; use pocketmine\timings\Timings; use pocketmine\utils\BinaryDataException; +use pocketmine\world\Position; use function bin2hex; use function count; use function get_class; @@ -761,18 +761,18 @@ class NetworkSession{ } public function startUsingChunk(int $chunkX, int $chunkZ, bool $spawn = false) : void{ - ChunkCache::getInstance($this->player->getLevel())->request($chunkX, $chunkZ)->onResolve( + ChunkCache::getInstance($this->player->getWorld())->request($chunkX, $chunkZ)->onResolve( //this callback may be called synchronously or asynchronously, depending on whether the promise is resolved yet function(CompressBatchPromise $promise) use($chunkX, $chunkZ, $spawn){ if(!$this->isConnected()){ return; } - $this->player->level->timings->syncChunkSendTimer->startTiming(); + $this->player->world->timings->syncChunkSendTimer->startTiming(); try{ $this->queueCompressed($promise); - foreach($this->player->getLevel()->getChunkEntities($chunkX, $chunkZ) as $entity){ + foreach($this->player->getWorld()->getChunkEntities($chunkX, $chunkZ) as $entity){ if($entity !== $this->player and !$entity->isClosed() and !$entity->isFlaggedForDespawn()){ $entity->spawnTo($this->player); } @@ -783,14 +783,14 @@ class NetworkSession{ $this->onTerrainReady(); } }finally{ - $this->player->level->timings->syncChunkSendTimer->stopTiming(); + $this->player->world->timings->syncChunkSendTimer->stopTiming(); } } ); } public function stopUsingChunk(int $chunkX, int $chunkZ) : void{ - foreach($this->player->getLevel()->getChunkEntities($chunkX, $chunkZ) as $entity){ + foreach($this->player->getWorld()->getChunkEntities($chunkX, $chunkZ) as $entity){ if($entity !== $this->player){ $entity->despawnFrom($this->player); } diff --git a/src/pocketmine/network/mcpe/handler/PreSpawnSessionHandler.php b/src/pocketmine/network/mcpe/handler/PreSpawnSessionHandler.php index 7c1abf5fb..1d69a38d0 100644 --- a/src/pocketmine/network/mcpe/handler/PreSpawnSessionHandler.php +++ b/src/pocketmine/network/mcpe/handler/PreSpawnSessionHandler.php @@ -64,12 +64,12 @@ class PreSpawnSessionHandler extends SessionHandler{ $pk->seed = -1; $pk->dimension = DimensionIds::OVERWORLD; //TODO: implement this properly $pk->worldGamemode = NetworkSession::getClientFriendlyGamemode($this->server->getGamemode()); - $pk->difficulty = $this->player->getLevel()->getDifficulty(); + $pk->difficulty = $this->player->getWorld()->getDifficulty(); $pk->spawnX = $spawnPosition->getFloorX(); $pk->spawnY = $spawnPosition->getFloorY(); $pk->spawnZ = $spawnPosition->getFloorZ(); $pk->hasAchievementsDisabled = true; - $pk->time = $this->player->getLevel()->getTime(); + $pk->time = $this->player->getWorld()->getTime(); $pk->eduMode = false; $pk->rainLevel = 0; //TODO: implement these properly $pk->lightningLevel = 0; @@ -83,7 +83,7 @@ class PreSpawnSessionHandler extends SessionHandler{ $this->player->setImmobile(); //HACK: fix client-side falling pre-spawn - $this->player->getLevel()->sendTime($this->player); + $this->player->getWorld()->sendTime($this->player); $this->session->syncAttributes($this->player, true); $this->session->syncAvailableCommands(); diff --git a/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php b/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php index 23bd64215..380ee768f 100644 --- a/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php +++ b/src/pocketmine/network/mcpe/handler/SimpleSessionHandler.php @@ -281,7 +281,7 @@ class SimpleSessionHandler extends SessionHandler{ } private function handleUseItemOnEntityTransaction(UseItemOnEntityTransactionData $data) : bool{ - $target = $this->player->getLevel()->getEntity($data->getEntityRuntimeId()); + $target = $this->player->getWorld()->getEntity($data->getEntityRuntimeId()); if($target === null){ return false; } @@ -448,7 +448,7 @@ class SimpleSessionHandler extends SessionHandler{ return false; } - $block = $this->player->getLevel()->getBlock($pos); + $block = $this->player->getWorld()->getBlock($pos); try{ $offset = 0; $nbt = (new NetworkNbtSerializer())->read($packet->namedtag, $offset, 512)->getTag(); @@ -466,7 +466,7 @@ class SimpleSessionHandler extends SessionHandler{ try{ if(!$block->updateText($this->player, $text)){ - $this->player->getLevel()->sendBlocks([$this->player], [$block]); + $this->player->getWorld()->sendBlocks([$this->player], [$block]); } }catch(\UnexpectedValueException $e){ throw new BadPacketException($e->getMessage(), 0, $e); @@ -509,7 +509,7 @@ class SimpleSessionHandler extends SessionHandler{ } public function handleItemFrameDropItem(ItemFrameDropItemPacket $packet) : bool{ - $block = $this->player->getLevel()->getBlockAt($packet->x, $packet->y, $packet->z); + $block = $this->player->getWorld()->getBlockAt($packet->x, $packet->y, $packet->z); if($block instanceof ItemFrame and $block->getFramedItem() !== null){ return $this->player->attackBlock(new Vector3($packet->x, $packet->y, $packet->z), $block->getFacing()); } @@ -588,7 +588,7 @@ class SimpleSessionHandler extends SessionHandler{ } public function handleLevelSoundEvent(LevelSoundEventPacket $packet) : bool{ - $this->player->getLevel()->broadcastPacketToViewers($this->player->asVector3(), $packet); + $this->player->getWorld()->broadcastPacketToViewers($this->player->asVector3(), $packet); return true; } diff --git a/src/pocketmine/scheduler/AsyncTask.php b/src/pocketmine/scheduler/AsyncTask.php index 08639ad58..a6add8740 100644 --- a/src/pocketmine/scheduler/AsyncTask.php +++ b/src/pocketmine/scheduler/AsyncTask.php @@ -210,7 +210,7 @@ abstract class AsyncTask extends \Threaded{ * leak. Usually this does not cause memory failure, but be aware that the object may be no longer usable when the * AsyncTask completes. Since a strong reference is retained, the objects still exist, but the implementation is * responsible for checking whether these objects are still usable. - * (E.g. a {@link \pocketmine\Level} object is no longer usable because it is unloaded while the AsyncTask is + * (E.g. a {@link \pocketmine\World} object is no longer usable because it is unloaded while the AsyncTask is * executing, or even a plugin might be unloaded). * * @param string $key diff --git a/src/pocketmine/tile/Banner.php b/src/pocketmine/tile/Banner.php index 6da72e874..0b8997f3d 100644 --- a/src/pocketmine/tile/Banner.php +++ b/src/pocketmine/tile/Banner.php @@ -26,11 +26,11 @@ namespace pocketmine\tile; use Ds\Deque; use pocketmine\block\utils\BannerPattern; use pocketmine\block\utils\DyeColor; -use pocketmine\level\Level; use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\ListTag; +use pocketmine\world\World; /** * @deprecated @@ -49,10 +49,10 @@ class Banner extends Spawnable{ /** @var BannerPattern[]|Deque */ private $patterns = []; - public function __construct(Level $level, Vector3 $pos){ + public function __construct(World $world, Vector3 $pos){ $this->baseColor = DyeColor::BLACK(); $this->patterns = new Deque(); - parent::__construct($level, $pos); + parent::__construct($world, $pos); } public function readSaveData(CompoundTag $nbt) : void{ diff --git a/src/pocketmine/tile/Bed.php b/src/pocketmine/tile/Bed.php index 442eb31b8..bc8f9b444 100644 --- a/src/pocketmine/tile/Bed.php +++ b/src/pocketmine/tile/Bed.php @@ -24,19 +24,19 @@ declare(strict_types=1); namespace pocketmine\tile; use pocketmine\block\utils\DyeColor; -use pocketmine\level\Level; use pocketmine\math\Vector3; use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\CompoundTag; +use pocketmine\world\World; class Bed extends Spawnable{ public const TAG_COLOR = "color"; /** @var DyeColor */ private $color; - public function __construct(Level $level, Vector3 $pos){ + public function __construct(World $world, Vector3 $pos){ $this->color = DyeColor::RED(); - parent::__construct($level, $pos); + parent::__construct($world, $pos); } public function getColor() : DyeColor{ diff --git a/src/pocketmine/tile/Chest.php b/src/pocketmine/tile/Chest.php index 7b2ffb25f..b59fd3b5f 100644 --- a/src/pocketmine/tile/Chest.php +++ b/src/pocketmine/tile/Chest.php @@ -26,10 +26,10 @@ namespace pocketmine\tile; use pocketmine\inventory\ChestInventory; use pocketmine\inventory\DoubleChestInventory; use pocketmine\inventory\InventoryHolder; -use pocketmine\level\Level; use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; +use pocketmine\world\World; class Chest extends Spawnable implements InventoryHolder, Container, Nameable{ use NameableTrait { @@ -53,9 +53,9 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{ /** @var int|null */ private $pairZ; - public function __construct(Level $level, Vector3 $pos){ + public function __construct(World $world, Vector3 $pos){ $this->inventory = new ChestInventory($this); - parent::__construct($level, $pos); + parent::__construct($world, $pos); } public function readSaveData(CompoundTag $nbt) : void{ @@ -90,7 +90,7 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{ $this->inventory->removeAllViewers(true); if($this->doubleInventory !== null){ - if($this->isPaired() and $this->level->isChunkLoaded($this->pairX >> 4, $this->pairZ >> 4)){ + if($this->isPaired() and $this->world->isChunkLoaded($this->pairX >> 4, $this->pairZ >> 4)){ $this->doubleInventory->removeAllViewers(true); $this->doubleInventory->invalidate(); if(($pair = $this->getPair()) !== null){ @@ -129,7 +129,7 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{ } protected function checkPairing(){ - if($this->isPaired() and !$this->getLevel()->isInLoadedTerrain(new Vector3($this->pairX, $this->y, $this->pairZ))){ + if($this->isPaired() and !$this->getWorld()->isInLoadedTerrain(new Vector3($this->pairX, $this->y, $this->pairZ))){ //paired to a tile in an unloaded chunk $this->doubleInventory = null; @@ -171,7 +171,7 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{ */ public function getPair() : ?Chest{ if($this->isPaired()){ - $tile = $this->getLevel()->getTileAt($this->pairX, $this->y, $this->pairZ); + $tile = $this->getWorld()->getTileAt($this->pairX, $this->y, $this->pairZ); if($tile instanceof Chest){ return $tile; } diff --git a/src/pocketmine/tile/ContainerTrait.php b/src/pocketmine/tile/ContainerTrait.php index efacc7bd2..1ef2737d1 100644 --- a/src/pocketmine/tile/ContainerTrait.php +++ b/src/pocketmine/tile/ContainerTrait.php @@ -25,11 +25,11 @@ namespace pocketmine\tile; use pocketmine\inventory\Inventory; use pocketmine\item\Item; -use pocketmine\level\Position; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\StringTag; +use pocketmine\world\Position; /** * This trait implements most methods in the {@link Container} interface. It should only be used by Tiles. @@ -101,7 +101,7 @@ trait ContainerTrait{ $pos = $this->asPosition(); foreach($inv->getContents() as $k => $item){ - $pos->level->dropItem($pos->add(0.5, 0.5, 0.5), $item); + $pos->world->dropItem($pos->add(0.5, 0.5, 0.5), $item); } $inv->clearAll(false); } diff --git a/src/pocketmine/tile/Furnace.php b/src/pocketmine/tile/Furnace.php index 29dbc53c5..ebf281c80 100644 --- a/src/pocketmine/tile/Furnace.php +++ b/src/pocketmine/tile/Furnace.php @@ -32,10 +32,10 @@ use pocketmine\inventory\Inventory; use pocketmine\inventory\InventoryHolder; use pocketmine\item\Item; use pocketmine\item\ItemFactory; -use pocketmine\level\Level; use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; use pocketmine\network\mcpe\protocol\ContainerSetDataPacket; +use pocketmine\world\World; use function ceil; use function max; @@ -58,14 +58,14 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{ /** @var int */ private $maxTime = 0; - public function __construct(Level $level, Vector3 $pos){ + public function __construct(World $world, Vector3 $pos){ $this->inventory = new FurnaceInventory($this); $this->inventory->setSlotChangeListener(function(Inventory $inventory, int $slot, Item $oldItem, Item $newItem) : ?Item{ $this->scheduleUpdate(); return $newItem; }); - parent::__construct($level, $pos); + parent::__construct($world, $pos); } public function readSaveData(CompoundTag $nbt) : void{ @@ -135,7 +135,7 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{ $block = $this->getBlock(); if($block instanceof BlockFurnace and !$block->isLit()){ $block->setLit(true); - $this->getLevel()->setBlock($block, $block); + $this->getWorld()->setBlock($block, $block); } if($this->burnTime > 0 and $ev->isBurning()){ @@ -163,7 +163,7 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{ $fuel = $this->inventory->getFuel(); $raw = $this->inventory->getSmelting(); $product = $this->inventory->getResult(); - $smelt = $this->level->getServer()->getCraftingManager()->matchFurnaceRecipe($raw); + $smelt = $this->world->getServer()->getCraftingManager()->matchFurnaceRecipe($raw); $canSmelt = ($smelt instanceof FurnaceRecipe and $raw->getCount() > 0 and (($smelt->getResult()->equals($product) and $product->getCount() < $product->getMaxStackSize()) or $product->isNull())); if($this->burnTime <= 0 and $canSmelt and $fuel->getFuelTime() > 0 and $fuel->getCount() > 0){ @@ -200,7 +200,7 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{ $block = $this->getBlock(); if($block instanceof BlockFurnace and $block->isLit()){ $block->setLit(false); - $this->getLevel()->setBlock($block, $block); + $this->getWorld()->setBlock($block, $block); } $this->burnTime = $this->cookTime = $this->maxTime = 0; } diff --git a/src/pocketmine/tile/ItemFrame.php b/src/pocketmine/tile/ItemFrame.php index 0841f540c..dd54ef6d6 100644 --- a/src/pocketmine/tile/ItemFrame.php +++ b/src/pocketmine/tile/ItemFrame.php @@ -25,9 +25,9 @@ namespace pocketmine\tile; use pocketmine\item\Item; use pocketmine\item\ItemFactory; -use pocketmine\level\Level; use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; +use pocketmine\world\World; /** * @deprecated @@ -45,9 +45,9 @@ class ItemFrame extends Spawnable{ /** @var float */ private $itemDropChance = 1.0; - public function __construct(Level $level, Vector3 $pos){ + public function __construct(World $world, Vector3 $pos){ $this->item = ItemFactory::air(); - parent::__construct($level, $pos); + parent::__construct($world, $pos); } public function readSaveData(CompoundTag $nbt) : void{ diff --git a/src/pocketmine/tile/Sign.php b/src/pocketmine/tile/Sign.php index b0ac37e37..09ff5d44f 100644 --- a/src/pocketmine/tile/Sign.php +++ b/src/pocketmine/tile/Sign.php @@ -24,10 +24,10 @@ declare(strict_types=1); namespace pocketmine\tile; use pocketmine\block\utils\SignText; -use pocketmine\level\Level; use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\StringTag; +use pocketmine\world\World; use function array_pad; use function array_slice; use function explode; @@ -50,9 +50,9 @@ class Sign extends Spawnable{ /** @var SignText */ protected $text; - public function __construct(Level $level, Vector3 $pos){ + public function __construct(World $world, Vector3 $pos){ $this->text = new SignText(); - parent::__construct($level, $pos); + parent::__construct($world, $pos); } public function readSaveData(CompoundTag $nbt) : void{ diff --git a/src/pocketmine/tile/Skull.php b/src/pocketmine/tile/Skull.php index 6567a1b02..10b330d8d 100644 --- a/src/pocketmine/tile/Skull.php +++ b/src/pocketmine/tile/Skull.php @@ -24,10 +24,10 @@ declare(strict_types=1); namespace pocketmine\tile; use pocketmine\block\utils\SkullType; -use pocketmine\level\Level; use pocketmine\math\Vector3; use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\CompoundTag; +use pocketmine\world\World; /** * @deprecated @@ -45,9 +45,9 @@ class Skull extends Spawnable{ /** @var int */ private $skullRotation = 0; - public function __construct(Level $level, Vector3 $pos){ + public function __construct(World $world, Vector3 $pos){ $this->skullType = SkullType::SKELETON(); - parent::__construct($level, $pos); + parent::__construct($world, $pos); } public function readSaveData(CompoundTag $nbt) : void{ diff --git a/src/pocketmine/tile/Spawnable.php b/src/pocketmine/tile/Spawnable.php index 0eaac5461..6bb21cddb 100644 --- a/src/pocketmine/tile/Spawnable.php +++ b/src/pocketmine/tile/Spawnable.php @@ -32,7 +32,7 @@ abstract class Spawnable extends Tile{ /** @var string|null */ private $spawnCompoundCache = null; /** @var bool */ - private $dirty = true; //default dirty, until it's been spawned appropriately on the level + private $dirty = true; //default dirty, until it's been spawned appropriately on the world /** @var NetworkNbtSerializer|null */ private static $nbtWriter = null; diff --git a/src/pocketmine/tile/Tile.php b/src/pocketmine/tile/Tile.php index c0caea151..ee041cc63 100644 --- a/src/pocketmine/tile/Tile.php +++ b/src/pocketmine/tile/Tile.php @@ -29,12 +29,12 @@ namespace pocketmine\tile; use pocketmine\block\Block; use pocketmine\item\Item; -use pocketmine\level\Level; -use pocketmine\level\Position; use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; use pocketmine\timings\Timings; use pocketmine\timings\TimingsHandler; +use pocketmine\world\Position; +use pocketmine\world\World; use function get_class; abstract class Tile extends Position{ @@ -51,9 +51,9 @@ abstract class Tile extends Position{ /** @var TimingsHandler */ protected $timings; - public function __construct(Level $level, Vector3 $pos){ + public function __construct(World $world, Vector3 $pos){ $this->timings = Timings::getTileEntityTimings($this); - parent::__construct($pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ(), $level); + parent::__construct($pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ(), $world); } /** @@ -104,7 +104,7 @@ abstract class Tile extends Position{ * @return Block */ public function getBlock() : Block{ - return $this->level->getBlockAt($this->x, $this->y, $this->z); + return $this->world->getBlockAt($this->x, $this->y, $this->z); } /** @@ -118,7 +118,7 @@ abstract class Tile extends Position{ if($this->closed){ throw new \InvalidStateException("Cannot schedule update on garbage tile " . get_class($this)); } - $this->level->updateTiles[Level::blockHash($this->x, $this->y, $this->z)] = $this; + $this->world->updateTiles[World::blockHash($this->x, $this->y, $this->z)] = $this; } public function isClosed() : bool{ @@ -149,8 +149,8 @@ abstract class Tile extends Position{ $this->closed = true; if($this->isValid()){ - $this->level->removeTile($this); - $this->setLevel(null); + $this->world->removeTile($this); + $this->setWorld(null); } } } diff --git a/src/pocketmine/tile/TileFactory.php b/src/pocketmine/tile/TileFactory.php index c329d4726..35bab3e89 100644 --- a/src/pocketmine/tile/TileFactory.php +++ b/src/pocketmine/tile/TileFactory.php @@ -23,10 +23,10 @@ declare(strict_types=1); namespace pocketmine\tile; -use pocketmine\level\Level; use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; use pocketmine\utils\Utils; +use pocketmine\world\World; use function assert; use function in_array; use function is_a; @@ -97,13 +97,13 @@ final class TileFactory{ /** * @param string $baseClass - * @param Level $level + * @param World $world * @param Vector3 $pos * * @return Tile (will be an instanceof $baseClass) * @throws \InvalidArgumentException if the specified class is not a registered tile */ - public static function create(string $baseClass, Level $level, Vector3 $pos) : Tile{ + public static function create(string $baseClass, World $world, Vector3 $pos) : Tile{ if(isset(self::$classMapping[$baseClass])){ $class = self::$classMapping[$baseClass]; assert(is_a($class, $baseClass, true)); @@ -111,7 +111,7 @@ final class TileFactory{ * @var Tile $tile * @see Tile::__construct() */ - $tile = new $class($level, $pos); + $tile = new $class($world, $pos); return $tile; } @@ -120,14 +120,14 @@ final class TileFactory{ } /** - * @internal - * - * @param Level $level + * @param World $world * @param CompoundTag $nbt * * @return Tile|null + *@internal + * */ - public static function createFromData(Level $level, CompoundTag $nbt) : ?Tile{ + public static function createFromData(World $world, CompoundTag $nbt) : ?Tile{ $type = $nbt->getString(Tile::TAG_ID, "", true); if(!isset(self::$knownTiles[$type])){ return null; @@ -138,7 +138,7 @@ final class TileFactory{ * @var Tile $tile * @see Tile::__construct() */ - $tile = new $class($level, new Vector3($nbt->getInt(Tile::TAG_X), $nbt->getInt(Tile::TAG_Y), $nbt->getInt(Tile::TAG_Z))); + $tile = new $class($world, new Vector3($nbt->getInt(Tile::TAG_X), $nbt->getInt(Tile::TAG_Y), $nbt->getInt(Tile::TAG_Z))); $tile->readSaveData($nbt); return $tile; diff --git a/src/pocketmine/timings/TimingsHandler.php b/src/pocketmine/timings/TimingsHandler.php index bb89d07e2..11db46a3a 100644 --- a/src/pocketmine/timings/TimingsHandler.php +++ b/src/pocketmine/timings/TimingsHandler.php @@ -64,9 +64,9 @@ class TimingsHandler{ $entities = 0; $livingEntities = 0; - foreach(Server::getInstance()->getLevelManager()->getLevels() as $level){ - $entities += count($level->getEntities()); - foreach($level->getEntities() as $e){ + foreach(Server::getInstance()->getWorldManager()->getWorlds() as $world){ + $entities += count($world->getEntities()); + foreach($world->getEntities() as $e){ if($e instanceof Living){ ++$livingEntities; } diff --git a/src/pocketmine/utils/EnumTrait.php b/src/pocketmine/utils/EnumTrait.php index 9843c4b14..518a84d61 100644 --- a/src/pocketmine/utils/EnumTrait.php +++ b/src/pocketmine/utils/EnumTrait.php @@ -174,4 +174,15 @@ public static function %1$s() : self{ public function getEnumName() : string{ return $this->enumName; } + + /** + * Returns whether the two objects are equivalent. + * + * @param self $other + * + * @return bool + */ + public function equals(self $other) : bool{ + return $this->enumName === $other->enumName; + } } diff --git a/src/pocketmine/level/BlockTransaction.php b/src/pocketmine/world/BlockTransaction.php similarity index 99% rename from src/pocketmine/level/BlockTransaction.php rename to src/pocketmine/world/BlockTransaction.php index d3aa55fc9..6232f4478 100644 --- a/src/pocketmine/level/BlockTransaction.php +++ b/src/pocketmine/world/BlockTransaction.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level; +namespace pocketmine\world; use pocketmine\block\Block; use pocketmine\math\Vector3; diff --git a/src/pocketmine/level/ChunkListener.php b/src/pocketmine/world/ChunkListener.php similarity index 93% rename from src/pocketmine/level/ChunkListener.php rename to src/pocketmine/world/ChunkListener.php index 74e80944a..3685d6dfa 100644 --- a/src/pocketmine/level/ChunkListener.php +++ b/src/pocketmine/world/ChunkListener.php @@ -21,18 +21,18 @@ declare(strict_types=1); -namespace pocketmine\level; +namespace pocketmine\world; use pocketmine\block\Block; -use pocketmine\level\format\Chunk; use pocketmine\math\Vector3; +use pocketmine\world\format\Chunk; /** * This interface allows you to listen for events occurring on or in specific chunks. This will receive events for any * chunks which it is registered to listen to. * - * @see Level::registerChunkListener() - * @see Level::unregisterChunkListener() + * @see World::registerChunkListener() + * @see World::unregisterChunkListener() * * WARNING: When you're done with the listener, make sure you unregister it from all chunks it's listening to, otherwise * the object will not be destroyed. diff --git a/src/pocketmine/level/ChunkLoader.php b/src/pocketmine/world/ChunkLoader.php similarity index 87% rename from src/pocketmine/level/ChunkLoader.php rename to src/pocketmine/world/ChunkLoader.php index 7529cb548..e68f88b56 100644 --- a/src/pocketmine/level/ChunkLoader.php +++ b/src/pocketmine/world/ChunkLoader.php @@ -21,13 +21,13 @@ declare(strict_types=1); -namespace pocketmine\level; +namespace pocketmine\world; /** - * If you want to keep chunks loaded, implement this interface and register it into Level. This will also tick chunks. + * If you want to keep chunks loaded, implement this interface and register it into World. This will also tick chunks. * - * @see Level::registerChunkLoader() - * @see Level::unregisterChunkLoader() + * @see World::registerChunkLoader() + * @see World::unregisterChunkLoader() * * WARNING: When moving this object around in the world or destroying it, * be sure to unregister the loader from chunks you're not using, otherwise you'll leak memory. diff --git a/src/pocketmine/level/ChunkManager.php b/src/pocketmine/world/ChunkManager.php similarity index 97% rename from src/pocketmine/level/ChunkManager.php rename to src/pocketmine/world/ChunkManager.php index c81453104..b0153b3d2 100644 --- a/src/pocketmine/level/ChunkManager.php +++ b/src/pocketmine/world/ChunkManager.php @@ -21,10 +21,10 @@ declare(strict_types=1); -namespace pocketmine\level; +namespace pocketmine\world; use pocketmine\block\Block; -use pocketmine\level\format\Chunk; +use pocketmine\world\format\Chunk; interface ChunkManager{ diff --git a/src/pocketmine/level/Explosion.php b/src/pocketmine/world/Explosion.php similarity index 86% rename from src/pocketmine/level/Explosion.php rename to src/pocketmine/world/Explosion.php index 14272a7a7..ee0b86c9e 100644 --- a/src/pocketmine/level/Explosion.php +++ b/src/pocketmine/world/Explosion.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level; +namespace pocketmine\world; use pocketmine\block\Block; use pocketmine\block\BlockFactory; @@ -34,13 +34,13 @@ use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityExplodeEvent; use pocketmine\item\ItemFactory; -use pocketmine\level\particle\HugeExplodeSeedParticle; -use pocketmine\level\sound\ExplodeSound; -use pocketmine\level\utils\SubChunkIteratorManager; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\ExplodePacket; +use pocketmine\world\particle\HugeExplodeSeedParticle; +use pocketmine\world\sound\ExplodeSound; +use pocketmine\world\utils\SubChunkIteratorManager; use function ceil; use function floor; use function mt_rand; @@ -48,8 +48,8 @@ use function mt_rand; class Explosion{ /** @var int */ private $rays = 16; - /** @var Level */ - public $level; + /** @var World */ + public $world; /** @var Position */ public $source; /** @var float */ @@ -75,7 +75,7 @@ class Explosion{ throw new \InvalidArgumentException("Position does not have a valid world"); } $this->source = $center; - $this->level = $center->getLevel(); + $this->world = $center->getWorld(); if($size <= 0){ throw new \InvalidArgumentException("Explosion radius must be greater than 0, got $size"); @@ -83,7 +83,7 @@ class Explosion{ $this->size = $size; $this->what = $what; - $this->subChunkHandler = new SubChunkIteratorManager($this->level, false); + $this->subChunkHandler = new SubChunkIteratorManager($this->world, false); } /** @@ -95,7 +95,7 @@ class Explosion{ } $vector = new Vector3(0, 0, 0); - $vBlock = new Position(0, 0, 0, $this->level); + $vBlock = new Position(0, 0, 0, $this->world); $currentChunk = null; $currentSubChunk = null; @@ -128,7 +128,7 @@ class Explosion{ if($state !== 0){ $blastForce -= (BlockFactory::$blastResistance[$state] / 5 + 0.3) * $this->stepLen; if($blastForce > 0){ - if(!isset($this->affectedBlocks[$index = Level::blockHash($vBlock->x, $vBlock->y, $vBlock->z)])){ + if(!isset($this->affectedBlocks[$index = World::blockHash($vBlock->x, $vBlock->y, $vBlock->z)])){ $this->affectedBlocks[$index] = BlockFactory::get($state >> 4, $state & 0xf, $vBlock); } } @@ -174,7 +174,7 @@ class Explosion{ $explosionBB = new AxisAlignedBB($minX, $minY, $minZ, $maxX, $maxY, $maxZ); - $list = $this->level->getNearbyEntities($explosionBB, $this->what instanceof Entity ? $this->what : null); + $list = $this->world->getNearbyEntities($explosionBB, $this->what instanceof Entity ? $this->what : null); foreach($list as $entity){ $distance = $entity->distance($this->source) / $explosionSize; @@ -208,28 +208,28 @@ class Explosion{ }else{ if(mt_rand(0, 100) < $yield){ foreach($block->getDrops($air) as $drop){ - $this->level->dropItem($block->add(0.5, 0.5, 0.5), $drop); + $this->world->dropItem($block->add(0.5, 0.5, 0.5), $drop); } } - if(($t = $this->level->getTileAt($block->x, $block->y, $block->z)) !== null){ + if(($t = $this->world->getTileAt($block->x, $block->y, $block->z)) !== null){ $t->onBlockDestroyed(); //needed to create drops for inventories } - $this->level->setBlockAt($block->x, $block->y, $block->z, $airBlock, false); //TODO: should updating really be disabled here? - $this->level->updateAllLight($block); + $this->world->setBlockAt($block->x, $block->y, $block->z, $airBlock, false); //TODO: should updating really be disabled here? + $this->world->updateAllLight($block); } $pos = new Vector3($block->x, $block->y, $block->z); foreach(Facing::ALL as $side){ $sideBlock = $pos->getSide($side); - if(!$this->level->isInWorld($sideBlock->x, $sideBlock->y, $sideBlock->z)){ + if(!$this->world->isInWorld($sideBlock->x, $sideBlock->y, $sideBlock->z)){ continue; } - if(!isset($this->affectedBlocks[$index = Level::blockHash($sideBlock->x, $sideBlock->y, $sideBlock->z)]) and !isset($updateBlocks[$index])){ - $ev = new BlockUpdateEvent($this->level->getBlockAt($sideBlock->x, $sideBlock->y, $sideBlock->z)); + if(!isset($this->affectedBlocks[$index = World::blockHash($sideBlock->x, $sideBlock->y, $sideBlock->z)]) and !isset($updateBlocks[$index])){ + $ev = new BlockUpdateEvent($this->world->getBlockAt($sideBlock->x, $sideBlock->y, $sideBlock->z)); $ev->call(); if(!$ev->isCancelled()){ - foreach($this->level->getNearbyEntities(AxisAlignedBB::one()->offset($sideBlock->x, $sideBlock->y, $sideBlock->z)->expand(1, 1, 1)) as $entity){ + foreach($this->world->getNearbyEntities(AxisAlignedBB::one()->offset($sideBlock->x, $sideBlock->y, $sideBlock->z)->expand(1, 1, 1)) as $entity){ $entity->onNearbyBlockChange(); } $ev->getBlock()->onNearbyBlockChange(); @@ -244,10 +244,10 @@ class Explosion{ $pk->position = $this->source->asVector3(); $pk->radius = $this->size; $pk->records = $send; - $this->level->broadcastPacketToViewers($source, $pk); + $this->world->broadcastPacketToViewers($source, $pk); - $this->level->addParticle($source, new HugeExplodeSeedParticle()); - $this->level->addSound($source, new ExplodeSound()); + $this->world->addParticle($source, new HugeExplodeSeedParticle()); + $this->world->addSound($source, new ExplodeSound()); return true; } diff --git a/src/pocketmine/level/Location.php b/src/pocketmine/world/Location.php similarity index 80% rename from src/pocketmine/level/Location.php rename to src/pocketmine/world/Location.php index 9b11d01d7..96349af86 100644 --- a/src/pocketmine/level/Location.php +++ b/src/pocketmine/world/Location.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level; +namespace pocketmine\world; use pocketmine\math\Vector3; @@ -38,24 +38,24 @@ class Location extends Position{ * @param int $z * @param float $yaw * @param float $pitch - * @param Level $level + * @param World $world */ - public function __construct($x = 0, $y = 0, $z = 0, float $yaw = 0.0, float $pitch = 0.0, ?Level $level = null){ + public function __construct($x = 0, $y = 0, $z = 0, float $yaw = 0.0, float $pitch = 0.0, ?World $world = null){ $this->yaw = $yaw; $this->pitch = $pitch; - parent::__construct($x, $y, $z, $level); + parent::__construct($x, $y, $z, $world); } /** * @param Vector3 $pos - * @param Level|null $level default null + * @param World|null $world default null * @param float $yaw default 0.0 * @param float $pitch default 0.0 * * @return Location */ - public static function fromObject(Vector3 $pos, ?Level $level = null, float $yaw = 0.0, float $pitch = 0.0){ - return new Location($pos->x, $pos->y, $pos->z, $yaw, $pitch, $level ?? (($pos instanceof Position) ? $pos->level : null)); + public static function fromObject(Vector3 $pos, ?World $world = null, float $yaw = 0.0, float $pitch = 0.0){ + return new Location($pos->x, $pos->y, $pos->z, $yaw, $pitch, $world ?? (($pos instanceof Position) ? $pos->world : null)); } /** @@ -64,7 +64,7 @@ class Location extends Position{ * @return Location */ public function asLocation() : Location{ - return new Location($this->x, $this->y, $this->z, $this->yaw, $this->pitch, $this->level); + return new Location($this->x, $this->y, $this->z, $this->yaw, $this->pitch, $this->world); } public function getYaw() : float{ @@ -76,7 +76,7 @@ class Location extends Position{ } public function __toString(){ - return "Location (level=" . ($this->isValid() ? $this->getLevel()->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/pocketmine/level/Position.php b/src/pocketmine/world/Position.php similarity index 61% rename from src/pocketmine/level/Position.php rename to src/pocketmine/world/Position.php index a6bb3ef67..58c8fbcf2 100644 --- a/src/pocketmine/level/Position.php +++ b/src/pocketmine/world/Position.php @@ -21,29 +21,29 @@ declare(strict_types=1); -namespace pocketmine\level; +namespace pocketmine\world; use pocketmine\math\Vector3; use function assert; class Position extends Vector3{ - /** @var Level */ - public $level = null; + /** @var World */ + public $world = null; /** * @param int $x * @param int $y * @param int $z - * @param Level $level + * @param World $world */ - public function __construct($x = 0, $y = 0, $z = 0, ?Level $level = null){ + public function __construct($x = 0, $y = 0, $z = 0, ?World $world = null){ parent::__construct($x, $y, $z); - $this->setLevel($level); + $this->setWorld($world); } - public static function fromObject(Vector3 $pos, ?Level $level = null){ - return new Position($pos->x, $pos->y, $pos->z, $level); + public static function fromObject(Vector3 $pos, ?World $world = null){ + return new Position($pos->x, $pos->y, $pos->z, $world); } /** @@ -52,55 +52,55 @@ class Position extends Vector3{ * @return Position */ public function asPosition() : Position{ - return new Position($this->x, $this->y, $this->z, $this->level); + return new Position($this->x, $this->y, $this->z, $this->world); } /** - * Returns the target Level, or null if the target is not valid. - * If a reference exists to a Level which is closed, the reference will be destroyed and null will be returned. + * 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 Level|null + * @return World|null */ - public function getLevel(){ - if($this->level !== null and $this->level->isClosed()){ + public function getWorld(){ + if($this->world !== null and $this->world->isClosed()){ \GlobalLogger::get()->debug("Position was holding a reference to an unloaded world"); - $this->level = null; + $this->world = null; } - return $this->level; + return $this->world; } /** - * Sets the target Level of the position. + * Sets the target world of the position. * - * @param Level|null $level + * @param World|null $world * * @return $this * - * @throws \InvalidArgumentException if the specified Level has been closed + * @throws \InvalidArgumentException if the specified World has been closed */ - public function setLevel(?Level $level){ - if($level !== null and $level->isClosed()){ + public function setWorld(?World $world){ + if($world !== null and $world->isClosed()){ throw new \InvalidArgumentException("Specified world has been unloaded and cannot be used"); } - $this->level = $level; + $this->world = $world; return $this; } /** - * Checks if this object has a valid reference to a loaded Level + * Checks if this object has a valid reference to a loaded world * * @return bool */ public function isValid() : bool{ - if($this->level !== null and $this->level->isClosed()){ - $this->level = null; + if($this->world !== null and $this->world->isClosed()){ + $this->world = null; return false; } - return $this->level !== null; + return $this->world !== null; } /** @@ -114,16 +114,16 @@ class Position extends Vector3{ public function getSide(int $side, int $step = 1){ assert($this->isValid()); - return Position::fromObject(parent::getSide($side, $step), $this->level); + return Position::fromObject(parent::getSide($side, $step), $this->world); } public function __toString(){ - return "Position(level=" . ($this->isValid() ? $this->getLevel()->getDisplayName() : "null") . ",x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")"; + return "Position(world=" . ($this->isValid() ? $this->getWorld()->getDisplayName() : "null") . ",x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")"; } public function equals(Vector3 $v) : bool{ if($v instanceof Position){ - return parent::equals($v) and $v->getLevel() === $this->getLevel(); + return parent::equals($v) and $v->getWorld() === $this->getWorld(); } return parent::equals($v); } diff --git a/src/pocketmine/level/SimpleChunkManager.php b/src/pocketmine/world/SimpleChunkManager.php similarity index 90% rename from src/pocketmine/level/SimpleChunkManager.php rename to src/pocketmine/world/SimpleChunkManager.php index d8eb2397c..d9297ebac 100644 --- a/src/pocketmine/level/SimpleChunkManager.php +++ b/src/pocketmine/world/SimpleChunkManager.php @@ -21,12 +21,12 @@ declare(strict_types=1); -namespace pocketmine\level; +namespace pocketmine\world; use pocketmine\block\Block; use pocketmine\block\BlockFactory; use pocketmine\block\BlockLegacyIds; -use pocketmine\level\format\Chunk; +use pocketmine\world\format\Chunk; use const INT32_MAX; use const INT32_MIN; @@ -42,7 +42,7 @@ class SimpleChunkManager implements ChunkManager{ * * @param int $worldHeight */ - public function __construct(int $worldHeight = Level::Y_MAX){ + public function __construct(int $worldHeight = World::Y_MAX){ $this->worldHeight = $worldHeight; } @@ -96,7 +96,7 @@ class SimpleChunkManager implements ChunkManager{ * @return Chunk|null */ public function getChunk(int $chunkX, int $chunkZ) : ?Chunk{ - return $this->chunks[Level::chunkHash($chunkX, $chunkZ)] ?? null; + return $this->chunks[World::chunkHash($chunkX, $chunkZ)] ?? null; } /** @@ -106,10 +106,10 @@ class SimpleChunkManager implements ChunkManager{ */ public function setChunk(int $chunkX, int $chunkZ, ?Chunk $chunk) : void{ if($chunk === null){ - unset($this->chunks[Level::chunkHash($chunkX, $chunkZ)]); + unset($this->chunks[World::chunkHash($chunkX, $chunkZ)]); return; } - $this->chunks[Level::chunkHash($chunkX, $chunkZ)] = $chunk; + $this->chunks[World::chunkHash($chunkX, $chunkZ)] = $chunk; } public function cleanChunks() : void{ diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/world/World.php similarity index 92% rename from src/pocketmine/level/Level.php rename to src/pocketmine/world/World.php index 3964f017b..a18d03da6 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/world/World.php @@ -22,9 +22,9 @@ declare(strict_types=1); /** - * All Level related classes are here, like Generators, Populators, Noise, ... + * All World related classes are here, like Generators, Populators, Noise, ... */ -namespace pocketmine\level; +namespace pocketmine\world; use pocketmine\block\Air; use pocketmine\block\Block; @@ -38,34 +38,15 @@ use pocketmine\entity\object\ItemEntity; use pocketmine\event\block\BlockBreakEvent; use pocketmine\event\block\BlockPlaceEvent; use pocketmine\event\block\BlockUpdateEvent; -use pocketmine\event\level\ChunkLoadEvent; -use pocketmine\event\level\ChunkPopulateEvent; -use pocketmine\event\level\ChunkUnloadEvent; -use pocketmine\event\level\LevelSaveEvent; -use pocketmine\event\level\SpawnChangeEvent; use pocketmine\event\player\PlayerInteractEvent; +use pocketmine\event\world\ChunkLoadEvent; +use pocketmine\event\world\ChunkPopulateEvent; +use pocketmine\event\world\ChunkUnloadEvent; +use pocketmine\event\world\SpawnChangeEvent; +use pocketmine\event\world\WorldSaveEvent; use pocketmine\item\Item; use pocketmine\item\ItemFactory; use pocketmine\item\ItemUseResult; -use pocketmine\level\biome\Biome; -use pocketmine\level\format\Chunk; -use pocketmine\level\format\ChunkException; -use pocketmine\level\format\EmptySubChunk; -use pocketmine\level\format\io\exception\CorruptedChunkException; -use pocketmine\level\format\io\exception\UnsupportedChunkFormatException; -use pocketmine\level\format\io\WritableLevelProvider; -use pocketmine\level\generator\Generator; -use pocketmine\level\generator\GeneratorManager; -use pocketmine\level\generator\GeneratorRegisterTask; -use pocketmine\level\generator\GeneratorUnregisterTask; -use pocketmine\level\generator\PopulationTask; -use pocketmine\level\light\BlockLightUpdate; -use pocketmine\level\light\LightPopulationTask; -use pocketmine\level\light\SkyLightUpdate; -use pocketmine\level\particle\DestroyBlockParticle; -use pocketmine\level\particle\Particle; -use pocketmine\level\sound\BlockPlaceSound; -use pocketmine\level\sound\Sound; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Vector3; use pocketmine\metadata\BlockMetadataStore; @@ -87,6 +68,25 @@ use pocketmine\tile\Spawnable; use pocketmine\tile\Tile; use pocketmine\timings\Timings; use pocketmine\utils\ReversePriorityQueue; +use pocketmine\world\biome\Biome; +use pocketmine\world\format\Chunk; +use pocketmine\world\format\ChunkException; +use pocketmine\world\format\EmptySubChunk; +use pocketmine\world\format\io\exception\CorruptedChunkException; +use pocketmine\world\format\io\exception\UnsupportedChunkFormatException; +use pocketmine\world\format\io\WritableWorldProvider; +use pocketmine\world\generator\Generator; +use pocketmine\world\generator\GeneratorManager; +use pocketmine\world\generator\GeneratorRegisterTask; +use pocketmine\world\generator\GeneratorUnregisterTask; +use pocketmine\world\generator\PopulationTask; +use pocketmine\world\light\BlockLightUpdate; +use pocketmine\world\light\LightPopulationTask; +use pocketmine\world\light\SkyLightUpdate; +use pocketmine\world\particle\DestroyBlockParticle; +use pocketmine\world\particle\Particle; +use pocketmine\world\sound\BlockPlaceSound; +use pocketmine\world\sound\Sound; use function abs; use function array_fill_keys; use function array_map; @@ -115,11 +115,11 @@ use const M_PI; use const PHP_INT_MAX; use const PHP_INT_MIN; -#include +#include -class Level implements ChunkManager, Metadatable{ +class World implements ChunkManager, Metadatable{ - private static $levelIdCounter = 1; + private static $worldIdCounter = 1; public const Y_MASK = 0xFF; public const Y_MAX = 0x100; //256 @@ -156,9 +156,9 @@ class Level implements ChunkManager, Metadatable{ private $server; /** @var int */ - private $levelId; + private $worldId; - /** @var WritableLevelProvider */ + /** @var WritableWorldProvider */ private $provider; /** @var int */ private $providerGarbageCollectionTicker = 0; @@ -250,7 +250,7 @@ class Level implements ChunkManager, Metadatable{ /** @var \SplFixedArray */ private $randomTickBlocks = null; - /** @var LevelTimings */ + /** @var WorldTimings */ public $timings; /** @var int */ @@ -275,10 +275,10 @@ class Level implements ChunkManager, Metadatable{ } public static function blockHash(int $x, int $y, int $z) : int{ - if($y < 0 or $y >= Level::Y_MAX){ + if($y < 0 or $y >= World::Y_MAX){ throw new \InvalidArgumentException("Y coordinate $y is out of range!"); } - return (($x & 0xFFFFFFF) << 36) | (($y & Level::Y_MASK) << 28) | ($z & 0xFFFFFFF); + return (($x & 0xFFFFFFF) << 36) | (($y & World::Y_MASK) << 28) | ($z & 0xFFFFFFF); } /** @@ -296,7 +296,7 @@ class Level implements ChunkManager, Metadatable{ public static function getBlockXYZ(int $hash, ?int &$x, ?int &$y, ?int &$z) : void{ $x = $hash >> 36; - $y = ($hash >> 28) & Level::Y_MASK; //it's always positive + $y = ($hash >> 28) & World::Y_MASK; //it's always positive $z = ($hash & 0xFFFFFFF) << 36 >> 36; } @@ -320,46 +320,46 @@ class Level implements ChunkManager, Metadatable{ case "0": case "peaceful": case "p": - return Level::DIFFICULTY_PEACEFUL; + return World::DIFFICULTY_PEACEFUL; case "1": case "easy": case "e": - return Level::DIFFICULTY_EASY; + return World::DIFFICULTY_EASY; case "2": case "normal": case "n": - return Level::DIFFICULTY_NORMAL; + return World::DIFFICULTY_NORMAL; case "3": case "hard": case "h": - return Level::DIFFICULTY_HARD; + return World::DIFFICULTY_HARD; } return -1; } /** - * Init the default level data + * Init the default world data * * @param Server $server * @param string $name - * @param WritableLevelProvider $provider + * @param WritableWorldProvider $provider */ - public function __construct(Server $server, string $name, WritableLevelProvider $provider){ - $this->levelId = static::$levelIdCounter++; + public function __construct(Server $server, string $name, WritableWorldProvider $provider){ + $this->worldId = static::$worldIdCounter++; $this->blockMetadata = new BlockMetadataStore($this); $this->server = $server; $this->provider = $provider; - $this->displayName = $this->provider->getLevelData()->getName(); + $this->displayName = $this->provider->getWorldData()->getName(); $this->worldHeight = $this->provider->getWorldHeight(); $this->server->getLogger()->info($this->server->getLanguage()->translateString("pocketmine.level.preparing", [$this->displayName])); - $this->generator = GeneratorManager::getGenerator($this->provider->getLevelData()->getGenerator(), true); + $this->generator = GeneratorManager::getGenerator($this->provider->getWorldData()->getGenerator(), true); //TODO: validate generator options $this->folderName = $name; @@ -369,7 +369,7 @@ class Level implements ChunkManager, Metadatable{ $this->neighbourBlockUpdateQueue = new \SplQueue(); - $this->time = $this->provider->getLevelData()->getTime(); + $this->time = $this->provider->getWorldData()->getTime(); $this->chunkTickRadius = min($this->server->getViewDistance(), max(1, (int) $this->server->getProperty("chunk-ticking.tick-radius", 4))); $this->chunksPerTick = (int) $this->server->getProperty("chunk-ticking.per-tick", 40); @@ -391,7 +391,7 @@ class Level implements ChunkManager, Metadatable{ } } - $this->timings = new LevelTimings($this); + $this->timings = new WorldTimings($this); $this->temporalPosition = new Position(0, 0, 0, $this); $this->temporalVector = new Vector3(0, 0, 0); } @@ -402,7 +402,7 @@ class Level implements ChunkManager, Metadatable{ public function registerGeneratorToWorker(int $worker) : void{ $this->generatorRegisteredWorkers[$worker] = true; - $this->server->getAsyncPool()->submitTaskToWorker(new GeneratorRegisterTask($this, $this->generator, $this->provider->getLevelData()->getGeneratorOptions()), $worker); + $this->server->getAsyncPool()->submitTaskToWorker(new GeneratorRegisterTask($this, $this->generator, $this->provider->getWorldData()->getGeneratorOptions()), $worker); } public function unregisterGenerator(){ @@ -423,15 +423,15 @@ class Level implements ChunkManager, Metadatable{ return $this->server; } - final public function getProvider() : WritableLevelProvider{ + final public function getProvider() : WritableWorldProvider{ return $this->provider; } /** - * Returns the unique level identifier + * Returns the unique world identifier */ final public function getId() : int{ - return $this->levelId; + return $this->worldId; } public function isClosed() : bool{ @@ -498,7 +498,7 @@ class Level implements ChunkManager, Metadatable{ /** * Broadcasts a LevelEvent to players in the area. This could be sound, particles, weather changes, etc. * - * @param Vector3|null $pos If null, broadcasts to every player in the Level + * @param Vector3|null $pos If null, broadcasts to every player in the World * @param int $evid * @param int $data */ @@ -531,7 +531,7 @@ class Level implements ChunkManager, Metadatable{ * @return Player[] */ public function getChunkPlayers(int $chunkX, int $chunkZ) : array{ - return $this->playerLoaders[Level::chunkHash($chunkX, $chunkZ)] ?? []; + return $this->playerLoaders[World::chunkHash($chunkX, $chunkZ)] ?? []; } /** @@ -543,7 +543,7 @@ class Level implements ChunkManager, Metadatable{ * @return ChunkLoader[] */ public function getChunkLoaders(int $chunkX, int $chunkZ) : array{ - return $this->chunkLoaders[Level::chunkHash($chunkX, $chunkZ)] ?? []; + return $this->chunkLoaders[World::chunkHash($chunkX, $chunkZ)] ?? []; } /** @@ -565,7 +565,7 @@ class Level implements ChunkManager, Metadatable{ * @param ClientboundPacket $packet */ public function addChunkPacket(int $chunkX, int $chunkZ, ClientboundPacket $packet){ - if(!isset($this->chunkPackets[$index = Level::chunkHash($chunkX, $chunkZ)])){ + if(!isset($this->chunkPackets[$index = World::chunkHash($chunkX, $chunkZ)])){ $this->chunkPackets[$index] = [$packet]; }else{ $this->chunkPackets[$index][] = $packet; @@ -583,7 +583,7 @@ class Level implements ChunkManager, Metadatable{ } /** - * Broadcasts a packet to every player in the level. + * Broadcasts a packet to every player in the world. * * @param ClientboundPacket $packet */ @@ -594,7 +594,7 @@ class Level implements ChunkManager, Metadatable{ public function registerChunkLoader(ChunkLoader $loader, int $chunkX, int $chunkZ, bool $autoLoad = true){ $loaderId = spl_object_id($loader); - if(!isset($this->chunkLoaders[$chunkHash = Level::chunkHash($chunkX, $chunkZ)])){ + if(!isset($this->chunkLoaders[$chunkHash = World::chunkHash($chunkX, $chunkZ)])){ $this->chunkLoaders[$chunkHash] = []; $this->playerLoaders[$chunkHash] = []; }elseif(isset($this->chunkLoaders[$chunkHash][$loaderId])){ @@ -621,7 +621,7 @@ class Level implements ChunkManager, Metadatable{ } public function unregisterChunkLoader(ChunkLoader $loader, int $chunkX, int $chunkZ){ - $chunkHash = Level::chunkHash($chunkX, $chunkZ); + $chunkHash = World::chunkHash($chunkX, $chunkZ); $loaderId = spl_object_id($loader); if(isset($this->chunkLoaders[$chunkHash][$loaderId])){ unset($this->chunkLoaders[$chunkHash][$loaderId]); @@ -647,7 +647,7 @@ class Level implements ChunkManager, Metadatable{ * @param int $chunkZ */ public function registerChunkListener(ChunkListener $listener, int $chunkX, int $chunkZ) : void{ - $hash = Level::chunkHash($chunkX, $chunkZ); + $hash = World::chunkHash($chunkX, $chunkZ); if(isset($this->chunkListeners[$hash])){ $this->chunkListeners[$hash][spl_object_id($listener)] = $listener; }else{ @@ -657,14 +657,16 @@ class Level implements ChunkManager, Metadatable{ /** * Unregisters a chunk listener previously registered. - * @see Level::registerChunkListener() * * @param ChunkListener $listener * @param int $chunkX * @param int $chunkZ + * + *@see World::registerChunkListener() + * */ public function unregisterChunkListener(ChunkListener $listener, int $chunkX, int $chunkZ) : void{ - $hash = Level::chunkHash($chunkX, $chunkZ); + $hash = World::chunkHash($chunkX, $chunkZ); if(isset($this->chunkListeners[$hash])){ unset($this->chunkListeners[$hash][spl_object_id($listener)]); if(empty($this->chunkListeners[$hash])){ @@ -674,7 +676,7 @@ class Level implements ChunkManager, Metadatable{ } /** - * Unregisters a chunk listener from all chunks it is listening on in this Level. + * Unregisters a chunk listener from all chunks it is listening on in this World. * * @param ChunkListener $listener */ @@ -699,13 +701,13 @@ class Level implements ChunkManager, Metadatable{ * @return ChunkListener[] */ public function getChunkListeners(int $chunkX, int $chunkZ) : array{ - return $this->chunkListeners[Level::chunkHash($chunkX, $chunkZ)] ?? []; + return $this->chunkListeners[World::chunkHash($chunkX, $chunkZ)] ?? []; } /** * @internal * - * @param Player ...$targets If empty, will send to all players in the level. + * @param Player ...$targets If empty, will send to all players in the world. */ public function sendTime(Player ...$targets){ $pk = new SetTimePacket(); @@ -773,14 +775,14 @@ class Level implements ChunkManager, Metadatable{ //Delayed updates while($this->scheduledBlockUpdateQueue->count() > 0 and $this->scheduledBlockUpdateQueue->current()["priority"] <= $currentTick){ $block = $this->getBlock($this->scheduledBlockUpdateQueue->extract()["data"]); - unset($this->scheduledBlockUpdateQueueIndex[Level::blockHash($block->x, $block->y, $block->z)]); + unset($this->scheduledBlockUpdateQueueIndex[World::blockHash($block->x, $block->y, $block->z)]); $block->onScheduledUpdate(); } //Normal updates while($this->neighbourBlockUpdateQueue->count() > 0){ $index = $this->neighbourBlockUpdateQueue->dequeue(); - Level::getBlockXYZ($index, $x, $y, $z); + World::getBlockXYZ($index, $x, $y, $z); $block = $this->getBlockAt($x, $y, $z); $block->readStateFromWorld(); //for blocks like fences, force recalculation of connected AABBs @@ -820,7 +822,7 @@ class Level implements ChunkManager, Metadatable{ unset($this->updateTiles[$blockHash]); } if(!$tile->isClosed() and $tile instanceof Spawnable and $tile->isDirty()){ - $chunkHash = Level::chunkHash($tile->getFloorX() >> 4, $tile->getFloorZ() >> 4); + $chunkHash = World::chunkHash($tile->getFloorX() >> 4, $tile->getFloorZ() >> 4); if(!isset($this->changedBlocks[$chunkHash])){ $this->changedBlocks[$chunkHash] = [$blockHash => $tile]; }else{ @@ -844,7 +846,7 @@ class Level implements ChunkManager, Metadatable{ if(empty($blocks)){ //blocks can be set normally and then later re-set with direct send continue; } - Level::getXZ($index, $chunkX, $chunkZ); + World::getXZ($index, $chunkX, $chunkZ); if(count($blocks) > 512){ $chunk = $this->getChunk($chunkX, $chunkZ); foreach($this->getChunkPlayers($chunkX, $chunkZ) as $p){ @@ -877,7 +879,7 @@ class Level implements ChunkManager, Metadatable{ } foreach($this->chunkPackets as $index => $entries){ - Level::getXZ($index, $chunkX, $chunkZ); + World::getXZ($index, $chunkX, $chunkZ); $chunkPlayers = $this->getChunkPlayers($chunkX, $chunkZ); if(count($chunkPlayers) > 0){ $this->server->broadcastPackets($chunkPlayers, $entries); @@ -901,10 +903,10 @@ class Level implements ChunkManager, Metadatable{ } if($resetTime){ - $time = $this->getTime() % Level::TIME_FULL; + $time = $this->getTime() % World::TIME_FULL; - if($time >= Level::TIME_NIGHT and $time < Level::TIME_SUNRISE){ - $this->setTime($this->getTime() + Level::TIME_FULL - $time); + if($time >= World::TIME_NIGHT and $time < World::TIME_SUNRISE){ + $this->setTime($this->getTime() + World::TIME_FULL - $time); foreach($this->getPlayers() as $p){ $p->stopSleep(); @@ -1006,12 +1008,12 @@ class Level implements ChunkManager, Metadatable{ for($chunk = 0; $chunk < $chunksPerLoader; ++$chunk){ $dx = mt_rand(-$randRange, $randRange); $dz = mt_rand(-$randRange, $randRange); - $hash = Level::chunkHash($dx + $chunkX, $dz + $chunkZ); + $hash = World::chunkHash($dx + $chunkX, $dz + $chunkZ); if(!isset($chunkTickList[$hash]) and isset($this->chunks[$hash])){ //check adjacent chunks are loaded for($cx = -1; $cx <= 1; ++$cx){ for($cz = -1; $cz <= 1; ++$cz){ - if(!isset($this->chunks[Level::chunkHash($chunkX + $dx + $cx, $chunkZ + $dz + $cz)])){ + if(!isset($this->chunks[World::chunkHash($chunkX + $dx + $cx, $chunkZ + $dz + $cz)])){ continue 3; } } @@ -1022,7 +1024,7 @@ class Level implements ChunkManager, Metadatable{ } foreach($chunkTickList as $index => $_){ - Level::getXZ($index, $chunkX, $chunkZ); + World::getXZ($index, $chunkX, $chunkZ); $chunk = $this->chunks[$index]; foreach($chunk->getEntities() as $entity){ @@ -1071,11 +1073,11 @@ class Level implements ChunkManager, Metadatable{ return false; } - (new LevelSaveEvent($this))->call(); + (new WorldSaveEvent($this))->call(); - $this->provider->getLevelData()->setTime($this->time); + $this->provider->getWorldData()->setTime($this->time); $this->saveChunks(); - $this->provider->getLevelData()->save(); + $this->provider->getWorldData()->save(); return true; } @@ -1104,7 +1106,7 @@ class Level implements ChunkManager, Metadatable{ public function scheduleDelayedBlockUpdate(Vector3 $pos, int $delay){ if( !$this->isInWorld($pos->x, $pos->y, $pos->z) or - (isset($this->scheduledBlockUpdateQueueIndex[$index = Level::blockHash($pos->x, $pos->y, $pos->z)]) and $this->scheduledBlockUpdateQueueIndex[$index] <= $delay) + (isset($this->scheduledBlockUpdateQueueIndex[$index = World::blockHash($pos->x, $pos->y, $pos->z)]) and $this->scheduledBlockUpdateQueueIndex[$index] <= $delay) ){ return; } @@ -1114,7 +1116,7 @@ class Level implements ChunkManager, Metadatable{ private function tryAddToNeighbourUpdateQueue(Vector3 $pos) : void{ if($this->isInWorld($pos->x, $pos->y, $pos->z)){ - $hash = Level::blockHash($pos->x, $pos->y, $pos->z); + $hash = World::blockHash($pos->x, $pos->y, $pos->z); if(!isset($this->neighbourBlockUpdateQueueIndex[$hash])){ $this->neighbourBlockUpdateQueue->enqueue($hash); $this->neighbourBlockUpdateQueueIndex[$hash] = true; @@ -1368,10 +1370,10 @@ class Level implements ChunkManager, Metadatable{ public function getBlockAt(int $x, int $y, int $z, bool $cached = true, bool $addToCache = true) : Block{ $fullState = 0; $relativeBlockHash = null; - $chunkHash = Level::chunkHash($x >> 4, $z >> 4); + $chunkHash = World::chunkHash($x >> 4, $z >> 4); if($this->isInWorld($x, $y, $z)){ - $relativeBlockHash = Level::chunkBlockHash($x, $y, $z); + $relativeBlockHash = World::chunkBlockHash($x, $y, $z); if($cached and isset($this->blockCache[$chunkHash][$relativeBlockHash])){ return $this->blockCache[$chunkHash][$relativeBlockHash]; @@ -1525,7 +1527,6 @@ class Level implements ChunkManager, Metadatable{ /** * Sets the block at the given Vector3 coordinates. - * @see Level::setBlockAt() * * @param Vector3 $pos * @param Block $block @@ -1534,6 +1535,8 @@ class Level implements ChunkManager, Metadatable{ * @return bool Whether the block has been updated or not * * @throws \InvalidArgumentException if the position is out of the world bounds + *@see World::setBlockAt() + * */ public function setBlock(Vector3 $pos, Block $block, bool $update = true) : bool{ return $this->setBlockAt((int) floor($pos->x), (int) floor($pos->y), (int) floor($pos->z), $block, $update); @@ -1567,8 +1570,8 @@ class Level implements ChunkManager, Metadatable{ $block->position($this, $x, $y, $z); $block->writeStateToWorld(); - $chunkHash = Level::chunkHash($x >> 4, $z >> 4); - $relativeBlockHash = Level::chunkBlockHash($x, $y, $z); + $chunkHash = World::chunkHash($x >> 4, $z >> 4); + $relativeBlockHash = World::chunkBlockHash($x, $y, $z); unset($this->blockCache[$chunkHash][$relativeBlockHash]); @@ -1887,7 +1890,7 @@ class Level implements ChunkManager, Metadatable{ } /** - * Gets the list of all the entities in this level + * Gets the list of all the entities in this world * * @return Entity[] */ @@ -1998,7 +2001,7 @@ class Level implements ChunkManager, Metadatable{ } /** - * Returns a list of the players in this level + * Returns a list of the players in this world * * @return Player[] */ @@ -2180,7 +2183,7 @@ class Level implements ChunkManager, Metadatable{ * @return Chunk|null */ public function getChunk(int $chunkX, int $chunkZ, bool $create = false) : ?Chunk{ - if(isset($this->chunks[$index = Level::chunkHash($chunkX, $chunkZ)])){ + if(isset($this->chunks[$index = World::chunkHash($chunkX, $chunkZ)])){ return $this->chunks[$index]; }elseif($this->loadChunk($chunkX, $chunkZ, $create)){ return $this->chunks[$index]; @@ -2225,7 +2228,7 @@ class Level implements ChunkManager, Metadatable{ } public function lockChunk(int $chunkX, int $chunkZ) : void{ - $chunkHash = Level::chunkHash($chunkX, $chunkZ); + $chunkHash = World::chunkHash($chunkX, $chunkZ); if(isset($this->chunkLock[$chunkHash])){ throw new \InvalidArgumentException("Chunk $chunkX $chunkZ is already locked"); } @@ -2233,16 +2236,16 @@ class Level implements ChunkManager, Metadatable{ } public function unlockChunk(int $chunkX, int $chunkZ) : void{ - unset($this->chunkLock[Level::chunkHash($chunkX, $chunkZ)]); + unset($this->chunkLock[World::chunkHash($chunkX, $chunkZ)]); } public function isChunkLocked(int $chunkX, int $chunkZ) : bool{ - return isset($this->chunkLock[Level::chunkHash($chunkX, $chunkZ)]); + return isset($this->chunkLock[World::chunkHash($chunkX, $chunkZ)]); } public function generateChunkCallback(int $x, int $z, ?Chunk $chunk){ Timings::$generationCallbackTimer->startTiming(); - if(isset($this->chunkPopulationQueue[$index = Level::chunkHash($x, $z)])){ + if(isset($this->chunkPopulationQueue[$index = World::chunkHash($x, $z)])){ for($xx = -1; $xx <= 1; ++$xx){ for($zz = -1; $zz <= 1; ++$zz){ $this->unlockChunk($x + $xx, $z + $zz); @@ -2286,7 +2289,7 @@ class Level implements ChunkManager, Metadatable{ $chunk->setX($chunkX); $chunk->setZ($chunkZ); - $chunkHash = Level::chunkHash($chunkX, $chunkZ); + $chunkHash = World::chunkHash($chunkX, $chunkZ); $oldChunk = $this->getChunk($chunkX, $chunkZ, false); if($oldChunk !== null and $oldChunk !== $chunk){ if($deleteEntitiesAndTiles){ @@ -2359,7 +2362,7 @@ class Level implements ChunkManager, Metadatable{ * @return bool */ public function isChunkLoaded(int $x, int $z) : bool{ - return isset($this->chunks[Level::chunkHash($x, $z)]); + return isset($this->chunks[World::chunkHash($x, $z)]); } /** @@ -2390,22 +2393,22 @@ class Level implements ChunkManager, Metadatable{ * @return Position */ public function getSpawnLocation() : Position{ - return Position::fromObject($this->provider->getLevelData()->getSpawn(), $this); + return Position::fromObject($this->provider->getWorldData()->getSpawn(), $this); } /** - * Sets the level spawn location + * Sets the world spawn location * * @param Vector3 $pos */ public function setSpawnLocation(Vector3 $pos){ $previousSpawn = $this->getSpawnLocation(); - $this->provider->getLevelData()->setSpawn($pos); + $this->provider->getWorldData()->setSpawn($pos); (new SpawnChangeEvent($this, $previousSpawn))->call(); } public function requestChunk(int $x, int $z, Player $player){ - $index = Level::chunkHash($x, $z); + $index = World::chunkHash($x, $z); if(!isset($this->chunkSendQueue[$index])){ $this->chunkSendQueue[$index] = []; } @@ -2414,7 +2417,7 @@ class Level implements ChunkManager, Metadatable{ } private function onChunkReady(int $x, int $z){ - if(isset($this->chunkSendQueue[$index = Level::chunkHash($x, $z)])){ + if(isset($this->chunkSendQueue[$index = World::chunkHash($x, $z)])){ foreach($this->chunkSendQueue[$index] as $player){ /** @var Player $player */ $player->onChunkReady($x, $z); @@ -2428,7 +2431,7 @@ class Level implements ChunkManager, Metadatable{ $this->timings->syncChunkSendTimer->startTiming(); foreach($this->chunkSendQueue as $index => $players){ - Level::getXZ($index, $x, $z); + World::getXZ($index, $x, $z); $this->timings->syncChunkSendPrepareTimer->startTiming(); @@ -2453,7 +2456,7 @@ class Level implements ChunkManager, Metadatable{ if($entity->isClosed()){ throw new \InvalidArgumentException("Attempted to add a garbage closed Entity to world"); } - if($entity->getLevel() !== $this){ + if($entity->getWorld() !== $this){ throw new \InvalidArgumentException("Invalid Entity world"); } @@ -2464,14 +2467,14 @@ class Level implements ChunkManager, Metadatable{ } /** - * Removes the entity from the level index + * Removes the entity from the world index * * @param Entity $entity * * @throws \InvalidArgumentException */ public function removeEntity(Entity $entity){ - if($entity->getLevel() !== $this){ + if($entity->getWorld() !== $this){ throw new \InvalidArgumentException("Invalid Entity world"); } @@ -2493,14 +2496,14 @@ class Level implements ChunkManager, Metadatable{ if($tile->isClosed()){ throw new \InvalidArgumentException("Attempted to add a garbage closed Tile to world"); } - if($tile->getLevel() !== $this){ + if($tile->getWorld() !== $this){ throw new \InvalidArgumentException("Invalid Tile world"); } $chunkX = $tile->getFloorX() >> 4; $chunkZ = $tile->getFloorZ() >> 4; - if(isset($this->chunks[$hash = Level::chunkHash($chunkX, $chunkZ)])){ + if(isset($this->chunks[$hash = World::chunkHash($chunkX, $chunkZ)])){ $this->chunks[$hash]->addTile($tile); }else{ throw new \InvalidStateException("Attempted to create tile " . get_class($tile) . " in unloaded chunk $chunkX $chunkZ"); @@ -2515,16 +2518,16 @@ class Level implements ChunkManager, Metadatable{ * @throws \InvalidArgumentException */ public function removeTile(Tile $tile){ - if($tile->getLevel() !== $this){ + if($tile->getWorld() !== $this){ throw new \InvalidArgumentException("Invalid Tile world"); } - unset($this->updateTiles[Level::blockHash($tile->x, $tile->y, $tile->z)]); + unset($this->updateTiles[World::blockHash($tile->x, $tile->y, $tile->z)]); $chunkX = $tile->getFloorX() >> 4; $chunkZ = $tile->getFloorZ() >> 4; - if(isset($this->chunks[$hash = Level::chunkHash($chunkX, $chunkZ)])){ + if(isset($this->chunks[$hash = World::chunkHash($chunkX, $chunkZ)])){ $this->chunks[$hash]->removeTile($tile); } foreach($this->getChunkListeners($chunkX, $chunkZ) as $listener){ @@ -2539,11 +2542,11 @@ class Level implements ChunkManager, Metadatable{ * @return bool */ public function isChunkInUse(int $x, int $z) : bool{ - return isset($this->chunkLoaders[$index = Level::chunkHash($x, $z)]) and count($this->chunkLoaders[$index]) > 0; + return isset($this->chunkLoaders[$index = World::chunkHash($x, $z)]) and count($this->chunkLoaders[$index]) > 0; } /** - * Attempts to load a chunk from the level provider (if not already loaded). + * Attempts to load a chunk from the world provider (if not already loaded). * * @param int $x * @param int $z @@ -2554,7 +2557,7 @@ class Level implements ChunkManager, Metadatable{ * @throws \InvalidStateException */ public function loadChunk(int $x, int $z, bool $create = true) : bool{ - if(isset($this->chunks[$chunkHash = Level::chunkHash($x, $z)])){ + if(isset($this->chunks[$chunkHash = World::chunkHash($x, $z)])){ return true; } @@ -2609,7 +2612,7 @@ class Level implements ChunkManager, Metadatable{ } private function queueUnloadChunk(int $x, int $z){ - $this->unloadQueue[Level::chunkHash($x, $z)] = microtime(true); + $this->unloadQueue[World::chunkHash($x, $z)] = microtime(true); } public function unloadChunkRequest(int $x, int $z, bool $safe = true){ @@ -2623,7 +2626,7 @@ class Level implements ChunkManager, Metadatable{ } public function cancelUnloadChunkRequest(int $x, int $z){ - unset($this->unloadQueue[Level::chunkHash($x, $z)]); + unset($this->unloadQueue[World::chunkHash($x, $z)]); } public function unloadChunk(int $x, int $z, bool $safe = true, bool $trySave = true) : bool{ @@ -2637,7 +2640,7 @@ class Level implements ChunkManager, Metadatable{ $this->timings->doChunkUnload->startTiming(); - $chunkHash = Level::chunkHash($x, $z); + $chunkHash = World::chunkHash($x, $z); $chunk = $this->chunks[$chunkHash] ?? null; @@ -2749,8 +2752,8 @@ class Level implements ChunkManager, Metadatable{ } /** - * Returns the Level display name. - * WARNING: This is NOT guaranteed to be unique. Multiple levels at runtime may share the same display name. + * Returns the World display name. + * WARNING: This is NOT guaranteed to be unique. Multiple worlds at runtime may share the same display name. * * @return string */ @@ -2759,7 +2762,7 @@ class Level implements ChunkManager, Metadatable{ } /** - * Returns the Level folder name. This will not change at runtime and will be unique to a level per runtime. + * Returns the World folder name. This will not change at runtime and will be unique to a world per runtime. * * @return string */ @@ -2768,7 +2771,7 @@ class Level implements ChunkManager, Metadatable{ } /** - * Sets the current time on the level + * Sets the current time on the world * * @param int $time */ @@ -2778,7 +2781,7 @@ class Level implements ChunkManager, Metadatable{ } /** - * Stops the time for the level, will not save the lock state to disk + * Stops the time for the world, will not save the lock state to disk */ public function stopTime(){ $this->stopTime = true; @@ -2794,12 +2797,12 @@ class Level implements ChunkManager, Metadatable{ } /** - * Gets the level seed + * Gets the world seed * * @return int */ public function getSeed() : int{ - return $this->provider->getLevelData()->getSeed(); + return $this->provider->getWorldData()->getSeed(); } public function getWorldHeight() : int{ @@ -2810,7 +2813,7 @@ class Level implements ChunkManager, Metadatable{ * @return int */ public function getDifficulty() : int{ - return $this->provider->getLevelData()->getDifficulty(); + return $this->provider->getWorldData()->getDifficulty(); } /** @@ -2820,7 +2823,7 @@ class Level implements ChunkManager, Metadatable{ if($difficulty < 0 or $difficulty > 3){ throw new \InvalidArgumentException("Invalid difficulty level $difficulty"); } - $this->provider->getLevelData()->setDifficulty($difficulty); + $this->provider->getWorldData()->setDifficulty($difficulty); $this->sendDifficulty(); } @@ -2839,7 +2842,7 @@ class Level implements ChunkManager, Metadatable{ } public function populateChunk(int $x, int $z, bool $force = false) : bool{ - if(isset($this->chunkPopulationQueue[$index = Level::chunkHash($x, $z)]) or (count($this->chunkPopulationQueue) >= $this->chunkPopulationQueueSize and !$force)){ + if(isset($this->chunkPopulationQueue[$index = World::chunkHash($x, $z)]) or (count($this->chunkPopulationQueue) >= $this->chunkPopulationQueueSize and !$force)){ return false; } for($xx = -1; $xx <= 1; ++$xx){ @@ -2880,7 +2883,7 @@ class Level implements ChunkManager, Metadatable{ foreach($this->chunks as $index => $chunk){ if(!isset($this->unloadQueue[$index])){ - Level::getXZ($index, $X, $Z); + World::getXZ($index, $X, $Z); if(!$this->isSpawnChunk($X, $Z)){ $this->unloadChunkRequest($X, $Z, true); } @@ -2898,7 +2901,7 @@ class Level implements ChunkManager, Metadatable{ $maxUnload = 96; $now = microtime(true); foreach($this->unloadQueue as $index => $time){ - Level::getXZ($index, $X, $Z); + World::getXZ($index, $X, $Z); if(!$force){ if($maxUnload <= 0){ @@ -2918,18 +2921,18 @@ class Level implements ChunkManager, Metadatable{ } public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue) : void{ - $this->server->getLevelMetadata()->setMetadata($this, $metadataKey, $newMetadataValue); + $this->server->getWorldMetadata()->setMetadata($this, $metadataKey, $newMetadataValue); } public function getMetadata(string $metadataKey){ - return $this->server->getLevelMetadata()->getMetadata($this, $metadataKey); + return $this->server->getWorldMetadata()->getMetadata($this, $metadataKey); } public function hasMetadata(string $metadataKey) : bool{ - return $this->server->getLevelMetadata()->hasMetadata($this, $metadataKey); + return $this->server->getWorldMetadata()->hasMetadata($this, $metadataKey); } public function removeMetadata(string $metadataKey, Plugin $owningPlugin) : void{ - $this->server->getLevelMetadata()->removeMetadata($this, $metadataKey, $owningPlugin); + $this->server->getWorldMetadata()->removeMetadata($this, $metadataKey, $owningPlugin); } } diff --git a/src/pocketmine/level/LevelException.php b/src/pocketmine/world/WorldException.php similarity index 91% rename from src/pocketmine/level/LevelException.php rename to src/pocketmine/world/WorldException.php index cda361f86..73966649f 100644 --- a/src/pocketmine/level/LevelException.php +++ b/src/pocketmine/world/WorldException.php @@ -21,10 +21,10 @@ declare(strict_types=1); -namespace pocketmine\level; +namespace pocketmine\world; use pocketmine\utils\ServerException; -class LevelException extends ServerException{ +class WorldException extends ServerException{ } diff --git a/src/pocketmine/level/LevelManager.php b/src/pocketmine/world/WorldManager.php similarity index 60% rename from src/pocketmine/level/LevelManager.php rename to src/pocketmine/world/WorldManager.php index 9581e780c..8c7990922 100644 --- a/src/pocketmine/level/LevelManager.php +++ b/src/pocketmine/world/WorldManager.php @@ -21,23 +21,23 @@ declare(strict_types=1); -namespace pocketmine\level; +namespace pocketmine\world; use pocketmine\entity\Entity; -use pocketmine\event\level\LevelInitEvent; -use pocketmine\event\level\LevelLoadEvent; -use pocketmine\event\level\LevelUnloadEvent; -use pocketmine\level\format\io\exception\UnsupportedLevelFormatException; -use pocketmine\level\format\io\FormatConverter; -use pocketmine\level\format\io\LevelProvider; -use pocketmine\level\format\io\LevelProviderManager; -use pocketmine\level\format\io\WritableLevelProvider; -use pocketmine\level\generator\Generator; -use pocketmine\level\generator\GeneratorManager; -use pocketmine\level\generator\normal\Normal; +use pocketmine\event\world\WorldInitEvent; +use pocketmine\event\world\WorldLoadEvent; +use pocketmine\event\world\WorldUnloadEvent; use pocketmine\Server; use pocketmine\timings\Timings; use pocketmine\utils\Utils; +use pocketmine\world\format\io\exception\UnsupportedWorldFormatException; +use pocketmine\world\format\io\FormatConverter; +use pocketmine\world\format\io\WorldProvider; +use pocketmine\world\format\io\WorldProviderManager; +use pocketmine\world\format\io\WritableWorldProvider; +use pocketmine\world\generator\Generator; +use pocketmine\world\generator\GeneratorManager; +use pocketmine\world\generator\normal\Normal; use function array_keys; use function array_shift; use function asort; @@ -52,11 +52,11 @@ use function trim; use const INT32_MAX; use const INT32_MIN; -class LevelManager{ - /** @var Level[] */ - private $levels = []; - /** @var Level|null */ - private $levelDefault; +class WorldManager{ + /** @var World[] */ + private $worlds = []; + /** @var World|null */ + private $defaultWorld; /** @var Server */ private $server; @@ -77,29 +77,29 @@ class LevelManager{ } /** - * @return Level[] + * @return World[] */ - public function getLevels() : array{ - return $this->levels; + public function getWorlds() : array{ + return $this->worlds; } /** - * @return Level|null + * @return World|null */ - public function getDefaultLevel() : ?Level{ - return $this->levelDefault; + public function getDefaultWorld() : ?World{ + return $this->defaultWorld; } /** - * Sets the default level to a different level + * Sets the default world to a different world * This won't change the level-name property, * it only affects the server on runtime * - * @param Level|null $level + * @param World|null $world */ - public function setDefaultLevel(?Level $level) : void{ - if($level === null or ($this->isLevelLoaded($level->getFolderName()) and $level !== $this->levelDefault)){ - $this->levelDefault = $level; + public function setDefaultWorld(?World $world) : void{ + if($world === null or ($this->isWorldLoaded($world->getFolderName()) and $world !== $this->defaultWorld)){ + $this->defaultWorld = $world; } } @@ -108,30 +108,30 @@ class LevelManager{ * * @return bool */ - public function isLevelLoaded(string $name) : bool{ - return $this->getLevelByName($name) instanceof Level; + public function isWorldLoaded(string $name) : bool{ + return $this->getWorldByName($name) instanceof World; } /** - * @param int $levelId + * @param int $worldId * - * @return Level|null + * @return World|null */ - public function getLevel(int $levelId) : ?Level{ - return $this->levels[$levelId] ?? null; + public function getLevel(int $worldId) : ?World{ + return $this->worlds[$worldId] ?? null; } /** - * NOTE: This matches levels based on the FOLDER name, NOT the display name. + * NOTE: This matches worlds based on the FOLDER name, NOT the display name. * * @param string $name * - * @return Level|null + * @return World|null */ - public function getLevelByName(string $name) : ?Level{ - foreach($this->levels as $level){ - if($level->getFolderName() === $name){ - return $level; + public function getWorldByName(string $name) : ?World{ + foreach($this->worlds as $world){ + if($world->getFolderName() === $name){ + return $world; } } @@ -139,23 +139,23 @@ class LevelManager{ } /** - * @param Level $level + * @param World $world * @param bool $forceUnload * * @return bool * * @throws \InvalidArgumentException */ - public function unloadLevel(Level $level, bool $forceUnload = false) : bool{ - if($level === $this->getDefaultLevel() and !$forceUnload){ + public function unloadWorld(World $world, bool $forceUnload = false) : bool{ + if($world === $this->getDefaultWorld() and !$forceUnload){ throw new \InvalidArgumentException("The default world cannot be unloaded while running, please switch worlds."); } - if($level->isDoingTick()){ + if($world->isDoingTick()){ throw new \InvalidArgumentException("Cannot unload a world during world tick"); } - $ev = new LevelUnloadEvent($level); - if($level === $this->levelDefault and !$forceUnload){ + $ev = new WorldUnloadEvent($world); + if($world === $this->defaultWorld and !$forceUnload){ $ev->setCancelled(true); } @@ -165,47 +165,47 @@ class LevelManager{ return false; } - $this->server->getLogger()->info($this->server->getLanguage()->translateString("pocketmine.level.unloading", [$level->getDisplayName()])); - foreach($level->getPlayers() as $player){ - if($level === $this->levelDefault or $this->levelDefault === null){ + $this->server->getLogger()->info($this->server->getLanguage()->translateString("pocketmine.level.unloading", [$world->getDisplayName()])); + foreach($world->getPlayers() as $player){ + if($world === $this->defaultWorld or $this->defaultWorld === null){ $player->disconnect("Forced default world unload"); - }elseif($this->levelDefault instanceof Level){ - $player->teleport($this->levelDefault->getSafeSpawn()); + }elseif($this->defaultWorld instanceof World){ + $player->teleport($this->defaultWorld->getSafeSpawn()); } } - if($level === $this->levelDefault){ - $this->levelDefault = null; + if($world === $this->defaultWorld){ + $this->defaultWorld = null; } - unset($this->levels[$level->getId()]); + unset($this->worlds[$world->getId()]); - $level->close(); + $world->close(); return true; } /** - * Loads a level from the data directory + * Loads a world from the data directory * * @param string $name * @param bool $autoUpgrade Converts worlds to the default format if the world's format is not writable / deprecated * * @return bool * - * @throws LevelException + * @throws WorldException */ - public function loadLevel(string $name, bool $autoUpgrade = false) : bool{ + public function loadWorld(string $name, bool $autoUpgrade = false) : bool{ if(trim($name) === ""){ - throw new LevelException("Invalid empty world name"); + throw new WorldException("Invalid empty world name"); } - if($this->isLevelLoaded($name)){ + if($this->isWorldLoaded($name)){ return true; - }elseif(!$this->isLevelGenerated($name)){ + }elseif(!$this->isWorldGenerated($name)){ return false; } $path = $this->server->getDataPath() . "worlds/" . $name . "/"; - $providers = LevelProviderManager::getMatchingProviders($path); + $providers = WorldProviderManager::getMatchingProviders($path); if(count($providers) !== 1){ $this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.level.loadError", [ $name, @@ -218,57 +218,57 @@ class LevelManager{ $providerClass = array_shift($providers); /** - * @var LevelProvider $provider - * @see LevelProvider::__construct() + * @var WorldProvider $provider + * @see WorldProvider::__construct() */ $provider = new $providerClass($path); try{ - GeneratorManager::getGenerator($provider->getLevelData()->getGenerator(), true); + GeneratorManager::getGenerator($provider->getWorldData()->getGenerator(), true); }catch(\InvalidArgumentException $e){ - $this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.level.loadError", [$name, "Unknown generator \"" . $provider->getLevelData()->getGenerator() . "\""])); + $this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.level.loadError", [$name, "Unknown generator \"" . $provider->getWorldData()->getGenerator() . "\""])); return false; } - if(!($provider instanceof WritableLevelProvider)){ + if(!($provider instanceof WritableWorldProvider)){ if(!$autoUpgrade){ - throw new LevelException("World \"$name\" is in an unsupported format and needs to be upgraded"); + throw new WorldException("World \"$name\" is in an unsupported format and needs to be upgraded"); } $this->server->getLogger()->notice("Upgrading world \"$name\" to new format. This may take a while."); - $converter = new FormatConverter($provider, LevelProviderManager::getDefault(), $this->server->getDataPath() . "world_conversion_backups", $this->server->getLogger()); + $converter = new FormatConverter($provider, WorldProviderManager::getDefault(), $this->server->getDataPath() . "world_conversion_backups", $this->server->getLogger()); $provider = $converter->execute(); $this->server->getLogger()->notice("Upgraded world \"$name\" to new format successfully. Backed up pre-conversion world at " . $converter->getBackupPath()); } try{ - $level = new Level($this->server, $name, $provider); - }catch(UnsupportedLevelFormatException $e){ + $world = new World($this->server, $name, $provider); + }catch(UnsupportedWorldFormatException $e){ $this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.level.loadError", [$name, $e->getMessage()])); return false; } - $this->levels[$level->getId()] = $level; - $level->setAutoSave($this->autoSave); + $this->worlds[$world->getId()] = $world; + $world->setAutoSave($this->autoSave); - (new LevelLoadEvent($level))->call(); + (new WorldLoadEvent($world))->call(); return true; } /** - * Generates a new level if it does not exist + * Generates a new world if it does not exist * * @param string $name * @param int|null $seed - * @param string $generator Class name that extends pocketmine\level\generator\Generator + * @param string $generator Class name that extends pocketmine\world\generator\Generator * @param array $options * @param bool $backgroundGeneration * * @return bool * @throws \InvalidArgumentException */ - public function generateLevel(string $name, ?int $seed = null, string $generator = Normal::class, array $options = [], bool $backgroundGeneration = true) : bool{ - if(trim($name) === "" or $this->isLevelGenerated($name)){ + public function generateWorld(string $name, ?int $seed = null, string $generator = Normal::class, array $options = [], bool $backgroundGeneration = true) : bool{ + if(trim($name) === "" or $this->isWorldGenerated($name)){ return false; } @@ -276,26 +276,26 @@ class LevelManager{ Utils::testValidInstance($generator, Generator::class); - $providerClass = LevelProviderManager::getDefault(); + $providerClass = WorldProviderManager::getDefault(); $path = $this->server->getDataPath() . "worlds/" . $name . "/"; - /** @var WritableLevelProvider $providerClass */ + /** @var WritableWorldProvider $providerClass */ $providerClass::generate($path, $name, $seed, $generator, $options); - /** @see WritableLevelProvider::__construct() */ - $level = new Level($this->server, $name, new $providerClass($path)); - $this->levels[$level->getId()] = $level; + /** @see WritableWorldProvider::__construct() */ + $world = new World($this->server, $name, new $providerClass($path)); + $this->worlds[$world->getId()] = $world; - $level->setAutoSave($this->autoSave); + $world->setAutoSave($this->autoSave); - (new LevelInitEvent($level))->call(); + (new WorldInitEvent($world))->call(); - (new LevelLoadEvent($level))->call(); + (new WorldLoadEvent($world))->call(); if($backgroundGeneration){ $this->server->getLogger()->notice($this->server->getLanguage()->translateString("pocketmine.level.backgroundGeneration", [$name])); - $spawnLocation = $level->getSpawnLocation(); + $spawnLocation = $world->getSpawnLocation(); $centerX = $spawnLocation->getFloorX() >> 4; $centerZ = $spawnLocation->getFloorZ() >> 4; @@ -306,7 +306,7 @@ class LevelManager{ $distance = $X ** 2 + $Z ** 2; $chunkX = $X + $centerX; $chunkZ = $Z + $centerZ; - $index = Level::chunkHash($chunkX, $chunkZ); + $index = World::chunkHash($chunkX, $chunkZ); $order[$index] = $distance; } } @@ -314,8 +314,8 @@ class LevelManager{ asort($order); foreach($order as $index => $distance){ - Level::getXZ($index, $chunkX, $chunkZ); - $level->populateChunk($chunkX, $chunkZ, true); + World::getXZ($index, $chunkX, $chunkZ); + $world->populateChunk($chunkX, $chunkZ, true); } } @@ -327,20 +327,20 @@ class LevelManager{ * * @return bool */ - public function isLevelGenerated(string $name) : bool{ + public function isWorldGenerated(string $name) : bool{ if(trim($name) === ""){ return false; } $path = $this->server->getDataPath() . "worlds/" . $name . "/"; - if(!($this->getLevelByName($name) instanceof Level)){ - return !empty(LevelProviderManager::getMatchingProviders($path)); + if(!($this->getWorldByName($name) instanceof World)){ + return !empty(WorldProviderManager::getMatchingProviders($path)); } return true; } /** - * Searches all levels for the entity with the specified ID. + * Searches all worlds for the entity with the specified ID. * Useful for tracking entities across multiple worlds without needing strong references. * * @param int $entityId @@ -348,9 +348,9 @@ class LevelManager{ * @return Entity|null */ public function findEntity(int $entityId) : ?Entity{ - foreach($this->levels as $level){ - assert(!$level->isClosed()); - if(($entity = $level->getEntity($entityId)) instanceof Entity){ + foreach($this->worlds as $world){ + assert(!$world->isClosed()); + if(($entity = $world->getEntity($entityId)) instanceof Entity){ return $entity; } } @@ -360,18 +360,18 @@ class LevelManager{ public function tick(int $currentTick) : void{ - foreach($this->levels as $k => $level){ - if(!isset($this->levels[$k])){ - // Level unloaded during the tick of a level earlier in this loop, perhaps by plugin + foreach($this->worlds as $k => $world){ + if(!isset($this->worlds[$k])){ + // World unloaded during the tick of a world earlier in this loop, perhaps by plugin continue; } - $levelTime = microtime(true); - $level->doTick($currentTick); - $tickMs = (microtime(true) - $levelTime) * 1000; - $level->tickRateTime = $tickMs; + $worldTime = microtime(true); + $world->doTick($currentTick); + $tickMs = (microtime(true) - $worldTime) * 1000; + $world->tickRateTime = $tickMs; if($tickMs >= 50){ - $this->server->getLogger()->debug(sprintf("World \"%s\" took too long to tick: %gms (%g ticks)", $level->getDisplayName(), $tickMs, round($tickMs / 50, 2))); + $this->server->getLogger()->debug(sprintf("World \"%s\" took too long to tick: %gms (%g ticks)", $world->getDisplayName(), $tickMs, round($tickMs / 50, 2))); } } @@ -398,8 +398,8 @@ class LevelManager{ */ public function setAutoSave(bool $value) : void{ $this->autoSave = $value; - foreach($this->levels as $level){ - $level->setAutoSave($this->autoSave); + foreach($this->worlds as $world){ + $world->setAutoSave($this->autoSave); } } @@ -424,13 +424,13 @@ class LevelManager{ private function doAutoSave() : void{ Timings::$worldSaveTimer->startTiming(); - foreach($this->levels as $level){ - foreach($level->getPlayers() as $player){ + foreach($this->worlds as $world){ + foreach($world->getPlayers() as $player){ if($player->spawned){ $player->save(); } } - $level->save(false); + $world->save(false); } Timings::$worldSaveTimer->stopTiming(); } diff --git a/src/pocketmine/level/LevelTimings.php b/src/pocketmine/world/WorldTimings.php similarity index 96% rename from src/pocketmine/level/LevelTimings.php rename to src/pocketmine/world/WorldTimings.php index de925cd6c..c79f48d7e 100644 --- a/src/pocketmine/level/LevelTimings.php +++ b/src/pocketmine/world/WorldTimings.php @@ -21,12 +21,12 @@ declare(strict_types=1); -namespace pocketmine\level; +namespace pocketmine\world; use pocketmine\timings\Timings; use pocketmine\timings\TimingsHandler; -class LevelTimings{ +class WorldTimings{ /** @var TimingsHandler */ public $setBlock; @@ -66,8 +66,8 @@ class LevelTimings{ /** @var TimingsHandler */ public $syncChunkSaveTimer; - public function __construct(Level $level){ - $name = $level->getFolderName() . " - "; + public function __construct(World $world){ + $name = $world->getFolderName() . " - "; $this->setBlock = new TimingsHandler("** " . $name . "setBlock"); $this->doBlockLightUpdates = new TimingsHandler("** " . $name . "doBlockLightUpdates"); diff --git a/src/pocketmine/level/biome/Biome.php b/src/pocketmine/world/biome/Biome.php similarity index 93% rename from src/pocketmine/level/biome/Biome.php rename to src/pocketmine/world/biome/Biome.php index 30b413927..92800eae0 100644 --- a/src/pocketmine/level/biome/Biome.php +++ b/src/pocketmine/world/biome/Biome.php @@ -21,13 +21,13 @@ declare(strict_types=1); -namespace pocketmine\level\biome; +namespace pocketmine\world\biome; use pocketmine\block\Block; use pocketmine\block\utils\TreeType; -use pocketmine\level\ChunkManager; -use pocketmine\level\generator\populator\Populator; use pocketmine\utils\Random; +use pocketmine\world\ChunkManager; +use pocketmine\world\generator\populator\Populator; abstract class Biome{ @@ -123,14 +123,14 @@ abstract class Biome{ } /** - * @param ChunkManager $level + * @param ChunkManager $world * @param int $chunkX * @param int $chunkZ * @param Random $random */ - public function populateChunk(ChunkManager $level, int $chunkX, int $chunkZ, Random $random) : void{ + public function populateChunk(ChunkManager $world, int $chunkX, int $chunkZ, Random $random) : void{ foreach($this->populators as $populator){ - $populator->populate($level, $chunkX, $chunkZ, $random); + $populator->populate($world, $chunkX, $chunkZ, $random); } } diff --git a/src/pocketmine/level/biome/DesertBiome.php b/src/pocketmine/world/biome/DesertBiome.php similarity index 96% rename from src/pocketmine/level/biome/DesertBiome.php rename to src/pocketmine/world/biome/DesertBiome.php index d520ad585..dac51c871 100644 --- a/src/pocketmine/level/biome/DesertBiome.php +++ b/src/pocketmine/world/biome/DesertBiome.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\biome; +namespace pocketmine\world\biome; class DesertBiome extends SandyBiome{ diff --git a/src/pocketmine/level/biome/ForestBiome.php b/src/pocketmine/world/biome/ForestBiome.php similarity index 91% rename from src/pocketmine/level/biome/ForestBiome.php rename to src/pocketmine/world/biome/ForestBiome.php index 4f44bfc21..b3e45cdcc 100644 --- a/src/pocketmine/level/biome/ForestBiome.php +++ b/src/pocketmine/world/biome/ForestBiome.php @@ -21,11 +21,11 @@ declare(strict_types=1); -namespace pocketmine\level\biome; +namespace pocketmine\world\biome; use pocketmine\block\utils\TreeType; -use pocketmine\level\generator\populator\TallGrass; -use pocketmine\level\generator\populator\Tree; +use pocketmine\world\generator\populator\TallGrass; +use pocketmine\world\generator\populator\Tree; class ForestBiome extends GrassyBiome{ diff --git a/src/pocketmine/level/biome/GrassyBiome.php b/src/pocketmine/world/biome/GrassyBiome.php similarity index 97% rename from src/pocketmine/level/biome/GrassyBiome.php rename to src/pocketmine/world/biome/GrassyBiome.php index 3a0d39cf1..142b18b81 100644 --- a/src/pocketmine/level/biome/GrassyBiome.php +++ b/src/pocketmine/world/biome/GrassyBiome.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\biome; +namespace pocketmine\world\biome; use pocketmine\block\BlockFactory; use pocketmine\block\BlockLegacyIds; diff --git a/src/pocketmine/level/biome/HellBiome.php b/src/pocketmine/world/biome/HellBiome.php similarity index 96% rename from src/pocketmine/level/biome/HellBiome.php rename to src/pocketmine/world/biome/HellBiome.php index 4fcb76192..38556ad25 100644 --- a/src/pocketmine/level/biome/HellBiome.php +++ b/src/pocketmine/world/biome/HellBiome.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\biome; +namespace pocketmine\world\biome; class HellBiome extends Biome{ diff --git a/src/pocketmine/level/biome/IcePlainsBiome.php b/src/pocketmine/world/biome/IcePlainsBiome.php similarity index 92% rename from src/pocketmine/level/biome/IcePlainsBiome.php rename to src/pocketmine/world/biome/IcePlainsBiome.php index 5d61c9ce6..5b7756971 100644 --- a/src/pocketmine/level/biome/IcePlainsBiome.php +++ b/src/pocketmine/world/biome/IcePlainsBiome.php @@ -21,9 +21,9 @@ declare(strict_types=1); -namespace pocketmine\level\biome; +namespace pocketmine\world\biome; -use pocketmine\level\generator\populator\TallGrass; +use pocketmine\world\generator\populator\TallGrass; class IcePlainsBiome extends SnowyBiome{ diff --git a/src/pocketmine/level/biome/MountainsBiome.php b/src/pocketmine/world/biome/MountainsBiome.php similarity index 90% rename from src/pocketmine/level/biome/MountainsBiome.php rename to src/pocketmine/world/biome/MountainsBiome.php index da3585b6d..0d9a8a0e2 100644 --- a/src/pocketmine/level/biome/MountainsBiome.php +++ b/src/pocketmine/world/biome/MountainsBiome.php @@ -21,10 +21,10 @@ declare(strict_types=1); -namespace pocketmine\level\biome; +namespace pocketmine\world\biome; -use pocketmine\level\generator\populator\TallGrass; -use pocketmine\level\generator\populator\Tree; +use pocketmine\world\generator\populator\TallGrass; +use pocketmine\world\generator\populator\Tree; class MountainsBiome extends GrassyBiome{ diff --git a/src/pocketmine/level/biome/OceanBiome.php b/src/pocketmine/world/biome/OceanBiome.php similarity index 94% rename from src/pocketmine/level/biome/OceanBiome.php rename to src/pocketmine/world/biome/OceanBiome.php index 3f9f1e637..c3274c90d 100644 --- a/src/pocketmine/level/biome/OceanBiome.php +++ b/src/pocketmine/world/biome/OceanBiome.php @@ -21,11 +21,11 @@ declare(strict_types=1); -namespace pocketmine\level\biome; +namespace pocketmine\world\biome; use pocketmine\block\BlockFactory; use pocketmine\block\BlockLegacyIds; -use pocketmine\level\generator\populator\TallGrass; +use pocketmine\world\generator\populator\TallGrass; class OceanBiome extends Biome{ diff --git a/src/pocketmine/level/biome/PlainBiome.php b/src/pocketmine/world/biome/PlainBiome.php similarity index 92% rename from src/pocketmine/level/biome/PlainBiome.php rename to src/pocketmine/world/biome/PlainBiome.php index 0f927a582..e6d0f07e1 100644 --- a/src/pocketmine/level/biome/PlainBiome.php +++ b/src/pocketmine/world/biome/PlainBiome.php @@ -21,9 +21,9 @@ declare(strict_types=1); -namespace pocketmine\level\biome; +namespace pocketmine\world\biome; -use pocketmine\level\generator\populator\TallGrass; +use pocketmine\world\generator\populator\TallGrass; class PlainBiome extends GrassyBiome{ diff --git a/src/pocketmine/level/biome/RiverBiome.php b/src/pocketmine/world/biome/RiverBiome.php similarity index 94% rename from src/pocketmine/level/biome/RiverBiome.php rename to src/pocketmine/world/biome/RiverBiome.php index 06e339384..7752d5da8 100644 --- a/src/pocketmine/level/biome/RiverBiome.php +++ b/src/pocketmine/world/biome/RiverBiome.php @@ -21,11 +21,11 @@ declare(strict_types=1); -namespace pocketmine\level\biome; +namespace pocketmine\world\biome; use pocketmine\block\BlockFactory; use pocketmine\block\BlockLegacyIds; -use pocketmine\level\generator\populator\TallGrass; +use pocketmine\world\generator\populator\TallGrass; class RiverBiome extends Biome{ diff --git a/src/pocketmine/level/biome/SandyBiome.php b/src/pocketmine/world/biome/SandyBiome.php similarity index 97% rename from src/pocketmine/level/biome/SandyBiome.php rename to src/pocketmine/world/biome/SandyBiome.php index b9f35642e..3e45c709b 100644 --- a/src/pocketmine/level/biome/SandyBiome.php +++ b/src/pocketmine/world/biome/SandyBiome.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\biome; +namespace pocketmine\world\biome; use pocketmine\block\BlockFactory; use pocketmine\block\BlockLegacyIds; diff --git a/src/pocketmine/level/biome/SmallMountainsBiome.php b/src/pocketmine/world/biome/SmallMountainsBiome.php similarity index 96% rename from src/pocketmine/level/biome/SmallMountainsBiome.php rename to src/pocketmine/world/biome/SmallMountainsBiome.php index 12a9b5229..8e649d889 100644 --- a/src/pocketmine/level/biome/SmallMountainsBiome.php +++ b/src/pocketmine/world/biome/SmallMountainsBiome.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\biome; +namespace pocketmine\world\biome; class SmallMountainsBiome extends MountainsBiome{ diff --git a/src/pocketmine/level/biome/SnowyBiome.php b/src/pocketmine/world/biome/SnowyBiome.php similarity index 97% rename from src/pocketmine/level/biome/SnowyBiome.php rename to src/pocketmine/world/biome/SnowyBiome.php index 0d3c18e20..19d8ca057 100644 --- a/src/pocketmine/level/biome/SnowyBiome.php +++ b/src/pocketmine/world/biome/SnowyBiome.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\biome; +namespace pocketmine\world\biome; use pocketmine\block\BlockFactory; use pocketmine\block\BlockLegacyIds; diff --git a/src/pocketmine/level/biome/SwampBiome.php b/src/pocketmine/world/biome/SwampBiome.php similarity index 96% rename from src/pocketmine/level/biome/SwampBiome.php rename to src/pocketmine/world/biome/SwampBiome.php index e80dc72e9..a1db3621a 100644 --- a/src/pocketmine/level/biome/SwampBiome.php +++ b/src/pocketmine/world/biome/SwampBiome.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\biome; +namespace pocketmine\world\biome; class SwampBiome extends GrassyBiome{ diff --git a/src/pocketmine/level/biome/TaigaBiome.php b/src/pocketmine/world/biome/TaigaBiome.php similarity index 90% rename from src/pocketmine/level/biome/TaigaBiome.php rename to src/pocketmine/world/biome/TaigaBiome.php index d1622ed24..18a8ca344 100644 --- a/src/pocketmine/level/biome/TaigaBiome.php +++ b/src/pocketmine/world/biome/TaigaBiome.php @@ -21,11 +21,11 @@ declare(strict_types=1); -namespace pocketmine\level\biome; +namespace pocketmine\world\biome; use pocketmine\block\utils\TreeType; -use pocketmine\level\generator\populator\TallGrass; -use pocketmine\level\generator\populator\Tree; +use pocketmine\world\generator\populator\TallGrass; +use pocketmine\world\generator\populator\Tree; class TaigaBiome extends SnowyBiome{ diff --git a/src/pocketmine/level/biome/UnknownBiome.php b/src/pocketmine/world/biome/UnknownBiome.php similarity index 96% rename from src/pocketmine/level/biome/UnknownBiome.php rename to src/pocketmine/world/biome/UnknownBiome.php index 7bed7718e..c8ac01897 100644 --- a/src/pocketmine/level/biome/UnknownBiome.php +++ b/src/pocketmine/world/biome/UnknownBiome.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\biome; +namespace pocketmine\world\biome; /** * Polyfill class for biomes that are unknown to PocketMine-MP diff --git a/src/pocketmine/level/format/Chunk.php b/src/pocketmine/world/format/Chunk.php similarity index 96% rename from src/pocketmine/level/format/Chunk.php rename to src/pocketmine/world/format/Chunk.php index a523df3c7..634663427 100644 --- a/src/pocketmine/level/format/Chunk.php +++ b/src/pocketmine/world/format/Chunk.php @@ -24,13 +24,12 @@ */ declare(strict_types=1); -namespace pocketmine\level\format; +namespace pocketmine\world\format; use pocketmine\block\BlockFactory; use pocketmine\block\BlockLegacyIds; use pocketmine\entity\Entity; use pocketmine\entity\EntityFactory; -use pocketmine\level\Level; use pocketmine\nbt\tag\CompoundTag; use pocketmine\network\mcpe\NetworkBinaryStream; use pocketmine\network\mcpe\protocol\types\RuntimeBlockMapping; @@ -39,6 +38,7 @@ use pocketmine\tile\Spawnable; use pocketmine\tile\Tile; use pocketmine\tile\TileFactory; use pocketmine\utils\BinaryStream; +use pocketmine\world\World; use function array_fill; use function array_filter; use function array_map; @@ -575,45 +575,45 @@ class Chunk{ /** * Deserializes tiles and entities from NBT * - * @param Level $level + * @param World $world */ - public function initChunk(Level $level) : void{ + public function initChunk(World $world) : void{ if(!$this->isInit){ $changed = false; if($this->NBTentities !== null){ - $level->timings->syncChunkLoadEntitiesTimer->startTiming(); + $world->timings->syncChunkLoadEntitiesTimer->startTiming(); foreach($this->NBTentities as $nbt){ if($nbt instanceof CompoundTag){ try{ - $entity = EntityFactory::createFromData($level, $nbt); + $entity = EntityFactory::createFromData($world, $nbt); if(!($entity instanceof Entity)){ - $level->getServer()->getLogger()->warning("Chunk $this->x $this->z: Deleted unknown entity type " . $nbt->getString("id", $nbt->getString("identifier", "", true), true)); + $world->getServer()->getLogger()->warning("Chunk $this->x $this->z: Deleted unknown entity type " . $nbt->getString("id", $nbt->getString("identifier", "", true), true)); $changed = true; continue; } }catch(\Exception $t){ //TODO: this shouldn't be here - $level->getServer()->getLogger()->logException($t); + $world->getServer()->getLogger()->logException($t); $changed = true; continue; } } } - $level->timings->syncChunkLoadEntitiesTimer->stopTiming(); + $world->timings->syncChunkLoadEntitiesTimer->stopTiming(); - $level->timings->syncChunkLoadTileEntitiesTimer->startTiming(); + $world->timings->syncChunkLoadTileEntitiesTimer->startTiming(); foreach($this->NBTtiles as $nbt){ if($nbt instanceof CompoundTag){ - if(($tile = TileFactory::createFromData($level, $nbt)) !== null){ - $level->addTile($tile); + if(($tile = TileFactory::createFromData($world, $nbt)) !== null){ + $world->addTile($tile); }else{ - $level->getServer()->getLogger()->warning("Chunk $this->x $this->z: Deleted unknown tile entity type " . $nbt->getString("id", "", true)); + $world->getServer()->getLogger()->warning("Chunk $this->x $this->z: Deleted unknown tile entity type " . $nbt->getString("id", "", true)); $changed = true; continue; } } } - $level->timings->syncChunkLoadTileEntitiesTimer->stopTiming(); + $world->timings->syncChunkLoadTileEntitiesTimer->stopTiming(); $this->NBTentities = null; $this->NBTtiles = null; diff --git a/src/pocketmine/level/format/ChunkException.php b/src/pocketmine/world/format/ChunkException.php similarity index 95% rename from src/pocketmine/level/format/ChunkException.php rename to src/pocketmine/world/format/ChunkException.php index 0d373f486..d8f97d057 100644 --- a/src/pocketmine/level/format/ChunkException.php +++ b/src/pocketmine/world/format/ChunkException.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\format; +namespace pocketmine\world\format; class ChunkException extends \RuntimeException{ diff --git a/src/pocketmine/level/format/EmptySubChunk.php b/src/pocketmine/world/format/EmptySubChunk.php similarity index 98% rename from src/pocketmine/level/format/EmptySubChunk.php rename to src/pocketmine/world/format/EmptySubChunk.php index 54bb0d69c..8606f1d39 100644 --- a/src/pocketmine/level/format/EmptySubChunk.php +++ b/src/pocketmine/world/format/EmptySubChunk.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\format; +namespace pocketmine\world\format; use function str_repeat; diff --git a/src/pocketmine/level/format/PalettedBlockArray.php b/src/pocketmine/world/format/PalettedBlockArray.php similarity index 92% rename from src/pocketmine/level/format/PalettedBlockArray.php rename to src/pocketmine/world/format/PalettedBlockArray.php index 90a380873..622f1150b 100644 --- a/src/pocketmine/level/format/PalettedBlockArray.php +++ b/src/pocketmine/world/format/PalettedBlockArray.php @@ -21,10 +21,11 @@ declare(strict_types=1); -namespace pocketmine\level\format; +namespace pocketmine\world\format; die("This is a stub file for code completion purposes"); +//TODO: this can't be moved right now because of compatibility issues with the extension class PalettedBlockArray{ public function __construct(int $fillEntry){} diff --git a/src/pocketmine/level/format/SubChunk.php b/src/pocketmine/world/format/SubChunk.php similarity index 99% rename from src/pocketmine/level/format/SubChunk.php rename to src/pocketmine/world/format/SubChunk.php index 78fb8046b..e1b0c6f50 100644 --- a/src/pocketmine/level/format/SubChunk.php +++ b/src/pocketmine/world/format/SubChunk.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\format; +namespace pocketmine\world\format; use pocketmine\block\BlockLegacyIds; use function array_values; diff --git a/src/pocketmine/level/format/SubChunkInterface.php b/src/pocketmine/world/format/SubChunkInterface.php similarity index 98% rename from src/pocketmine/level/format/SubChunkInterface.php rename to src/pocketmine/world/format/SubChunkInterface.php index 245c49298..fff078c9b 100644 --- a/src/pocketmine/level/format/SubChunkInterface.php +++ b/src/pocketmine/world/format/SubChunkInterface.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\format; +namespace pocketmine\world\format; interface SubChunkInterface{ diff --git a/src/pocketmine/level/format/io/BaseLevelProvider.php b/src/pocketmine/world/format/io/BaseWorldProvider.php similarity index 74% rename from src/pocketmine/level/format/io/BaseLevelProvider.php rename to src/pocketmine/world/format/io/BaseWorldProvider.php index 89a809d97..97be13a15 100644 --- a/src/pocketmine/level/format/io/BaseLevelProvider.php +++ b/src/pocketmine/world/format/io/BaseWorldProvider.php @@ -21,40 +21,40 @@ declare(strict_types=1); -namespace pocketmine\level\format\io; +namespace pocketmine\world\format\io; -use pocketmine\level\format\Chunk; -use pocketmine\level\format\io\exception\CorruptedChunkException; -use pocketmine\level\format\io\exception\UnsupportedChunkFormatException; -use pocketmine\level\LevelException; +use pocketmine\world\format\Chunk; +use pocketmine\world\format\io\exception\CorruptedChunkException; +use pocketmine\world\format\io\exception\UnsupportedChunkFormatException; +use pocketmine\world\WorldException; use function file_exists; -abstract class BaseLevelProvider implements LevelProvider{ +abstract class BaseWorldProvider implements WorldProvider{ /** @var string */ protected $path; - /** @var LevelData */ - protected $levelData; + /** @var WorldData */ + protected $worldData; public function __construct(string $path){ if(!file_exists($path)){ - throw new LevelException("World does not exist"); + throw new WorldException("World does not exist"); } $this->path = $path; - $this->levelData = $this->loadLevelData(); + $this->worldData = $this->loadLevelData(); } - abstract protected function loadLevelData() : LevelData; + abstract protected function loadLevelData() : WorldData; public function getPath() : string{ return $this->path; } /** - * @return LevelData + * @return WorldData */ - public function getLevelData() : LevelData{ - return $this->levelData; + public function getWorldData() : WorldData{ + return $this->worldData; } /** diff --git a/src/pocketmine/level/format/io/ChunkUtils.php b/src/pocketmine/world/format/io/ChunkUtils.php similarity index 98% rename from src/pocketmine/level/format/io/ChunkUtils.php rename to src/pocketmine/world/format/io/ChunkUtils.php index fcb980076..2eb0d2ff1 100644 --- a/src/pocketmine/level/format/io/ChunkUtils.php +++ b/src/pocketmine/world/format/io/ChunkUtils.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\format\io; +namespace pocketmine\world\format\io; use function chr; use function extension_loaded; diff --git a/src/pocketmine/level/format/io/FormatConverter.php b/src/pocketmine/world/format/io/FormatConverter.php similarity index 83% rename from src/pocketmine/level/format/io/FormatConverter.php rename to src/pocketmine/world/format/io/FormatConverter.php index 878b81c33..c86daa084 100644 --- a/src/pocketmine/level/format/io/FormatConverter.php +++ b/src/pocketmine/world/format/io/FormatConverter.php @@ -21,10 +21,10 @@ declare(strict_types=1); -namespace pocketmine\level\format\io; +namespace pocketmine\world\format\io; -use pocketmine\level\generator\GeneratorManager; use pocketmine\utils\Utils; +use pocketmine\world\generator\GeneratorManager; use function basename; use function crc32; use function file_exists; @@ -39,9 +39,9 @@ use const DIRECTORY_SEPARATOR; class FormatConverter{ - /** @var LevelProvider */ + /** @var WorldProvider */ private $oldProvider; - /** @var WritableLevelProvider|string */ + /** @var WritableWorldProvider|string */ private $newProvider; /** @var string */ @@ -50,11 +50,11 @@ class FormatConverter{ /** @var \Logger */ private $logger; - public function __construct(LevelProvider $oldProvider, string $newProvider, string $backupPath, \Logger $logger){ + public function __construct(WorldProvider $oldProvider, string $newProvider, string $backupPath, \Logger $logger){ $this->oldProvider = $oldProvider; - Utils::testValidInstance($newProvider, WritableLevelProvider::class); + Utils::testValidInstance($newProvider, WritableWorldProvider::class); $this->newProvider = $newProvider; - $this->logger = new \PrefixedLogger($logger, "World Converter - " . $this->oldProvider->getLevelData()->getName()); + $this->logger = new \PrefixedLogger($logger, "World Converter - " . $this->oldProvider->getWorldData()->getName()); if(!file_exists($backupPath)){ @mkdir($backupPath, 0777, true); @@ -70,10 +70,10 @@ class FormatConverter{ return $this->backupPath; } - public function execute() : WritableLevelProvider{ + public function execute() : WritableWorldProvider{ $new = $this->generateNew(); - $this->populateLevelData($new->getLevelData()); + $this->populateLevelData($new->getWorldData()); $this->convertTerrain($new); $path = $this->oldProvider->getPath(); @@ -86,14 +86,14 @@ class FormatConverter{ $this->logger->info("Conversion completed"); /** - * @see WritableLevelProvider::__construct() + * @see WritableWorldProvider::__construct() */ return new $this->newProvider($path); } - private function generateNew() : WritableLevelProvider{ + private function generateNew() : WritableWorldProvider{ $this->logger->info("Generating new world"); - $data = $this->oldProvider->getLevelData(); + $data = $this->oldProvider->getWorldData(); $convertedOutput = rtrim($this->oldProvider->getPath(), "/\\") . "_converted" . DIRECTORY_SEPARATOR; if(file_exists($convertedOutput)){ @@ -103,14 +103,14 @@ class FormatConverter{ $this->newProvider::generate($convertedOutput, $data->getName(), $data->getSeed(), GeneratorManager::getGenerator($data->getGenerator()), $data->getGeneratorOptions()); /** - * @see WritableLevelProvider::__construct() + * @see WritableWorldProvider::__construct() */ return new $this->newProvider($convertedOutput); } - private function populateLevelData(LevelData $data) : void{ + private function populateLevelData(WorldData $data) : void{ $this->logger->info("Converting world manifest"); - $oldData = $this->oldProvider->getLevelData(); + $oldData = $this->oldProvider->getWorldData(); $data->setDifficulty($oldData->getDifficulty()); $data->setLightningLevel($oldData->getLightningLevel()); $data->setLightningTime($oldData->getLightningTime()); @@ -124,7 +124,7 @@ class FormatConverter{ //TODO: add more properties as-needed } - private function convertTerrain(WritableLevelProvider $new) : void{ + private function convertTerrain(WritableWorldProvider $new) : void{ $this->logger->info("Calculating chunk count"); $count = $this->oldProvider->calculateChunkCount(); $this->logger->info("Discovered $count chunks"); diff --git a/src/pocketmine/level/format/io/LevelData.php b/src/pocketmine/world/format/io/WorldData.php similarity index 93% rename from src/pocketmine/level/format/io/LevelData.php rename to src/pocketmine/world/format/io/WorldData.php index 15b2980e9..b24b660d2 100644 --- a/src/pocketmine/level/format/io/LevelData.php +++ b/src/pocketmine/world/format/io/WorldData.php @@ -21,14 +21,14 @@ declare(strict_types=1); -namespace pocketmine\level\format\io; +namespace pocketmine\world\format\io; use pocketmine\math\Vector3; -interface LevelData{ +interface WorldData{ /** - * Saves information about the level state, such as weather, time, etc. + * Saves information about the world state, such as weather, time, etc. */ public function save() : void; @@ -78,7 +78,7 @@ interface LevelData{ public function setSpawn(Vector3 $pos) : void; /** - * Returns the world difficulty. This will be one of the Level constants. + * Returns the world difficulty. This will be one of the World constants. * @return int */ public function getDifficulty() : int; diff --git a/src/pocketmine/level/format/io/LevelProvider.php b/src/pocketmine/world/format/io/WorldProvider.php similarity index 80% rename from src/pocketmine/level/format/io/LevelProvider.php rename to src/pocketmine/world/format/io/WorldProvider.php index e70bf2cc3..62f98cb68 100644 --- a/src/pocketmine/level/format/io/LevelProvider.php +++ b/src/pocketmine/world/format/io/WorldProvider.php @@ -21,13 +21,13 @@ declare(strict_types=1); -namespace pocketmine\level\format\io; +namespace pocketmine\world\format\io; -use pocketmine\level\format\Chunk; -use pocketmine\level\format\io\exception\CorruptedChunkException; -use pocketmine\level\format\io\exception\UnsupportedChunkFormatException; +use pocketmine\world\format\Chunk; +use pocketmine\world\format\io\exception\CorruptedChunkException; +use pocketmine\world\format\io\exception\UnsupportedChunkFormatException; -interface LevelProvider{ +interface WorldProvider{ /** * @param string $path @@ -47,7 +47,7 @@ interface LevelProvider{ public function getPath() : string; /** - * Tells if the path is a valid level. + * Tells if the path is a valid world. * This must tell if the current format supports opening the files in the directory * * @param string $path @@ -70,24 +70,24 @@ interface LevelProvider{ public function loadChunk(int $chunkX, int $chunkZ) : ?Chunk; /** - * Performs garbage collection in the level provider, such as cleaning up regions in Region-based worlds. + * Performs garbage collection in the world provider, such as cleaning up regions in Region-based worlds. */ public function doGarbageCollection() : void; /** * Returns information about the world * - * @return LevelData + * @return WorldData */ - public function getLevelData() : LevelData; + public function getWorldData() : WorldData; /** - * Performs cleanups necessary when the level provider is closed and no longer needed. + * Performs cleanups necessary when the world provider is closed and no longer needed. */ public function close() : void; /** - * Returns a generator which yields all the chunks in this level. + * Returns a generator which yields all the chunks in this world. * * @param bool $skipCorrupted * diff --git a/src/pocketmine/level/format/io/LevelProviderManager.php b/src/pocketmine/world/format/io/WorldProviderManager.php similarity index 73% rename from src/pocketmine/level/format/io/LevelProviderManager.php rename to src/pocketmine/world/format/io/WorldProviderManager.php index 75268fd88..cdd655653 100644 --- a/src/pocketmine/level/format/io/LevelProviderManager.php +++ b/src/pocketmine/world/format/io/WorldProviderManager.php @@ -21,20 +21,20 @@ declare(strict_types=1); -namespace pocketmine\level\format\io; +namespace pocketmine\world\format\io; -use pocketmine\level\format\io\leveldb\LevelDB; -use pocketmine\level\format\io\region\Anvil; -use pocketmine\level\format\io\region\McRegion; -use pocketmine\level\format\io\region\PMAnvil; use pocketmine\utils\Utils; +use pocketmine\world\format\io\leveldb\LevelDB; +use pocketmine\world\format\io\region\Anvil; +use pocketmine\world\format\io\region\McRegion; +use pocketmine\world\format\io\region\PMAnvil; use function strtolower; use function trim; -abstract class LevelProviderManager{ +abstract class WorldProviderManager{ protected static $providers = []; - /** @var string|LevelProvider */ + /** @var string|WorldProvider */ private static $default = LevelDB::class; public static function init() : void{ @@ -45,9 +45,9 @@ abstract class LevelProviderManager{ } /** - * Returns the default format used to generate new levels. + * Returns the default format used to generate new worlds. * - * @return string|WritableLevelProvider + * @return string|WritableWorldProvider */ public static function getDefault() : string{ return self::$default; @@ -56,12 +56,12 @@ abstract class LevelProviderManager{ /** * Sets the default format. * - * @param string $class Class implementing WritableLevelProvider + * @param string $class Class implementing WritableWorldProvider * * @throws \InvalidArgumentException */ public static function setDefault(string $class) : void{ - Utils::testValidInstance($class, WritableLevelProvider::class); + Utils::testValidInstance($class, WritableWorldProvider::class); self::$default = $class; } @@ -73,28 +73,28 @@ abstract class LevelProviderManager{ * @param bool $overwrite */ public static function addProvider(string $class, string $name, bool $overwrite = false) : void{ - Utils::testValidInstance($class, LevelProvider::class); + Utils::testValidInstance($class, WorldProvider::class); $name = strtolower($name); if(!$overwrite and isset(self::$providers[$name])){ throw new \InvalidArgumentException("Alias \"$name\" is already assigned"); } - /** @var LevelProvider $class */ + /** @var WorldProvider $class */ self::$providers[$name] = $class; } /** - * Returns a LevelProvider class for this path, or null + * Returns a WorldProvider class for this path, or null * * @param string $path * - * @return string[]|LevelProvider[] + * @return string[]|WorldProvider[] */ public static function getMatchingProviders(string $path) : array{ $result = []; foreach(self::$providers as $alias => $provider){ - /** @var LevelProvider|string $provider */ + /** @var WorldProvider|string $provider */ if($provider::isValid($path)){ $result[$alias] = $provider; } @@ -103,7 +103,7 @@ abstract class LevelProviderManager{ } /** - * Returns a LevelProvider by name, or null if not found + * Returns a WorldProvider by name, or null if not found * * @param string $name * diff --git a/src/pocketmine/level/format/io/WritableLevelProvider.php b/src/pocketmine/world/format/io/WritableWorldProvider.php similarity index 90% rename from src/pocketmine/level/format/io/WritableLevelProvider.php rename to src/pocketmine/world/format/io/WritableWorldProvider.php index fca2024d6..e94724002 100644 --- a/src/pocketmine/level/format/io/WritableLevelProvider.php +++ b/src/pocketmine/world/format/io/WritableWorldProvider.php @@ -21,11 +21,11 @@ declare(strict_types=1); -namespace pocketmine\level\format\io; +namespace pocketmine\world\format\io; -use pocketmine\level\format\Chunk; +use pocketmine\world\format\Chunk; -interface WritableLevelProvider extends LevelProvider{ +interface WritableWorldProvider extends WorldProvider{ /** * Generate the needed files in the path given * diff --git a/src/pocketmine/level/format/io/data/BaseNbtLevelData.php b/src/pocketmine/world/format/io/data/BaseNbtWorldData.php similarity index 93% rename from src/pocketmine/level/format/io/data/BaseNbtLevelData.php rename to src/pocketmine/world/format/io/data/BaseNbtWorldData.php index 75eaf29c4..3d2568f1f 100644 --- a/src/pocketmine/level/format/io/data/BaseNbtLevelData.php +++ b/src/pocketmine/world/format/io/data/BaseNbtWorldData.php @@ -21,15 +21,15 @@ declare(strict_types=1); -namespace pocketmine\level\format\io\data; +namespace pocketmine\world\format\io\data; -use pocketmine\level\format\io\LevelData; -use pocketmine\level\LevelException; use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; +use pocketmine\world\format\io\WorldData; +use pocketmine\world\WorldException; use function file_exists; -abstract class BaseNbtLevelData implements LevelData{ +abstract class BaseNbtWorldData implements WorldData{ /** @var string */ protected $dataPath; @@ -41,12 +41,12 @@ abstract class BaseNbtLevelData implements LevelData{ $this->dataPath = $dataPath; if(!file_exists($this->dataPath)){ - throw new LevelException("Level data not found at $dataPath"); + throw new WorldException("World data not found at $dataPath"); } $this->compoundTag = $this->load(); if($this->compoundTag === null){ - throw new LevelException("Invalid level data"); + throw new WorldException("Invalid world data"); } $this->fix(); } diff --git a/src/pocketmine/level/format/io/data/BedrockLevelData.php b/src/pocketmine/world/format/io/data/BedrockWorldData.php similarity index 88% rename from src/pocketmine/level/format/io/data/BedrockLevelData.php rename to src/pocketmine/world/format/io/data/BedrockWorldData.php index 7f793b939..042cbfee2 100644 --- a/src/pocketmine/level/format/io/data/BedrockLevelData.php +++ b/src/pocketmine/world/format/io/data/BedrockWorldData.php @@ -21,13 +21,8 @@ declare(strict_types=1); -namespace pocketmine\level\format\io\data; +namespace pocketmine\world\format\io\data; -use pocketmine\level\format\io\exception\UnsupportedLevelFormatException; -use pocketmine\level\generator\Flat; -use pocketmine\level\generator\Generator; -use pocketmine\level\generator\GeneratorManager; -use pocketmine\level\Level; use pocketmine\nbt\LittleEndianNbtSerializer; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; @@ -36,13 +31,18 @@ use pocketmine\nbt\TreeRoot; use pocketmine\network\mcpe\protocol\ProtocolInfo; use pocketmine\utils\Binary; use pocketmine\utils\Utils; +use pocketmine\world\format\io\exception\UnsupportedWorldFormatException; +use pocketmine\world\generator\Flat; +use pocketmine\world\generator\Generator; +use pocketmine\world\generator\GeneratorManager; +use pocketmine\world\World; use function file_get_contents; use function file_put_contents; use function strlen; use function substr; use function time; -class BedrockLevelData extends BaseNbtLevelData{ +class BedrockWorldData extends BaseNbtWorldData{ public const CURRENT_STORAGE_VERSION = 8; @@ -61,10 +61,10 @@ class BedrockLevelData extends BaseNbtLevelData{ //TODO: add support for limited worlds } - $levelData = CompoundTag::create() + $worldData = CompoundTag::create() //Vanilla fields ->setInt("DayCycleStopTime", -1) - ->setInt("Difficulty", Level::getDifficultyFromString((string) ($options["difficulty"] ?? "normal"))) + ->setInt("Difficulty", World::getDifficultyFromString((string) ($options["difficulty"] ?? "normal"))) ->setByte("ForceGameType", 0) ->setInt("GameType", 0) ->setInt("Generator", $generatorType) @@ -98,20 +98,20 @@ class BedrockLevelData extends BaseNbtLevelData{ ->setString("generatorOptions", $options["preset"] ?? ""); $nbt = new LittleEndianNbtSerializer(); - $buffer = $nbt->write(new TreeRoot($levelData)); + $buffer = $nbt->write(new TreeRoot($worldData)); file_put_contents($path . "level.dat", Binary::writeLInt(self::CURRENT_STORAGE_VERSION) . Binary::writeLInt(strlen($buffer)) . $buffer); } protected function load() : ?CompoundTag{ $nbt = new LittleEndianNbtSerializer(); - $levelData = $nbt->read(substr(file_get_contents($this->dataPath), 8))->getTag(); + $worldData = $nbt->read(substr(file_get_contents($this->dataPath), 8))->getTag(); - $version = $levelData->getInt("StorageVersion", INT32_MAX, true); + $version = $worldData->getInt("StorageVersion", INT32_MAX, true); if($version > self::CURRENT_STORAGE_VERSION){ - throw new UnsupportedLevelFormatException("Specified LevelDB world format version ($version) is not supported by " . \pocketmine\NAME); + throw new UnsupportedWorldFormatException("Specified LevelDB world format version ($version) is not supported by " . \pocketmine\NAME); } - return $levelData; + return $worldData; } protected function fix() : void{ @@ -128,9 +128,9 @@ class BedrockLevelData extends BaseNbtLevelData{ $this->compoundTag->setString("generatorOptions", ""); break; case self::GENERATOR_LIMITED: - throw new UnsupportedLevelFormatException("Limited worlds are not currently supported"); + throw new UnsupportedWorldFormatException("Limited worlds are not currently supported"); default: - throw new UnsupportedLevelFormatException("Unknown LevelDB world format type, this world cannot be loaded"); + throw new UnsupportedWorldFormatException("Unknown LevelDB world format type, this world cannot be loaded"); } }else{ $this->compoundTag->setString("generatorName", "default"); @@ -154,7 +154,7 @@ class BedrockLevelData extends BaseNbtLevelData{ } public function getDifficulty() : int{ - return $this->compoundTag->getInt("Difficulty", Level::DIFFICULTY_NORMAL); + return $this->compoundTag->getInt("Difficulty", World::DIFFICULTY_NORMAL); } public function setDifficulty(int $difficulty) : void{ diff --git a/src/pocketmine/level/format/io/data/JavaLevelData.php b/src/pocketmine/world/format/io/data/JavaWorldData.php similarity index 88% rename from src/pocketmine/level/format/io/data/JavaLevelData.php rename to src/pocketmine/world/format/io/data/JavaWorldData.php index c360b1dec..875b800b0 100644 --- a/src/pocketmine/level/format/io/data/JavaLevelData.php +++ b/src/pocketmine/world/format/io/data/JavaWorldData.php @@ -21,30 +21,30 @@ declare(strict_types=1); -namespace pocketmine\level\format\io\data; +namespace pocketmine\world\format\io\data; -use pocketmine\level\generator\Generator; -use pocketmine\level\generator\GeneratorManager; -use pocketmine\level\Level; use pocketmine\nbt\BigEndianNbtSerializer; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\FloatTag; use pocketmine\nbt\tag\StringTag; use pocketmine\nbt\TreeRoot; use pocketmine\utils\Utils; +use pocketmine\world\generator\Generator; +use pocketmine\world\generator\GeneratorManager; +use pocketmine\world\World; use function ceil; use function file_get_contents; use function file_put_contents; use function microtime; -class JavaLevelData extends BaseNbtLevelData{ +class JavaWorldData extends BaseNbtWorldData{ public static function generate(string $path, string $name, int $seed, string $generator, array $options = [], int $version = 19133) : void{ Utils::testValidInstance($generator, Generator::class); //TODO, add extra details - $levelData = CompoundTag::create() + $worldData = CompoundTag::create() ->setByte("hardcore", ($options["hardcore"] ?? false) === true ? 1 : 0) - ->setByte("Difficulty", Level::getDifficultyFromString((string) ($options["difficulty"] ?? "normal"))) + ->setByte("Difficulty", World::getDifficultyFromString((string) ($options["difficulty"] ?? "normal"))) ->setByte("initialized", 1) ->setInt("GameType", 0) ->setInt("generatorVersion", 1) //2 in MCPE @@ -63,15 +63,15 @@ class JavaLevelData extends BaseNbtLevelData{ ->setTag("GameRules", new CompoundTag()); $nbt = new BigEndianNbtSerializer(); - $buffer = $nbt->writeCompressed(new TreeRoot(CompoundTag::create()->setTag("Data", $levelData))); + $buffer = $nbt->writeCompressed(new TreeRoot(CompoundTag::create()->setTag("Data", $worldData))); file_put_contents($path . "level.dat", $buffer); } protected function load() : ?CompoundTag{ $nbt = new BigEndianNbtSerializer(); - $levelData = $nbt->readCompressed(file_get_contents($this->dataPath))->getTag(); - if($levelData->hasTag("Data", CompoundTag::class)){ - return $levelData->getCompoundTag("Data"); + $worldData = $nbt->readCompressed(file_get_contents($this->dataPath))->getTag(); + if($worldData->hasTag("Data", CompoundTag::class)){ + return $worldData->getCompoundTag("Data"); } return null; } @@ -96,7 +96,7 @@ class JavaLevelData extends BaseNbtLevelData{ public function getDifficulty() : int{ - return $this->compoundTag->getByte("Difficulty", Level::DIFFICULTY_NORMAL); + return $this->compoundTag->getByte("Difficulty", World::DIFFICULTY_NORMAL); } public function setDifficulty(int $difficulty) : void{ diff --git a/src/pocketmine/level/format/io/exception/CorruptedChunkException.php b/src/pocketmine/world/format/io/exception/CorruptedChunkException.php similarity index 89% rename from src/pocketmine/level/format/io/exception/CorruptedChunkException.php rename to src/pocketmine/world/format/io/exception/CorruptedChunkException.php index 9c0705fbd..38dd61f6d 100644 --- a/src/pocketmine/level/format/io/exception/CorruptedChunkException.php +++ b/src/pocketmine/world/format/io/exception/CorruptedChunkException.php @@ -21,9 +21,9 @@ declare(strict_types=1); -namespace pocketmine\level\format\io\exception; +namespace pocketmine\world\format\io\exception; -use pocketmine\level\format\ChunkException; +use pocketmine\world\format\ChunkException; class CorruptedChunkException extends ChunkException{ diff --git a/src/pocketmine/level/format/io/exception/UnsupportedChunkFormatException.php b/src/pocketmine/world/format/io/exception/UnsupportedChunkFormatException.php similarity index 89% rename from src/pocketmine/level/format/io/exception/UnsupportedChunkFormatException.php rename to src/pocketmine/world/format/io/exception/UnsupportedChunkFormatException.php index e88ba4f83..3694c9f46 100644 --- a/src/pocketmine/level/format/io/exception/UnsupportedChunkFormatException.php +++ b/src/pocketmine/world/format/io/exception/UnsupportedChunkFormatException.php @@ -21,9 +21,9 @@ declare(strict_types=1); -namespace pocketmine\level\format\io\exception; +namespace pocketmine\world\format\io\exception; -use pocketmine\level\format\ChunkException; +use pocketmine\world\format\ChunkException; class UnsupportedChunkFormatException extends ChunkException{ diff --git a/src/pocketmine/level/format/io/exception/UnsupportedLevelFormatException.php b/src/pocketmine/world/format/io/exception/UnsupportedWorldFormatException.php similarity index 86% rename from src/pocketmine/level/format/io/exception/UnsupportedLevelFormatException.php rename to src/pocketmine/world/format/io/exception/UnsupportedWorldFormatException.php index 4e0dc310c..8ed53b84c 100644 --- a/src/pocketmine/level/format/io/exception/UnsupportedLevelFormatException.php +++ b/src/pocketmine/world/format/io/exception/UnsupportedWorldFormatException.php @@ -21,8 +21,8 @@ declare(strict_types=1); -namespace pocketmine\level\format\io\exception; +namespace pocketmine\world\format\io\exception; -class UnsupportedLevelFormatException extends \RuntimeException{ +class UnsupportedWorldFormatException extends \RuntimeException{ } diff --git a/src/pocketmine/level/format/io/leveldb/LevelDB.php b/src/pocketmine/world/format/io/leveldb/LevelDB.php similarity index 93% rename from src/pocketmine/level/format/io/leveldb/LevelDB.php rename to src/pocketmine/world/format/io/leveldb/LevelDB.php index 111c8f3bb..c49ce1853 100644 --- a/src/pocketmine/level/format/io/leveldb/LevelDB.php +++ b/src/pocketmine/world/format/io/leveldb/LevelDB.php @@ -21,22 +21,9 @@ declare(strict_types=1); -namespace pocketmine\level\format\io\leveldb; +namespace pocketmine\world\format\io\leveldb; use pocketmine\block\BlockLegacyIds; -use pocketmine\level\format\Chunk; -use pocketmine\level\format\io\BaseLevelProvider; -use pocketmine\level\format\io\ChunkUtils; -use pocketmine\level\format\io\data\BedrockLevelData; -use pocketmine\level\format\io\exception\CorruptedChunkException; -use pocketmine\level\format\io\exception\UnsupportedChunkFormatException; -use pocketmine\level\format\io\exception\UnsupportedLevelFormatException; -use pocketmine\level\format\io\LevelData; -use pocketmine\level\format\io\SubChunkConverter; -use pocketmine\level\format\io\WritableLevelProvider; -use pocketmine\level\format\PalettedBlockArray; -use pocketmine\level\format\SubChunk; -use pocketmine\level\generator\Generator; use pocketmine\nbt\LittleEndianNbtSerializer; use pocketmine\nbt\NbtDataException; use pocketmine\nbt\tag\CompoundTag; @@ -45,6 +32,19 @@ use pocketmine\utils\Binary; use pocketmine\utils\BinaryDataException; use pocketmine\utils\BinaryStream; use pocketmine\utils\Utils; +use pocketmine\world\format\Chunk; +use pocketmine\world\format\io\BaseWorldProvider; +use pocketmine\world\format\io\ChunkUtils; +use pocketmine\world\format\io\data\BedrockWorldData; +use pocketmine\world\format\io\exception\CorruptedChunkException; +use pocketmine\world\format\io\exception\UnsupportedChunkFormatException; +use pocketmine\world\format\io\exception\UnsupportedWorldFormatException; +use pocketmine\world\format\io\SubChunkConverter; +use pocketmine\world\format\io\WorldData; +use pocketmine\world\format\io\WritableWorldProvider; +use pocketmine\world\format\PalettedBlockArray; +use pocketmine\world\format\SubChunk; +use pocketmine\world\generator\Generator; use function array_flip; use function array_map; use function array_values; @@ -64,7 +64,7 @@ use function substr; use function unpack; use const LEVELDB_ZLIB_RAW_COMPRESSION; -class LevelDB extends BaseLevelProvider implements WritableLevelProvider{ +class LevelDB extends BaseWorldProvider implements WritableWorldProvider{ //According to Tomasso, these aren't supposed to be readable anymore. Thankfully he didn't change the readable ones... protected const TAG_DATA_2D = "\x2d"; @@ -97,11 +97,11 @@ class LevelDB extends BaseLevelProvider implements WritableLevelProvider{ private static function checkForLevelDBExtension() : void{ if(!extension_loaded('leveldb')){ - throw new UnsupportedLevelFormatException("The leveldb PHP extension is required to use this world format"); + throw new UnsupportedWorldFormatException("The leveldb PHP extension is required to use this world format"); } if(!defined('LEVELDB_ZLIB_RAW_COMPRESSION')){ - throw new UnsupportedLevelFormatException("Given version of php-leveldb doesn't support zlib raw compression"); + throw new UnsupportedWorldFormatException("Given version of php-leveldb doesn't support zlib raw compression"); } } @@ -118,8 +118,8 @@ class LevelDB extends BaseLevelProvider implements WritableLevelProvider{ $this->db = self::createDB($path); } - protected function loadLevelData() : LevelData{ - return new BedrockLevelData($this->getPath() . "level.dat"); + protected function loadLevelData() : WorldData{ + return new BedrockWorldData($this->getPath() . "level.dat"); } public function getWorldHeight() : int{ @@ -138,7 +138,7 @@ class LevelDB extends BaseLevelProvider implements WritableLevelProvider{ mkdir($path . "/db", 0777, true); } - BedrockLevelData::generate($path, $name, $seed, $generator, $options); + BedrockWorldData::generate($path, $name, $seed, $generator, $options); } protected function deserializePaletted(BinaryStream $stream) : PalettedBlockArray{ diff --git a/src/pocketmine/level/format/io/region/Anvil.php b/src/pocketmine/world/format/io/region/Anvil.php similarity index 89% rename from src/pocketmine/level/format/io/region/Anvil.php rename to src/pocketmine/world/format/io/region/Anvil.php index 6d81486b3..e66e2a345 100644 --- a/src/pocketmine/level/format/io/region/Anvil.php +++ b/src/pocketmine/world/format/io/region/Anvil.php @@ -21,13 +21,13 @@ declare(strict_types=1); -namespace pocketmine\level\format\io\region; +namespace pocketmine\world\format\io\region; -use pocketmine\level\format\io\SubChunkConverter; -use pocketmine\level\format\SubChunk; use pocketmine\nbt\tag\CompoundTag; +use pocketmine\world\format\io\SubChunkConverter; +use pocketmine\world\format\SubChunk; -class Anvil extends RegionLevelProvider{ +class Anvil extends RegionWorldProvider{ use LegacyAnvilChunkTrait; protected function serializeSubChunk(SubChunk $subChunk) : CompoundTag{ diff --git a/src/pocketmine/level/format/io/region/CorruptedRegionException.php b/src/pocketmine/world/format/io/region/CorruptedRegionException.php similarity index 94% rename from src/pocketmine/level/format/io/region/CorruptedRegionException.php rename to src/pocketmine/world/format/io/region/CorruptedRegionException.php index 6a6308022..6c3943bcd 100644 --- a/src/pocketmine/level/format/io/region/CorruptedRegionException.php +++ b/src/pocketmine/world/format/io/region/CorruptedRegionException.php @@ -22,7 +22,7 @@ declare(strict_types=1); -namespace pocketmine\level\format\io\region; +namespace pocketmine\world\format\io\region; class CorruptedRegionException extends RegionException{ diff --git a/src/pocketmine/level/format/io/region/LegacyAnvilChunkTrait.php b/src/pocketmine/world/format/io/region/LegacyAnvilChunkTrait.php similarity index 93% rename from src/pocketmine/level/format/io/region/LegacyAnvilChunkTrait.php rename to src/pocketmine/world/format/io/region/LegacyAnvilChunkTrait.php index 6f0df55b7..8a82aa8db 100644 --- a/src/pocketmine/level/format/io/region/LegacyAnvilChunkTrait.php +++ b/src/pocketmine/world/format/io/region/LegacyAnvilChunkTrait.php @@ -21,12 +21,12 @@ declare(strict_types=1); -namespace pocketmine\level\format\io\region; +namespace pocketmine\world\format\io\region; -use pocketmine\level\format\Chunk; -use pocketmine\level\format\io\ChunkUtils; -use pocketmine\level\format\io\exception\CorruptedChunkException; -use pocketmine\level\format\SubChunk; +use pocketmine\world\format\Chunk; +use pocketmine\world\format\io\ChunkUtils; +use pocketmine\world\format\io\exception\CorruptedChunkException; +use pocketmine\world\format\SubChunk; use pocketmine\nbt\BigEndianNbtSerializer; use pocketmine\nbt\NbtDataException; use pocketmine\nbt\tag\CompoundTag; diff --git a/src/pocketmine/level/format/io/region/McRegion.php b/src/pocketmine/world/format/io/region/McRegion.php similarity index 90% rename from src/pocketmine/level/format/io/region/McRegion.php rename to src/pocketmine/world/format/io/region/McRegion.php index 56146df0a..46e2b9f38 100644 --- a/src/pocketmine/level/format/io/region/McRegion.php +++ b/src/pocketmine/world/format/io/region/McRegion.php @@ -21,21 +21,21 @@ declare(strict_types=1); -namespace pocketmine\level\format\io\region; +namespace pocketmine\world\format\io\region; -use pocketmine\level\format\Chunk; -use pocketmine\level\format\io\ChunkUtils; -use pocketmine\level\format\io\exception\CorruptedChunkException; -use pocketmine\level\format\io\SubChunkConverter; -use pocketmine\level\format\SubChunk; use pocketmine\nbt\BigEndianNbtSerializer; use pocketmine\nbt\NbtDataException; use pocketmine\nbt\tag\ByteArrayTag; use pocketmine\nbt\tag\IntArrayTag; use pocketmine\nbt\tag\ListTag; +use pocketmine\world\format\Chunk; +use pocketmine\world\format\io\ChunkUtils; +use pocketmine\world\format\io\exception\CorruptedChunkException; +use pocketmine\world\format\io\SubChunkConverter; +use pocketmine\world\format\SubChunk; use function str_repeat; -class McRegion extends RegionLevelProvider{ +class McRegion extends RegionWorldProvider{ /** * @param Chunk $chunk diff --git a/src/pocketmine/level/format/io/region/PMAnvil.php b/src/pocketmine/world/format/io/region/PMAnvil.php similarity index 89% rename from src/pocketmine/level/format/io/region/PMAnvil.php rename to src/pocketmine/world/format/io/region/PMAnvil.php index c726ea6d4..3842dff7d 100644 --- a/src/pocketmine/level/format/io/region/PMAnvil.php +++ b/src/pocketmine/world/format/io/region/PMAnvil.php @@ -21,17 +21,17 @@ declare(strict_types=1); -namespace pocketmine\level\format\io\region; +namespace pocketmine\world\format\io\region; -use pocketmine\level\format\io\SubChunkConverter; -use pocketmine\level\format\SubChunk; use pocketmine\nbt\tag\CompoundTag; +use pocketmine\world\format\io\SubChunkConverter; +use pocketmine\world\format\SubChunk; /** * This format is exactly the same as the PC Anvil format, with the only difference being that the stored data order * is XZY instead of YZX for more performance loading and saving worlds. */ -class PMAnvil extends RegionLevelProvider{ +class PMAnvil extends RegionWorldProvider{ use LegacyAnvilChunkTrait; protected function deserializeSubChunk(CompoundTag $subChunk) : SubChunk{ diff --git a/src/pocketmine/level/format/io/region/RegionException.php b/src/pocketmine/world/format/io/region/RegionException.php similarity index 94% rename from src/pocketmine/level/format/io/region/RegionException.php rename to src/pocketmine/world/format/io/region/RegionException.php index 4118a00d3..fc9dcdb04 100644 --- a/src/pocketmine/level/format/io/region/RegionException.php +++ b/src/pocketmine/world/format/io/region/RegionException.php @@ -22,7 +22,7 @@ declare(strict_types=1); -namespace pocketmine\level\format\io\region; +namespace pocketmine\world\format\io\region; class RegionException extends \RuntimeException{ diff --git a/src/pocketmine/level/format/io/region/RegionLoader.php b/src/pocketmine/world/format/io/region/RegionLoader.php similarity index 98% rename from src/pocketmine/level/format/io/region/RegionLoader.php rename to src/pocketmine/world/format/io/region/RegionLoader.php index 9d0aac0ff..492a1110a 100644 --- a/src/pocketmine/level/format/io/region/RegionLoader.php +++ b/src/pocketmine/world/format/io/region/RegionLoader.php @@ -21,10 +21,10 @@ declare(strict_types=1); -namespace pocketmine\level\format\io\region; +namespace pocketmine\world\format\io\region; -use pocketmine\level\format\ChunkException; -use pocketmine\level\format\io\exception\CorruptedChunkException; +use pocketmine\world\format\ChunkException; +use pocketmine\world\format\io\exception\CorruptedChunkException; use pocketmine\utils\Binary; use function ceil; use function chr; diff --git a/src/pocketmine/level/format/io/region/RegionLocationTableEntry.php b/src/pocketmine/world/format/io/region/RegionLocationTableEntry.php similarity index 98% rename from src/pocketmine/level/format/io/region/RegionLocationTableEntry.php rename to src/pocketmine/world/format/io/region/RegionLocationTableEntry.php index f17ae5bdc..2d5c69ee6 100644 --- a/src/pocketmine/level/format/io/region/RegionLocationTableEntry.php +++ b/src/pocketmine/world/format/io/region/RegionLocationTableEntry.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\format\io\region; +namespace pocketmine\world\format\io\region; use function range; diff --git a/src/pocketmine/level/format/io/region/RegionLevelProvider.php b/src/pocketmine/world/format/io/region/RegionWorldProvider.php similarity index 89% rename from src/pocketmine/level/format/io/region/RegionLevelProvider.php rename to src/pocketmine/world/format/io/region/RegionWorldProvider.php index d0e634bea..0fc1aed40 100644 --- a/src/pocketmine/level/format/io/region/RegionLevelProvider.php +++ b/src/pocketmine/world/format/io/region/RegionWorldProvider.php @@ -21,16 +21,16 @@ declare(strict_types=1); -namespace pocketmine\level\format\io\region; +namespace pocketmine\world\format\io\region; -use pocketmine\level\format\Chunk; -use pocketmine\level\format\io\BaseLevelProvider; -use pocketmine\level\format\io\data\JavaLevelData; -use pocketmine\level\format\io\exception\CorruptedChunkException; -use pocketmine\level\format\io\LevelData; -use pocketmine\level\generator\Generator; -use pocketmine\level\Level; use pocketmine\utils\Utils; +use pocketmine\world\format\Chunk; +use pocketmine\world\format\io\BaseWorldProvider; +use pocketmine\world\format\io\data\JavaWorldData; +use pocketmine\world\format\io\exception\CorruptedChunkException; +use pocketmine\world\format\io\WorldData; +use pocketmine\world\generator\Generator; +use pocketmine\world\World; use function assert; use function file_exists; use function is_dir; @@ -43,7 +43,7 @@ use function substr; use function time; use const SCANDIR_SORT_NONE; -abstract class RegionLevelProvider extends BaseLevelProvider{ +abstract class RegionWorldProvider extends BaseWorldProvider{ /** * Returns the file extension used for regions in this region-based format. @@ -80,14 +80,14 @@ abstract class RegionLevelProvider extends BaseLevelProvider{ mkdir($path . "/region", 0777); } - JavaLevelData::generate($path, $name, $seed, $generator, $options, static::getPcWorldFormatVersion()); + JavaWorldData::generate($path, $name, $seed, $generator, $options, static::getPcWorldFormatVersion()); } /** @var RegionLoader[] */ protected $regions = []; - protected function loadLevelData() : LevelData{ - return new JavaLevelData($this->getPath() . "level.dat"); + protected function loadLevelData() : WorldData{ + return new JavaWorldData($this->getPath() . "level.dat"); } public function doGarbageCollection() : void{ @@ -118,7 +118,7 @@ abstract class RegionLevelProvider extends BaseLevelProvider{ * @return RegionLoader|null */ protected function getRegion(int $regionX, int $regionZ) : ?RegionLoader{ - return $this->regions[Level::chunkHash($regionX, $regionZ)] ?? null; + return $this->regions[World::chunkHash($regionX, $regionZ)] ?? null; } /** @@ -138,7 +138,7 @@ abstract class RegionLevelProvider extends BaseLevelProvider{ * @param int $regionZ */ protected function loadRegion(int $regionX, int $regionZ) : void{ - if(!isset($this->regions[$index = Level::chunkHash($regionX, $regionZ)])){ + if(!isset($this->regions[$index = World::chunkHash($regionX, $regionZ)])){ $path = $this->pathToRegion($regionX, $regionZ); $region = new RegionLoader($path); @@ -163,7 +163,7 @@ abstract class RegionLevelProvider extends BaseLevelProvider{ } protected function unloadRegion(int $regionX, int $regionZ) : void{ - if(isset($this->regions[$hash = Level::chunkHash($regionX, $regionZ)])){ + if(isset($this->regions[$hash = World::chunkHash($regionX, $regionZ)])){ $this->regions[$hash]->close(); unset($this->regions[$hash]); } diff --git a/src/pocketmine/level/generator/Flat.php b/src/pocketmine/world/generator/Flat.php similarity index 90% rename from src/pocketmine/level/generator/Flat.php rename to src/pocketmine/world/generator/Flat.php index 1b41e6093..1ea1b9b66 100644 --- a/src/pocketmine/level/generator/Flat.php +++ b/src/pocketmine/world/generator/Flat.php @@ -21,16 +21,16 @@ declare(strict_types=1); -namespace pocketmine\level\generator; +namespace pocketmine\world\generator; use pocketmine\block\BlockFactory; use pocketmine\block\BlockLegacyIds; use pocketmine\item\ItemFactory; -use pocketmine\level\ChunkManager; -use pocketmine\level\format\Chunk; -use pocketmine\level\generator\object\OreType; -use pocketmine\level\generator\populator\Ore; -use pocketmine\level\generator\populator\Populator; +use pocketmine\world\ChunkManager; +use pocketmine\world\format\Chunk; +use pocketmine\world\generator\object\OreType; +use pocketmine\world\generator\populator\Ore; +use pocketmine\world\generator\populator\Populator; use function array_map; use function count; use function explode; @@ -52,14 +52,14 @@ class Flat extends Generator{ private $preset; /** - * @param ChunkManager $level + * @param ChunkManager $world * @param int $seed * @param array $options * * @throws InvalidGeneratorOptionsException */ - public function __construct(ChunkManager $level, int $seed, array $options = []){ - parent::__construct($level, $seed, $options); + public function __construct(ChunkManager $world, int $seed, array $options = []){ + parent::__construct($world, $seed, $options); if(isset($this->options["preset"]) and $this->options["preset"] != ""){ $this->preset = $this->options["preset"]; @@ -174,13 +174,13 @@ class Flat extends Generator{ $chunk = clone $this->chunk; $chunk->setX($chunkX); $chunk->setZ($chunkZ); - $this->level->setChunk($chunkX, $chunkZ, $chunk); + $this->world->setChunk($chunkX, $chunkZ, $chunk); } public function populateChunk(int $chunkX, int $chunkZ) : void{ $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->seed); foreach($this->populators as $populator){ - $populator->populate($this->level, $chunkX, $chunkZ, $this->random); + $populator->populate($this->world, $chunkX, $chunkZ, $this->random); } } diff --git a/src/pocketmine/level/generator/Generator.php b/src/pocketmine/world/generator/Generator.php similarity index 85% rename from src/pocketmine/level/generator/Generator.php rename to src/pocketmine/world/generator/Generator.php index 8357a8e6f..0005138ac 100644 --- a/src/pocketmine/level/generator/Generator.php +++ b/src/pocketmine/world/generator/Generator.php @@ -22,19 +22,19 @@ declare(strict_types=1); /** - * Noise classes used in Levels + * Noise classes used in world generation */ -namespace pocketmine\level\generator; +namespace pocketmine\world\generator; -use pocketmine\level\ChunkManager; use pocketmine\utils\Random; use pocketmine\utils\Utils; +use pocketmine\world\ChunkManager; use function ctype_digit; abstract class Generator{ /** - * Converts a string level seed into an integer for use by the generator. + * Converts a string world seed into an integer for use by the generator. * * @param string $seed * @@ -53,7 +53,7 @@ abstract class Generator{ } /** @var ChunkManager */ - protected $level; + protected $world; /** @var int */ protected $seed; /** @var array */ @@ -63,14 +63,14 @@ abstract class Generator{ protected $random; /** - * @param ChunkManager $level + * @param ChunkManager $world * @param int $seed * @param array $options * * @throws InvalidGeneratorOptionsException */ - public function __construct(ChunkManager $level, int $seed, array $options = []){ - $this->level = $level; + public function __construct(ChunkManager $world, int $seed, array $options = []){ + $this->world = $world; $this->seed = $seed; $this->options = $options; $this->random = new Random($seed); diff --git a/src/pocketmine/level/generator/GeneratorManager.php b/src/pocketmine/world/generator/GeneratorManager.php similarity index 94% rename from src/pocketmine/level/generator/GeneratorManager.php rename to src/pocketmine/world/generator/GeneratorManager.php index 765499ab3..38e40007b 100644 --- a/src/pocketmine/level/generator/GeneratorManager.php +++ b/src/pocketmine/world/generator/GeneratorManager.php @@ -21,11 +21,11 @@ declare(strict_types=1); -namespace pocketmine\level\generator; +namespace pocketmine\world\generator; -use pocketmine\level\generator\hell\Nether; -use pocketmine\level\generator\normal\Normal; use pocketmine\utils\Utils; +use pocketmine\world\generator\hell\Nether; +use pocketmine\world\generator\normal\Normal; use function array_keys; use function strtolower; @@ -45,7 +45,7 @@ final class GeneratorManager{ } /** - * @param string $class Fully qualified name of class that extends \pocketmine\level\generator\Generator + * @param string $class Fully qualified name of class that extends \pocketmine\world\generator\Generator * @param string $name Alias for this generator type that can be written in configs * @param bool $overwrite Whether to force overwriting any existing registered generator with the same name * @@ -93,7 +93,7 @@ final class GeneratorManager{ /** * Returns the registered name of the given Generator class. * - * @param string $class Fully qualified name of class that extends \pocketmine\level\generator\Generator + * @param string $class Fully qualified name of class that extends \pocketmine\world\generator\Generator * * @return string * @throws \InvalidArgumentException if the class type cannot be matched to a known alias diff --git a/src/pocketmine/level/generator/GeneratorRegisterTask.php b/src/pocketmine/world/generator/GeneratorRegisterTask.php similarity index 71% rename from src/pocketmine/level/generator/GeneratorRegisterTask.php rename to src/pocketmine/world/generator/GeneratorRegisterTask.php index ebb64e2c5..8dd110c66 100644 --- a/src/pocketmine/level/generator/GeneratorRegisterTask.php +++ b/src/pocketmine/world/generator/GeneratorRegisterTask.php @@ -21,13 +21,13 @@ declare(strict_types=1); -namespace pocketmine\level\generator; +namespace pocketmine\world\generator; use pocketmine\block\BlockFactory; -use pocketmine\level\biome\Biome; -use pocketmine\level\Level; -use pocketmine\level\SimpleChunkManager; use pocketmine\scheduler\AsyncTask; +use pocketmine\world\biome\Biome; +use pocketmine\world\SimpleChunkManager; +use pocketmine\world\World; use function serialize; use function unserialize; @@ -36,28 +36,28 @@ class GeneratorRegisterTask extends AsyncTask{ public $generatorClass; public $settings; public $seed; - public $levelId; - public $worldHeight = Level::Y_MAX; + public $worldId; + public $worldHeight = World::Y_MAX; - public function __construct(Level $level, string $generatorClass, array $generatorSettings = []){ + public function __construct(World $world, string $generatorClass, array $generatorSettings = []){ $this->generatorClass = $generatorClass; $this->settings = serialize($generatorSettings); - $this->seed = $level->getSeed(); - $this->levelId = $level->getId(); - $this->worldHeight = $level->getWorldHeight(); + $this->seed = $world->getSeed(); + $this->worldId = $world->getId(); + $this->worldHeight = $world->getWorldHeight(); } public function onRun() : void{ BlockFactory::init(); Biome::init(); $manager = new SimpleChunkManager($this->worldHeight); - $this->worker->saveToThreadStore("generation.level{$this->levelId}.manager", $manager); + $this->worker->saveToThreadStore("generation.world{$this->worldId}.manager", $manager); /** * @var Generator $generator * @see Generator::__construct() */ $generator = new $this->generatorClass($manager, $this->seed, unserialize($this->settings)); - $this->worker->saveToThreadStore("generation.level{$this->levelId}.generator", $generator); + $this->worker->saveToThreadStore("generation.world{$this->worldId}.generator", $generator); } } diff --git a/src/pocketmine/level/generator/GeneratorUnregisterTask.php b/src/pocketmine/world/generator/GeneratorUnregisterTask.php similarity index 72% rename from src/pocketmine/level/generator/GeneratorUnregisterTask.php rename to src/pocketmine/world/generator/GeneratorUnregisterTask.php index 9732571a0..4f7a5c7e0 100644 --- a/src/pocketmine/level/generator/GeneratorUnregisterTask.php +++ b/src/pocketmine/world/generator/GeneratorUnregisterTask.php @@ -21,21 +21,21 @@ declare(strict_types=1); -namespace pocketmine\level\generator; +namespace pocketmine\world\generator; -use pocketmine\level\Level; use pocketmine\scheduler\AsyncTask; +use pocketmine\world\World; class GeneratorUnregisterTask extends AsyncTask{ - public $levelId; + public $worldId; - public function __construct(Level $level){ - $this->levelId = $level->getId(); + public function __construct(World $world){ + $this->worldId = $world->getId(); } public function onRun() : void{ - $this->worker->removeFromThreadStore("generation.level{$this->levelId}.manager"); - $this->worker->removeFromThreadStore("generation.level{$this->levelId}.generator"); + $this->worker->removeFromThreadStore("generation.world{$this->worldId}.manager"); + $this->worker->removeFromThreadStore("generation.world{$this->worldId}.generator"); } } diff --git a/src/pocketmine/level/generator/InvalidGeneratorOptionsException.php b/src/pocketmine/world/generator/InvalidGeneratorOptionsException.php similarity index 95% rename from src/pocketmine/level/generator/InvalidGeneratorOptionsException.php rename to src/pocketmine/world/generator/InvalidGeneratorOptionsException.php index 9489589f0..b6274f91b 100644 --- a/src/pocketmine/level/generator/InvalidGeneratorOptionsException.php +++ b/src/pocketmine/world/generator/InvalidGeneratorOptionsException.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\generator; +namespace pocketmine\world\generator; class InvalidGeneratorOptionsException extends \UnexpectedValueException{ diff --git a/src/pocketmine/level/generator/PopulationTask.php b/src/pocketmine/world/generator/PopulationTask.php similarity index 80% rename from src/pocketmine/level/generator/PopulationTask.php rename to src/pocketmine/world/generator/PopulationTask.php index 7dcb32c32..f599dce8e 100644 --- a/src/pocketmine/level/generator/PopulationTask.php +++ b/src/pocketmine/world/generator/PopulationTask.php @@ -21,18 +21,18 @@ declare(strict_types=1); -namespace pocketmine\level\generator; +namespace pocketmine\world\generator; -use pocketmine\level\format\Chunk; -use pocketmine\level\Level; -use pocketmine\level\SimpleChunkManager; use pocketmine\scheduler\AsyncTask; +use pocketmine\world\format\Chunk; +use pocketmine\world\SimpleChunkManager; +use pocketmine\world\World; class PopulationTask extends AsyncTask{ private const TLS_KEY_WORLD = "world"; public $state; - public $levelId; + public $worldId; public $chunk; public $chunk0; @@ -45,23 +45,23 @@ class PopulationTask extends AsyncTask{ public $chunk7; public $chunk8; - public function __construct(Level $level, Chunk $chunk){ + public function __construct(World $world, Chunk $chunk){ $this->state = true; - $this->levelId = $level->getId(); + $this->worldId = $world->getId(); $this->chunk = $chunk->fastSerialize(); - foreach($level->getAdjacentChunks($chunk->getX(), $chunk->getZ()) as $i => $c){ + foreach($world->getAdjacentChunks($chunk->getX(), $chunk->getZ()) as $i => $c){ $this->{"chunk$i"} = $c !== null ? $c->fastSerialize() : null; } - $this->storeLocal(self::TLS_KEY_WORLD, $level); + $this->storeLocal(self::TLS_KEY_WORLD, $world); } public function onRun() : void{ /** @var SimpleChunkManager $manager */ - $manager = $this->worker->getFromThreadStore("generation.level{$this->levelId}.manager"); + $manager = $this->worker->getFromThreadStore("generation.world{$this->worldId}.manager"); /** @var Generator $generator */ - $generator = $this->worker->getFromThreadStore("generation.level{$this->levelId}.generator"); + $generator = $this->worker->getFromThreadStore("generation.world{$this->worldId}.generator"); if($manager === null or $generator === null){ $this->state = false; return; @@ -138,11 +138,11 @@ class PopulationTask extends AsyncTask{ } public function onCompletion() : void{ - /** @var Level $level */ - $level = $this->fetchLocal(self::TLS_KEY_WORLD); - if(!$level->isClosed()){ + /** @var World $world */ + $world = $this->fetchLocal(self::TLS_KEY_WORLD); + if(!$world->isClosed()){ if(!$this->state){ - $level->registerGeneratorToWorker($this->worker->getAsyncWorkerId()); + $world->registerGeneratorToWorker($this->worker->getAsyncWorkerId()); } $chunk = Chunk::fastDeserialize($this->chunk); @@ -154,11 +154,11 @@ class PopulationTask extends AsyncTask{ $c = $this->{"chunk$i"}; if($c !== null){ $c = Chunk::fastDeserialize($c); - $level->generateChunkCallback($c->getX(), $c->getZ(), $this->state ? $c : null); + $world->generateChunkCallback($c->getX(), $c->getZ(), $this->state ? $c : null); } } - $level->generateChunkCallback($chunk->getX(), $chunk->getZ(), $this->state ? $chunk : null); + $world->generateChunkCallback($chunk->getX(), $chunk->getZ(), $this->state ? $chunk : null); } } } diff --git a/src/pocketmine/level/generator/biome/BiomeSelector.php b/src/pocketmine/world/generator/biome/BiomeSelector.php similarity index 93% rename from src/pocketmine/level/generator/biome/BiomeSelector.php rename to src/pocketmine/world/generator/biome/BiomeSelector.php index 6ff55e9ad..28e2fff14 100644 --- a/src/pocketmine/level/generator/biome/BiomeSelector.php +++ b/src/pocketmine/world/generator/biome/BiomeSelector.php @@ -21,11 +21,11 @@ declare(strict_types=1); -namespace pocketmine\level\generator\biome; +namespace pocketmine\world\generator\biome; -use pocketmine\level\biome\Biome; -use pocketmine\level\biome\UnknownBiome; -use pocketmine\level\generator\noise\Simplex; +use pocketmine\world\biome\Biome; +use pocketmine\world\biome\UnknownBiome; +use pocketmine\world\generator\noise\Simplex; use pocketmine\utils\Random; abstract class BiomeSelector{ diff --git a/src/pocketmine/level/generator/hell/Nether.php b/src/pocketmine/world/generator/hell/Nether.php similarity index 81% rename from src/pocketmine/level/generator/hell/Nether.php rename to src/pocketmine/world/generator/hell/Nether.php index bb89cfedb..da8bef88a 100644 --- a/src/pocketmine/level/generator/hell/Nether.php +++ b/src/pocketmine/world/generator/hell/Nether.php @@ -21,16 +21,16 @@ declare(strict_types=1); -namespace pocketmine\level\generator\hell; +namespace pocketmine\world\generator\hell; use pocketmine\block\BlockFactory; use pocketmine\block\BlockLegacyIds; -use pocketmine\level\biome\Biome; -use pocketmine\level\ChunkManager; -use pocketmine\level\generator\Generator; -use pocketmine\level\generator\InvalidGeneratorOptionsException; -use pocketmine\level\generator\noise\Simplex; -use pocketmine\level\generator\populator\Populator; +use pocketmine\world\biome\Biome; +use pocketmine\world\ChunkManager; +use pocketmine\world\generator\Generator; +use pocketmine\world\generator\InvalidGeneratorOptionsException; +use pocketmine\world\generator\noise\Simplex; +use pocketmine\world\generator\populator\Populator; use function abs; class Nether extends Generator{ @@ -52,14 +52,14 @@ class Nether extends Generator{ private $noiseBase; /** - * @param ChunkManager $level + * @param ChunkManager $world * @param int $seed * @param array $options * * @throws InvalidGeneratorOptionsException */ - public function __construct(ChunkManager $level, int $seed, array $options = []){ - parent::__construct($level, $seed, $options); + public function __construct(ChunkManager $world, int $seed, array $options = []){ + parent::__construct($world, $seed, $options); $this->noiseBase = new Simplex($this->random, 4, 1 / 4, 1 / 64); $this->random->setSeed($this->seed); @@ -83,7 +83,7 @@ class Nether extends Generator{ $noise = $this->noiseBase->getFastNoise3D(16, 128, 16, 4, 8, 4, $chunkX * 16, 0, $chunkZ * 16); - $chunk = $this->level->getChunk($chunkX, $chunkZ); + $chunk = $this->world->getChunk($chunkX, $chunkZ); $bedrock = BlockFactory::get(BlockLegacyIds::BEDROCK)->getFullId(); $netherrack = BlockFactory::get(BlockLegacyIds::NETHERRACK)->getFullId(); @@ -113,18 +113,18 @@ class Nether extends Generator{ } foreach($this->generationPopulators as $populator){ - $populator->populate($this->level, $chunkX, $chunkZ, $this->random); + $populator->populate($this->world, $chunkX, $chunkZ, $this->random); } } public function populateChunk(int $chunkX, int $chunkZ) : void{ $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->seed); foreach($this->populators as $populator){ - $populator->populate($this->level, $chunkX, $chunkZ, $this->random); + $populator->populate($this->world, $chunkX, $chunkZ, $this->random); } - $chunk = $this->level->getChunk($chunkX, $chunkZ); + $chunk = $this->world->getChunk($chunkX, $chunkZ); $biome = Biome::getBiome($chunk->getBiomeId(7, 7)); - $biome->populateChunk($this->level, $chunkX, $chunkZ, $this->random); + $biome->populateChunk($this->world, $chunkX, $chunkZ, $this->random); } } diff --git a/src/pocketmine/level/generator/noise/Noise.php b/src/pocketmine/world/generator/noise/Noise.php similarity index 98% rename from src/pocketmine/level/generator/noise/Noise.php rename to src/pocketmine/world/generator/noise/Noise.php index 4059eb78e..90e2b48eb 100644 --- a/src/pocketmine/level/generator/noise/Noise.php +++ b/src/pocketmine/world/generator/noise/Noise.php @@ -22,9 +22,9 @@ declare(strict_types=1); /** - * Different noise generators for level generation + * Different noise generators for world generation */ -namespace pocketmine\level\generator\noise; +namespace pocketmine\world\generator\noise; use function array_fill; diff --git a/src/pocketmine/level/generator/noise/Simplex.php b/src/pocketmine/world/generator/noise/Simplex.php similarity index 99% rename from src/pocketmine/level/generator/noise/Simplex.php rename to src/pocketmine/world/generator/noise/Simplex.php index ea604d021..85ee993b3 100644 --- a/src/pocketmine/level/generator/noise/Simplex.php +++ b/src/pocketmine/world/generator/noise/Simplex.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\generator\noise; +namespace pocketmine\world\generator\noise; use pocketmine\utils\Random; use const M_SQRT3; diff --git a/src/pocketmine/level/generator/normal/Normal.php b/src/pocketmine/world/generator/normal/Normal.php similarity index 86% rename from src/pocketmine/level/generator/normal/Normal.php rename to src/pocketmine/world/generator/normal/Normal.php index c6141d36a..dd9627283 100644 --- a/src/pocketmine/level/generator/normal/Normal.php +++ b/src/pocketmine/world/generator/normal/Normal.php @@ -21,21 +21,21 @@ declare(strict_types=1); -namespace pocketmine\level\generator\normal; +namespace pocketmine\world\generator\normal; use pocketmine\block\BlockFactory; use pocketmine\block\BlockLegacyIds; -use pocketmine\level\biome\Biome; -use pocketmine\level\ChunkManager; -use pocketmine\level\generator\biome\BiomeSelector; -use pocketmine\level\generator\Generator; -use pocketmine\level\generator\InvalidGeneratorOptionsException; -use pocketmine\level\generator\noise\Simplex; -use pocketmine\level\generator\object\OreType; -use pocketmine\level\generator\populator\GroundCover; -use pocketmine\level\generator\populator\Ore; -use pocketmine\level\generator\populator\Populator; -use pocketmine\level\Level; +use pocketmine\world\biome\Biome; +use pocketmine\world\ChunkManager; +use pocketmine\world\generator\biome\BiomeSelector; +use pocketmine\world\generator\Generator; +use pocketmine\world\generator\InvalidGeneratorOptionsException; +use pocketmine\world\generator\noise\Simplex; +use pocketmine\world\generator\object\OreType; +use pocketmine\world\generator\populator\GroundCover; +use pocketmine\world\generator\populator\Ore; +use pocketmine\world\generator\populator\Populator; +use pocketmine\world\World; use function exp; class Normal extends Generator{ @@ -57,14 +57,14 @@ class Normal extends Generator{ private static $SMOOTH_SIZE = 2; /** - * @param ChunkManager $level + * @param ChunkManager $world * @param int $seed * @param array $options * * @throws InvalidGeneratorOptionsException */ - public function __construct(ChunkManager $level, int $seed, array $options = []){ - parent::__construct($level, $seed, $options); + public function __construct(ChunkManager $world, int $seed, array $options = []){ + parent::__construct($world, $seed, $options); if(self::$GAUSSIAN_KERNEL === null){ self::generateKernel(); } @@ -169,7 +169,7 @@ class Normal extends Generator{ $noise = $this->noiseBase->getFastNoise3D(16, 128, 16, 4, 8, 4, $chunkX * 16, 0, $chunkZ * 16); - $chunk = $this->level->getChunk($chunkX, $chunkZ); + $chunk = $this->world->getChunk($chunkX, $chunkZ); $biomeCache = []; @@ -194,7 +194,7 @@ class Normal extends Generator{ if($sx === 0 and $sz === 0){ $adjacent = $biome; }else{ - $index = Level::chunkHash($chunkX * 16 + $x + $sx, $chunkZ * 16 + $z + $sz); + $index = World::chunkHash($chunkX * 16 + $x + $sx, $chunkZ * 16 + $z + $sz); if(isset($biomeCache[$index])){ $adjacent = $biomeCache[$index]; }else{ @@ -231,18 +231,18 @@ class Normal extends Generator{ } foreach($this->generationPopulators as $populator){ - $populator->populate($this->level, $chunkX, $chunkZ, $this->random); + $populator->populate($this->world, $chunkX, $chunkZ, $this->random); } } public function populateChunk(int $chunkX, int $chunkZ) : void{ $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->seed); foreach($this->populators as $populator){ - $populator->populate($this->level, $chunkX, $chunkZ, $this->random); + $populator->populate($this->world, $chunkX, $chunkZ, $this->random); } - $chunk = $this->level->getChunk($chunkX, $chunkZ); + $chunk = $this->world->getChunk($chunkX, $chunkZ); $biome = Biome::getBiome($chunk->getBiomeId(7, 7)); - $biome->populateChunk($this->level, $chunkX, $chunkZ, $this->random); + $biome->populateChunk($this->world, $chunkX, $chunkZ, $this->random); } } diff --git a/src/pocketmine/level/generator/object/BirchTree.php b/src/pocketmine/world/generator/object/BirchTree.php similarity index 87% rename from src/pocketmine/level/generator/object/BirchTree.php rename to src/pocketmine/world/generator/object/BirchTree.php index 001e60148..65c3365e7 100644 --- a/src/pocketmine/level/generator/object/BirchTree.php +++ b/src/pocketmine/world/generator/object/BirchTree.php @@ -21,13 +21,13 @@ declare(strict_types=1); -namespace pocketmine\level\generator\object; +namespace pocketmine\world\generator\object; use pocketmine\block\BlockFactory; use pocketmine\block\BlockLegacyIds; use pocketmine\block\utils\TreeType; -use pocketmine\level\ChunkManager; use pocketmine\utils\Random; +use pocketmine\world\ChunkManager; class BirchTree extends Tree{ /** @var bool */ @@ -38,11 +38,11 @@ class BirchTree extends Tree{ $this->superBirch = $superBirch; } - public function placeObject(ChunkManager $level, int $x, int $y, int $z, Random $random) : void{ + public function placeObject(ChunkManager $world, int $x, int $y, int $z, Random $random) : void{ $this->treeHeight = $random->nextBoundedInt(3) + 5; if($this->superBirch){ $this->treeHeight += 5; } - parent::placeObject($level, $x, $y, $z, $random); + parent::placeObject($world, $x, $y, $z, $random); } } diff --git a/src/pocketmine/level/generator/object/JungleTree.php b/src/pocketmine/world/generator/object/JungleTree.php similarity index 96% rename from src/pocketmine/level/generator/object/JungleTree.php rename to src/pocketmine/world/generator/object/JungleTree.php index bbf45c4bc..0daeaaa67 100644 --- a/src/pocketmine/level/generator/object/JungleTree.php +++ b/src/pocketmine/world/generator/object/JungleTree.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\generator\object; +namespace pocketmine\world\generator\object; use pocketmine\block\BlockFactory; use pocketmine\block\BlockLegacyIds; diff --git a/src/pocketmine/level/generator/object/OakTree.php b/src/pocketmine/world/generator/object/OakTree.php similarity index 86% rename from src/pocketmine/level/generator/object/OakTree.php rename to src/pocketmine/world/generator/object/OakTree.php index 715798cd4..01d06425a 100644 --- a/src/pocketmine/level/generator/object/OakTree.php +++ b/src/pocketmine/world/generator/object/OakTree.php @@ -21,13 +21,13 @@ declare(strict_types=1); -namespace pocketmine\level\generator\object; +namespace pocketmine\world\generator\object; use pocketmine\block\BlockFactory; use pocketmine\block\BlockLegacyIds; use pocketmine\block\utils\TreeType; -use pocketmine\level\ChunkManager; use pocketmine\utils\Random; +use pocketmine\world\ChunkManager; class OakTree extends Tree{ @@ -35,8 +35,8 @@ class OakTree extends Tree{ parent::__construct(BlockFactory::get(BlockLegacyIds::LOG, TreeType::OAK()->getMagicNumber()), BlockFactory::get(BlockLegacyIds::LEAVES, TreeType::OAK()->getMagicNumber())); } - public function placeObject(ChunkManager $level, int $x, int $y, int $z, Random $random) : void{ + public function placeObject(ChunkManager $world, int $x, int $y, int $z, Random $random) : void{ $this->treeHeight = $random->nextBoundedInt(3) + 4; - parent::placeObject($level, $x, $y, $z, $random); + parent::placeObject($world, $x, $y, $z, $random); } } diff --git a/src/pocketmine/level/generator/object/Ore.php b/src/pocketmine/world/generator/object/Ore.php similarity index 86% rename from src/pocketmine/level/generator/object/Ore.php rename to src/pocketmine/world/generator/object/Ore.php index 859cc1415..6e3981ec8 100644 --- a/src/pocketmine/level/generator/object/Ore.php +++ b/src/pocketmine/world/generator/object/Ore.php @@ -21,12 +21,12 @@ declare(strict_types=1); -namespace pocketmine\level\generator\object; +namespace pocketmine\world\generator\object; use pocketmine\block\BlockLegacyIds; -use pocketmine\level\ChunkManager; use pocketmine\math\VectorMath; use pocketmine\utils\Random; +use pocketmine\world\ChunkManager; use function sin; use const M_PI; @@ -45,11 +45,11 @@ class Ore{ return $this->type; } - public function canPlaceObject(ChunkManager $level, int $x, int $y, int $z) : bool{ - return $level->getBlockAt($x, $y, $z)->getId() === BlockLegacyIds::STONE; + public function canPlaceObject(ChunkManager $world, int $x, int $y, int $z) : bool{ + return $world->getBlockAt($x, $y, $z)->getId() === BlockLegacyIds::STONE; } - public function placeObject(ChunkManager $level, int $x, int $y, int $z) : void{ + public function placeObject(ChunkManager $world, int $x, int $y, int $z) : void{ $clusterSize = $this->type->clusterSize; $angle = $this->random->nextFloat() * M_PI; $offset = VectorMath::getDirection2D($angle)->multiply($clusterSize / 8); @@ -86,8 +86,8 @@ class Ore{ $sizeZ = ($z + 0.5 - $seedZ) / $size; $sizeZ *= $sizeZ; - if(($sizeX + $sizeY + $sizeZ) < 1 and $level->getBlockAt($x, $y, $z)->getId() === BlockLegacyIds::STONE){ - $level->setBlockAt($x, $y, $z, $this->type->material); + if(($sizeX + $sizeY + $sizeZ) < 1 and $world->getBlockAt($x, $y, $z)->getId() === BlockLegacyIds::STONE){ + $world->setBlockAt($x, $y, $z, $this->type->material); } } } diff --git a/src/pocketmine/level/generator/object/OreType.php b/src/pocketmine/world/generator/object/OreType.php similarity index 96% rename from src/pocketmine/level/generator/object/OreType.php rename to src/pocketmine/world/generator/object/OreType.php index 84269d072..1f10ea7b9 100644 --- a/src/pocketmine/level/generator/object/OreType.php +++ b/src/pocketmine/world/generator/object/OreType.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\generator\object; +namespace pocketmine\world\generator\object; use pocketmine\block\Block; diff --git a/src/pocketmine/level/generator/object/SpruceTree.php b/src/pocketmine/world/generator/object/SpruceTree.php similarity index 90% rename from src/pocketmine/level/generator/object/SpruceTree.php rename to src/pocketmine/world/generator/object/SpruceTree.php index 7bc65c9d9..59f74e83d 100644 --- a/src/pocketmine/level/generator/object/SpruceTree.php +++ b/src/pocketmine/world/generator/object/SpruceTree.php @@ -21,14 +21,14 @@ declare(strict_types=1); -namespace pocketmine\level\generator\object; +namespace pocketmine\world\generator\object; use pocketmine\block\BlockFactory; use pocketmine\block\BlockLegacyIds; use pocketmine\block\utils\TreeType; -use pocketmine\level\BlockTransaction; -use pocketmine\level\ChunkManager; use pocketmine\utils\Random; +use pocketmine\world\BlockTransaction; +use pocketmine\world\ChunkManager; use function abs; class SpruceTree extends Tree{ @@ -41,9 +41,9 @@ class SpruceTree extends Tree{ return $this->treeHeight - $random->nextBoundedInt(3); } - public function placeObject(ChunkManager $level, int $x, int $y, int $z, Random $random) : void{ + public function placeObject(ChunkManager $world, int $x, int $y, int $z, Random $random) : void{ $this->treeHeight = $random->nextBoundedInt(4) + 6; - parent::placeObject($level, $x, $y, $z, $random); + parent::placeObject($world, $x, $y, $z, $random); } protected function placeCanopy(int $x, int $y, int $z, Random $random, BlockTransaction $transaction) : void{ diff --git a/src/pocketmine/level/generator/object/TallGrass.php b/src/pocketmine/world/generator/object/TallGrass.php similarity index 81% rename from src/pocketmine/level/generator/object/TallGrass.php rename to src/pocketmine/world/generator/object/TallGrass.php index 34ef563b0..eb8fc38af 100644 --- a/src/pocketmine/level/generator/object/TallGrass.php +++ b/src/pocketmine/world/generator/object/TallGrass.php @@ -21,19 +21,19 @@ declare(strict_types=1); -namespace pocketmine\level\generator\object; +namespace pocketmine\world\generator\object; use pocketmine\block\Block; use pocketmine\block\BlockFactory; use pocketmine\block\BlockLegacyIds; -use pocketmine\level\ChunkManager; use pocketmine\math\Vector3; use pocketmine\utils\Random; +use pocketmine\world\ChunkManager; use function count; class TallGrass{ - public static function growGrass(ChunkManager $level, Vector3 $pos, Random $random, int $count = 15, int $radius = 10) : void{ + public static function growGrass(ChunkManager $world, Vector3 $pos, Random $random, int $count = 15, int $radius = 10) : void{ /** @var Block[] $arr */ $arr = [ BlockFactory::get(BlockLegacyIds::DANDELION), @@ -47,8 +47,8 @@ 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($level->getBlockAt($x, $pos->y + 1, $z)->getId() === BlockLegacyIds::AIR and $level->getBlockAt($x, $pos->y, $z)->getId() === BlockLegacyIds::GRASS){ - $level->setBlockAt($x, $pos->y + 1, $z, $arr[$random->nextRange(0, $arrC)]); + if($world->getBlockAt($x, $pos->y + 1, $z)->getId() === BlockLegacyIds::AIR and $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/pocketmine/level/generator/object/Tree.php b/src/pocketmine/world/generator/object/Tree.php similarity index 88% rename from src/pocketmine/level/generator/object/Tree.php rename to src/pocketmine/world/generator/object/Tree.php index 5af5fdbe2..eaa914236 100644 --- a/src/pocketmine/level/generator/object/Tree.php +++ b/src/pocketmine/world/generator/object/Tree.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\generator\object; +namespace pocketmine\world\generator\object; use pocketmine\block\Block; use pocketmine\block\BlockFactory; @@ -29,9 +29,9 @@ use pocketmine\block\BlockLegacyIds; use pocketmine\block\Leaves; use pocketmine\block\Sapling; use pocketmine\block\utils\TreeType; -use pocketmine\level\BlockTransaction; -use pocketmine\level\ChunkManager; use pocketmine\utils\Random; +use pocketmine\world\BlockTransaction; +use pocketmine\world\ChunkManager; use function abs; abstract class Tree{ @@ -51,7 +51,7 @@ abstract class Tree{ } /** - * @param ChunkManager $level + * @param ChunkManager $world * @param int $x * @param int $y * @param int $z @@ -60,7 +60,7 @@ abstract class Tree{ * * @throws \InvalidArgumentException */ - public static function growTree(ChunkManager $level, int $x, int $y, int $z, Random $random, ?TreeType $type = null) : void{ + public static function growTree(ChunkManager $world, int $x, int $y, int $z, Random $random, ?TreeType $type = null) : void{ /** @var null|Tree $tree */ $tree = null; $type = $type ?? TreeType::OAK(); @@ -83,13 +83,13 @@ abstract class Tree{ //} } - if($tree !== null and $tree->canPlaceObject($level, $x, $y, $z, $random)){ - $tree->placeObject($level, $x, $y, $z, $random); + if($tree !== null and $tree->canPlaceObject($world, $x, $y, $z, $random)){ + $tree->placeObject($world, $x, $y, $z, $random); } } - public function canPlaceObject(ChunkManager $level, 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; for($yy = 0; $yy < $this->treeHeight + 3; ++$yy){ if($yy === 1 or $yy === $this->treeHeight){ @@ -97,7 +97,7 @@ abstract class Tree{ } for($xx = -$radiusToCheck; $xx < ($radiusToCheck + 1); ++$xx){ for($zz = -$radiusToCheck; $zz < ($radiusToCheck + 1); ++$zz){ - if(!$this->canOverride($level->getBlockAt($x + $xx, $y + $yy, $z + $zz))){ + if(!$this->canOverride($world->getBlockAt($x + $xx, $y + $yy, $z + $zz))){ return false; } } @@ -107,8 +107,8 @@ abstract class Tree{ return true; } - public function placeObject(ChunkManager $level, int $x, int $y, int $z, Random $random) : void{ - $transaction = new BlockTransaction($level); + public function placeObject(ChunkManager $world, int $x, int $y, int $z, Random $random) : void{ + $transaction = new BlockTransaction($world); $this->placeTrunk($x, $y, $z, $random, $this->generateChunkHeight($random), $transaction); $this->placeCanopy($x, $y, $z, $random, $transaction); diff --git a/src/pocketmine/level/generator/populator/GroundCover.php b/src/pocketmine/world/generator/populator/GroundCover.php similarity index 89% rename from src/pocketmine/level/generator/populator/GroundCover.php rename to src/pocketmine/world/generator/populator/GroundCover.php index 578fcd0f3..dff67ce7b 100644 --- a/src/pocketmine/level/generator/populator/GroundCover.php +++ b/src/pocketmine/world/generator/populator/GroundCover.php @@ -21,21 +21,21 @@ declare(strict_types=1); -namespace pocketmine\level\generator\populator; +namespace pocketmine\world\generator\populator; use pocketmine\block\BlockFactory; use pocketmine\block\BlockLegacyIds; use pocketmine\block\Liquid; -use pocketmine\level\biome\Biome; -use pocketmine\level\ChunkManager; use pocketmine\utils\Random; +use pocketmine\world\biome\Biome; +use pocketmine\world\ChunkManager; use function count; use function min; class GroundCover extends Populator{ - public function populate(ChunkManager $level, int $chunkX, int $chunkZ, Random $random) : void{ - $chunk = $level->getChunk($chunkX, $chunkZ); + public function populate(ChunkManager $world, int $chunkX, int $chunkZ, Random $random) : void{ + $chunk = $world->getChunk($chunkX, $chunkZ); for($x = 0; $x < 16; ++$x){ for($z = 0; $z < 16; ++$z){ $biome = Biome::getBiome($chunk->getBiomeId($x, $z)); diff --git a/src/pocketmine/level/generator/populator/Ore.php b/src/pocketmine/world/generator/populator/Ore.php similarity index 79% rename from src/pocketmine/level/generator/populator/Ore.php rename to src/pocketmine/world/generator/populator/Ore.php index 0b7f982e8..8590852d8 100644 --- a/src/pocketmine/level/generator/populator/Ore.php +++ b/src/pocketmine/world/generator/populator/Ore.php @@ -21,26 +21,26 @@ declare(strict_types=1); -namespace pocketmine\level\generator\populator; +namespace pocketmine\world\generator\populator; -use pocketmine\level\ChunkManager; -use pocketmine\level\generator\object\Ore as ObjectOre; -use pocketmine\level\generator\object\OreType; use pocketmine\utils\Random; +use pocketmine\world\ChunkManager; +use pocketmine\world\generator\object\Ore as ObjectOre; +use pocketmine\world\generator\object\OreType; class Ore extends Populator{ /** @var OreType[] */ private $oreTypes = []; - public function populate(ChunkManager $level, int $chunkX, int $chunkZ, Random $random) : void{ + public function populate(ChunkManager $world, int $chunkX, int $chunkZ, Random $random) : void{ foreach($this->oreTypes as $type){ $ore = new ObjectOre($random, $type); for($i = 0; $i < $ore->type->clusterCount; ++$i){ $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15); $y = $random->nextRange($ore->type->minHeight, $ore->type->maxHeight); $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15); - if($ore->canPlaceObject($level, $x, $y, $z)){ - $ore->placeObject($level, $x, $y, $z); + if($ore->canPlaceObject($world, $x, $y, $z)){ + $ore->placeObject($world, $x, $y, $z); } } } diff --git a/src/pocketmine/level/generator/populator/Populator.php b/src/pocketmine/world/generator/populator/Populator.php similarity index 84% rename from src/pocketmine/level/generator/populator/Populator.php rename to src/pocketmine/world/generator/populator/Populator.php index c913e7a61..5c43d964c 100644 --- a/src/pocketmine/level/generator/populator/Populator.php +++ b/src/pocketmine/world/generator/populator/Populator.php @@ -24,18 +24,18 @@ declare(strict_types=1); /** * All the Object populator classes */ -namespace pocketmine\level\generator\populator; +namespace pocketmine\world\generator\populator; -use pocketmine\level\ChunkManager; use pocketmine\utils\Random; +use pocketmine\world\ChunkManager; abstract class Populator{ /** - * @param ChunkManager $level + * @param ChunkManager $world * @param int $chunkX * @param int $chunkZ * @param Random $random */ - abstract public function populate(ChunkManager $level, int $chunkX, int $chunkZ, Random $random) : void; + abstract public function populate(ChunkManager $world, int $chunkX, int $chunkZ, Random $random) : void; } diff --git a/src/pocketmine/level/generator/populator/TallGrass.php b/src/pocketmine/world/generator/populator/TallGrass.php similarity index 83% rename from src/pocketmine/level/generator/populator/TallGrass.php rename to src/pocketmine/world/generator/populator/TallGrass.php index 88d21690f..d46026744 100644 --- a/src/pocketmine/level/generator/populator/TallGrass.php +++ b/src/pocketmine/world/generator/populator/TallGrass.php @@ -21,16 +21,16 @@ declare(strict_types=1); -namespace pocketmine\level\generator\populator; +namespace pocketmine\world\generator\populator; use pocketmine\block\BlockFactory; use pocketmine\block\BlockLegacyIds; -use pocketmine\level\ChunkManager; use pocketmine\utils\Random; +use pocketmine\world\ChunkManager; class TallGrass extends Populator{ /** @var ChunkManager */ - private $level; + private $world; private $randomAmount; private $baseAmount; @@ -42,8 +42,8 @@ class TallGrass extends Populator{ $this->baseAmount = $amount; } - public function populate(ChunkManager $level, int $chunkX, int $chunkZ, Random $random) : void{ - $this->level = $level; + public function populate(ChunkManager $world, int $chunkX, int $chunkZ, Random $random) : void{ + $this->world = $world; $amount = $random->nextRange(0, $this->randomAmount + 1) + $this->baseAmount; $block = BlockFactory::get(BlockLegacyIds::TALL_GRASS, 1); @@ -53,19 +53,19 @@ class TallGrass extends Populator{ $y = $this->getHighestWorkableBlock($x, $z); if($y !== -1 and $this->canTallGrassStay($x, $y, $z)){ - $this->level->setBlockAt($x, $y, $z, $block); + $this->world->setBlockAt($x, $y, $z, $block); } } } private function canTallGrassStay(int $x, int $y, int $z) : bool{ - $b = $this->level->getBlockAt($x, $y, $z)->getId(); - return ($b === BlockLegacyIds::AIR or $b === BlockLegacyIds::SNOW_LAYER) and $this->level->getBlockAt($x, $y - 1, $z)->getId() === BlockLegacyIds::GRASS; + $b = $this->world->getBlockAt($x, $y, $z)->getId(); + return ($b === BlockLegacyIds::AIR or $b === BlockLegacyIds::SNOW_LAYER) and $this->world->getBlockAt($x, $y - 1, $z)->getId() === BlockLegacyIds::GRASS; } private function getHighestWorkableBlock(int $x, int $z) : int{ for($y = 127; $y >= 0; --$y){ - $b = $this->level->getBlockAt($x, $y, $z)->getId(); + $b = $this->world->getBlockAt($x, $y, $z)->getId(); if($b !== BlockLegacyIds::AIR and $b !== BlockLegacyIds::LEAVES and $b !== BlockLegacyIds::LEAVES2 and $b !== BlockLegacyIds::SNOW_LAYER){ break; } diff --git a/src/pocketmine/level/generator/populator/Tree.php b/src/pocketmine/world/generator/populator/Tree.php similarity index 84% rename from src/pocketmine/level/generator/populator/Tree.php rename to src/pocketmine/world/generator/populator/Tree.php index ca7be9e2c..cc577d9b9 100644 --- a/src/pocketmine/level/generator/populator/Tree.php +++ b/src/pocketmine/world/generator/populator/Tree.php @@ -21,17 +21,17 @@ declare(strict_types=1); -namespace pocketmine\level\generator\populator; +namespace pocketmine\world\generator\populator; use pocketmine\block\BlockLegacyIds; use pocketmine\block\utils\TreeType; -use pocketmine\level\ChunkManager; -use pocketmine\level\generator\object\Tree as ObjectTree; use pocketmine\utils\Random; +use pocketmine\world\ChunkManager; +use pocketmine\world\generator\object\Tree as ObjectTree; class Tree extends Populator{ /** @var ChunkManager */ - private $level; + private $world; private $randomAmount; private $baseAmount; @@ -53,8 +53,8 @@ class Tree extends Populator{ $this->baseAmount = $amount; } - public function populate(ChunkManager $level, int $chunkX, int $chunkZ, Random $random) : void{ - $this->level = $level; + public function populate(ChunkManager $world, int $chunkX, int $chunkZ, Random $random) : void{ + $this->world = $world; $amount = $random->nextRange(0, $this->randomAmount + 1) + $this->baseAmount; for($i = 0; $i < $amount; ++$i){ $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15); @@ -63,13 +63,13 @@ class Tree extends Populator{ if($y === -1){ continue; } - ObjectTree::growTree($this->level, $x, $y, $z, $random, $this->type); + ObjectTree::growTree($this->world, $x, $y, $z, $random, $this->type); } } private function getHighestWorkableBlock(int $x, int $z) : int{ for($y = 127; $y > 0; --$y){ - $b = $this->level->getBlockAt($x, $y, $z)->getId(); + $b = $this->world->getBlockAt($x, $y, $z)->getId(); if($b === BlockLegacyIds::DIRT or $b === BlockLegacyIds::GRASS){ break; }elseif($b !== BlockLegacyIds::AIR and $b !== BlockLegacyIds::SNOW_LAYER){ diff --git a/src/pocketmine/level/light/BlockLightUpdate.php b/src/pocketmine/world/light/BlockLightUpdate.php similarity index 97% rename from src/pocketmine/level/light/BlockLightUpdate.php rename to src/pocketmine/world/light/BlockLightUpdate.php index 153816581..bfc014fd4 100644 --- a/src/pocketmine/level/light/BlockLightUpdate.php +++ b/src/pocketmine/world/light/BlockLightUpdate.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\light; +namespace pocketmine\world\light; class BlockLightUpdate extends LightUpdate{ diff --git a/src/pocketmine/level/light/LightPopulationTask.php b/src/pocketmine/world/light/LightPopulationTask.php similarity index 78% rename from src/pocketmine/level/light/LightPopulationTask.php rename to src/pocketmine/world/light/LightPopulationTask.php index fdff68f6c..1c1e7c7e8 100644 --- a/src/pocketmine/level/light/LightPopulationTask.php +++ b/src/pocketmine/world/light/LightPopulationTask.php @@ -21,20 +21,20 @@ declare(strict_types=1); -namespace pocketmine\level\light; +namespace pocketmine\world\light; use pocketmine\block\BlockFactory; -use pocketmine\level\format\Chunk; -use pocketmine\level\Level; use pocketmine\scheduler\AsyncTask; +use pocketmine\world\format\Chunk; +use pocketmine\world\World; class LightPopulationTask extends AsyncTask{ private const TLS_KEY_WORLD = "world"; public $chunk; - public function __construct(Level $level, Chunk $chunk){ - $this->storeLocal(self::TLS_KEY_WORLD, $level); + public function __construct(World $world, Chunk $chunk){ + $this->storeLocal(self::TLS_KEY_WORLD, $world); $this->chunk = $chunk->fastSerialize(); } @@ -53,12 +53,12 @@ class LightPopulationTask extends AsyncTask{ } public function onCompletion() : void{ - /** @var Level $level */ - $level = $this->fetchLocal(self::TLS_KEY_WORLD); - if(!$level->isClosed()){ + /** @var World $world */ + $world = $this->fetchLocal(self::TLS_KEY_WORLD); + if(!$world->isClosed()){ /** @var Chunk $chunk */ $chunk = Chunk::fastDeserialize($this->chunk); - $level->generateChunkCallback($chunk->getX(), $chunk->getZ(), $chunk); + $world->generateChunkCallback($chunk->getX(), $chunk->getZ(), $chunk); } } } diff --git a/src/pocketmine/level/light/LightUpdate.php b/src/pocketmine/world/light/LightUpdate.php similarity index 87% rename from src/pocketmine/level/light/LightUpdate.php rename to src/pocketmine/world/light/LightUpdate.php index c141b2ee3..fe0d153ae 100644 --- a/src/pocketmine/level/light/LightUpdate.php +++ b/src/pocketmine/world/light/LightUpdate.php @@ -21,18 +21,18 @@ declare(strict_types=1); -namespace pocketmine\level\light; +namespace pocketmine\world\light; use pocketmine\block\BlockFactory; -use pocketmine\level\ChunkManager; -use pocketmine\level\Level; -use pocketmine\level\utils\SubChunkIteratorManager; +use pocketmine\world\ChunkManager; +use pocketmine\world\utils\SubChunkIteratorManager; +use pocketmine\world\World; //TODO: make light updates asynchronous abstract class LightUpdate{ /** @var ChunkManager */ - protected $level; + protected $world; /** @var int[] blockhash => new light level */ protected $updateNodes = []; @@ -49,12 +49,12 @@ abstract class LightUpdate{ /** @var SubChunkIteratorManager */ protected $subChunkHandler; - public function __construct(ChunkManager $level){ - $this->level = $level; + public function __construct(ChunkManager $world){ + $this->world = $world; $this->removalQueue = new \SplQueue(); $this->spreadQueue = new \SplQueue(); - $this->subChunkHandler = new SubChunkIteratorManager($this->level); + $this->subChunkHandler = new SubChunkIteratorManager($this->world); } abstract protected function getLight(int $x, int $y, int $z) : int; @@ -62,7 +62,7 @@ abstract class LightUpdate{ abstract protected function setLight(int $x, int $y, int $z, int $level) : void; public function setAndUpdateLight(int $x, int $y, int $z, int $newLevel) : void{ - $this->updateNodes[Level::blockHash($x, $y, $z)] = [$x, $y, $z, $newLevel]; + $this->updateNodes[World::blockHash($x, $y, $z)] = [$x, $y, $z, $newLevel]; } private function prepareNodes() : void{ @@ -109,7 +109,7 @@ abstract class LightUpdate{ while(!$this->spreadQueue->isEmpty()){ list($x, $y, $z) = $this->spreadQueue->dequeue(); - unset($this->spreadVisited[Level::blockHash($x, $y, $z)]); + unset($this->spreadVisited[World::blockHash($x, $y, $z)]); if(!$this->subChunkHandler->moveTo($x, $y, $z)){ continue; @@ -143,14 +143,14 @@ abstract class LightUpdate{ if($current !== 0 and $current < $oldAdjacentLevel){ $this->setLight($x, $y, $z, 0); - if(!isset($this->removalVisited[$index = Level::blockHash($x, $y, $z)])){ + if(!isset($this->removalVisited[$index = World::blockHash($x, $y, $z)])){ $this->removalVisited[$index] = true; if($current > 1){ $this->removalQueue->enqueue([$x, $y, $z, $current]); } } }elseif($current >= $oldAdjacentLevel){ - if(!isset($this->spreadVisited[$index = Level::blockHash($x, $y, $z)])){ + if(!isset($this->spreadVisited[$index = World::blockHash($x, $y, $z)])){ $this->spreadVisited[$index] = true; $this->spreadQueue->enqueue([$x, $y, $z]); } @@ -164,7 +164,7 @@ abstract class LightUpdate{ if($current < $potentialLight){ $this->setLight($x, $y, $z, $potentialLight); - if(!isset($this->spreadVisited[$index = Level::blockHash($x, $y, $z)]) and $potentialLight > 1){ + if(!isset($this->spreadVisited[$index = World::blockHash($x, $y, $z)]) and $potentialLight > 1){ $this->spreadVisited[$index] = true; $this->spreadQueue->enqueue([$x, $y, $z]); } diff --git a/src/pocketmine/level/light/SkyLightUpdate.php b/src/pocketmine/world/light/SkyLightUpdate.php similarity index 97% rename from src/pocketmine/level/light/SkyLightUpdate.php rename to src/pocketmine/world/light/SkyLightUpdate.php index bc6666b69..224160419 100644 --- a/src/pocketmine/level/light/SkyLightUpdate.php +++ b/src/pocketmine/world/light/SkyLightUpdate.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\light; +namespace pocketmine\world\light; class SkyLightUpdate extends LightUpdate{ diff --git a/src/pocketmine/level/particle/AngryVillagerParticle.php b/src/pocketmine/world/particle/AngryVillagerParticle.php similarity index 96% rename from src/pocketmine/level/particle/AngryVillagerParticle.php rename to src/pocketmine/world/particle/AngryVillagerParticle.php index 5841170c8..c265c34f1 100644 --- a/src/pocketmine/level/particle/AngryVillagerParticle.php +++ b/src/pocketmine/world/particle/AngryVillagerParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/BlockForceFieldParticle.php b/src/pocketmine/world/particle/BlockForceFieldParticle.php similarity index 96% rename from src/pocketmine/level/particle/BlockForceFieldParticle.php rename to src/pocketmine/world/particle/BlockForceFieldParticle.php index 2da0a9aa6..2ea6e5e18 100644 --- a/src/pocketmine/level/particle/BlockForceFieldParticle.php +++ b/src/pocketmine/world/particle/BlockForceFieldParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/BubbleParticle.php b/src/pocketmine/world/particle/BubbleParticle.php similarity index 96% rename from src/pocketmine/level/particle/BubbleParticle.php rename to src/pocketmine/world/particle/BubbleParticle.php index 777eade96..47e9618ad 100644 --- a/src/pocketmine/level/particle/BubbleParticle.php +++ b/src/pocketmine/world/particle/BubbleParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/CriticalParticle.php b/src/pocketmine/world/particle/CriticalParticle.php similarity index 96% rename from src/pocketmine/level/particle/CriticalParticle.php rename to src/pocketmine/world/particle/CriticalParticle.php index 17e7ca128..b35ca5075 100644 --- a/src/pocketmine/level/particle/CriticalParticle.php +++ b/src/pocketmine/world/particle/CriticalParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/DestroyBlockParticle.php b/src/pocketmine/world/particle/DestroyBlockParticle.php similarity index 96% rename from src/pocketmine/level/particle/DestroyBlockParticle.php rename to src/pocketmine/world/particle/DestroyBlockParticle.php index 98126e7ce..71fe7075d 100644 --- a/src/pocketmine/level/particle/DestroyBlockParticle.php +++ b/src/pocketmine/world/particle/DestroyBlockParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\block\Block; use pocketmine\math\Vector3; diff --git a/src/pocketmine/level/particle/DragonEggTeleportParticle.php b/src/pocketmine/world/particle/DragonEggTeleportParticle.php similarity index 97% rename from src/pocketmine/level/particle/DragonEggTeleportParticle.php rename to src/pocketmine/world/particle/DragonEggTeleportParticle.php index 96bb822c8..b8a615f8e 100644 --- a/src/pocketmine/level/particle/DragonEggTeleportParticle.php +++ b/src/pocketmine/world/particle/DragonEggTeleportParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/particle/DustParticle.php b/src/pocketmine/world/particle/DustParticle.php similarity index 96% rename from src/pocketmine/level/particle/DustParticle.php rename to src/pocketmine/world/particle/DustParticle.php index bd3b40d14..483e87cd8 100644 --- a/src/pocketmine/level/particle/DustParticle.php +++ b/src/pocketmine/world/particle/DustParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/EnchantParticle.php b/src/pocketmine/world/particle/EnchantParticle.php similarity index 96% rename from src/pocketmine/level/particle/EnchantParticle.php rename to src/pocketmine/world/particle/EnchantParticle.php index 5be274b69..abe6a151c 100644 --- a/src/pocketmine/level/particle/EnchantParticle.php +++ b/src/pocketmine/world/particle/EnchantParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/EnchantmentTableParticle.php b/src/pocketmine/world/particle/EnchantmentTableParticle.php similarity index 96% rename from src/pocketmine/level/particle/EnchantmentTableParticle.php rename to src/pocketmine/world/particle/EnchantmentTableParticle.php index bd6e288db..2ccf22166 100644 --- a/src/pocketmine/level/particle/EnchantmentTableParticle.php +++ b/src/pocketmine/world/particle/EnchantmentTableParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/EndermanTeleportParticle.php b/src/pocketmine/world/particle/EndermanTeleportParticle.php similarity index 96% rename from src/pocketmine/level/particle/EndermanTeleportParticle.php rename to src/pocketmine/world/particle/EndermanTeleportParticle.php index cb117e107..18689d9a9 100644 --- a/src/pocketmine/level/particle/EndermanTeleportParticle.php +++ b/src/pocketmine/world/particle/EndermanTeleportParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/particle/EntityFlameParticle.php b/src/pocketmine/world/particle/EntityFlameParticle.php similarity index 96% rename from src/pocketmine/level/particle/EntityFlameParticle.php rename to src/pocketmine/world/particle/EntityFlameParticle.php index e3a94c53c..7274a7376 100644 --- a/src/pocketmine/level/particle/EntityFlameParticle.php +++ b/src/pocketmine/world/particle/EntityFlameParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/ExplodeParticle.php b/src/pocketmine/world/particle/ExplodeParticle.php similarity index 96% rename from src/pocketmine/level/particle/ExplodeParticle.php rename to src/pocketmine/world/particle/ExplodeParticle.php index 962f57655..239459f72 100644 --- a/src/pocketmine/level/particle/ExplodeParticle.php +++ b/src/pocketmine/world/particle/ExplodeParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/FlameParticle.php b/src/pocketmine/world/particle/FlameParticle.php similarity index 96% rename from src/pocketmine/level/particle/FlameParticle.php rename to src/pocketmine/world/particle/FlameParticle.php index 41a643319..e117192f3 100644 --- a/src/pocketmine/level/particle/FlameParticle.php +++ b/src/pocketmine/world/particle/FlameParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/FloatingTextParticle.php b/src/pocketmine/world/particle/FloatingTextParticle.php similarity index 98% rename from src/pocketmine/level/particle/FloatingTextParticle.php rename to src/pocketmine/world/particle/FloatingTextParticle.php index 1eef46fd8..d8efe445b 100644 --- a/src/pocketmine/level/particle/FloatingTextParticle.php +++ b/src/pocketmine/world/particle/FloatingTextParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\entity\EntityFactory; use pocketmine\entity\Skin; diff --git a/src/pocketmine/level/particle/GenericParticle.php b/src/pocketmine/world/particle/GenericParticle.php similarity index 96% rename from src/pocketmine/level/particle/GenericParticle.php rename to src/pocketmine/world/particle/GenericParticle.php index 892dad64a..778a18441 100644 --- a/src/pocketmine/level/particle/GenericParticle.php +++ b/src/pocketmine/world/particle/GenericParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/particle/HappyVillagerParticle.php b/src/pocketmine/world/particle/HappyVillagerParticle.php similarity index 96% rename from src/pocketmine/level/particle/HappyVillagerParticle.php rename to src/pocketmine/world/particle/HappyVillagerParticle.php index 71ce2d6b6..bb452744e 100644 --- a/src/pocketmine/level/particle/HappyVillagerParticle.php +++ b/src/pocketmine/world/particle/HappyVillagerParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/HeartParticle.php b/src/pocketmine/world/particle/HeartParticle.php similarity index 96% rename from src/pocketmine/level/particle/HeartParticle.php rename to src/pocketmine/world/particle/HeartParticle.php index dc196ca3b..e115976d4 100644 --- a/src/pocketmine/level/particle/HeartParticle.php +++ b/src/pocketmine/world/particle/HeartParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/HugeExplodeParticle.php b/src/pocketmine/world/particle/HugeExplodeParticle.php similarity index 96% rename from src/pocketmine/level/particle/HugeExplodeParticle.php rename to src/pocketmine/world/particle/HugeExplodeParticle.php index 26f80fc75..fe0d67ecc 100644 --- a/src/pocketmine/level/particle/HugeExplodeParticle.php +++ b/src/pocketmine/world/particle/HugeExplodeParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/HugeExplodeSeedParticle.php b/src/pocketmine/world/particle/HugeExplodeSeedParticle.php similarity index 96% rename from src/pocketmine/level/particle/HugeExplodeSeedParticle.php rename to src/pocketmine/world/particle/HugeExplodeSeedParticle.php index 409d08a2e..153d05f73 100644 --- a/src/pocketmine/level/particle/HugeExplodeSeedParticle.php +++ b/src/pocketmine/world/particle/HugeExplodeSeedParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/InkParticle.php b/src/pocketmine/world/particle/InkParticle.php similarity index 96% rename from src/pocketmine/level/particle/InkParticle.php rename to src/pocketmine/world/particle/InkParticle.php index 7a6e8d6af..b7e88531a 100644 --- a/src/pocketmine/level/particle/InkParticle.php +++ b/src/pocketmine/world/particle/InkParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/InstantEnchantParticle.php b/src/pocketmine/world/particle/InstantEnchantParticle.php similarity index 96% rename from src/pocketmine/level/particle/InstantEnchantParticle.php rename to src/pocketmine/world/particle/InstantEnchantParticle.php index da58d1696..4a49833a2 100644 --- a/src/pocketmine/level/particle/InstantEnchantParticle.php +++ b/src/pocketmine/world/particle/InstantEnchantParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/ItemBreakParticle.php b/src/pocketmine/world/particle/ItemBreakParticle.php similarity index 96% rename from src/pocketmine/level/particle/ItemBreakParticle.php rename to src/pocketmine/world/particle/ItemBreakParticle.php index 3e706c687..574c3dcda 100644 --- a/src/pocketmine/level/particle/ItemBreakParticle.php +++ b/src/pocketmine/world/particle/ItemBreakParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\item\Item; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/LavaDripParticle.php b/src/pocketmine/world/particle/LavaDripParticle.php similarity index 96% rename from src/pocketmine/level/particle/LavaDripParticle.php rename to src/pocketmine/world/particle/LavaDripParticle.php index 6ca209e0b..adf6d7163 100644 --- a/src/pocketmine/level/particle/LavaDripParticle.php +++ b/src/pocketmine/world/particle/LavaDripParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/LavaParticle.php b/src/pocketmine/world/particle/LavaParticle.php similarity index 96% rename from src/pocketmine/level/particle/LavaParticle.php rename to src/pocketmine/world/particle/LavaParticle.php index 9a3e65e66..c9eafc2dc 100644 --- a/src/pocketmine/level/particle/LavaParticle.php +++ b/src/pocketmine/world/particle/LavaParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/MobSpawnParticle.php b/src/pocketmine/world/particle/MobSpawnParticle.php similarity index 97% rename from src/pocketmine/level/particle/MobSpawnParticle.php rename to src/pocketmine/world/particle/MobSpawnParticle.php index 5955a2c88..6ebe243a2 100644 --- a/src/pocketmine/level/particle/MobSpawnParticle.php +++ b/src/pocketmine/world/particle/MobSpawnParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/particle/Particle.php b/src/pocketmine/world/particle/Particle.php similarity index 96% rename from src/pocketmine/level/particle/Particle.php rename to src/pocketmine/world/particle/Particle.php index ab393ecfd..b800a66d9 100644 --- a/src/pocketmine/level/particle/Particle.php +++ b/src/pocketmine/world/particle/Particle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\ClientboundPacket; diff --git a/src/pocketmine/level/particle/PortalParticle.php b/src/pocketmine/world/particle/PortalParticle.php similarity index 96% rename from src/pocketmine/level/particle/PortalParticle.php rename to src/pocketmine/world/particle/PortalParticle.php index 9175d3a6b..fa511145e 100644 --- a/src/pocketmine/level/particle/PortalParticle.php +++ b/src/pocketmine/world/particle/PortalParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/PotionSplashParticle.php b/src/pocketmine/world/particle/PotionSplashParticle.php similarity index 97% rename from src/pocketmine/level/particle/PotionSplashParticle.php rename to src/pocketmine/world/particle/PotionSplashParticle.php index 73b91632d..70ccd9632 100644 --- a/src/pocketmine/level/particle/PotionSplashParticle.php +++ b/src/pocketmine/world/particle/PotionSplashParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/particle/RainSplashParticle.php b/src/pocketmine/world/particle/RainSplashParticle.php similarity index 96% rename from src/pocketmine/level/particle/RainSplashParticle.php rename to src/pocketmine/world/particle/RainSplashParticle.php index 20ca50ec0..cafa5b324 100644 --- a/src/pocketmine/level/particle/RainSplashParticle.php +++ b/src/pocketmine/world/particle/RainSplashParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/RedstoneParticle.php b/src/pocketmine/world/particle/RedstoneParticle.php similarity index 96% rename from src/pocketmine/level/particle/RedstoneParticle.php rename to src/pocketmine/world/particle/RedstoneParticle.php index 15b464e4b..13fbacba7 100644 --- a/src/pocketmine/level/particle/RedstoneParticle.php +++ b/src/pocketmine/world/particle/RedstoneParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/SmokeParticle.php b/src/pocketmine/world/particle/SmokeParticle.php similarity index 96% rename from src/pocketmine/level/particle/SmokeParticle.php rename to src/pocketmine/world/particle/SmokeParticle.php index f057c5ed5..501e373e1 100644 --- a/src/pocketmine/level/particle/SmokeParticle.php +++ b/src/pocketmine/world/particle/SmokeParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/SnowballPoofParticle.php b/src/pocketmine/world/particle/SnowballPoofParticle.php similarity index 96% rename from src/pocketmine/level/particle/SnowballPoofParticle.php rename to src/pocketmine/world/particle/SnowballPoofParticle.php index 24e8d14c1..b5b4f1fc1 100644 --- a/src/pocketmine/level/particle/SnowballPoofParticle.php +++ b/src/pocketmine/world/particle/SnowballPoofParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/SplashParticle.php b/src/pocketmine/world/particle/SplashParticle.php similarity index 96% rename from src/pocketmine/level/particle/SplashParticle.php rename to src/pocketmine/world/particle/SplashParticle.php index b79e8ee07..8d9e96596 100644 --- a/src/pocketmine/level/particle/SplashParticle.php +++ b/src/pocketmine/world/particle/SplashParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/SporeParticle.php b/src/pocketmine/world/particle/SporeParticle.php similarity index 96% rename from src/pocketmine/level/particle/SporeParticle.php rename to src/pocketmine/world/particle/SporeParticle.php index 846c7149e..23e2b3e0a 100644 --- a/src/pocketmine/level/particle/SporeParticle.php +++ b/src/pocketmine/world/particle/SporeParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/TerrainParticle.php b/src/pocketmine/world/particle/TerrainParticle.php similarity index 96% rename from src/pocketmine/level/particle/TerrainParticle.php rename to src/pocketmine/world/particle/TerrainParticle.php index 296934af8..2514cc66a 100644 --- a/src/pocketmine/level/particle/TerrainParticle.php +++ b/src/pocketmine/world/particle/TerrainParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\block\Block; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/WaterDripParticle.php b/src/pocketmine/world/particle/WaterDripParticle.php similarity index 96% rename from src/pocketmine/level/particle/WaterDripParticle.php rename to src/pocketmine/world/particle/WaterDripParticle.php index 6a8431fa2..65b2f12e2 100644 --- a/src/pocketmine/level/particle/WaterDripParticle.php +++ b/src/pocketmine/world/particle/WaterDripParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/particle/WaterParticle.php b/src/pocketmine/world/particle/WaterParticle.php similarity index 96% rename from src/pocketmine/level/particle/WaterParticle.php rename to src/pocketmine/world/particle/WaterParticle.php index fb85ff9d6..473a226e0 100644 --- a/src/pocketmine/level/particle/WaterParticle.php +++ b/src/pocketmine/world/particle/WaterParticle.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\particle; +namespace pocketmine\world\particle; use pocketmine\network\mcpe\protocol\types\ParticleIds; diff --git a/src/pocketmine/level/sound/AnvilBreakSound.php b/src/pocketmine/world/sound/AnvilBreakSound.php similarity index 96% rename from src/pocketmine/level/sound/AnvilBreakSound.php rename to src/pocketmine/world/sound/AnvilBreakSound.php index a7dc6a2a7..7a75dd415 100644 --- a/src/pocketmine/level/sound/AnvilBreakSound.php +++ b/src/pocketmine/world/sound/AnvilBreakSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/sound/AnvilFallSound.php b/src/pocketmine/world/sound/AnvilFallSound.php similarity index 96% rename from src/pocketmine/level/sound/AnvilFallSound.php rename to src/pocketmine/world/sound/AnvilFallSound.php index 82fa3c480..08aebde71 100644 --- a/src/pocketmine/level/sound/AnvilFallSound.php +++ b/src/pocketmine/world/sound/AnvilFallSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/sound/AnvilUseSound.php b/src/pocketmine/world/sound/AnvilUseSound.php similarity index 96% rename from src/pocketmine/level/sound/AnvilUseSound.php rename to src/pocketmine/world/sound/AnvilUseSound.php index d3862c2d8..090289a3d 100644 --- a/src/pocketmine/level/sound/AnvilUseSound.php +++ b/src/pocketmine/world/sound/AnvilUseSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/sound/ArrowHitSound.php b/src/pocketmine/world/sound/ArrowHitSound.php similarity index 96% rename from src/pocketmine/level/sound/ArrowHitSound.php rename to src/pocketmine/world/sound/ArrowHitSound.php index e19bdd16a..0490d5fa8 100644 --- a/src/pocketmine/level/sound/ArrowHitSound.php +++ b/src/pocketmine/world/sound/ArrowHitSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; diff --git a/src/pocketmine/level/sound/BlazeShootSound.php b/src/pocketmine/world/sound/BlazeShootSound.php similarity index 96% rename from src/pocketmine/level/sound/BlazeShootSound.php rename to src/pocketmine/world/sound/BlazeShootSound.php index c9d32f4bd..97ac023cc 100644 --- a/src/pocketmine/level/sound/BlazeShootSound.php +++ b/src/pocketmine/world/sound/BlazeShootSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/sound/BlockBreakSound.php b/src/pocketmine/world/sound/BlockBreakSound.php similarity index 97% rename from src/pocketmine/level/sound/BlockBreakSound.php rename to src/pocketmine/world/sound/BlockBreakSound.php index c951b0c7a..32ea532da 100644 --- a/src/pocketmine/level/sound/BlockBreakSound.php +++ b/src/pocketmine/world/sound/BlockBreakSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\block\Block; use pocketmine\math\Vector3; diff --git a/src/pocketmine/level/sound/BlockPlaceSound.php b/src/pocketmine/world/sound/BlockPlaceSound.php similarity index 97% rename from src/pocketmine/level/sound/BlockPlaceSound.php rename to src/pocketmine/world/sound/BlockPlaceSound.php index 1d0b8b75c..3f5427472 100644 --- a/src/pocketmine/level/sound/BlockPlaceSound.php +++ b/src/pocketmine/world/sound/BlockPlaceSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\block\Block; use pocketmine\math\Vector3; diff --git a/src/pocketmine/level/sound/BowShootSound.php b/src/pocketmine/world/sound/BowShootSound.php similarity index 96% rename from src/pocketmine/level/sound/BowShootSound.php rename to src/pocketmine/world/sound/BowShootSound.php index 139abbf34..00355b17f 100644 --- a/src/pocketmine/level/sound/BowShootSound.php +++ b/src/pocketmine/world/sound/BowShootSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; diff --git a/src/pocketmine/level/sound/BucketEmptyLavaSound.php b/src/pocketmine/world/sound/BucketEmptyLavaSound.php similarity index 96% rename from src/pocketmine/level/sound/BucketEmptyLavaSound.php rename to src/pocketmine/world/sound/BucketEmptyLavaSound.php index 254933400..d33fa5d15 100644 --- a/src/pocketmine/level/sound/BucketEmptyLavaSound.php +++ b/src/pocketmine/world/sound/BucketEmptyLavaSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; diff --git a/src/pocketmine/level/sound/BucketEmptyWaterSound.php b/src/pocketmine/world/sound/BucketEmptyWaterSound.php similarity index 96% rename from src/pocketmine/level/sound/BucketEmptyWaterSound.php rename to src/pocketmine/world/sound/BucketEmptyWaterSound.php index 11995a2c0..47a4686d3 100644 --- a/src/pocketmine/level/sound/BucketEmptyWaterSound.php +++ b/src/pocketmine/world/sound/BucketEmptyWaterSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; diff --git a/src/pocketmine/level/sound/BucketFillLavaSound.php b/src/pocketmine/world/sound/BucketFillLavaSound.php similarity index 96% rename from src/pocketmine/level/sound/BucketFillLavaSound.php rename to src/pocketmine/world/sound/BucketFillLavaSound.php index f2c88090d..83cebdc0f 100644 --- a/src/pocketmine/level/sound/BucketFillLavaSound.php +++ b/src/pocketmine/world/sound/BucketFillLavaSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; diff --git a/src/pocketmine/level/sound/BucketFillWaterSound.php b/src/pocketmine/world/sound/BucketFillWaterSound.php similarity index 96% rename from src/pocketmine/level/sound/BucketFillWaterSound.php rename to src/pocketmine/world/sound/BucketFillWaterSound.php index de146e5ec..24bb70983 100644 --- a/src/pocketmine/level/sound/BucketFillWaterSound.php +++ b/src/pocketmine/world/sound/BucketFillWaterSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; diff --git a/src/pocketmine/level/sound/ChestCloseSound.php b/src/pocketmine/world/sound/ChestCloseSound.php similarity index 96% rename from src/pocketmine/level/sound/ChestCloseSound.php rename to src/pocketmine/world/sound/ChestCloseSound.php index 3d19f8bd7..78fc5e740 100644 --- a/src/pocketmine/level/sound/ChestCloseSound.php +++ b/src/pocketmine/world/sound/ChestCloseSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; diff --git a/src/pocketmine/level/sound/ChestOpenSound.php b/src/pocketmine/world/sound/ChestOpenSound.php similarity index 96% rename from src/pocketmine/level/sound/ChestOpenSound.php rename to src/pocketmine/world/sound/ChestOpenSound.php index 5eb1f9d27..33dde6627 100644 --- a/src/pocketmine/level/sound/ChestOpenSound.php +++ b/src/pocketmine/world/sound/ChestOpenSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; diff --git a/src/pocketmine/level/sound/ClickSound.php b/src/pocketmine/world/sound/ClickSound.php similarity index 96% rename from src/pocketmine/level/sound/ClickSound.php rename to src/pocketmine/world/sound/ClickSound.php index 79509bd8e..cec95842d 100644 --- a/src/pocketmine/level/sound/ClickSound.php +++ b/src/pocketmine/world/sound/ClickSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/sound/DoorBumpSound.php b/src/pocketmine/world/sound/DoorBumpSound.php similarity index 96% rename from src/pocketmine/level/sound/DoorBumpSound.php rename to src/pocketmine/world/sound/DoorBumpSound.php index 88dac8efa..7ae4e0c92 100644 --- a/src/pocketmine/level/sound/DoorBumpSound.php +++ b/src/pocketmine/world/sound/DoorBumpSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/sound/DoorCrashSound.php b/src/pocketmine/world/sound/DoorCrashSound.php similarity index 96% rename from src/pocketmine/level/sound/DoorCrashSound.php rename to src/pocketmine/world/sound/DoorCrashSound.php index 6946593ed..d702e83f5 100644 --- a/src/pocketmine/level/sound/DoorCrashSound.php +++ b/src/pocketmine/world/sound/DoorCrashSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/sound/DoorSound.php b/src/pocketmine/world/sound/DoorSound.php similarity index 96% rename from src/pocketmine/level/sound/DoorSound.php rename to src/pocketmine/world/sound/DoorSound.php index ee5a52674..779942258 100644 --- a/src/pocketmine/level/sound/DoorSound.php +++ b/src/pocketmine/world/sound/DoorSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/sound/EnderChestCloseSound.php b/src/pocketmine/world/sound/EnderChestCloseSound.php similarity index 96% rename from src/pocketmine/level/sound/EnderChestCloseSound.php rename to src/pocketmine/world/sound/EnderChestCloseSound.php index f6446c446..d092646c2 100644 --- a/src/pocketmine/level/sound/EnderChestCloseSound.php +++ b/src/pocketmine/world/sound/EnderChestCloseSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; diff --git a/src/pocketmine/level/sound/EnderChestOpenSound.php b/src/pocketmine/world/sound/EnderChestOpenSound.php similarity index 96% rename from src/pocketmine/level/sound/EnderChestOpenSound.php rename to src/pocketmine/world/sound/EnderChestOpenSound.php index e2cba0e19..e8b02367f 100644 --- a/src/pocketmine/level/sound/EnderChestOpenSound.php +++ b/src/pocketmine/world/sound/EnderChestOpenSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; diff --git a/src/pocketmine/level/sound/EndermanTeleportSound.php b/src/pocketmine/world/sound/EndermanTeleportSound.php similarity index 96% rename from src/pocketmine/level/sound/EndermanTeleportSound.php rename to src/pocketmine/world/sound/EndermanTeleportSound.php index ab8801657..d29787a4e 100644 --- a/src/pocketmine/level/sound/EndermanTeleportSound.php +++ b/src/pocketmine/world/sound/EndermanTeleportSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/sound/ExplodeSound.php b/src/pocketmine/world/sound/ExplodeSound.php similarity index 96% rename from src/pocketmine/level/sound/ExplodeSound.php rename to src/pocketmine/world/sound/ExplodeSound.php index cee3fbd2f..11849ef1f 100644 --- a/src/pocketmine/level/sound/ExplodeSound.php +++ b/src/pocketmine/world/sound/ExplodeSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; diff --git a/src/pocketmine/level/sound/FizzSound.php b/src/pocketmine/world/sound/FizzSound.php similarity index 96% rename from src/pocketmine/level/sound/FizzSound.php rename to src/pocketmine/world/sound/FizzSound.php index 09fb4b9af..52d525620 100644 --- a/src/pocketmine/level/sound/FizzSound.php +++ b/src/pocketmine/world/sound/FizzSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/sound/FlintSteelSound.php b/src/pocketmine/world/sound/FlintSteelSound.php similarity index 96% rename from src/pocketmine/level/sound/FlintSteelSound.php rename to src/pocketmine/world/sound/FlintSteelSound.php index a4240c475..94d130bdf 100644 --- a/src/pocketmine/level/sound/FlintSteelSound.php +++ b/src/pocketmine/world/sound/FlintSteelSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; diff --git a/src/pocketmine/level/sound/GhastShootSound.php b/src/pocketmine/world/sound/GhastShootSound.php similarity index 96% rename from src/pocketmine/level/sound/GhastShootSound.php rename to src/pocketmine/world/sound/GhastShootSound.php index 0d2b3fe64..c376afbf5 100644 --- a/src/pocketmine/level/sound/GhastShootSound.php +++ b/src/pocketmine/world/sound/GhastShootSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/sound/GhastSound.php b/src/pocketmine/world/sound/GhastSound.php similarity index 96% rename from src/pocketmine/level/sound/GhastSound.php rename to src/pocketmine/world/sound/GhastSound.php index 13cd6509f..3b29b1d79 100644 --- a/src/pocketmine/level/sound/GhastSound.php +++ b/src/pocketmine/world/sound/GhastSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/sound/IgniteSound.php b/src/pocketmine/world/sound/IgniteSound.php similarity index 96% rename from src/pocketmine/level/sound/IgniteSound.php rename to src/pocketmine/world/sound/IgniteSound.php index 3fa28ffac..4d70f65c5 100644 --- a/src/pocketmine/level/sound/IgniteSound.php +++ b/src/pocketmine/world/sound/IgniteSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/sound/ItemBreakSound.php b/src/pocketmine/world/sound/ItemBreakSound.php similarity index 96% rename from src/pocketmine/level/sound/ItemBreakSound.php rename to src/pocketmine/world/sound/ItemBreakSound.php index 35cf8e258..d1246c712 100644 --- a/src/pocketmine/level/sound/ItemBreakSound.php +++ b/src/pocketmine/world/sound/ItemBreakSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; diff --git a/src/pocketmine/level/sound/LaunchSound.php b/src/pocketmine/world/sound/LaunchSound.php similarity index 96% rename from src/pocketmine/level/sound/LaunchSound.php rename to src/pocketmine/world/sound/LaunchSound.php index 243c5fc2e..7b02daff6 100644 --- a/src/pocketmine/level/sound/LaunchSound.php +++ b/src/pocketmine/world/sound/LaunchSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/sound/LevelEventSound.php b/src/pocketmine/world/sound/LevelEventSound.php similarity index 97% rename from src/pocketmine/level/sound/LevelEventSound.php rename to src/pocketmine/world/sound/LevelEventSound.php index 37c6ee316..1e2d75b45 100644 --- a/src/pocketmine/level/sound/LevelEventSound.php +++ b/src/pocketmine/world/sound/LevelEventSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/sound/PopSound.php b/src/pocketmine/world/sound/PopSound.php similarity index 96% rename from src/pocketmine/level/sound/PopSound.php rename to src/pocketmine/world/sound/PopSound.php index 126ca9366..e74a25352 100644 --- a/src/pocketmine/level/sound/PopSound.php +++ b/src/pocketmine/world/sound/PopSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/sound/PotionSplashSound.php b/src/pocketmine/world/sound/PotionSplashSound.php similarity index 96% rename from src/pocketmine/level/sound/PotionSplashSound.php rename to src/pocketmine/world/sound/PotionSplashSound.php index af5473efd..24ce0fcdf 100644 --- a/src/pocketmine/level/sound/PotionSplashSound.php +++ b/src/pocketmine/world/sound/PotionSplashSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; diff --git a/src/pocketmine/level/sound/RedstonePowerOffSound.php b/src/pocketmine/world/sound/RedstonePowerOffSound.php similarity index 96% rename from src/pocketmine/level/sound/RedstonePowerOffSound.php rename to src/pocketmine/world/sound/RedstonePowerOffSound.php index 24505d11a..5e2dcf16e 100644 --- a/src/pocketmine/level/sound/RedstonePowerOffSound.php +++ b/src/pocketmine/world/sound/RedstonePowerOffSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; diff --git a/src/pocketmine/level/sound/RedstonePowerOnSound.php b/src/pocketmine/world/sound/RedstonePowerOnSound.php similarity index 96% rename from src/pocketmine/level/sound/RedstonePowerOnSound.php rename to src/pocketmine/world/sound/RedstonePowerOnSound.php index 3abae6778..bcd238939 100644 --- a/src/pocketmine/level/sound/RedstonePowerOnSound.php +++ b/src/pocketmine/world/sound/RedstonePowerOnSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; diff --git a/src/pocketmine/level/sound/Sound.php b/src/pocketmine/world/sound/Sound.php similarity index 96% rename from src/pocketmine/level/sound/Sound.php rename to src/pocketmine/world/sound/Sound.php index 83f1ff443..63f6739be 100644 --- a/src/pocketmine/level/sound/Sound.php +++ b/src/pocketmine/world/sound/Sound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\ClientboundPacket; diff --git a/src/pocketmine/level/sound/ThrowSound.php b/src/pocketmine/world/sound/ThrowSound.php similarity index 96% rename from src/pocketmine/level/sound/ThrowSound.php rename to src/pocketmine/world/sound/ThrowSound.php index 0d6a84fe8..bc387654a 100644 --- a/src/pocketmine/level/sound/ThrowSound.php +++ b/src/pocketmine/world/sound/ThrowSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; diff --git a/src/pocketmine/level/sound/TotemUseSound.php b/src/pocketmine/world/sound/TotemUseSound.php similarity index 96% rename from src/pocketmine/level/sound/TotemUseSound.php rename to src/pocketmine/world/sound/TotemUseSound.php index 8f67a7e69..20d3810f2 100644 --- a/src/pocketmine/level/sound/TotemUseSound.php +++ b/src/pocketmine/world/sound/TotemUseSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/sound/XpCollectSound.php b/src/pocketmine/world/sound/XpCollectSound.php similarity index 96% rename from src/pocketmine/level/sound/XpCollectSound.php rename to src/pocketmine/world/sound/XpCollectSound.php index 2374699dd..8b3994ecc 100644 --- a/src/pocketmine/level/sound/XpCollectSound.php +++ b/src/pocketmine/world/sound/XpCollectSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; diff --git a/src/pocketmine/level/sound/XpLevelUpSound.php b/src/pocketmine/world/sound/XpLevelUpSound.php similarity index 97% rename from src/pocketmine/level/sound/XpLevelUpSound.php rename to src/pocketmine/world/sound/XpLevelUpSound.php index 0020e0ea6..e173ca7be 100644 --- a/src/pocketmine/level/sound/XpLevelUpSound.php +++ b/src/pocketmine/world/sound/XpLevelUpSound.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\sound; +namespace pocketmine\world\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; diff --git a/src/pocketmine/level/utils/SubChunkIteratorManager.php b/src/pocketmine/world/utils/SubChunkIteratorManager.php similarity index 83% rename from src/pocketmine/level/utils/SubChunkIteratorManager.php rename to src/pocketmine/world/utils/SubChunkIteratorManager.php index 62bcf2dfc..ef1e6cdee 100644 --- a/src/pocketmine/level/utils/SubChunkIteratorManager.php +++ b/src/pocketmine/world/utils/SubChunkIteratorManager.php @@ -21,16 +21,16 @@ declare(strict_types=1); -namespace pocketmine\level\utils; +namespace pocketmine\world\utils; -use pocketmine\level\ChunkManager; -use pocketmine\level\format\Chunk; -use pocketmine\level\format\EmptySubChunk; -use pocketmine\level\format\SubChunkInterface; +use pocketmine\world\ChunkManager; +use pocketmine\world\format\Chunk; +use pocketmine\world\format\EmptySubChunk; +use pocketmine\world\format\SubChunkInterface; class SubChunkIteratorManager{ /** @var ChunkManager */ - public $level; + public $world; /** @var Chunk|null */ public $currentChunk; @@ -46,8 +46,8 @@ class SubChunkIteratorManager{ /** @var bool */ protected $allocateEmptySubs = true; - public function __construct(ChunkManager $level, bool $allocateEmptySubs = true){ - $this->level = $level; + public function __construct(ChunkManager $world, bool $allocateEmptySubs = true){ + $this->world = $world; $this->allocateEmptySubs = $allocateEmptySubs; } @@ -57,7 +57,7 @@ class SubChunkIteratorManager{ $this->currentZ = $z >> 4; $this->currentSubChunk = null; - $this->currentChunk = $this->level->getChunk($this->currentX, $this->currentZ); + $this->currentChunk = $this->world->getChunk($this->currentX, $this->currentZ); if($this->currentChunk === null){ return false; } diff --git a/tests/phpunit/level/format/io/AbstractLevelProvider.php b/tests/phpunit/level/format/io/AbstractWorldProvider.php similarity index 87% rename from tests/phpunit/level/format/io/AbstractLevelProvider.php rename to tests/phpunit/level/format/io/AbstractWorldProvider.php index 7f63048e1..29e78451e 100644 --- a/tests/phpunit/level/format/io/AbstractLevelProvider.php +++ b/tests/phpunit/level/format/io/AbstractWorldProvider.php @@ -21,8 +21,8 @@ declare(strict_types=1); -namespace pocketmine\level\format\io; +namespace pocketmine\world\format\io; -abstract class AbstractLevelProvider implements LevelProvider{ +abstract class AbstractWorldProvider implements WorldProvider{ } diff --git a/tests/phpunit/level/format/io/InterfaceLevelProvider.php b/tests/phpunit/level/format/io/InterfaceWorldProvider.php similarity index 88% rename from tests/phpunit/level/format/io/InterfaceLevelProvider.php rename to tests/phpunit/level/format/io/InterfaceWorldProvider.php index e01f08e43..baaa3337d 100644 --- a/tests/phpunit/level/format/io/InterfaceLevelProvider.php +++ b/tests/phpunit/level/format/io/InterfaceWorldProvider.php @@ -21,8 +21,8 @@ declare(strict_types=1); -namespace pocketmine\level\format\io; +namespace pocketmine\world\format\io; -interface InterfaceLevelProvider extends LevelProvider{ +interface InterfaceWorldProvider extends WorldProvider{ } diff --git a/tests/phpunit/level/format/io/LevelProviderManagerTest.php b/tests/phpunit/level/format/io/LevelProviderManagerTest.php index 10c484a76..738a16bc3 100644 --- a/tests/phpunit/level/format/io/LevelProviderManagerTest.php +++ b/tests/phpunit/level/format/io/LevelProviderManagerTest.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\level\format\io; +namespace pocketmine\world\format\io; use PHPUnit\Framework\TestCase; @@ -30,24 +30,24 @@ class LevelProviderManagerTest extends TestCase{ public function testAddNonClassProvider() : void{ $this->expectException(\InvalidArgumentException::class); - LevelProviderManager::addProvider("lol", "nope"); + WorldProviderManager::addProvider("lol", "nope"); } public function testAddAbstractClassProvider() : void{ $this->expectException(\InvalidArgumentException::class); - LevelProviderManager::addProvider(AbstractLevelProvider::class, "abstract"); + WorldProviderManager::addProvider(AbstractWorldProvider::class, "abstract"); } public function testAddInterfaceProvider() : void{ $this->expectException(\InvalidArgumentException::class); - LevelProviderManager::addProvider(InterfaceLevelProvider::class, "interface"); + WorldProviderManager::addProvider(InterfaceWorldProvider::class, "interface"); } public function testAddWrongClassProvider() : void{ $this->expectException(\InvalidArgumentException::class); - LevelProviderManager::addProvider(LevelProviderManagerTest::class, "bad_class"); + WorldProviderManager::addProvider(LevelProviderManagerTest::class, "bad_class"); } } diff --git a/src/pocketmine/level/format/io/SubChunkConverter.php b/tests/phpunit/level/format/io/SubChunkConverter.php similarity index 86% rename from src/pocketmine/level/format/io/SubChunkConverter.php rename to tests/phpunit/level/format/io/SubChunkConverter.php index 8aaab68ce..a5f6d4dfa 100644 --- a/src/pocketmine/level/format/io/SubChunkConverter.php +++ b/tests/phpunit/level/format/io/SubChunkConverter.php @@ -21,12 +21,13 @@ declare(strict_types=1); -namespace pocketmine\level\format\io; +namespace pocketmine\world\format\io; -use pocketmine\level\format\PalettedBlockArray; +use pocketmine\world\format\PalettedBlockArray; die("This is a stub file for code completion purposes"); +//TODO: this can't be moved right now because of compatibility issues with the extension class SubChunkConverter{ public static function convertSubChunkXZY(string $idArray, string $metaArray) : PalettedBlockArray{} diff --git a/tests/phpunit/level/format/io/region/RegionLoaderTest.php b/tests/phpunit/level/format/io/region/RegionLoaderTest.php index 39b69bc4f..3ed4c4a73 100644 --- a/tests/phpunit/level/format/io/region/RegionLoaderTest.php +++ b/tests/phpunit/level/format/io/region/RegionLoaderTest.php @@ -21,10 +21,10 @@ declare(strict_types=1); -namespace pocketmine\level\format\io\region; +namespace pocketmine\world\format\io\region; use PHPUnit\Framework\TestCase; -use pocketmine\level\format\ChunkException; +use pocketmine\world\format\ChunkException; use function file_exists; use function random_bytes; use function str_repeat; @@ -105,11 +105,12 @@ class RegionLoaderTest extends TestCase{ /** * @dataProvider outOfBoundsCoordsProvider + * * @param int $x * @param int $z * * @throws \InvalidArgumentException - * @throws \pocketmine\level\format\io\exception\CorruptedChunkException + * @throws \pocketmine\world\format\io\exception\CorruptedChunkException */ public function testReadChunkOutOfBounds(int $x, int $z) : void{ $this->expectException(\InvalidArgumentException::class); diff --git a/tests/preprocessor b/tests/preprocessor index b01f50c50..63e0092d6 160000 --- a/tests/preprocessor +++ b/tests/preprocessor @@ -1 +1 @@ -Subproject commit b01f50c50ef6546d000bdde16dc868b4147b31ba +Subproject commit 63e0092d623d13e47f9083b3d65fdf431933a471