mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 16:24:05 +00:00
This commit is contained in:
parent
95b5979351
commit
cb4a970631
@ -520,7 +520,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
return $this->spawnPosition;
|
||||
}else{
|
||||
$level = $this->server->getDefaultLevel();
|
||||
return $level->getSpawn();
|
||||
return $level->getSafeSpawn();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1740,7 +1740,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
$this->craftingType = 0;
|
||||
|
||||
$this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $this->spawnPosition));
|
||||
$this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $this->getSpawn()));
|
||||
|
||||
$this->teleport($ev->getRespawnPosition());
|
||||
//$this->entity->fire = 0;
|
||||
|
@ -1635,9 +1635,10 @@ class Level implements ChunkManager, Metadatable{
|
||||
* Sets the spawnpoint
|
||||
*
|
||||
* @param Vector3 $pos
|
||||
* @deprecated
|
||||
*/
|
||||
public function setSpawn(Vector3 $pos){
|
||||
$this->provider->setSpawn($pos);
|
||||
$this->setSpawnLocation($pos);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,24 +67,16 @@ class Anvil extends McRegion{
|
||||
return new ChunkRequestTask($this, $this->getLevel()->getID(), $x, $z);
|
||||
}
|
||||
|
||||
public function loadChunk($chunkX, $chunkZ, $create = false){
|
||||
$index = Level::chunkHash($chunkX, $chunkZ);
|
||||
if(isset($this->chunks[$index])){
|
||||
return true;
|
||||
}
|
||||
$regionX = $regionZ = null;
|
||||
self::getRegionIndex($chunkX, $chunkZ, $regionX, $regionZ);
|
||||
$this->loadRegion($regionX, $regionZ);
|
||||
/**
|
||||
* @param $x
|
||||
* @param $z
|
||||
*
|
||||
* @return RegionLoader
|
||||
*/
|
||||
protected function getRegion($x, $z){
|
||||
$index = $x . ":" . $z;
|
||||
|
||||
$this->level->timings->syncChunkLoadDataTimer->startTiming();
|
||||
$chunk = $this->getRegion($regionX, $regionZ)->readChunk($chunkX - $regionX * 32, $chunkZ - $regionZ * 32, $create); //generate empty chunk if not loaded
|
||||
$this->level->timings->syncChunkLoadDataTimer->stopTiming();
|
||||
|
||||
if($chunk instanceof Chunk){
|
||||
$this->chunks[$index] = $chunk;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
return isset($this->regions[$index]) ? $this->regions[$index] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,10 +104,9 @@ class Anvil extends McRegion{
|
||||
$region->removeChunk($chunkX - $region->getX() * 32, $chunkZ - $region->getZ() * 32);
|
||||
$this->loadChunk($chunkX, $chunkZ);
|
||||
}else{
|
||||
$newChunk = clone $chunk;
|
||||
$newChunk->setX($chunkX);
|
||||
$newChunk->setZ($chunkZ);
|
||||
$this->chunks[Level::chunkHash($chunkX, $chunkZ)] = $newChunk;
|
||||
$chunk->setX($chunkX);
|
||||
$chunk->setZ($chunkZ);
|
||||
$this->chunks[Level::chunkHash($chunkX, $chunkZ)] = $chunk;
|
||||
//$this->saveChunk($chunkX, $chunkZ);
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ 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\Player;
|
||||
use pocketmine\utils\Binary;
|
||||
@ -93,6 +94,8 @@ class Chunk extends BaseChunk{
|
||||
}
|
||||
|
||||
parent::__construct($level, $this->nbt["xPos"], $this->nbt["zPos"], $sections, $this->nbt->Biomes->getValue(), $this->nbt->BiomeColors->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue());
|
||||
|
||||
unset($this->nbt->Sections);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -151,6 +154,9 @@ class Chunk extends BaseChunk{
|
||||
public function toBinary(){
|
||||
$nbt = $this->getNBT();
|
||||
|
||||
$nbt->xPos = new Int("xPos", $this->x);
|
||||
$nbt->zPos = new Int("zPos", $this->z);
|
||||
|
||||
$nbt->Sections = new Enum("Sections", []);
|
||||
$nbt->Sections->setTagType(NBT::TAG_Compound);
|
||||
foreach($this->getSections() as $section){
|
||||
|
@ -22,7 +22,6 @@
|
||||
namespace pocketmine\level\format\anvil;
|
||||
|
||||
use pocketmine\level\format\LevelProvider;
|
||||
use pocketmine\level\format\mcregion\Chunk;
|
||||
use pocketmine\nbt\NBT;
|
||||
use pocketmine\nbt\tag\Byte;
|
||||
use pocketmine\nbt\tag\ByteArray;
|
||||
@ -31,7 +30,6 @@ use pocketmine\nbt\tag\Enum;
|
||||
use pocketmine\nbt\tag\Int;
|
||||
use pocketmine\nbt\tag\IntArray;
|
||||
use pocketmine\nbt\tag\Long;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\utils\Binary;
|
||||
|
||||
class RegionLoader extends \pocketmine\level\format\mcregion\RegionLoader{
|
||||
@ -130,8 +128,4 @@ class RegionLoader extends \pocketmine\level\format\mcregion\RegionLoader{
|
||||
$this->saveChunk($x, $z, $chunkData);
|
||||
}
|
||||
|
||||
public function writeChunk(Chunk $chunk){
|
||||
$this->saveChunk($chunk->getX() - ($this->getX() * 32), $chunk->getZ() - ($this->getZ() * 32), $chunk->toBinary());
|
||||
}
|
||||
|
||||
}
|
@ -28,6 +28,7 @@ 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\Player;
|
||||
use pocketmine\utils\Binary;
|
||||
@ -70,6 +71,10 @@ class Chunk extends BaseFullChunk{
|
||||
}
|
||||
|
||||
parent::__construct($level, $this->nbt["xPos"], $this->nbt["zPos"], $this->nbt["Blocks"], $this->nbt["Data"], $this->nbt["SkyLight"], $this->nbt["BlockLight"], $this->nbt->Biomes->getValue(), $this->nbt->BiomeColors->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue());
|
||||
unset($this->nbt->Blocks);
|
||||
unset($this->nbt->Data);
|
||||
unset($this->nbt->SkyLight);
|
||||
unset($this->nbt->BlockLight);
|
||||
}
|
||||
|
||||
public function getBlockId($x, $y, $z){
|
||||
@ -245,6 +250,9 @@ class Chunk extends BaseFullChunk{
|
||||
public function toBinary(){
|
||||
$nbt = $this->getNBT();
|
||||
|
||||
$nbt->xPos = new Int("xPos", $this->x);
|
||||
$nbt->zPos = new Int("zPos", $this->z);
|
||||
|
||||
$nbt->Blocks = new ByteArray("Blocks", $this->getBlockIdArray());
|
||||
$nbt->Data = new ByteArray("Data", $this->getBlockDataArray());
|
||||
$nbt->SkyLight = new ByteArray("SkyLight", $this->getBlockSkyLightArray());
|
||||
|
@ -142,12 +142,11 @@ class McRegion extends BaseLevelProvider{
|
||||
$regionX = $regionZ = null;
|
||||
self::getRegionIndex($chunkX, $chunkZ, $regionX, $regionZ);
|
||||
$this->loadRegion($regionX, $regionZ);
|
||||
|
||||
$this->level->timings->syncChunkLoadDataTimer->startTiming();
|
||||
$chunk = $this->getRegion($regionX, $regionZ)->readChunk($chunkX - $regionX * 32, $chunkZ - $regionZ * 32, $create); //generate empty chunk if not loaded
|
||||
$this->level->timings->syncChunkLoadDataTimer->stopTiming();
|
||||
|
||||
if($chunk instanceof Chunk){
|
||||
if($chunk instanceof FullChunk){
|
||||
$this->chunks[$index] = $chunk;
|
||||
}else{
|
||||
return false;
|
||||
@ -156,7 +155,7 @@ class McRegion extends BaseLevelProvider{
|
||||
|
||||
public function unloadChunk($x, $z, $safe = true){
|
||||
$chunk = $this->getChunk($x, $z, false);
|
||||
if($chunk instanceof Chunk){
|
||||
if($chunk instanceof FullChunk){
|
||||
if($safe === true and $this->isChunkLoaded($x, $z)){
|
||||
foreach($chunk->getEntities() as $entity){
|
||||
if($entity instanceof Player){
|
||||
@ -233,10 +232,9 @@ class McRegion extends BaseLevelProvider{
|
||||
$region->removeChunk($chunkX - $region->getX() * 32, $chunkZ - $region->getZ() * 32);
|
||||
$this->loadChunk($chunkX, $chunkZ);
|
||||
}else{
|
||||
$newChunk = clone $chunk;
|
||||
$newChunk->setX($chunkX);
|
||||
$newChunk->setZ($chunkZ);
|
||||
$this->chunks[Level::chunkHash($chunkX, $chunkZ)] = $newChunk;
|
||||
$chunk->setX($chunkX);
|
||||
$chunk->setZ($chunkZ);
|
||||
$this->chunks[Level::chunkHash($chunkX, $chunkZ)] = $chunk;
|
||||
//$this->saveChunk($chunkX, $chunkZ);
|
||||
}
|
||||
}
|
||||
@ -255,7 +253,7 @@ class McRegion extends BaseLevelProvider{
|
||||
|
||||
public function isChunkPopulated($chunkX, $chunkZ){
|
||||
$chunk = $this->getChunk($chunkX, $chunkZ);
|
||||
if($chunk instanceof Chunk){
|
||||
if($chunk instanceof FullChunk){
|
||||
return $chunk->isPopulated();
|
||||
}else{
|
||||
return false;
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
namespace pocketmine\level\format\mcregion;
|
||||
|
||||
use pocketmine\level\format\FullChunk;
|
||||
use pocketmine\level\format\LevelProvider;
|
||||
use pocketmine\nbt\NBT;
|
||||
use pocketmine\nbt\tag\Byte;
|
||||
@ -180,7 +181,7 @@ class RegionLoader{
|
||||
$this->locationTable[$index][1] = 0;
|
||||
}
|
||||
|
||||
public function writeChunk(Chunk $chunk){
|
||||
public function writeChunk(FullChunk $chunk){
|
||||
$this->saveChunk($chunk->getX() - ($this->getX() * 32), $chunk->getZ() - ($this->getZ() * 32), $chunk->toBinary());
|
||||
}
|
||||
|
||||
|
@ -122,6 +122,7 @@ class Flat extends Generator{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
preg_match_all('#(([0-9a-z_]{1,})\(?([0-9a-z_ =:]{0,})\)?),?#', $options, $matches);
|
||||
foreach($matches[2] as $i => $option){
|
||||
$params = true;
|
||||
|
@ -85,6 +85,7 @@ class GenerationChunkManager implements ChunkManager{
|
||||
$index = Level::chunkHash($chunkX, $chunkZ);
|
||||
$chunk = !isset($this->chunks[$index]) ? $this->requestChunk($chunkX, $chunkZ) : $this->chunks[$index];
|
||||
$this->unloadQueue->detach($chunk);
|
||||
$this->changes[$index] = $chunk;
|
||||
return $chunk;
|
||||
}
|
||||
|
||||
@ -112,6 +113,9 @@ class GenerationChunkManager implements ChunkManager{
|
||||
}
|
||||
|
||||
foreach($this->chunks as $chunk){
|
||||
if(isset($this->changes[$index = Level::chunkHash($chunk->getX(), $chunk->getZ())])){
|
||||
continue;
|
||||
}
|
||||
$this->unloadQueue->attach($chunk);
|
||||
}
|
||||
}
|
||||
@ -150,13 +154,11 @@ class GenerationChunkManager implements ChunkManager{
|
||||
public function setChunkGenerated($chunkX, $chunkZ){
|
||||
$chunk = $this->getChunk($chunkX, $chunkZ);
|
||||
$chunk->setGenerated(true);
|
||||
$this->changes[Level::chunkHash($chunkX, $chunkZ)] = $chunk;
|
||||
}
|
||||
|
||||
public function setChunkPopulated($chunkX, $chunkZ){
|
||||
$chunk = $this->getChunk($chunkX, $chunkZ);
|
||||
$chunk->setPopulated(true);
|
||||
$this->changes[Level::chunkHash($chunkX, $chunkZ)] = $chunk;
|
||||
}
|
||||
|
||||
protected function requestChunk($chunkX, $chunkZ){
|
||||
|
Loading…
x
Reference in New Issue
Block a user