Removed @deprecated classes, methods and properties, added some type hints

This commit is contained in:
Shoghi Cervantes
2015-09-12 17:10:11 +02:00
parent 29a5012c02
commit 3ffdb8e552
39 changed files with 166 additions and 891 deletions

View File

@ -19,6 +19,8 @@
*
*/
declare(strict_types=1);
namespace pocketmine\level;
use pocketmine\level\format\FullChunk;
@ -33,7 +35,7 @@ interface ChunkManager{
*
* @return int 0-255
*/
public function getBlockIdAt($x, $y, $z);
public function getBlockIdAt(int $x, int $y, int $z) : int;
/**
* Sets the raw block id.
@ -43,7 +45,7 @@ interface ChunkManager{
* @param int $z
* @param int $id 0-255
*/
public function setBlockIdAt($x, $y, $z, $id);
public function setBlockIdAt(int $x, int $y, int $z, int $id);
/**
* Gets the raw block metadata
@ -54,7 +56,7 @@ interface ChunkManager{
*
* @return int 0-15
*/
public function getBlockDataAt($x, $y, $z);
public function getBlockDataAt(int $x, int $y, int $z) : int;
/**
* Sets the raw block metadata.
@ -64,27 +66,27 @@ interface ChunkManager{
* @param int $z
* @param int $data 0-15
*/
public function setBlockDataAt($x, $y, $z, $data);
public function setBlockDataAt(int $x, int $y, int $z, int $data);
/**
* @param int $chunkX
* @param int $chunkZ
*
* @return FullChunk
* @return FullChunk|null
*/
public function getChunk($chunkX, $chunkZ);
public function getChunk(int $chunkX, int $chunkZ);
/**
* @param int $chunkX
* @param int $chunkZ
* @param FullChunk $chunk
*/
public function setChunk($chunkX, $chunkZ, FullChunk $chunk = null);
public function setChunk(int $chunkX, int $chunkZ, FullChunk $chunk = null);
/**
* Gets the level seed
*
* @return int
*/
public function getSeed();
public function getSeed() : int;
}

View File

@ -63,18 +63,6 @@ class Explosion{
$this->what = $what;
}
/**
* @deprecated
* @return bool
*/
public function explode(){
if($this->explodeA()){
return $this->explodeB();
}
return false;
}
/**
* @return bool
*/

View File

@ -19,6 +19,8 @@
*
*/
declare(strict_types=1);
/**
* All Level related classes are here, like Generators, Populators, Noise, ...
*/
@ -266,23 +268,15 @@ class Level implements ChunkManager, Metadatable{
/** @var Generator */
private $generatorInstance;
/**
* Returns the chunk unique hash/key
*
* @param int $x
* @param int $z
*
* @return string
*/
public static function chunkHash($x, $z){
public static function chunkHash(int $x, int $z){
return PHP_INT_SIZE === 8 ? (($x & 0xFFFFFFFF) << 32) | ($z & 0xFFFFFFFF) : $x . ":" . $z;
}
public static function blockHash($x, $y, $z){
public static function blockHash(int $x, int $y, int $z){
return PHP_INT_SIZE === 8 ? (($x & 0xFFFFFFF) << 35) | (($y & 0x7f) << 28) | ($z & 0xFFFFFFF) : $x . ":" . $y .":". $z;
}
public static function chunkBlockHash($x, $y, $z){
public static function chunkBlockHash(int $x, int $y, int $z) : int{
return ($x << 11) | ($z << 7) | $y;
}
@ -310,7 +304,7 @@ class Level implements ChunkManager, Metadatable{
}
}
public static function generateChunkLoaderId(ChunkLoader $loader){
public static function generateChunkLoaderId(ChunkLoader $loader) : int{
if($loader->getLoaderId() === 0 or $loader->getLoaderId() === null or $loader->getLoaderId() === null){
return self::$chunkLoaderCounter++;
}else{
@ -328,7 +322,7 @@ class Level implements ChunkManager, Metadatable{
*
* @throws \Exception
*/
public function __construct(Server $server, $name, $path, $provider){
public function __construct(Server $server, string $name, string $path, string $provider){
$this->blockStates = Block::$fullList;
$this->levelId = static::$levelIdCounter++;
$this->blockMetadata = new BlockMetadataStore($this);
@ -367,16 +361,16 @@ class Level implements ChunkManager, Metadatable{
$this->tickRate = 1;
}
public function getTickRate(){
public function getTickRate() : int{
return $this->tickRate;
}
public function getTickRateTime(){
public function getTickRateTime() : int{
return $this->tickRateTime;
}
public function setTickRate($tickRate){
$this->tickRate = (int) $tickRate;
public function setTickRate(int $tickRate){
$this->tickRate = $tickRate;
}
public function initLevel(){
@ -401,33 +395,22 @@ class Level implements ChunkManager, Metadatable{
}
}
/**
* @return BlockMetadataStore
*/
public function getBlockMetadata(){
public function getBlockMetadata() : BlockMetadataStore{
return $this->blockMetadata;
}
/**
* @return Server
*/
public function getServer(){
public function getServer() : Server{
return $this->server;
}
/**
* @return LevelProvider
*/
final public function getProvider(){
final public function getProvider() : LevelProvider{
return $this->provider;
}
/**
* Returns the unique level identifier
*
* @return int
*/
final public function getId(){
final public function getId() : int{
return $this->levelId;
}
@ -498,17 +481,11 @@ class Level implements ChunkManager, Metadatable{
}
}
/**
* @return bool
*/
public function getAutoSave(){
public function getAutoSave() : bool{
return $this->autoSave;
}
/**
* @param bool $value
*/
public function setAutoSave($value){
public function setAutoSave(bool $value){
$this->autoSave = $value;
}
@ -519,7 +496,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return bool
*/
public function unload($force = false){
public function unload(bool $force = false) : bool{
$ev = new LevelUnloadEvent($this);
@ -552,13 +529,6 @@ class Level implements ChunkManager, Metadatable{
return true;
}
/**
* @deprecated Use Level->getChunkPlayers($chunkX, $chunkZ)
*/
public function getUsingChunk($chunkX, $chunkZ){
return $this->getChunkPlayers($chunkX, $chunkZ);
}
/**
* Gets the players being used in a specific chunk
*
@ -567,7 +537,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return Player[]
*/
public function getChunkPlayers($chunkX, $chunkZ){
public function getChunkPlayers(int $chunkX, int $chunkZ) : array{
return isset($this->playerLoaders[$index = Level::chunkHash($chunkX, $chunkZ)]) ? $this->playerLoaders[$index] : [];
}
@ -579,11 +549,11 @@ class Level implements ChunkManager, Metadatable{
*
* @return ChunkLoader[]
*/
public function getChunkLoaders($chunkX, $chunkZ){
public function getChunkLoaders(int $chunkX, int $chunkZ) : array{
return isset($this->chunkLoaders[$index = Level::chunkHash($chunkX, $chunkZ)]) ? $this->chunkLoaders[$index] : [];
}
public function addChunkPacket($chunkX, $chunkZ, DataPacket $packet){
public function addChunkPacket(int $chunkX, int $chunkZ, DataPacket $packet){
if(!isset($this->chunkPackets[$index = Level::chunkHash($chunkX, $chunkZ)])){
$this->chunkPackets[$index] = [$packet];
}else{
@ -591,7 +561,7 @@ class Level implements ChunkManager, Metadatable{
}
}
public function registerChunkLoader(ChunkLoader $loader, $chunkX, $chunkZ, $autoLoad = true){
public function registerChunkLoader(ChunkLoader $loader, int $chunkX, int $chunkZ, bool $autoLoad = true){
$hash = $loader->getLoaderId();
if(!isset($this->chunkLoaders[$index = Level::chunkHash($chunkX, $chunkZ)])){
@ -620,7 +590,7 @@ class Level implements ChunkManager, Metadatable{
}
}
public function unregisterChunkLoader(ChunkLoader $loader, $chunkX, $chunkZ){
public function unregisterChunkLoader(ChunkLoader $loader, int $chunkX, int $chunkZ){
if(isset($this->chunkLoaders[$index = Level::chunkHash($chunkX, $chunkZ)][$hash = $loader->getLoaderId()])){
unset($this->chunkLoaders[$index][$hash]);
unset($this->playerLoaders[$index][$hash]);
@ -667,9 +637,8 @@ class Level implements ChunkManager, Metadatable{
*
* @param int $currentTick
*
* @return bool
*/
public function doTick($currentTick){
public function doTick(int $currentTick){
$this->timings->doTick->startTiming();
@ -804,7 +773,7 @@ class Level implements ChunkManager, Metadatable{
}
}
public function sendBlockExtraData($x, $y, $z, $id, $data, array $targets = null){
public function sendBlockExtraData(int $x, int $y, int $z, int $id, int $data, array $targets = null){
$pk = new LevelEventPacket;
$pk->evid = LevelEventPacket::EVENT_SET_DATA;
$pk->x = $x + 0.5;
@ -821,7 +790,7 @@ class Level implements ChunkManager, Metadatable{
* @param int $flags
* @param bool $optimizeRebuilds
*/
public function sendBlocks(array $target, array $blocks, $flags = UpdateBlockPacket::FLAG_NONE, $optimizeRebuilds = false){
public function sendBlocks(array $target, array $blocks, $flags = UpdateBlockPacket::FLAG_NONE, bool $optimizeRebuilds = false){
$pk = new UpdateBlockPacket();
if($optimizeRebuilds){
@ -862,7 +831,7 @@ class Level implements ChunkManager, Metadatable{
Server::broadcastPacket($target, $pk);
}
public function clearCache($full = false){
public function clearCache(bool $full = false){
if($full){
$this->chunkCache = [];
$this->blockCache = [];
@ -879,7 +848,7 @@ class Level implements ChunkManager, Metadatable{
}
public function clearChunkCache($chunkX, $chunkZ){
public function clearChunkCache(int $chunkX, int $chunkZ){
unset($this->chunkCache[Level::chunkHash($chunkX, $chunkZ)]);
}
@ -983,7 +952,7 @@ class Level implements ChunkManager, Metadatable{
}
}
public function __debugInfo(){
public function __debugInfo() : array{
return [];
}
@ -992,7 +961,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return bool
*/
public function save($force = false){
public function save(bool $force = false){
if(!$this->getAutoSave() and !$force){
return false;
@ -1058,7 +1027,7 @@ class Level implements ChunkManager, Metadatable{
* @param Vector3 $pos
* @param int $delay
*/
public function scheduleUpdate(Vector3 $pos, $delay){
public function scheduleUpdate(Vector3 $pos, int $delay){
if(isset($this->updateQueueIndex[$index = Level::blockHash($pos->x, $pos->y, $pos->z)]) and $this->updateQueueIndex[$index] <= $delay){
return;
}
@ -1072,7 +1041,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return Block[]
*/
public function getCollisionBlocks(AxisAlignedBB $bb, $targetFirst = false){
public function getCollisionBlocks(AxisAlignedBB $bb, bool $targetFirst = false) : array{
$minX = Math::floorFloat($bb->minX);
$minY = Math::floorFloat($bb->minY);
$minZ = Math::floorFloat($bb->minZ);
@ -1115,7 +1084,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return bool
*/
public function isFullBlock(Vector3 $pos){
public function isFullBlock(Vector3 $pos) : bool{
if($pos instanceof Block){
if($pos->isSolid()){
return true;
@ -1135,7 +1104,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return AxisAlignedBB[]
*/
public function getCollisionCubes(Entity $entity, AxisAlignedBB $bb, $entities = true){
public function getCollisionCubes(Entity $entity, AxisAlignedBB $bb, bool $entities = true) : array{
$minX = Math::floorFloat($bb->minX);
$minY = Math::floorFloat($bb->minY);
$minZ = Math::floorFloat($bb->minZ);
@ -1237,10 +1206,10 @@ class Level implements ChunkManager, Metadatable{
}
*/
public function getFullLight(Vector3 $pos){
public function getFullLight(Vector3 $pos) : int{
$chunk = $this->getChunk($pos->x >> 4, $pos->z >> 4, false);
$level = 0;
if($chunk instanceof FullChunk){
if($chunk !== null){
$level = $chunk->getBlockSkyLight($pos->x & 0x0f, $pos->y & 0x7f, $pos->z & 0x0f);
//TODO: decrease light level by time of day
if($level < 15){
@ -1258,7 +1227,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return int bitmap, (id << 4) | data
*/
public function getFullBlock($x, $y, $z){
public function getFullBlock(int $x, int $y, int $z) : int{
return $this->getChunk($x >> 4, $z >> 4, false)->getFullBlock($x & 0x0f, $y & 0x7f, $z & 0x0f);
}
@ -1270,7 +1239,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return Block
*/
public function getBlock(Vector3 $pos, $cached = true){
public function getBlock(Vector3 $pos, $cached = true) : Block{
$index = Level::blockHash($pos->x, $pos->y, $pos->z);
if($cached and isset($this->blockCache[$index])){
return $this->blockCache[$index];
@ -1295,11 +1264,11 @@ class Level implements ChunkManager, Metadatable{
$this->updateBlockLight($pos->x, $pos->y, $pos->z);
}
public function updateBlockSkyLight($x, $y, $z){
public function updateBlockSkyLight(int $x, int $y, int $z){
//TODO
}
public function updateBlockLight($x, $y, $z){
public function updateBlockLight(int $x, int $y, int $z){
$lightPropagationQueue = new \SplQueue();
$lightRemovalQueue = new \SplQueue();
$visited = [];
@ -1351,7 +1320,7 @@ class Level implements ChunkManager, Metadatable{
}
}
private function computeRemoveBlockLight($x, $y, $z, $currentLight, \SplQueue $queue, \SplQueue $spreadQueue, array &$visited, array &$spreadVisited){
private function computeRemoveBlockLight(int $x, int $y, int $z, int $currentLight, \SplQueue $queue, \SplQueue $spreadQueue, array &$visited, array &$spreadVisited){
$current = $this->getBlockLightAt($x, $y, $z);
if($current !== 0 and $current < $currentLight){
@ -1371,7 +1340,7 @@ class Level implements ChunkManager, Metadatable{
}
}
private function computeSpreadBlockLight($x, $y, $z, $currentLight, \SplQueue $queue, array &$visited){
private function computeSpreadBlockLight(int $x, int $y, int $z, int $currentLight, \SplQueue $queue, array &$visited){
$current = $this->getBlockLightAt($x, $y, $z);
if($current < $currentLight){
@ -1404,7 +1373,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return bool Whether the block has been updated or not
*/
public function setBlock(Vector3 $pos, Block $block, $direct = false, $update = true){
public function setBlock(Vector3 $pos, Block $block, bool $direct = false, bool $update = true) : bool{
if($pos->y < 0 or $pos->y >= 128){
return false;
}
@ -1460,7 +1429,7 @@ class Level implements ChunkManager, Metadatable{
* @param Vector3 $motion
* @param int $delay
*/
public function dropItem(Vector3 $source, Item $item, Vector3 $motion = null, $delay = 10){
public function dropItem(Vector3 $source, Item $item, Vector3 $motion = null, int $delay = 10){
$motion = $motion === null ? new Vector3(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1) : $motion;
$itemTag = NBT::putItemHelper($item);
$itemTag->setName("Item");
@ -1500,9 +1469,9 @@ class Level implements ChunkManager, Metadatable{
* @param Player $player
* @param bool $createParticles
*
* @return boolean
* @return boole
*/
public function useBreakOn(Vector3 $vector, Item &$item = null, Player $player = null, $createParticles = false){
public function useBreakOn(Vector3 $vector, Item &$item = null, Player $player = null, bool $createParticles = false) : bool{
$target = $this->getBlock($vector);
//TODO: Adventure mode checks
@ -1640,9 +1609,9 @@ class Level implements ChunkManager, Metadatable{
* @param float $fz default 0.0
* @param Player $player default null
*
* @return boolean
* @return bool
*/
public function useItemOn(Vector3 $vector, Item &$item, $face, $fx = 0.0, $fy = 0.0, $fz = 0.0, Player $player = null){
public function useItemOn(Vector3 $vector, Item &$item, int $face, float $fx = 0.0, float $fy = 0.0, float $fz = 0.0, Player $player = null) : bool{
$target = $this->getBlock($vector);
$block = $target->getSide($face);
@ -1805,7 +1774,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return Entity
*/
public function getEntity($entityId){
public function getEntity(int $entityId){
return isset($this->entities[$entityId]) ? $this->entities[$entityId] : null;
}
@ -1814,7 +1783,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return Entity[]
*/
public function getEntities(){
public function getEntities() : array{
return $this->entities;
}
@ -1826,7 +1795,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return Entity[]
*/
public function getCollidingEntities(AxisAlignedBB $bb, Entity $entity = null){
public function getCollidingEntities(AxisAlignedBB $bb, Entity $entity = null) : array{
$nearby = [];
if($entity === null or $entity->canCollide){
@ -1857,7 +1826,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return Entity[]
*/
public function getNearbyEntities(AxisAlignedBB $bb, Entity $entity = null){
public function getNearbyEntities(AxisAlignedBB $bb, Entity $entity = null) : array{
$nearby = [];
$minX = Math::floorFloat(($bb->minX - 2) / 16);
@ -1883,7 +1852,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return Tile[]
*/
public function getTiles(){
public function getTiles() : array{
return $this->tiles;
}
@ -1892,7 +1861,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return Tile
*/
public function getTileById($tileId){
public function getTileById(int $tileId){
return isset($this->tiles[$tileId]) ? $this->tiles[$tileId] : null;
}
@ -1901,14 +1870,14 @@ class Level implements ChunkManager, Metadatable{
*
* @return Player[]
*/
public function getPlayers(){
public function getPlayers() : array{
return $this->players;
}
/**
* @return ChunkLoader[]
*/
public function getLoaders(){
public function getLoaders() : array{
return $this->loaders;
}
@ -1937,7 +1906,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return Entity[]
*/
public function getChunkEntities($X, $Z){
public function getChunkEntities($X, $Z) : array{
return ($chunk = $this->getChunk($X, $Z)) !== null ? $chunk->getEntities() : [];
}
@ -1949,7 +1918,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return Tile[]
*/
public function getChunkTiles($X, $Z){
public function getChunkTiles($X, $Z) : array{
return ($chunk = $this->getChunk($X, $Z)) !== null ? $chunk->getTiles() : [];
}
@ -1962,7 +1931,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return int 0-255
*/
public function getBlockIdAt($x, $y, $z){
public function getBlockIdAt(int $x, int $y, int $z) : int{
return $this->getChunk($x >> 4, $z >> 4, true)->getBlockId($x & 0x0f, $y & 0x7f, $z & 0x0f);
}
@ -1974,7 +1943,7 @@ class Level implements ChunkManager, Metadatable{
* @param int $z
* @param int $id 0-255
*/
public function setBlockIdAt($x, $y, $z, $id){
public function setBlockIdAt(int $x, int $y, int $z, int $id){
unset($this->blockCache[Level::blockHash($x, $y, $z)]);
$this->getChunk($x >> 4, $z >> 4, true)->setBlockId($x & 0x0f, $y & 0x7f, $z & 0x0f, $id & 0xff);
@ -1996,7 +1965,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return int 16-bit
*/
public function getBlockExtraDataAt($x, $y, $z){
public function getBlockExtraDataAt(int $x, int $y, int $z) : int{
return $this->getChunk($x >> 4, $z >> 4, true)->getBlockExtraData($x & 0x0f, $y & 0x7f, $z & 0x0f);
}
@ -2009,7 +1978,7 @@ class Level implements ChunkManager, Metadatable{
* @param int $id
* @param int $data
*/
public function setBlockExtraDataAt($x, $y, $z, $id, $data){
public function setBlockExtraDataAt(int $x, int $y, int $z, int $id, int $data){
$this->getChunk($x >> 4, $z >> 4, true)->setBlockExtraData($x & 0x0f, $y & 0x7f, $z & 0x0f, ($data << 8) | $id);
$this->sendBlockExtraData($x, $y, $z, $id, $data);
@ -2024,7 +1993,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return int 0-15
*/
public function getBlockDataAt($x, $y, $z){
public function getBlockDataAt(int $x, int $y, int $z) : int{
return $this->getChunk($x >> 4, $z >> 4, true)->getBlockData($x & 0x0f, $y & 0x7f, $z & 0x0f);
}
@ -2036,7 +2005,7 @@ class Level implements ChunkManager, Metadatable{
* @param int $z
* @param int $data 0-15
*/
public function setBlockDataAt($x, $y, $z, $data){
public function setBlockDataAt(int $x, int $y, int $z, int $data){
unset($this->blockCache[Level::blockHash($x, $y, $z)]);
$this->getChunk($x >> 4, $z >> 4, true)->setBlockData($x & 0x0f, $y & 0x7f, $z & 0x0f, $data & 0x0f);
@ -2058,7 +2027,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return int 0-15
*/
public function getBlockSkyLightAt($x, $y, $z){
public function getBlockSkyLightAt(int $x, int $y, int $z) : int{
return $this->getChunk($x >> 4, $z >> 4, true)->getBlockSkyLight($x & 0x0f, $y & 0x7f, $z & 0x0f);
}
@ -2070,7 +2039,7 @@ class Level implements ChunkManager, Metadatable{
* @param int $z
* @param int $level 0-15
*/
public function setBlockSkyLightAt($x, $y, $z, $level){
public function setBlockSkyLightAt(int $x, int $y, int $z, int $level){
$this->getChunk($x >> 4, $z >> 4, true)->setBlockSkyLight($x & 0x0f, $y & 0x7f, $z & 0x0f, $level & 0x0f);
}
@ -2083,7 +2052,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return int 0-15
*/
public function getBlockLightAt($x, $y, $z){
public function getBlockLightAt(int $x, int $y, int $z) : int{
return $this->getChunk($x >> 4, $z >> 4, true)->getBlockLight($x & 0x0f, $y & 0x7f, $z & 0x0f);
}
@ -2095,7 +2064,7 @@ class Level implements ChunkManager, Metadatable{
* @param int $z
* @param int $level 0-15
*/
public function setBlockLightAt($x, $y, $z, $level){
public function setBlockLightAt(int $x, int $y, int $z, int $level){
$this->getChunk($x >> 4, $z >> 4, true)->setBlockLight($x & 0x0f, $y & 0x7f, $z & 0x0f, $level & 0x0f);
}
@ -2105,7 +2074,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return int
*/
public function getBiomeId($x, $z){
public function getBiomeId(int $x, int $z) : int{
return $this->getChunk($x >> 4, $z >> 4, true)->getBiomeId($x & 0x0f, $z & 0x0f);
}
@ -2115,7 +2084,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return int[]
*/
public function getBiomeColor($x, $z){
public function getBiomeColor(int $x, int $z) : array{
return $this->getChunk($x >> 4, $z >> 4, true)->getBiomeColor($x & 0x0f, $z & 0x0f);
}
@ -2125,7 +2094,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return int
*/
public function getHeightMap($x, $z){
public function getHeightMap(int $x, int $z) : int{
return $this->getChunk($x >> 4, $z >> 4, true)->getHeightMap($x & 0x0f, $z & 0x0f);
}
@ -2134,7 +2103,7 @@ class Level implements ChunkManager, Metadatable{
* @param int $z
* @param int $biomeId
*/
public function setBiomeId($x, $z, $biomeId){
public function setBiomeId(int $x, int $z, int $biomeId){
$this->getChunk($x >> 4, $z >> 4, true)->setBiomeId($x & 0x0f, $z & 0x0f, $biomeId);
}
@ -2145,7 +2114,7 @@ class Level implements ChunkManager, Metadatable{
* @param int $G
* @param int $B
*/
public function setBiomeColor($x, $z, $R, $G, $B){
public function setBiomeColor(int $x, int $z, int $R, int $G, int $B){
$this->getChunk($x >> 4, $z >> 4, true)->setBiomeColor($x & 0x0f, $z & 0x0f, $R, $G, $B);
}
@ -2154,14 +2123,14 @@ class Level implements ChunkManager, Metadatable{
* @param int $z
* @param int $value
*/
public function setHeightMap($x, $z, $value){
public function setHeightMap(int $x, int $z, int $value){
$this->getChunk($x >> 4, $z >> 4, true)->setHeightMap($x & 0x0f, $z & 0x0f, $value);
}
/**
* @return FullChunk[]|Chunk[]
*/
public function getChunks(){
public function getChunks() : array{
return $this->chunks;
}
@ -2174,7 +2143,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return FullChunk|Chunk
*/
public function getChunk($x, $z, $create = false){
public function getChunk(int $x, int $z, bool $create = false){
if(isset($this->chunks[$index = Level::chunkHash($x, $z)])){
return $this->chunks[$index];
}elseif($this->loadChunk($x, $z, $create)){
@ -2184,20 +2153,7 @@ class Level implements ChunkManager, Metadatable{
return null;
}
/**
* @param int $x
* @param int $z
* @param bool $create
*
* @return FullChunk|Chunk
*
* @deprecated
*/
public function getChunkAt($x, $z, $create = false){
return $this->getChunk($x, $z, $create);
}
public function generateChunkCallback($x, $z, FullChunk $chunk){
public function generateChunkCallback(int $x, int $z, FullChunk $chunk){
Timings::$generationCallbackTimer->startTiming();
if(isset($this->chunkPopulationQueue[$index = Level::chunkHash($x, $z)])){
$oldChunk = $this->getChunk($x, $z, false);
@ -2235,7 +2191,7 @@ class Level implements ChunkManager, Metadatable{
* @param FullChunk $chunk
* @param bool $unload
*/
public function setChunk($chunkX, $chunkZ, FullChunk $chunk = null, $unload = true){
public function setChunk(int $chunkX, int $chunkZ, FullChunk $chunk = null, bool $unload = true){
if($chunk === null){
return;
}
@ -2284,7 +2240,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return int 0-127
*/
public function getHighestBlockAt($x, $z){
public function getHighestBlockAt(int $x, int $z) : int{
return $this->getChunk($x >> 4, $z >> 4, true)->getHighestBlockAt($x & 0x0f, $z & 0x0f);
}
@ -2294,7 +2250,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return bool
*/
public function isChunkLoaded($x, $z){
public function isChunkLoaded(int $x, int $z) : bool{
return isset($this->chunks[Level::chunkHash($x, $z)]) or $this->provider->isChunkLoaded($x, $z);
}
@ -2304,7 +2260,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return bool
*/
public function isChunkGenerated($x, $z){
public function isChunkGenerated(int $x, int $z) : bool{
$chunk = $this->getChunk($x, $z);
return $chunk !== null ? $chunk->isGenerated() : false;
}
@ -2315,7 +2271,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return bool
*/
public function isChunkPopulated($x, $z){
public function isChunkPopulated(int $x, int $z) : bool{
$chunk = $this->getChunk($x, $z);
return $chunk !== null ? $chunk->isPopulated() : false;
}
@ -2325,7 +2281,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return Position
*/
public function getSpawnLocation(){
public function getSpawnLocation() : Position{
return Position::fromObject($this->provider->getSpawn(), $this);
}
@ -2340,7 +2296,7 @@ class Level implements ChunkManager, Metadatable{
$this->server->getPluginManager()->callEvent(new SpawnChangeEvent($this, $previousSpawn));
}
public function requestChunk($x, $z, Player $player){
public function requestChunk(int $x, int $z, Player $player){
$index = Level::chunkHash($x, $z);
if(!isset($this->chunkSendQueue[$index])){
$this->chunkSendQueue[$index] = [];
@ -2349,7 +2305,7 @@ class Level implements ChunkManager, Metadatable{
$this->chunkSendQueue[$index][$player->getLoaderId()] = $player;
}
private function sendChunkFromCache($x, $z){
private function sendChunkFromCache(int $x, int $z){
if(isset($this->chunkSendTasks[$index = Level::chunkHash($x, $z)])){
foreach($this->chunkSendQueue[$index] as $player){
/** @var Player $player */
@ -2390,7 +2346,7 @@ class Level implements ChunkManager, Metadatable{
}
}
public function chunkRequestCallback($x, $z, $payload, $ordering = FullChunkDataPacket::ORDER_COLUMNS){
public function chunkRequestCallback(int $x, int $z, string $payload, int $ordering = FullChunkDataPacket::ORDER_COLUMNS){
$this->timings->syncChunkSendTimer->startTiming();
$index = Level::chunkHash($x, $z);
@ -2487,7 +2443,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return bool
*/
public function isChunkInUse($x, $z){
public function isChunkInUse(int $x, int $z) : bool{
return isset($this->chunkLoaders[$index = Level::chunkHash($x, $z)]) and count($this->chunkLoaders[$index]) > 0;
}
@ -2498,7 +2454,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return bool
*/
public function loadChunk($x, $z, $generate = true){
public function loadChunk(int $x, int $z, bool $generate = true) : bool{
if(isset($this->chunks[$index = Level::chunkHash($x, $z)])){
return true;
}
@ -2543,12 +2499,12 @@ class Level implements ChunkManager, Metadatable{
return true;
}
private function queueUnloadChunk($x, $z){
private function queueUnloadChunk(int $x, int $z){
$this->unloadQueue[$index = Level::chunkHash($x, $z)] = microtime(true);
unset($this->chunkTickList[$index]);
}
public function unloadChunkRequest($x, $z, $safe = true){
public function unloadChunkRequest(int $x, int $z, bool $safe = true){
if(($safe === true and $this->isChunkInUse($x, $z)) or $this->isSpawnChunk($x, $z)){
return false;
}
@ -2558,11 +2514,11 @@ class Level implements ChunkManager, Metadatable{
return true;
}
public function cancelUnloadChunkRequest($x, $z){
public function cancelUnloadChunkRequest(int $x, int $z){
unset($this->unloadQueue[Level::chunkHash($x, $z)]);
}
public function unloadChunk($x, $z, $safe = true, $trySave = true){
public function unloadChunk(int $x, int $z, bool $safe = true, bool $trySave = true) : bool{
if(($safe === true and $this->isChunkInUse($x, $z))){
return false;
}
@ -2632,23 +2588,13 @@ class Level implements ChunkManager, Metadatable{
*
* @return bool
*/
public function isSpawnChunk($X, $Z){
public function isSpawnChunk(int $X, int $Z) : bool{
$spawnX = $this->provider->getSpawn()->getX() >> 4;
$spawnZ = $this->provider->getSpawn()->getZ() >> 4;
return abs($X - $spawnX) <= 1 and abs($Z - $spawnZ) <= 1;
}
/**
* Returns the raw spawnpoint
*
* @deprecated
* @return Position
*/
public function getSpawn(){
return $this->getSpawnLocation();
}
/**
* @param Vector3 $spawn default null
*
@ -2702,23 +2648,12 @@ class Level implements ChunkManager, Metadatable{
return false;
}
/**
* Sets the spawnpoint
*
* @param Vector3 $pos
*
* @deprecated
*/
public function setSpawn(Vector3 $pos){
$this->setSpawnLocation($pos);
}
/**
* Gets the current time
*
* @return int
*/
public function getTime(){
public function getTime() : int{
return (int) $this->time;
}
@ -2727,7 +2662,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return string
*/
public function getName(){
public function getName() : string{
return $this->provider->getName();
}
@ -2736,7 +2671,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return string
*/
public function getFolderName(){
public function getFolderName() : string{
return $this->folderName;
}
@ -2745,8 +2680,8 @@ class Level implements ChunkManager, Metadatable{
*
* @param int $time
*/
public function setTime($time){
$this->time = (int) $time;
public function setTime(int $time){
$this->time = $time;
$this->sendTime();
}
@ -2771,7 +2706,7 @@ class Level implements ChunkManager, Metadatable{
*
* @return int
*/
public function getSeed(){
public function getSeed() : int{
return $this->provider->getSeed();
}
@ -2780,12 +2715,12 @@ class Level implements ChunkManager, Metadatable{
*
* @param int $seed
*/
public function setSeed($seed){
public function setSeed(int $seed){
$this->provider->setSeed($seed);
}
public function populateChunk($x, $z, $force = false){
public function populateChunk(int $x, int $z, bool $force = false) : bool{
if(isset($this->chunkPopulationQueue[$index = Level::chunkHash($x, $z)]) or (count($this->chunkPopulationQueue) >= $this->chunkPopulationQueueSize and !$force)){
return false;
}
@ -2823,7 +2758,7 @@ class Level implements ChunkManager, Metadatable{
return true;
}
public function generateChunk($x, $z, $force = false){
public function generateChunk(int $x, int $z, bool $force = false){
if(count($this->chunkGenerationQueue) >= $this->chunkGenerationQueueSize and !$force){
return;
}
@ -2837,7 +2772,7 @@ class Level implements ChunkManager, Metadatable{
}
}
public function regenerateChunk($x, $z){
public function regenerateChunk(int $x, int $z){
$this->unloadChunk($x, $z, false);
$this->cancelUnloadChunkRequest($x, $z);
@ -2872,7 +2807,7 @@ class Level implements ChunkManager, Metadatable{
$this->timings->doChunkGC->stopTiming();
}
public function unloadChunks($force = false){
public function unloadChunks(bool $force = false){
if(count($this->unloadQueue) > 0){
$maxUnload = 96;
$now = microtime(true);
@ -2912,14 +2847,14 @@ class Level implements ChunkManager, Metadatable{
$this->server->getLevelMetadata()->removeMetadata($this, $metadataKey, $plugin);
}
public function addEntityMotion($chunkX, $chunkZ, $entityId, $x, $y, $z){
public function addEntityMotion(int $chunkX, int $chunkZ, int $entityId, float $x, float $y, float $z){
if(!isset($this->motionToSend[$index = Level::chunkHash($chunkX, $chunkZ)])){
$this->motionToSend[$index] = [];
}
$this->motionToSend[$index][$entityId] = [$entityId, $x, $y, $z];
}
public function addEntityMovement($chunkX, $chunkZ, $entityId, $x, $y, $z, $yaw, $pitch, $headYaw = null){
public function addEntityMovement(int $chunkX, int $chunkZ, int $entityId, float $x, float $y, float $z, float $yaw, float $pitch, $headYaw = null){
if(!isset($this->moveToSend[$index = Level::chunkHash($chunkX, $chunkZ)])){
$this->moveToSend[$index] = [];
}

View File

@ -67,30 +67,6 @@ class Position extends Vector3{
return $this->level !== null;
}
/**
* Marks the level reference as strong so it won't be collected
* by the garbage collector.
*
* @deprecated
*
* @return bool
*/
public function setStrong(){
return false;
}
/**
* Marks the level reference as weak so it won't have effect against
* the garbage collector decision.
*
* @deprecated
*
* @return bool
*/
public function setWeak(){
return false;
}
/**
* Returns a side Vector
*

View File

@ -19,6 +19,8 @@
*
*/
declare(strict_types=1);
namespace pocketmine\level;
use pocketmine\level\format\FullChunk;
@ -43,7 +45,7 @@ class SimpleChunkManager implements ChunkManager{
*
* @return int 0-255
*/
public function getBlockIdAt($x, $y, $z){
public function getBlockIdAt(int $x, int $y, int $z) : int{
if($chunk = $this->getChunk($x >> 4, $z >> 4)){
return $chunk->getBlockId($x & 0xf, $y & 0x7f, $z & 0xf);
}
@ -58,7 +60,7 @@ class SimpleChunkManager implements ChunkManager{
* @param int $z
* @param int $id 0-255
*/
public function setBlockIdAt($x, $y, $z, $id){
public function setBlockIdAt(int $x, int $y, int $z, int $id){
if($chunk = $this->getChunk($x >> 4, $z >> 4)){
$chunk->setBlockId($x & 0xf, $y & 0x7f, $z & 0xf, $id);
}
@ -73,7 +75,7 @@ class SimpleChunkManager implements ChunkManager{
*
* @return int 0-15
*/
public function getBlockDataAt($x, $y, $z){
public function getBlockDataAt(int $x, int $y, int $z) : int{
if($chunk = $this->getChunk($x >> 4, $z >> 4)){
return $chunk->getBlockData($x & 0xf, $y & 0x7f, $z & 0xf);
}
@ -88,7 +90,7 @@ class SimpleChunkManager implements ChunkManager{
* @param int $z
* @param int $data 0-15
*/
public function setBlockDataAt($x, $y, $z, $data){
public function setBlockDataAt(int $x, int $y, int $z, int $data){
if($chunk = $this->getChunk($x >> 4, $z >> 4)){
$chunk->setBlockData($x & 0xf, $y & 0x7f, $z & 0xf, $data);
}
@ -98,9 +100,9 @@ class SimpleChunkManager implements ChunkManager{
* @param int $chunkX
* @param int $chunkZ
*
* @return FullChunk
* @return FullChunk|null
*/
public function getChunk($chunkX, $chunkZ){
public function getChunk(int $chunkX, int $chunkZ){
return isset($this->chunks[$index = Level::chunkHash($chunkX, $chunkZ)]) ? $this->chunks[$index] : null;
}
@ -109,7 +111,7 @@ class SimpleChunkManager implements ChunkManager{
* @param int $chunkZ
* @param FullChunk $chunk
*/
public function setChunk($chunkX, $chunkZ, FullChunk $chunk = null){
public function setChunk(int $chunkX, int $chunkZ, FullChunk $chunk = null){
if($chunk === null){
unset($this->chunks[Level::chunkHash($chunkX, $chunkZ)]);
return;
@ -126,7 +128,7 @@ class SimpleChunkManager implements ChunkManager{
*
* @return int
*/
public function getSeed(){
public function getSeed() : int{
return $this->seed;
}
}

View File

@ -62,19 +62,6 @@ interface ChunkSection{
*/
public function setBlockData($x, $y, $z, $data);
/**
* Modifies $blockId and $meta
*
* @deprecated
*
* @param int $x 0-15
* @param int $y 0-15
* @param int $z 0-15
* @param int &$blockId
* @param int &$meta
*/
public function getBlock($x, $y, $z, &$blockId, &$meta = null);
/**
* Gets block and meta in one go
*

View File

@ -50,20 +50,6 @@ interface FullChunk{
*/
public function setProvider(LevelProvider $provider);
/**
* Modifies $blockId and $meta
*
* @deprecated
*
* @param int $x 0-15
* @param int $y 0-127
* @param int $z 0-15
* @param int &$blockId
* @param int &$meta
*/
public function getBlock($x, $y, $z, &$blockId, &$meta = null);
/**
* Gets block and meta in one go
*

View File

@ -70,12 +70,6 @@ class ChunkSection implements \pocketmine\level\format\ChunkSection{
}
}
public function getBlock($x, $y, $z, &$blockId, &$meta = null){
$full = $this->getFullBlock($x, $y, $z);
$blockId = $full >> 4;
$meta = $full & 0x0f;
}
public function getFullBlock($x, $y, $z){
$i = ($y << 8) + ($z << 4) + $x;
if(($x & 1) === 0){

View File

@ -77,12 +77,6 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{
$this->NBTentities = $entities;
}
public function getBlock($x, $y, $z, &$blockId, &$meta = null){
$full = $this->sections[$y >> 4]->getFullBlock($x, $y & 0x0f, $z);
$blockId = $full >> 4;
$meta = $full & 0x0f;
}
public function getFullBlock($x, $y, $z){
return $this->sections[$y >> 4]->getFullBlock($x, $y & 0x0f, $z);
}

View File

@ -203,15 +203,6 @@ abstract class BaseFullChunk implements FullChunk{
$this->z = $z;
}
/**
* @return LevelProvider
*
* @deprecated
*/
public function getLevel(){
return $this->getProvider();
}
/**
* @return LevelProvider
*/

View File

@ -101,12 +101,6 @@ class Chunk extends BaseFullChunk{
}
}
public function getBlock($x, $y, $z, &$blockId, &$meta = null){
$full = $this->getFullBlock($x, $y, $z);
$blockId = $full >> 4;
$meta = $full & 0x0f;
}
public function setBlock($x, $y, $z, $blockId = null, $meta = null){
$i = ($x << 11) | ($z << 7) | $y;

View File

@ -155,12 +155,6 @@ class Chunk extends BaseFullChunk{
}
}
public function getBlock($x, $y, $z, &$blockId, &$meta = null){
$full = $this->getFullBlock($x, $y, $z);
$blockId = $full >> 4;
$meta = $full & 0x0f;
}
public function setBlock($x, $y, $z, $blockId = null, $meta = null){
$i = ($x << 11) | ($z << 7) | $y;