Renaming "Level" -> "World" (#2907)

This has been a pain point for a long time due to the misleading nature of the name "level". It's also confusing when trying to do things like getting the XP level of the player or such, and also does not translate well to other languages.

This transition was already executed on the UI some time ago (language strings) and now it's time for the same change to occur on the API.

This will burn a lot of plugins, but they'll acclimatize. Despite the scary size of this PR, there isn't actually so many changes to make. Most of this came from renaming `Position->getLevel()` to `Position->getWorld()`, or cosmetic changes like changing variable names or doc comments.
This commit is contained in:
Dylan T 2019-05-07 14:47:28 +01:00 committed by GitHub
parent 427e334426
commit 3cd6e12e71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
310 changed files with 1647 additions and 1628 deletions

View File

@ -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 ..

View File

@ -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();
}
}

View File

@ -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;
}

View File

@ -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){

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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);
}
}
}

View File

@ -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;

View File

@ -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());
}
}
}

View File

@ -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);
}
}
}

View File

@ -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());
}
}

View File

@ -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);
}
}

View File

@ -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

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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();
}

View File

@ -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());
}
}
}

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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());

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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));
}
}
}

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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());
}

View File

@ -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;
}

View File

@ -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));
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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{

View File

@ -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);
}
}
}

View File

@ -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()
);

View File

@ -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
}
}

View File

@ -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());
}
}
}

View File

@ -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());
}
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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());
}
}
}

View File

@ -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);
}
}
}

View File

@ -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();
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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);
}
}
}

View File

@ -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{

View File

@ -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);
}
}
}

View File

@ -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();
}
}

View File

@ -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]));

View File

@ -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();

View File

@ -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

View File

@ -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)]));

View File

@ -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"));

View File

@ -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"));

View File

@ -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]));

View File

@ -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)]));

View File

@ -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)]));

View File

@ -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"
);
}

View File

@ -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{

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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){

View File

@ -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){

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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());
}

View File

@ -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{

View File

@ -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)));
}
}
}

View File

@ -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));
}

View File

@ -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));
}
}

View File

@ -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;
}

View File

@ -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());
}
}
}

View File

@ -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));
}
}
}

View File

@ -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);
}
}

View File

@ -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);
}
/**

View File

@ -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

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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{

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\event\player;
use pocketmine\level\Position;
use pocketmine\world\Position;
use pocketmine\Player;
/**

View File

@ -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";

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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)

View File

@ -21,7 +21,7 @@
declare(strict_types=1);
namespace pocketmine\event\level;
namespace pocketmine\event\world;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;

Some files were not shown because too many files have changed in this diff Show More