mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-03 00:25:04 +00:00
PHP7 to master
This commit is contained in:
@ -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;
|
||||
}
|
@ -32,11 +32,11 @@ use pocketmine\item\Item;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Math;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\nbt\tag\Byte;
|
||||
use pocketmine\nbt\tag\Compound;
|
||||
use pocketmine\nbt\tag\Double;
|
||||
use pocketmine\nbt\tag\Enum;
|
||||
use pocketmine\nbt\tag\Float;
|
||||
use pocketmine\nbt\tag\ByteTag;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\nbt\tag\DoubleTag;
|
||||
use pocketmine\nbt\tag\ListTag;
|
||||
use pocketmine\nbt\tag\FloatTag;
|
||||
use pocketmine\network\Network;
|
||||
use pocketmine\network\protocol\ExplodePacket;
|
||||
|
||||
@ -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
|
||||
*/
|
||||
@ -186,22 +174,22 @@ class Explosion{
|
||||
foreach($this->affectedBlocks as $block){
|
||||
if($block->getId() === Block::TNT){
|
||||
$mot = (new Random())->nextSignedFloat() * M_PI * 2;
|
||||
$tnt = Entity::createEntity("PrimedTNT", $this->level->getChunk($block->x >> 4, $block->z >> 4), new Compound("", [
|
||||
"Pos" => new Enum("Pos", [
|
||||
new Double("", $block->x + 0.5),
|
||||
new Double("", $block->y),
|
||||
new Double("", $block->z + 0.5)
|
||||
$tnt = Entity::createEntity("PrimedTNT", $this->level->getChunk($block->x >> 4, $block->z >> 4), new CompoundTag("", [
|
||||
"Pos" => new ListTag("Pos", [
|
||||
new DoubleTag("", $block->x + 0.5),
|
||||
new DoubleTag("", $block->y),
|
||||
new DoubleTag("", $block->z + 0.5)
|
||||
]),
|
||||
"Motion" => new Enum("Motion", [
|
||||
new Double("", -sin($mot) * 0.02),
|
||||
new Double("", 0.2),
|
||||
new Double("", -cos($mot) * 0.02)
|
||||
"Motion" => new ListTag("Motion", [
|
||||
new DoubleTag("", -sin($mot) * 0.02),
|
||||
new DoubleTag("", 0.2),
|
||||
new DoubleTag("", -cos($mot) * 0.02)
|
||||
]),
|
||||
"Rotation" => new Enum("Rotation", [
|
||||
new Float("", 0),
|
||||
new Float("", 0)
|
||||
"Rotation" => new ListTag("Rotation", [
|
||||
new FloatTag("", 0),
|
||||
new FloatTag("", 0)
|
||||
]),
|
||||
"Fuse" => new Byte("Fuse", mt_rand(10, 30))
|
||||
"Fuse" => new ByteTag("Fuse", mt_rand(10, 30))
|
||||
]));
|
||||
$tnt->spawnToAll();
|
||||
}elseif(mt_rand(0, 100) < $yield){
|
||||
|
@ -19,6 +19,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* All Level related classes are here, like Generators, Populators, Noise, ...
|
||||
*/
|
||||
@ -81,13 +83,13 @@ use pocketmine\metadata\Metadatable;
|
||||
use pocketmine\metadata\MetadataValue;
|
||||
use pocketmine\nbt\NBT;
|
||||
|
||||
use pocketmine\nbt\tag\Compound;
|
||||
use pocketmine\nbt\tag\Double;
|
||||
use pocketmine\nbt\tag\Enum;
|
||||
use pocketmine\nbt\tag\Float;
|
||||
use pocketmine\nbt\tag\Int;
|
||||
use pocketmine\nbt\tag\Short;
|
||||
use pocketmine\nbt\tag\String;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\nbt\tag\DoubleTag;
|
||||
use pocketmine\nbt\tag\ListTag;
|
||||
use pocketmine\nbt\tag\FloatTag;
|
||||
use pocketmine\nbt\tag\IntTag;
|
||||
use pocketmine\nbt\tag\ShortTag;
|
||||
use pocketmine\nbt\tag\StringTag;
|
||||
use pocketmine\network\Network;
|
||||
use pocketmine\network\protocol\DataPacket;
|
||||
use pocketmine\network\protocol\FullChunkDataPacket;
|
||||
@ -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() : float{
|
||||
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,31 +1429,31 @@ 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");
|
||||
|
||||
if($item->getId() > 0 and $item->getCount() > 0){
|
||||
$itemEntity = Entity::createEntity("Item", $this->getChunk($source->getX() >> 4, $source->getZ() >> 4, true), new Compound("", [
|
||||
"Pos" => new Enum("Pos", [
|
||||
new Double("", $source->getX()),
|
||||
new Double("", $source->getY()),
|
||||
new Double("", $source->getZ())
|
||||
$itemEntity = Entity::createEntity("Item", $this->getChunk($source->getX() >> 4, $source->getZ() >> 4, true), new CompoundTag("", [
|
||||
"Pos" => new ListTag("Pos", [
|
||||
new DoubleTag("", $source->getX()),
|
||||
new DoubleTag("", $source->getY()),
|
||||
new DoubleTag("", $source->getZ())
|
||||
]),
|
||||
|
||||
"Motion" => new Enum("Motion", [
|
||||
new Double("", $motion->x),
|
||||
new Double("", $motion->y),
|
||||
new Double("", $motion->z)
|
||||
"Motion" => new ListTag("Motion", [
|
||||
new DoubleTag("", $motion->x),
|
||||
new DoubleTag("", $motion->y),
|
||||
new DoubleTag("", $motion->z)
|
||||
]),
|
||||
"Rotation" => new Enum("Rotation", [
|
||||
new Float("", lcg_value() * 360),
|
||||
new Float("", 0)
|
||||
"Rotation" => new ListTag("Rotation", [
|
||||
new FloatTag("", lcg_value() * 360),
|
||||
new FloatTag("", 0)
|
||||
]),
|
||||
"Health" => new Short("Health", 5),
|
||||
"Health" => new ShortTag("Health", 5),
|
||||
"Item" => $itemTag,
|
||||
"PickupDelay" => new Short("PickupDelay", $delay)
|
||||
"PickupDelay" => new ShortTag("PickupDelay", $delay)
|
||||
]));
|
||||
|
||||
$itemEntity->spawnToAll();
|
||||
@ -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
|
||||
|
||||
@ -1568,10 +1537,10 @@ class Level implements ChunkManager, Metadatable{
|
||||
}
|
||||
|
||||
$tag = $item->getNamedTagEntry("CanDestroy");
|
||||
if($tag instanceof Enum){
|
||||
if($tag instanceof ListTag){
|
||||
$canBreak = false;
|
||||
foreach($tag as $v){
|
||||
if($v instanceof String){
|
||||
if($v instanceof StringTag){
|
||||
$entry = Item::fromString($v->getValue());
|
||||
if($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()){
|
||||
$canBreak = true;
|
||||
@ -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);
|
||||
|
||||
@ -1730,10 +1699,10 @@ class Level implements ChunkManager, Metadatable{
|
||||
}
|
||||
|
||||
$tag = $item->getNamedTagEntry("CanPlaceOn");
|
||||
if($tag instanceof Enum){
|
||||
if($tag instanceof ListTag){
|
||||
$canPlace = false;
|
||||
foreach($tag as $v){
|
||||
if($v instanceof String){
|
||||
if($v instanceof StringTag){
|
||||
$entry = Item::fromString($v->getValue());
|
||||
if($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()){
|
||||
$canPlace = true;
|
||||
@ -1769,19 +1738,19 @@ class Level implements ChunkManager, Metadatable{
|
||||
|
||||
if($hand->getId() === Item::SIGN_POST or $hand->getId() === Item::WALL_SIGN){
|
||||
|
||||
$nbt = new Compound("", [
|
||||
"id" => new String("id", Tile::SIGN),
|
||||
"x" => new Int("x", $block->x),
|
||||
"y" => new Int("y", $block->y),
|
||||
"z" => new Int("z", $block->z),
|
||||
"Text1" => new String("Text1", ""),
|
||||
"Text2" => new String("Text2", ""),
|
||||
"Text3" => new String("Text3", ""),
|
||||
"Text4" => new String("Text4", "")
|
||||
$nbt = new CompoundTag("", [
|
||||
"id" => new StringTag("id", Tile::SIGN),
|
||||
"x" => new IntTag("x", $block->x),
|
||||
"y" => new IntTag("y", $block->y),
|
||||
"z" => new IntTag("z", $block->z),
|
||||
"Text1" => new StringTag("Text1", ""),
|
||||
"Text2" => new StringTag("Text2", ""),
|
||||
"Text3" => new StringTag("Text3", ""),
|
||||
"Text4" => new StringTag("Text4", "")
|
||||
]);
|
||||
|
||||
if($player !== null){
|
||||
$nbt->Creator = new String("Creator", $player->getRawUniqueId());
|
||||
$nbt->Creator = new StringTag("Creator", $player->getRawUniqueId());
|
||||
}
|
||||
|
||||
if($item->hasCustomBlockData()){
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -2500,7 +2456,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
*
|
||||
* @throws \InvalidStateException
|
||||
*/
|
||||
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;
|
||||
}
|
||||
@ -2545,12 +2501,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;
|
||||
}
|
||||
@ -2560,11 +2516,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;
|
||||
}
|
||||
@ -2609,12 +2565,10 @@ class Level implements ChunkManager, Metadatable{
|
||||
}
|
||||
}
|
||||
$this->provider->unloadChunk($x, $z, $safe);
|
||||
}catch(\Exception $e){
|
||||
}catch(\Throwable $e){
|
||||
$logger = $this->server->getLogger();
|
||||
$logger->error($this->server->getLanguage()->translateString("pocketmine.level.chunkUnloadError", [$e->getMessage()]));
|
||||
if($logger instanceof MainLogger){
|
||||
$logger->logException($e);
|
||||
}
|
||||
$logger->logException($e);
|
||||
}
|
||||
|
||||
unset($this->chunks[$index]);
|
||||
@ -2634,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
|
||||
*
|
||||
@ -2704,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;
|
||||
}
|
||||
|
||||
@ -2729,7 +2662,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(){
|
||||
public function getName() : string{
|
||||
return $this->provider->getName();
|
||||
}
|
||||
|
||||
@ -2738,7 +2671,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFolderName(){
|
||||
public function getFolderName() : string{
|
||||
return $this->folderName;
|
||||
}
|
||||
|
||||
@ -2747,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();
|
||||
}
|
||||
|
||||
@ -2773,7 +2706,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getSeed(){
|
||||
public function getSeed() : int{
|
||||
return $this->provider->getSeed();
|
||||
}
|
||||
|
||||
@ -2782,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;
|
||||
}
|
||||
@ -2825,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;
|
||||
}
|
||||
@ -2839,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);
|
||||
@ -2874,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);
|
||||
@ -2914,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] = [];
|
||||
}
|
||||
|
@ -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
|
||||
*
|
||||
@ -102,9 +78,7 @@ class Position extends Vector3{
|
||||
* @throws LevelException
|
||||
*/
|
||||
public function getSide($side, $step = 1){
|
||||
if(!$this->isValid()){
|
||||
throw new LevelException("Undefined Level reference");
|
||||
}
|
||||
assert($this->isValid());
|
||||
|
||||
return Position::fromObject(parent::getSide($side, $step), $this->level);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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
|
||||
*
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -25,9 +25,9 @@ use pocketmine\level\format\FullChunk;
|
||||
use pocketmine\level\format\mcregion\McRegion;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\nbt\NBT;
|
||||
use pocketmine\nbt\tag\Byte;
|
||||
use pocketmine\nbt\tag\ByteArray;
|
||||
use pocketmine\nbt\tag\Compound;
|
||||
use pocketmine\nbt\tag\ByteTag;
|
||||
use pocketmine\nbt\tag\ByteArrayTag;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\network\protocol\FullChunkDataPacket;
|
||||
use pocketmine\tile\Spawnable;
|
||||
use pocketmine\utils\BinaryStream;
|
||||
@ -152,12 +152,12 @@ class Anvil extends McRegion{
|
||||
}
|
||||
|
||||
public static function createChunkSection($Y){
|
||||
return new ChunkSection(new Compound("", [
|
||||
"Y" => new Byte("Y", $Y),
|
||||
"Blocks" => new ByteArray("Blocks", str_repeat("\x00", 4096)),
|
||||
"Data" => new ByteArray("Data", str_repeat("\x00", 2048)),
|
||||
"SkyLight" => new ByteArray("SkyLight", str_repeat("\xff", 2048)),
|
||||
"BlockLight" => new ByteArray("BlockLight", str_repeat("\x00", 2048))
|
||||
return new ChunkSection(new CompoundTag("", [
|
||||
"Y" => new ByteTag("Y", $Y),
|
||||
"Blocks" => new ByteArrayTag("Blocks", str_repeat("\x00", 4096)),
|
||||
"Data" => new ByteArrayTag("Data", str_repeat("\x00", 2048)),
|
||||
"SkyLight" => new ByteArrayTag("SkyLight", str_repeat("\xff", 2048)),
|
||||
"BlockLight" => new ByteArrayTag("BlockLight", str_repeat("\x00", 2048))
|
||||
]));
|
||||
}
|
||||
|
||||
|
@ -25,62 +25,62 @@ use pocketmine\level\format\generic\BaseChunk;
|
||||
use pocketmine\level\format\generic\EmptyChunkSection;
|
||||
use pocketmine\level\format\LevelProvider;
|
||||
use pocketmine\nbt\NBT;
|
||||
use pocketmine\nbt\tag\Byte;
|
||||
use pocketmine\nbt\tag\ByteArray;
|
||||
use pocketmine\nbt\tag\Compound;
|
||||
use pocketmine\nbt\tag\Enum;
|
||||
use pocketmine\nbt\tag\Int;
|
||||
use pocketmine\nbt\tag\IntArray;
|
||||
use pocketmine\nbt\tag\Long;
|
||||
use pocketmine\nbt\tag\ByteTag;
|
||||
use pocketmine\nbt\tag\ByteArrayTag;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\nbt\tag\ListTag;
|
||||
use pocketmine\nbt\tag\IntTag;
|
||||
use pocketmine\nbt\tag\IntArrayTag;
|
||||
use pocketmine\nbt\tag\LongTag;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\utils\Binary;
|
||||
use pocketmine\utils\BinaryStream;
|
||||
|
||||
class Chunk extends BaseChunk{
|
||||
|
||||
/** @var Compound */
|
||||
/** @var CompoundTag */
|
||||
protected $nbt;
|
||||
|
||||
public function __construct($level, Compound $nbt = null){
|
||||
public function __construct($level, CompoundTag $nbt = null){
|
||||
if($nbt === null){
|
||||
$this->provider = $level;
|
||||
$this->nbt = new Compound("Level", []);
|
||||
$this->nbt = new CompoundTag("Level", []);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->nbt = $nbt;
|
||||
|
||||
if(!isset($this->nbt->Entities) or !($this->nbt->Entities instanceof Enum)){
|
||||
$this->nbt->Entities = new Enum("Entities", []);
|
||||
if(!isset($this->nbt->Entities) or !($this->nbt->Entities instanceof ListTag)){
|
||||
$this->nbt->Entities = new ListTag("Entities", []);
|
||||
$this->nbt->Entities->setTagType(NBT::TAG_Compound);
|
||||
}
|
||||
|
||||
if(!isset($this->nbt->TileEntities) or !($this->nbt->TileEntities instanceof Enum)){
|
||||
$this->nbt->TileEntities = new Enum("TileEntities", []);
|
||||
if(!isset($this->nbt->TileEntities) or !($this->nbt->TileEntities instanceof ListTag)){
|
||||
$this->nbt->TileEntities = new ListTag("TileEntities", []);
|
||||
$this->nbt->TileEntities->setTagType(NBT::TAG_Compound);
|
||||
}
|
||||
|
||||
if(!isset($this->nbt->TileTicks) or !($this->nbt->TileTicks instanceof Enum)){
|
||||
$this->nbt->TileTicks = new Enum("TileTicks", []);
|
||||
if(!isset($this->nbt->TileTicks) or !($this->nbt->TileTicks instanceof ListTag)){
|
||||
$this->nbt->TileTicks = new ListTag("TileTicks", []);
|
||||
$this->nbt->TileTicks->setTagType(NBT::TAG_Compound);
|
||||
}
|
||||
|
||||
if(!isset($this->nbt->Sections) or !($this->nbt->Sections instanceof Enum)){
|
||||
$this->nbt->Sections = new Enum("Sections", []);
|
||||
if(!isset($this->nbt->Sections) or !($this->nbt->Sections instanceof ListTag)){
|
||||
$this->nbt->Sections = new ListTag("Sections", []);
|
||||
$this->nbt->Sections->setTagType(NBT::TAG_Compound);
|
||||
}
|
||||
|
||||
if(!isset($this->nbt->BiomeColors) or !($this->nbt->BiomeColors instanceof IntArray)){
|
||||
$this->nbt->BiomeColors = new IntArray("BiomeColors", array_fill(0, 256, 0));
|
||||
if(!isset($this->nbt->BiomeColors) or !($this->nbt->BiomeColors instanceof IntArrayTag)){
|
||||
$this->nbt->BiomeColors = new IntArrayTag("BiomeColors", array_fill(0, 256, 0));
|
||||
}
|
||||
|
||||
if(!isset($this->nbt->HeightMap) or !($this->nbt->HeightMap instanceof IntArray)){
|
||||
$this->nbt->HeightMap = new IntArray("HeightMap", array_fill(0, 256, 0));
|
||||
if(!isset($this->nbt->HeightMap) or !($this->nbt->HeightMap instanceof IntArrayTag)){
|
||||
$this->nbt->HeightMap = new IntArrayTag("HeightMap", array_fill(0, 256, 0));
|
||||
}
|
||||
|
||||
$sections = [];
|
||||
foreach($this->nbt->Sections as $section){
|
||||
if($section instanceof Compound){
|
||||
if($section instanceof CompoundTag){
|
||||
$y = (int) $section["Y"];
|
||||
if($y < 8){
|
||||
$sections[$y] = new ChunkSection($section);
|
||||
@ -95,8 +95,8 @@ class Chunk extends BaseChunk{
|
||||
|
||||
$extraData = [];
|
||||
|
||||
if(!isset($this->nbt->ExtraData) or !($this->nbt->ExtraData instanceof ByteArray)){
|
||||
$this->nbt->ExtraData = new ByteArray("ExtraData", Binary::writeInt(0));
|
||||
if(!isset($this->nbt->ExtraData) or !($this->nbt->ExtraData instanceof ByteArrayTag)){
|
||||
$this->nbt->ExtraData = new ByteArrayTag("ExtraData", Binary::writeInt(0));
|
||||
}else{
|
||||
$stream = new BinaryStream($this->nbt->ExtraData->getValue());
|
||||
$count = $stream->getInt();
|
||||
@ -121,7 +121,7 @@ class Chunk extends BaseChunk{
|
||||
}
|
||||
|
||||
public function setLightPopulated($value = 1){
|
||||
$this->nbt->LightPopulated = new Byte("LightPopulated", $value);
|
||||
$this->nbt->LightPopulated = new ByteTag("LightPopulated", $value);
|
||||
$this->hasChanged = true;
|
||||
}
|
||||
|
||||
@ -136,7 +136,7 @@ class Chunk extends BaseChunk{
|
||||
* @param int $value
|
||||
*/
|
||||
public function setPopulated($value = 1){
|
||||
$this->nbt->TerrainPopulated = new Byte("TerrainPopulated", $value);
|
||||
$this->nbt->TerrainPopulated = new ByteTag("TerrainPopulated", $value);
|
||||
$this->hasChanged = true;
|
||||
}
|
||||
|
||||
@ -151,12 +151,12 @@ class Chunk extends BaseChunk{
|
||||
* @param int $value
|
||||
*/
|
||||
public function setGenerated($value = 1){
|
||||
$this->nbt->TerrainGenerated = new Byte("TerrainGenerated", $value);
|
||||
$this->nbt->TerrainGenerated = new ByteTag("TerrainGenerated", $value);
|
||||
$this->hasChanged = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Compound
|
||||
* @return CompoundTag
|
||||
*/
|
||||
public function getNBT(){
|
||||
return $this->nbt;
|
||||
@ -175,12 +175,12 @@ class Chunk extends BaseChunk{
|
||||
$nbt->readCompressed($data, ZLIB_ENCODING_DEFLATE);
|
||||
$chunk = $nbt->getData();
|
||||
|
||||
if(!isset($chunk->Level) or !($chunk->Level instanceof Compound)){
|
||||
if(!isset($chunk->Level) or !($chunk->Level instanceof CompoundTag)){
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Chunk($provider instanceof LevelProvider ? $provider : Anvil::class, $chunk->Level);
|
||||
}catch(\Exception $e){
|
||||
}catch(\Throwable $e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -198,12 +198,12 @@ class Chunk extends BaseChunk{
|
||||
$nbt->read($data);
|
||||
$chunk = $nbt->getData();
|
||||
|
||||
if(!isset($chunk->Level) or !($chunk->Level instanceof Compound)){
|
||||
if(!isset($chunk->Level) or !($chunk->Level instanceof CompoundTag)){
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Chunk($provider instanceof LevelProvider ? $provider : Anvil::class, $chunk->Level);
|
||||
}catch(\Exception $e){
|
||||
}catch(\Throwable $e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -211,27 +211,27 @@ class Chunk extends BaseChunk{
|
||||
public function toFastBinary(){
|
||||
$nbt = clone $this->getNBT();
|
||||
|
||||
$nbt->xPos = new Int("xPos", $this->x);
|
||||
$nbt->zPos = new Int("zPos", $this->z);
|
||||
$nbt->xPos = new IntTag("xPos", $this->x);
|
||||
$nbt->zPos = new IntTag("zPos", $this->z);
|
||||
|
||||
$nbt->Sections = new Enum("Sections", []);
|
||||
$nbt->Sections = new ListTag("Sections", []);
|
||||
$nbt->Sections->setTagType(NBT::TAG_Compound);
|
||||
foreach($this->getSections() as $section){
|
||||
if($section instanceof EmptyChunkSection){
|
||||
continue;
|
||||
}
|
||||
$nbt->Sections[$section->getY()] = new Compound(null, [
|
||||
"Y" => new Byte("Y", $section->getY()),
|
||||
"Blocks" => new ByteArray("Blocks", $section->getIdArray()),
|
||||
"Data" => new ByteArray("Data", $section->getDataArray()),
|
||||
"BlockLight" => new ByteArray("BlockLight", $section->getLightArray()),
|
||||
"SkyLight" => new ByteArray("SkyLight", $section->getSkyLightArray())
|
||||
$nbt->Sections[$section->getY()] = new CompoundTag(null, [
|
||||
"Y" => new ByteTag("Y", $section->getY()),
|
||||
"Blocks" => new ByteArrayTag("Blocks", $section->getIdArray()),
|
||||
"Data" => new ByteArrayTag("Data", $section->getDataArray()),
|
||||
"BlockLight" => new ByteArrayTag("BlockLight", $section->getLightArray()),
|
||||
"SkyLight" => new ByteArrayTag("SkyLight", $section->getSkyLightArray())
|
||||
]);
|
||||
}
|
||||
|
||||
$nbt->BiomeColors = new IntArray("BiomeColors", $this->getBiomeColorArray());
|
||||
$nbt->BiomeColors = new IntArrayTag("BiomeColors", $this->getBiomeColorArray());
|
||||
|
||||
$nbt->HeightMap = new IntArray("HeightMap", $this->getHeightMapArray());
|
||||
$nbt->HeightMap = new IntArrayTag("HeightMap", $this->getHeightMapArray());
|
||||
|
||||
$entities = [];
|
||||
|
||||
@ -242,7 +242,7 @@ class Chunk extends BaseChunk{
|
||||
}
|
||||
}
|
||||
|
||||
$nbt->Entities = new Enum("Entities", $entities);
|
||||
$nbt->Entities = new ListTag("Entities", $entities);
|
||||
$nbt->Entities->setTagType(NBT::TAG_Compound);
|
||||
|
||||
|
||||
@ -252,7 +252,7 @@ class Chunk extends BaseChunk{
|
||||
$tiles[] = $tile->namedtag;
|
||||
}
|
||||
|
||||
$nbt->TileEntities = new Enum("TileEntities", $tiles);
|
||||
$nbt->TileEntities = new ListTag("TileEntities", $tiles);
|
||||
$nbt->TileEntities->setTagType(NBT::TAG_Compound);
|
||||
|
||||
$extraData = new BinaryStream();
|
||||
@ -262,11 +262,11 @@ class Chunk extends BaseChunk{
|
||||
$extraData->putShort($value);
|
||||
}
|
||||
|
||||
$nbt->ExtraData = new ByteArray("ExtraData", $extraData->getBuffer());
|
||||
$nbt->ExtraData = new ByteArrayTag("ExtraData", $extraData->getBuffer());
|
||||
|
||||
$writer = new NBT(NBT::BIG_ENDIAN);
|
||||
$nbt->setName("Level");
|
||||
$writer->setData(new Compound("", ["Level" => $nbt]));
|
||||
$writer->setData(new CompoundTag("", ["Level" => $nbt]));
|
||||
|
||||
return $writer->write();
|
||||
}
|
||||
@ -274,27 +274,27 @@ class Chunk extends BaseChunk{
|
||||
public function toBinary(){
|
||||
$nbt = clone $this->getNBT();
|
||||
|
||||
$nbt->xPos = new Int("xPos", $this->x);
|
||||
$nbt->zPos = new Int("zPos", $this->z);
|
||||
$nbt->xPos = new IntTag("xPos", $this->x);
|
||||
$nbt->zPos = new IntTag("zPos", $this->z);
|
||||
|
||||
$nbt->Sections = new Enum("Sections", []);
|
||||
$nbt->Sections = new ListTag("Sections", []);
|
||||
$nbt->Sections->setTagType(NBT::TAG_Compound);
|
||||
foreach($this->getSections() as $section){
|
||||
if($section instanceof EmptyChunkSection){
|
||||
continue;
|
||||
}
|
||||
$nbt->Sections[$section->getY()] = new Compound(null, [
|
||||
"Y" => new Byte("Y", $section->getY()),
|
||||
"Blocks" => new ByteArray("Blocks", $section->getIdArray()),
|
||||
"Data" => new ByteArray("Data", $section->getDataArray()),
|
||||
"BlockLight" => new ByteArray("BlockLight", $section->getLightArray()),
|
||||
"SkyLight" => new ByteArray("SkyLight", $section->getSkyLightArray())
|
||||
$nbt->Sections[$section->getY()] = new CompoundTag(null, [
|
||||
"Y" => new ByteTag("Y", $section->getY()),
|
||||
"Blocks" => new ByteArrayTag("Blocks", $section->getIdArray()),
|
||||
"Data" => new ByteArrayTag("Data", $section->getDataArray()),
|
||||
"BlockLight" => new ByteArrayTag("BlockLight", $section->getLightArray()),
|
||||
"SkyLight" => new ByteArrayTag("SkyLight", $section->getSkyLightArray())
|
||||
]);
|
||||
}
|
||||
|
||||
$nbt->BiomeColors = new IntArray("BiomeColors", $this->getBiomeColorArray());
|
||||
$nbt->BiomeColors = new IntArrayTag("BiomeColors", $this->getBiomeColorArray());
|
||||
|
||||
$nbt->HeightMap = new IntArray("HeightMap", $this->getHeightMapArray());
|
||||
$nbt->HeightMap = new IntArrayTag("HeightMap", $this->getHeightMapArray());
|
||||
|
||||
$entities = [];
|
||||
|
||||
@ -305,7 +305,7 @@ class Chunk extends BaseChunk{
|
||||
}
|
||||
}
|
||||
|
||||
$nbt->Entities = new Enum("Entities", $entities);
|
||||
$nbt->Entities = new ListTag("Entities", $entities);
|
||||
$nbt->Entities->setTagType(NBT::TAG_Compound);
|
||||
|
||||
|
||||
@ -315,7 +315,7 @@ class Chunk extends BaseChunk{
|
||||
$tiles[] = $tile->namedtag;
|
||||
}
|
||||
|
||||
$nbt->TileEntities = new Enum("TileEntities", $tiles);
|
||||
$nbt->TileEntities = new ListTag("TileEntities", $tiles);
|
||||
$nbt->TileEntities->setTagType(NBT::TAG_Compound);
|
||||
|
||||
$extraData = new BinaryStream();
|
||||
@ -325,11 +325,11 @@ class Chunk extends BaseChunk{
|
||||
$extraData->putShort($value);
|
||||
}
|
||||
|
||||
$nbt->ExtraData = new ByteArray("ExtraData", $extraData->getBuffer());
|
||||
$nbt->ExtraData = new ByteArrayTag("ExtraData", $extraData->getBuffer());
|
||||
|
||||
$writer = new NBT(NBT::BIG_ENDIAN);
|
||||
$nbt->setName("Level");
|
||||
$writer->setData(new Compound("", ["Level" => $nbt]));
|
||||
$writer->setData(new CompoundTag("", ["Level" => $nbt]));
|
||||
|
||||
return $writer->writeCompressed(ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
|
||||
}
|
||||
@ -354,14 +354,14 @@ class Chunk extends BaseChunk{
|
||||
$chunk->heightMap = array_fill(0, 256, 0);
|
||||
$chunk->biomeColors = array_fill(0, 256, 0);
|
||||
|
||||
$chunk->nbt->V = new Byte("V", 1);
|
||||
$chunk->nbt->InhabitedTime = new Long("InhabitedTime", 0);
|
||||
$chunk->nbt->TerrainGenerated = new Byte("TerrainGenerated", 0);
|
||||
$chunk->nbt->TerrainPopulated = new Byte("TerrainPopulated", 0);
|
||||
$chunk->nbt->LightPopulated = new Byte("LightPopulated", 0);
|
||||
$chunk->nbt->V = new ByteTag("V", 1);
|
||||
$chunk->nbt->InhabitedTime = new LongTag("InhabitedTime", 0);
|
||||
$chunk->nbt->TerrainGenerated = new ByteTag("TerrainGenerated", 0);
|
||||
$chunk->nbt->TerrainPopulated = new ByteTag("TerrainPopulated", 0);
|
||||
$chunk->nbt->LightPopulated = new ByteTag("LightPopulated", 0);
|
||||
|
||||
return $chunk;
|
||||
}catch(\Exception $e){
|
||||
}catch(\Throwable $e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
namespace pocketmine\level\format\anvil;
|
||||
|
||||
use pocketmine\nbt\tag\Compound;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
|
||||
class ChunkSection implements \pocketmine\level\format\ChunkSection{
|
||||
|
||||
@ -31,7 +31,7 @@ class ChunkSection implements \pocketmine\level\format\ChunkSection{
|
||||
private $blockLight;
|
||||
private $skyLight;
|
||||
|
||||
public function __construct(Compound $nbt){
|
||||
public function __construct(CompoundTag $nbt){
|
||||
$this->y = (int) $nbt["Y"];
|
||||
$this->blocks = (string) $nbt["Blocks"];
|
||||
$this->data = (string) $nbt["Data"];
|
||||
@ -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){
|
||||
|
@ -24,7 +24,7 @@ namespace pocketmine\level\format\generic;
|
||||
use pocketmine\level\format\Chunk;
|
||||
use pocketmine\level\format\ChunkSection;
|
||||
use pocketmine\level\format\LevelProvider;
|
||||
use pocketmine\nbt\tag\Compound;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\utils\Binary;
|
||||
use pocketmine\utils\ChunkException;
|
||||
|
||||
@ -40,8 +40,8 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{
|
||||
* @param ChunkSection[] $sections
|
||||
* @param int[] $biomeColors
|
||||
* @param int[] $heightMap
|
||||
* @param Compound[] $entities
|
||||
* @param Compound[] $tiles
|
||||
* @param CompoundTag[] $entities
|
||||
* @param CompoundTag[] $tiles
|
||||
*
|
||||
* @throws ChunkException
|
||||
*/
|
||||
@ -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);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ use pocketmine\level\format\FullChunk;
|
||||
use pocketmine\level\format\LevelProvider;
|
||||
use pocketmine\level\generator\biome\Biome;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\nbt\tag\Compound;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\tile\Tile;
|
||||
|
||||
@ -82,8 +82,8 @@ abstract class BaseFullChunk implements FullChunk{
|
||||
* @param string $blockLight
|
||||
* @param int[] $biomeColors
|
||||
* @param int[] $heightMap
|
||||
* @param Compound[] $entities
|
||||
* @param Compound[] $tiles
|
||||
* @param CompoundTag[] $entities
|
||||
* @param CompoundTag[] $tiles
|
||||
*/
|
||||
protected function __construct($provider, $x, $z, $blocks, $data, $skyLight, $blockLight, array $biomeColors = [], array $heightMap = [], array $entities = [], array $tiles = [], array $extraData = []){
|
||||
$this->provider = $provider;
|
||||
@ -134,7 +134,7 @@ abstract class BaseFullChunk implements FullChunk{
|
||||
if($this->NBTentities !== null){
|
||||
$this->getProvider()->getLevel()->timings->syncChunkLoadEntitiesTimer->startTiming();
|
||||
foreach($this->NBTentities as $nbt){
|
||||
if($nbt instanceof Compound){
|
||||
if($nbt instanceof CompoundTag){
|
||||
if(!isset($nbt->id)){
|
||||
$this->setChanged();
|
||||
continue;
|
||||
@ -157,7 +157,7 @@ abstract class BaseFullChunk implements FullChunk{
|
||||
|
||||
$this->getProvider()->getLevel()->timings->syncChunkLoadTileEntitiesTimer->startTiming();
|
||||
foreach($this->NBTtiles as $nbt){
|
||||
if($nbt instanceof Compound){
|
||||
if($nbt instanceof CompoundTag){
|
||||
if(!isset($nbt->id)){
|
||||
$changed = true;
|
||||
continue;
|
||||
@ -203,15 +203,6 @@ abstract class BaseFullChunk implements FullChunk{
|
||||
$this->z = $z;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LevelProvider
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public function getLevel(){
|
||||
return $this->getProvider();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LevelProvider
|
||||
*/
|
||||
|
@ -26,9 +26,9 @@ use pocketmine\level\generator\Generator;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\nbt\NBT;
|
||||
use pocketmine\nbt\tag\Compound;
|
||||
use pocketmine\nbt\tag\Int;
|
||||
use pocketmine\nbt\tag\String;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\nbt\tag\IntTag;
|
||||
use pocketmine\nbt\tag\StringTag;
|
||||
use pocketmine\utils\LevelException;
|
||||
|
||||
abstract class BaseLevelProvider implements LevelProvider{
|
||||
@ -36,7 +36,7 @@ abstract class BaseLevelProvider implements LevelProvider{
|
||||
protected $level;
|
||||
/** @var string */
|
||||
protected $path;
|
||||
/** @var Compound */
|
||||
/** @var CompoundTag */
|
||||
protected $levelData;
|
||||
|
||||
public function __construct(Level $level, $path){
|
||||
@ -48,18 +48,18 @@ abstract class BaseLevelProvider implements LevelProvider{
|
||||
$nbt = new NBT(NBT::BIG_ENDIAN);
|
||||
$nbt->readCompressed(file_get_contents($this->getPath() . "level.dat"));
|
||||
$levelData = $nbt->getData();
|
||||
if($levelData->Data instanceof Compound){
|
||||
if($levelData->Data instanceof CompoundTag){
|
||||
$this->levelData = $levelData->Data;
|
||||
}else{
|
||||
throw new LevelException("Invalid level.dat");
|
||||
}
|
||||
|
||||
if(!isset($this->levelData->generatorName)){
|
||||
$this->levelData->generatorName = new String("generatorName", Generator::getGenerator("DEFAULT"));
|
||||
$this->levelData->generatorName = new StringTag("generatorName", Generator::getGenerator("DEFAULT"));
|
||||
}
|
||||
|
||||
if(!isset($this->levelData->generatorOptions)){
|
||||
$this->levelData->generatorOptions = new String("generatorOptions", "");
|
||||
$this->levelData->generatorOptions = new StringTag("generatorOptions", "");
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ abstract class BaseLevelProvider implements LevelProvider{
|
||||
}
|
||||
|
||||
public function setTime($value){
|
||||
$this->levelData->Time = new Int("Time", (int) $value);
|
||||
$this->levelData->Time = new IntTag("Time", (int) $value);
|
||||
}
|
||||
|
||||
public function getSeed(){
|
||||
@ -92,7 +92,7 @@ abstract class BaseLevelProvider implements LevelProvider{
|
||||
}
|
||||
|
||||
public function setSeed($value){
|
||||
$this->levelData->RandomSeed = new Int("RandomSeed", (int) $value);
|
||||
$this->levelData->RandomSeed = new IntTag("RandomSeed", (int) $value);
|
||||
}
|
||||
|
||||
public function getSpawn(){
|
||||
@ -100,9 +100,9 @@ abstract class BaseLevelProvider implements LevelProvider{
|
||||
}
|
||||
|
||||
public function setSpawn(Vector3 $pos){
|
||||
$this->levelData->SpawnX = new Int("SpawnX", (int) $pos->x);
|
||||
$this->levelData->SpawnY = new Int("SpawnY", (int) $pos->y);
|
||||
$this->levelData->SpawnZ = new Int("SpawnZ", (int) $pos->z);
|
||||
$this->levelData->SpawnX = new IntTag("SpawnX", (int) $pos->x);
|
||||
$this->levelData->SpawnY = new IntTag("SpawnY", (int) $pos->y);
|
||||
$this->levelData->SpawnZ = new IntTag("SpawnZ", (int) $pos->z);
|
||||
}
|
||||
|
||||
public function doGarbageCollection(){
|
||||
@ -110,7 +110,7 @@ abstract class BaseLevelProvider implements LevelProvider{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Compound
|
||||
* @return CompoundTag
|
||||
*/
|
||||
public function getLevelData(){
|
||||
return $this->levelData;
|
||||
@ -118,7 +118,7 @@ abstract class BaseLevelProvider implements LevelProvider{
|
||||
|
||||
public function saveLevelData(){
|
||||
$nbt = new NBT(NBT::BIG_ENDIAN);
|
||||
$nbt->setData(new Compound("", [
|
||||
$nbt->setData(new CompoundTag("", [
|
||||
"Data" => $this->levelData
|
||||
]));
|
||||
$buffer = $nbt->writeCompressed();
|
||||
|
@ -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;
|
||||
|
||||
@ -305,7 +299,7 @@ class Chunk extends BaseFullChunk{
|
||||
$chunk->setLightPopulated();
|
||||
}
|
||||
return $chunk;
|
||||
}catch(\Exception $e){
|
||||
}catch(\Throwable $e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -393,7 +387,7 @@ class Chunk extends BaseFullChunk{
|
||||
$chunk = new Chunk($provider instanceof LevelProvider ? $provider : LevelDB::class, $chunkX, $chunkZ, str_repeat("\x00", self::DATA_LENGTH));
|
||||
$chunk->skyLight = str_repeat("\xff", 16384);
|
||||
return $chunk;
|
||||
}catch(\Exception $e){
|
||||
}catch(\Throwable $e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -26,11 +26,11 @@ use pocketmine\level\format\generic\BaseLevelProvider;
|
||||
use pocketmine\level\generator\Generator;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\nbt\NBT;
|
||||
use pocketmine\nbt\tag\Byte;
|
||||
use pocketmine\nbt\tag\Compound;
|
||||
use pocketmine\nbt\tag\Int;
|
||||
use pocketmine\nbt\tag\Long;
|
||||
use pocketmine\nbt\tag\String;
|
||||
use pocketmine\nbt\tag\ByteTag;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\nbt\tag\IntTag;
|
||||
use pocketmine\nbt\tag\LongTag;
|
||||
use pocketmine\nbt\tag\StringTag;
|
||||
use pocketmine\tile\Spawnable;
|
||||
use pocketmine\utils\Binary;
|
||||
use pocketmine\utils\BinaryStream;
|
||||
@ -62,18 +62,18 @@ class LevelDB extends BaseLevelProvider{
|
||||
$nbt = new NBT(NBT::LITTLE_ENDIAN);
|
||||
$nbt->read(substr(file_get_contents($this->getPath() . "level.dat"), 8));
|
||||
$levelData = $nbt->getData();
|
||||
if($levelData instanceof Compound){
|
||||
if($levelData instanceof CompoundTag){
|
||||
$this->levelData = $levelData;
|
||||
}else{
|
||||
throw new LevelException("Invalid level.dat");
|
||||
}
|
||||
|
||||
if(!isset($this->levelData->generatorName)){
|
||||
$this->levelData->generatorName = new String("generatorName", Generator::getGenerator("DEFAULT"));
|
||||
$this->levelData->generatorName = new StringTag("generatorName", Generator::getGenerator("DEFAULT"));
|
||||
}
|
||||
|
||||
if(!isset($this->levelData->generatorOptions)){
|
||||
$this->levelData->generatorOptions = new String("generatorOptions", "");
|
||||
$this->levelData->generatorOptions = new StringTag("generatorOptions", "");
|
||||
}
|
||||
|
||||
$this->db = new \LevelDB($this->path . "/db", [
|
||||
@ -105,24 +105,24 @@ class LevelDB extends BaseLevelProvider{
|
||||
mkdir($path . "/db", 0777, true);
|
||||
}
|
||||
//TODO, add extra details
|
||||
$levelData = new Compound("", [
|
||||
"hardcore" => new Byte("hardcore", 0),
|
||||
"initialized" => new Byte("initialized", 1),
|
||||
"GameType" => new Int("GameType", 0),
|
||||
"generatorVersion" => new Int("generatorVersion", 1), //2 in MCPE
|
||||
"SpawnX" => new Int("SpawnX", 128),
|
||||
"SpawnY" => new Int("SpawnY", 70),
|
||||
"SpawnZ" => new Int("SpawnZ", 128),
|
||||
"version" => new Int("version", 19133),
|
||||
"DayTime" => new Int("DayTime", 0),
|
||||
"LastPlayed" => new Long("LastPlayed", microtime(true) * 1000),
|
||||
"RandomSeed" => new Long("RandomSeed", $seed),
|
||||
"SizeOnDisk" => new Long("SizeOnDisk", 0),
|
||||
"Time" => new Long("Time", 0),
|
||||
"generatorName" => new String("generatorName", Generator::getGeneratorName($generator)),
|
||||
"generatorOptions" => new String("generatorOptions", isset($options["preset"]) ? $options["preset"] : ""),
|
||||
"LevelName" => new String("LevelName", $name),
|
||||
"GameRules" => new Compound("GameRules", [])
|
||||
$levelData = new CompoundTag("", [
|
||||
"hardcore" => new ByteTag("hardcore", 0),
|
||||
"initialized" => new ByteTag("initialized", 1),
|
||||
"GameType" => new IntTag("GameType", 0),
|
||||
"generatorVersion" => new IntTag("generatorVersion", 1), //2 in MCPE
|
||||
"SpawnX" => new IntTag("SpawnX", 128),
|
||||
"SpawnY" => new IntTag("SpawnY", 70),
|
||||
"SpawnZ" => new IntTag("SpawnZ", 128),
|
||||
"version" => new IntTag("version", 19133),
|
||||
"DayTime" => new IntTag("DayTime", 0),
|
||||
"LastPlayed" => new LongTag("LastPlayed", microtime(true) * 1000),
|
||||
"RandomSeed" => new LongTag("RandomSeed", $seed),
|
||||
"SizeOnDisk" => new LongTag("SizeOnDisk", 0),
|
||||
"Time" => new LongTag("Time", 0),
|
||||
"generatorName" => new StringTag("generatorName", Generator::getGeneratorName($generator)),
|
||||
"generatorOptions" => new StringTag("generatorOptions", isset($options["preset"]) ? $options["preset"] : ""),
|
||||
"LevelName" => new StringTag("LevelName", $name),
|
||||
"GameRules" => new CompoundTag("GameRules", [])
|
||||
]);
|
||||
$nbt = new NBT(NBT::LITTLE_ENDIAN);
|
||||
$nbt->setData($levelData);
|
||||
|
@ -24,74 +24,74 @@ namespace pocketmine\level\format\mcregion;
|
||||
use pocketmine\level\format\generic\BaseFullChunk;
|
||||
use pocketmine\level\format\LevelProvider;
|
||||
use pocketmine\nbt\NBT;
|
||||
use pocketmine\nbt\tag\Byte;
|
||||
use pocketmine\nbt\tag\ByteArray;
|
||||
use pocketmine\nbt\tag\Compound;
|
||||
use pocketmine\nbt\tag\Enum;
|
||||
use pocketmine\nbt\tag\Int;
|
||||
use pocketmine\nbt\tag\IntArray;
|
||||
use pocketmine\nbt\tag\Long;
|
||||
use pocketmine\nbt\tag\ByteTag;
|
||||
use pocketmine\nbt\tag\ByteArrayTag;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\nbt\tag\ListTag;
|
||||
use pocketmine\nbt\tag\IntTag;
|
||||
use pocketmine\nbt\tag\IntArrayTag;
|
||||
use pocketmine\nbt\tag\LongTag;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\utils\Binary;
|
||||
use pocketmine\utils\BinaryStream;
|
||||
|
||||
class Chunk extends BaseFullChunk{
|
||||
|
||||
/** @var Compound */
|
||||
/** @var CompoundTag */
|
||||
protected $nbt;
|
||||
|
||||
public function __construct($level, Compound $nbt = null){
|
||||
public function __construct($level, CompoundTag $nbt = null){
|
||||
if($nbt === null){
|
||||
$this->provider = $level;
|
||||
$this->nbt = new Compound("Level", []);
|
||||
$this->nbt = new CompoundTag("Level", []);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->nbt = $nbt;
|
||||
|
||||
if(isset($this->nbt->Entities) and $this->nbt->Entities instanceof Enum){
|
||||
if(isset($this->nbt->Entities) and $this->nbt->Entities instanceof ListTag){
|
||||
$this->nbt->Entities->setTagType(NBT::TAG_Compound);
|
||||
}else{
|
||||
$this->nbt->Entities = new Enum("Entities", []);
|
||||
$this->nbt->Entities = new ListTag("Entities", []);
|
||||
$this->nbt->Entities->setTagType(NBT::TAG_Compound);
|
||||
}
|
||||
|
||||
if(isset($this->nbt->TileEntities) and $this->nbt->TileEntities instanceof Enum){
|
||||
if(isset($this->nbt->TileEntities) and $this->nbt->TileEntities instanceof ListTag){
|
||||
$this->nbt->TileEntities->setTagType(NBT::TAG_Compound);
|
||||
}else{
|
||||
$this->nbt->TileEntities = new Enum("TileEntities", []);
|
||||
$this->nbt->TileEntities = new ListTag("TileEntities", []);
|
||||
$this->nbt->TileEntities->setTagType(NBT::TAG_Compound);
|
||||
}
|
||||
|
||||
if(isset($this->nbt->TileTicks) and $this->nbt->TileTicks instanceof Enum){
|
||||
if(isset($this->nbt->TileTicks) and $this->nbt->TileTicks instanceof ListTag){
|
||||
$this->nbt->TileTicks->setTagType(NBT::TAG_Compound);
|
||||
}else{
|
||||
$this->nbt->TileTicks = new Enum("TileTicks", []);
|
||||
$this->nbt->TileTicks = new ListTag("TileTicks", []);
|
||||
$this->nbt->TileTicks->setTagType(NBT::TAG_Compound);
|
||||
}
|
||||
|
||||
if(!isset($this->nbt->BiomeColors) or !($this->nbt->BiomeColors instanceof IntArray)){
|
||||
$this->nbt->BiomeColors = new IntArray("BiomeColors", array_fill(0, 256, 0));
|
||||
if(!isset($this->nbt->BiomeColors) or !($this->nbt->BiomeColors instanceof IntArrayTag)){
|
||||
$this->nbt->BiomeColors = new IntArrayTag("BiomeColors", array_fill(0, 256, 0));
|
||||
}
|
||||
|
||||
if(!isset($this->nbt->HeightMap) or !($this->nbt->HeightMap instanceof IntArray)){
|
||||
$this->nbt->HeightMap = new IntArray("HeightMap", array_fill(0, 256, 0));
|
||||
if(!isset($this->nbt->HeightMap) or !($this->nbt->HeightMap instanceof IntArrayTag)){
|
||||
$this->nbt->HeightMap = new IntArrayTag("HeightMap", array_fill(0, 256, 0));
|
||||
}
|
||||
|
||||
if(!isset($this->nbt->Blocks)){
|
||||
$this->nbt->Blocks = new ByteArray("Blocks", str_repeat("\x00", 32768));
|
||||
$this->nbt->Blocks = new ByteArrayTag("Blocks", str_repeat("\x00", 32768));
|
||||
}
|
||||
|
||||
if(!isset($this->nbt->Data)){
|
||||
$this->nbt->Data = new ByteArray("Data", $half = str_repeat("\x00", 16384));
|
||||
$this->nbt->SkyLight = new ByteArray("SkyLight", $half);
|
||||
$this->nbt->BlockLight = new ByteArray("BlockLight", $half);
|
||||
$this->nbt->Data = new ByteArrayTag("Data", $half = str_repeat("\x00", 16384));
|
||||
$this->nbt->SkyLight = new ByteArrayTag("SkyLight", $half);
|
||||
$this->nbt->BlockLight = new ByteArrayTag("BlockLight", $half);
|
||||
}
|
||||
|
||||
$extraData = [];
|
||||
|
||||
if(!isset($this->nbt->ExtraData) or !($this->nbt->ExtraData instanceof ByteArray)){
|
||||
$this->nbt->ExtraData = new ByteArray("ExtraData", Binary::writeInt(0));
|
||||
if(!isset($this->nbt->ExtraData) or !($this->nbt->ExtraData instanceof ByteArrayTag)){
|
||||
$this->nbt->ExtraData = new ByteArrayTag("ExtraData", Binary::writeInt(0));
|
||||
}else{
|
||||
$stream = new BinaryStream($this->nbt->ExtraData->getValue());
|
||||
$count = $stream->getInt();
|
||||
@ -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;
|
||||
|
||||
@ -258,7 +252,7 @@ class Chunk extends BaseFullChunk{
|
||||
}
|
||||
|
||||
public function setLightPopulated($value = 1){
|
||||
$this->nbt->LightPopulated = new Byte("LightPopulated", $value ? 1 : 0);
|
||||
$this->nbt->LightPopulated = new ByteTag("LightPopulated", $value ? 1 : 0);
|
||||
$this->hasChanged = true;
|
||||
}
|
||||
|
||||
@ -273,7 +267,7 @@ class Chunk extends BaseFullChunk{
|
||||
* @param int $value
|
||||
*/
|
||||
public function setPopulated($value = 1){
|
||||
$this->nbt->TerrainPopulated = new Byte("TerrainPopulated", $value ? 1 : 0);
|
||||
$this->nbt->TerrainPopulated = new ByteTag("TerrainPopulated", $value ? 1 : 0);
|
||||
$this->hasChanged = true;
|
||||
}
|
||||
|
||||
@ -293,7 +287,7 @@ class Chunk extends BaseFullChunk{
|
||||
* @param int $value
|
||||
*/
|
||||
public function setGenerated($value = 1){
|
||||
$this->nbt->TerrainGenerated = new Byte("TerrainGenerated", (int) $value);
|
||||
$this->nbt->TerrainGenerated = new ByteTag("TerrainGenerated", (int) $value);
|
||||
$this->hasChanged = true;
|
||||
}
|
||||
|
||||
@ -310,12 +304,12 @@ class Chunk extends BaseFullChunk{
|
||||
$nbt->readCompressed($data, ZLIB_ENCODING_DEFLATE);
|
||||
$chunk = $nbt->getData();
|
||||
|
||||
if(!isset($chunk->Level) or !($chunk->Level instanceof Compound)){
|
||||
if(!isset($chunk->Level) or !($chunk->Level instanceof CompoundTag)){
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Chunk($provider instanceof LevelProvider ? $provider : McRegion::class, $chunk->Level);
|
||||
}catch(\Exception $e){
|
||||
}catch(\Throwable $e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -348,12 +342,12 @@ class Chunk extends BaseFullChunk{
|
||||
|
||||
$flags = ord($data{$offset++});
|
||||
|
||||
$chunk->nbt->TerrainGenerated = new Byte("TerrainGenerated", $flags & 0b1);
|
||||
$chunk->nbt->TerrainPopulated = new Byte("TerrainPopulated", ($flags >> 1) & 0b1);
|
||||
$chunk->nbt->LightPopulated = new Byte("LightPopulated", ($flags >> 2) & 0b1);
|
||||
$chunk->nbt->TerrainGenerated = new ByteTag("TerrainGenerated", $flags & 0b1);
|
||||
$chunk->nbt->TerrainPopulated = new ByteTag("TerrainPopulated", ($flags >> 1) & 0b1);
|
||||
$chunk->nbt->LightPopulated = new ByteTag("LightPopulated", ($flags >> 2) & 0b1);
|
||||
|
||||
return $chunk;
|
||||
}catch(\Exception $e){
|
||||
}catch(\Throwable $e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -374,18 +368,18 @@ class Chunk extends BaseFullChunk{
|
||||
public function toBinary(){
|
||||
$nbt = clone $this->getNBT();
|
||||
|
||||
$nbt->xPos = new Int("xPos", $this->x);
|
||||
$nbt->zPos = new Int("zPos", $this->z);
|
||||
$nbt->xPos = new IntTag("xPos", $this->x);
|
||||
$nbt->zPos = new IntTag("zPos", $this->z);
|
||||
|
||||
if($this->isGenerated()){
|
||||
$nbt->Blocks = new ByteArray("Blocks", $this->getBlockIdArray());
|
||||
$nbt->Data = new ByteArray("Data", $this->getBlockDataArray());
|
||||
$nbt->SkyLight = new ByteArray("SkyLight", $this->getBlockSkyLightArray());
|
||||
$nbt->BlockLight = new ByteArray("BlockLight", $this->getBlockLightArray());
|
||||
$nbt->Blocks = new ByteArrayTag("Blocks", $this->getBlockIdArray());
|
||||
$nbt->Data = new ByteArrayTag("Data", $this->getBlockDataArray());
|
||||
$nbt->SkyLight = new ByteArrayTag("SkyLight", $this->getBlockSkyLightArray());
|
||||
$nbt->BlockLight = new ByteArrayTag("BlockLight", $this->getBlockLightArray());
|
||||
|
||||
$nbt->BiomeColors = new IntArray("BiomeColors", $this->getBiomeColorArray());
|
||||
$nbt->BiomeColors = new IntArrayTag("BiomeColors", $this->getBiomeColorArray());
|
||||
|
||||
$nbt->HeightMap = new IntArray("HeightMap", $this->getHeightMapArray());
|
||||
$nbt->HeightMap = new IntArrayTag("HeightMap", $this->getHeightMapArray());
|
||||
}
|
||||
|
||||
$entities = [];
|
||||
@ -397,7 +391,7 @@ class Chunk extends BaseFullChunk{
|
||||
}
|
||||
}
|
||||
|
||||
$nbt->Entities = new Enum("Entities", $entities);
|
||||
$nbt->Entities = new ListTag("Entities", $entities);
|
||||
$nbt->Entities->setTagType(NBT::TAG_Compound);
|
||||
|
||||
|
||||
@ -407,7 +401,7 @@ class Chunk extends BaseFullChunk{
|
||||
$tiles[] = $tile->namedtag;
|
||||
}
|
||||
|
||||
$nbt->TileEntities = new Enum("TileEntities", $tiles);
|
||||
$nbt->TileEntities = new ListTag("TileEntities", $tiles);
|
||||
$nbt->TileEntities->setTagType(NBT::TAG_Compound);
|
||||
|
||||
$extraData = new BinaryStream();
|
||||
@ -417,17 +411,17 @@ class Chunk extends BaseFullChunk{
|
||||
$extraData->putShort($value);
|
||||
}
|
||||
|
||||
$nbt->ExtraData = new ByteArray("ExtraData", $extraData->getBuffer());
|
||||
$nbt->ExtraData = new ByteArrayTag("ExtraData", $extraData->getBuffer());
|
||||
|
||||
$writer = new NBT(NBT::BIG_ENDIAN);
|
||||
$nbt->setName("Level");
|
||||
$writer->setData(new Compound("", ["Level" => $nbt]));
|
||||
$writer->setData(new CompoundTag("", ["Level" => $nbt]));
|
||||
|
||||
return $writer->writeCompressed(ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Compound
|
||||
* @return CompoundTag
|
||||
*/
|
||||
public function getNBT(){
|
||||
return $this->nbt;
|
||||
@ -454,14 +448,14 @@ class Chunk extends BaseFullChunk{
|
||||
$chunk->heightMap = array_fill(0, 256, 0);
|
||||
$chunk->biomeColors = array_fill(0, 256, 0);
|
||||
|
||||
$chunk->nbt->V = new Byte("V", 1);
|
||||
$chunk->nbt->InhabitedTime = new Long("InhabitedTime", 0);
|
||||
$chunk->nbt->TerrainGenerated = new Byte("TerrainGenerated", 0);
|
||||
$chunk->nbt->TerrainPopulated = new Byte("TerrainPopulated", 0);
|
||||
$chunk->nbt->LightPopulated = new Byte("LightPopulated", 0);
|
||||
$chunk->nbt->V = new ByteTag("V", 1);
|
||||
$chunk->nbt->InhabitedTime = new LongTag("InhabitedTime", 0);
|
||||
$chunk->nbt->TerrainGenerated = new ByteTag("TerrainGenerated", 0);
|
||||
$chunk->nbt->TerrainPopulated = new ByteTag("TerrainPopulated", 0);
|
||||
$chunk->nbt->LightPopulated = new ByteTag("LightPopulated", 0);
|
||||
|
||||
return $chunk;
|
||||
}catch(\Exception $e){
|
||||
}catch(\Throwable $e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -26,11 +26,11 @@ use pocketmine\level\format\generic\BaseLevelProvider;
|
||||
use pocketmine\level\generator\Generator;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\nbt\NBT;
|
||||
use pocketmine\nbt\tag\Byte;
|
||||
use pocketmine\nbt\tag\Compound;
|
||||
use pocketmine\nbt\tag\Int;
|
||||
use pocketmine\nbt\tag\Long;
|
||||
use pocketmine\nbt\tag\String;
|
||||
use pocketmine\nbt\tag\ByteTag;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\nbt\tag\IntTag;
|
||||
use pocketmine\nbt\tag\LongTag;
|
||||
use pocketmine\nbt\tag\StringTag;
|
||||
use pocketmine\tile\Spawnable;
|
||||
|
||||
use pocketmine\utils\BinaryStream;
|
||||
@ -81,27 +81,27 @@ class McRegion extends BaseLevelProvider{
|
||||
mkdir($path . "/region", 0777);
|
||||
}
|
||||
//TODO, add extra details
|
||||
$levelData = new Compound("Data", [
|
||||
"hardcore" => new Byte("hardcore", 0),
|
||||
"initialized" => new Byte("initialized", 1),
|
||||
"GameType" => new Int("GameType", 0),
|
||||
"generatorVersion" => new Int("generatorVersion", 1), //2 in MCPE
|
||||
"SpawnX" => new Int("SpawnX", 128),
|
||||
"SpawnY" => new Int("SpawnY", 70),
|
||||
"SpawnZ" => new Int("SpawnZ", 128),
|
||||
"version" => new Int("version", 19133),
|
||||
"DayTime" => new Int("DayTime", 0),
|
||||
"LastPlayed" => new Long("LastPlayed", microtime(true) * 1000),
|
||||
"RandomSeed" => new Long("RandomSeed", $seed),
|
||||
"SizeOnDisk" => new Long("SizeOnDisk", 0),
|
||||
"Time" => new Long("Time", 0),
|
||||
"generatorName" => new String("generatorName", Generator::getGeneratorName($generator)),
|
||||
"generatorOptions" => new String("generatorOptions", isset($options["preset"]) ? $options["preset"] : ""),
|
||||
"LevelName" => new String("LevelName", $name),
|
||||
"GameRules" => new Compound("GameRules", [])
|
||||
$levelData = new CompoundTag("Data", [
|
||||
"hardcore" => new ByteTag("hardcore", 0),
|
||||
"initialized" => new ByteTag("initialized", 1),
|
||||
"GameType" => new IntTag("GameType", 0),
|
||||
"generatorVersion" => new IntTag("generatorVersion", 1), //2 in MCPE
|
||||
"SpawnX" => new IntTag("SpawnX", 128),
|
||||
"SpawnY" => new IntTag("SpawnY", 70),
|
||||
"SpawnZ" => new IntTag("SpawnZ", 128),
|
||||
"version" => new IntTag("version", 19133),
|
||||
"DayTime" => new IntTag("DayTime", 0),
|
||||
"LastPlayed" => new LongTag("LastPlayed", microtime(true) * 1000),
|
||||
"RandomSeed" => new LongTag("RandomSeed", $seed),
|
||||
"SizeOnDisk" => new LongTag("SizeOnDisk", 0),
|
||||
"Time" => new LongTag("Time", 0),
|
||||
"generatorName" => new StringTag("generatorName", Generator::getGeneratorName($generator)),
|
||||
"generatorOptions" => new StringTag("generatorOptions", isset($options["preset"]) ? $options["preset"] : ""),
|
||||
"LevelName" => new StringTag("LevelName", $name),
|
||||
"GameRules" => new CompoundTag("GameRules", [])
|
||||
]);
|
||||
$nbt = new NBT(NBT::BIG_ENDIAN);
|
||||
$nbt->setData(new Compound("", [
|
||||
$nbt->setData(new CompoundTag("", [
|
||||
"Data" => $levelData
|
||||
]));
|
||||
$buffer = $nbt->writeCompressed();
|
||||
|
@ -195,7 +195,7 @@ class RegionLoader{
|
||||
|
||||
try{
|
||||
$chunk = zlib_decode(substr($chunk, 5));
|
||||
}catch(\Exception $e){
|
||||
}catch(\Throwable $e){
|
||||
$this->locationTable[$i] = [0, 0, 0]; //Corrupted chunk, remove it
|
||||
continue;
|
||||
}
|
||||
|
@ -123,15 +123,10 @@ abstract class Generator{
|
||||
* @throws \InvalidArgumentCountException
|
||||
*/
|
||||
public static function getFastNoise2D(Noise $noise, $xSize, $zSize, $samplingRate, $x, $y, $z){
|
||||
if($samplingRate === 0){
|
||||
throw new \InvalidArgumentException("samplingRate cannot be 0");
|
||||
}
|
||||
if ($xSize % $samplingRate !== 0) {
|
||||
throw new \InvalidArgumentCountException("xSize % samplingRate must return 0");
|
||||
}
|
||||
if ($zSize % $samplingRate !== 0) {
|
||||
throw new \InvalidArgumentCountException("zSize % samplingRate must return 0");
|
||||
}
|
||||
assert($samplingRate !== 0, new \InvalidArgumentException("samplingRate cannot be 0"));
|
||||
|
||||
assert($xSize % $samplingRate === 0, new \InvalidArgumentCountException("xSize % samplingRate must return 0"));
|
||||
assert($zSize % $samplingRate === 0, new \InvalidArgumentCountException("zSize % samplingRate must return 0"));
|
||||
|
||||
$noiseArray = new \SplFixedArray($xSize + 1);
|
||||
|
||||
@ -181,24 +176,14 @@ abstract class Generator{
|
||||
* @throws \InvalidArgumentCountException
|
||||
*/
|
||||
public static function getFastNoise3D(Noise $noise, $xSize, $ySize, $zSize, $xSamplingRate, $ySamplingRate, $zSamplingRate, $x, $y, $z){
|
||||
if($xSamplingRate === 0){
|
||||
throw new \InvalidArgumentException("xSamplingRate cannot be 0");
|
||||
}
|
||||
if($zSamplingRate === 0){
|
||||
throw new \InvalidArgumentException("zSamplingRate cannot be 0");
|
||||
}
|
||||
if($ySamplingRate === 0){
|
||||
throw new \InvalidArgumentException("ySamplingRate cannot be 0");
|
||||
}
|
||||
if ($xSize % $xSamplingRate !== 0) {
|
||||
throw new \InvalidArgumentCountException("xSize % xSamplingRate must return 0");
|
||||
}
|
||||
if ($zSize % $zSamplingRate !== 0) {
|
||||
throw new \InvalidArgumentCountException("zSize % zSamplingRate must return 0");
|
||||
}
|
||||
if ($ySize % $ySamplingRate !== 0) {
|
||||
throw new \InvalidArgumentCountException("ySize % ySamplingRate must return 0");
|
||||
}
|
||||
|
||||
assert($xSamplingRate !== 0, new \InvalidArgumentException("xSamplingRate cannot be 0"));
|
||||
assert($zSamplingRate !== 0, new \InvalidArgumentException("zSamplingRate cannot be 0"));
|
||||
assert($ySamplingRate !== 0, new \InvalidArgumentException("ySamplingRate cannot be 0"));
|
||||
|
||||
assert($xSize % $xSamplingRate === 0, new \InvalidArgumentCountException("xSize % xSamplingRate must return 0"));
|
||||
assert($zSize % $zSamplingRate === 0, new \InvalidArgumentCountException("zSize % zSamplingRate must return 0"));
|
||||
assert($ySize % $ySamplingRate === 0, new \InvalidArgumentCountException("ySize % ySamplingRate must return 0"));
|
||||
|
||||
$noiseArray = array_fill(0, $xSize + 1, array_fill(0, $zSize + 1, []));
|
||||
|
||||
|
@ -39,7 +39,7 @@ class GeneratorRegisterTask extends AsyncTask{
|
||||
|
||||
public function __construct(Level $level, Generator $generator){
|
||||
$this->generator = get_class($generator);
|
||||
$this->settings = $generator->getSettings();
|
||||
$this->settings = serialize($generator->getSettings());
|
||||
$this->seed = $level->getSeed();
|
||||
$this->levelId = $level->getId();
|
||||
}
|
||||
@ -51,7 +51,7 @@ class GeneratorRegisterTask extends AsyncTask{
|
||||
$this->saveToThreadStore("generation.level{$this->levelId}.manager", $manager);
|
||||
/** @var Generator $generator */
|
||||
$generator = $this->generator;
|
||||
$generator = new $generator($this->settings);
|
||||
$generator = new $generator(unserialize($this->settings));
|
||||
$generator->init($manager, new Random($manager->getSeed()));
|
||||
$this->saveToThreadStore("generation.level{$this->levelId}.generator", $generator);
|
||||
}
|
||||
|
Reference in New Issue
Block a user