mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-15 10:19:39 +00:00
Worked on chunk loading
This commit is contained in:
parent
d8f9f9231f
commit
2566f2c4cb
@ -612,20 +612,25 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
$index = key($this->chunksOrder);
|
||||
LevelFormat::getXZ($index, $X, $Z);
|
||||
$this->getLevel()->loadChunk($X, $Z);
|
||||
if(!$this->getLevel()->isChunkPopulated($X, $Z)){
|
||||
$this->getLevel()->loadChunk($X - 1, $Z);
|
||||
$this->getLevel()->loadChunk($X + 1, $Z);
|
||||
$this->getLevel()->loadChunk($X, $Z - 1);
|
||||
$this->getLevel()->loadChunk($X, $Z + 1);
|
||||
$this->getLevel()->loadChunk($X + 1, $Z + 1);
|
||||
$this->getLevel()->loadChunk($X + 1, $Z - 1);
|
||||
$this->getLevel()->loadChunk($X - 1, $Z - 1);
|
||||
$this->getLevel()->loadChunk($X - 1, $Z + 1);
|
||||
$radius = 1;
|
||||
for($z = $Z - $radius; $z <= ($Z + $radius); ++$z){
|
||||
for($x = $X - $radius; $x <= ($X + $radius); ++$x){
|
||||
$this->getLevel()->loadChunk($x, $z);
|
||||
if(!$this->getLevel()->isChunkPopulated($x, $z)){
|
||||
$this->getLevel()->loadChunk($x - 1, $z);
|
||||
$this->getLevel()->loadChunk($x + 1, $z);
|
||||
$this->getLevel()->loadChunk($x, $z - 1);
|
||||
$this->getLevel()->loadChunk($x, $z + 1);
|
||||
$this->getLevel()->loadChunk($x + 1, $z + 1);
|
||||
$this->getLevel()->loadChunk($x + 1, $z - 1);
|
||||
$this->getLevel()->loadChunk($x - 1, $z - 1);
|
||||
$this->getLevel()->loadChunk($x - 1, $z + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach($lastChunk as $index => $Yndex){
|
||||
if($Yndex !== 0xff){
|
||||
if($Yndex === 0){
|
||||
$X = null;
|
||||
$Z = null;
|
||||
LevelFormat::getXZ($index, $X, $Z);
|
||||
@ -1153,6 +1158,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
$this->server->getPluginManager()->callEvent(new PlayerJoinEvent($this, $this->username . " joined the game"));
|
||||
|
||||
$this->orderChunks(); //Get first chunk ready
|
||||
break;
|
||||
case ProtocolInfo::READY_PACKET:
|
||||
if($this->loggedIn === false){
|
||||
|
@ -95,6 +95,7 @@ class Level{
|
||||
/** @var Server */
|
||||
private $server;
|
||||
private $name;
|
||||
/** @var Player[][] */
|
||||
private $usedChunks;
|
||||
private $changedBlocks;
|
||||
private $changedCount;
|
||||
@ -302,16 +303,18 @@ class Level{
|
||||
|
||||
if(count($this->changedBlocks) > 0){
|
||||
foreach($this->changedBlocks as $index => $mini){
|
||||
foreach($mini as $blocks){
|
||||
/** @var Block $b */
|
||||
foreach($blocks as $b){
|
||||
$pk = new UpdateBlockPacket;
|
||||
$pk->x = $b->x;
|
||||
$pk->y = $b->y;
|
||||
$pk->z = $b->z;
|
||||
$pk->block = $b->getID();
|
||||
$pk->meta = $b->getDamage();
|
||||
$this->server->broadcastPacket($this->players, $pk);
|
||||
if(isset($this->usedChunks[$index]) and count($this->usedChunks[$index]) > 0){
|
||||
foreach($mini as $blocks){
|
||||
/** @var Block $b */
|
||||
foreach($blocks as $b){
|
||||
$pk = new UpdateBlockPacket;
|
||||
$pk->x = $b->x;
|
||||
$pk->y = $b->y;
|
||||
$pk->z = $b->z;
|
||||
$pk->block = $b->getID();
|
||||
$pk->meta = $b->getDamage();
|
||||
$this->server->broadcastPacket($this->usedChunks[$index], $pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -383,7 +386,6 @@ class Level{
|
||||
public function populateChunk($X, $Z){
|
||||
$this->level->setPopulated($X, $Z);
|
||||
$this->generator->populateChunk($X, $Z);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -471,7 +473,7 @@ class Level{
|
||||
* @param int $type
|
||||
*/
|
||||
public function updateAround(Vector3 $pos, $type = self::BLOCK_UPDATE_NORMAL){
|
||||
$block = $this->getBlockRaw($pos);
|
||||
$block = $this->getBlock($pos);
|
||||
$block->getSide(0)->onUpdate($type);
|
||||
$block->getSide(1)->onUpdate($type);
|
||||
$block->getSide(2)->onUpdate($type);
|
||||
@ -583,33 +585,35 @@ class Level{
|
||||
*/
|
||||
public function setBlockRaw(Vector3 $pos, Block $block, $direct = true, $send = true){
|
||||
if(($ret = $this->level->setBlock($pos->x, $pos->y, $pos->z, $block->getID(), $block->getDamage())) === true and $send !== false){
|
||||
if($direct === true){
|
||||
$pk = new UpdateBlockPacket;
|
||||
$pk->x = $pos->x;
|
||||
$pk->y = $pos->y;
|
||||
$pk->z = $pos->z;
|
||||
$pk->block = $block->getID();
|
||||
$pk->meta = $block->getDamage();
|
||||
$this->server->broadcastPacket($this->players, $pk);
|
||||
}elseif($direct === false){
|
||||
if(!($pos instanceof Position)){
|
||||
$pos = new Position($pos->x, $pos->y, $pos->z, $this);
|
||||
$index = LevelFormat::getIndex($pos->x >> 4, $pos->z >> 4);
|
||||
if(isset($this->usedChunks[$index]) and count($this->usedChunks[$index]) > 0){
|
||||
if($direct === true){
|
||||
$pk = new UpdateBlockPacket;
|
||||
$pk->x = $pos->x;
|
||||
$pk->y = $pos->y;
|
||||
$pk->z = $pos->z;
|
||||
$pk->block = $block->getID();
|
||||
$pk->meta = $block->getDamage();
|
||||
$this->server->broadcastPacket($this->usedChunks[$index], $pk);
|
||||
}elseif($direct === false){
|
||||
if(!($pos instanceof Position)){
|
||||
$pos = new Position($pos->x, $pos->y, $pos->z, $this);
|
||||
}
|
||||
$block->position($pos);
|
||||
if(ADVANCED_CACHE == true){
|
||||
Cache::remove("world:{$this->name}:{$index}");
|
||||
}
|
||||
if(!isset($this->changedBlocks[$index])){
|
||||
$this->changedBlocks[$index] = [];
|
||||
$this->changedCount[$index] = 0;
|
||||
}
|
||||
$Y = $pos->y >> 4;
|
||||
if(!isset($this->changedBlocks[$index][$Y])){
|
||||
$this->changedBlocks[$index][$Y] = [];
|
||||
$this->changedCount[$index] |= 1 << $Y;
|
||||
}
|
||||
$this->changedBlocks[$index][$Y][] = clone $block;
|
||||
}
|
||||
$block->position($pos);
|
||||
$index = LevelFormat::getIndex($pos->x >> 4, $pos->z >> 4);
|
||||
if(ADVANCED_CACHE == true){
|
||||
Cache::remove("world:{$this->name}:{$index}");
|
||||
}
|
||||
if(!isset($this->changedBlocks[$index])){
|
||||
$this->changedBlocks[$index] = [];
|
||||
$this->changedCount[$index] = 0;
|
||||
}
|
||||
$Y = $pos->y >> 4;
|
||||
if(!isset($this->changedBlocks[$index][$Y])){
|
||||
$this->changedBlocks[$index][$Y] = [];
|
||||
$this->changedCount[$index] |= 1 << $Y;
|
||||
}
|
||||
$this->changedBlocks[$index][$Y][] = clone $block;
|
||||
}
|
||||
}
|
||||
|
||||
@ -637,29 +641,32 @@ class Level{
|
||||
}
|
||||
$block->position($pos);
|
||||
|
||||
if($direct === true){
|
||||
$pk = new UpdateBlockPacket;
|
||||
$pk->x = $pos->x;
|
||||
$pk->y = $pos->y;
|
||||
$pk->z = $pos->z;
|
||||
$pk->block = $block->getID();
|
||||
$pk->meta = $block->getDamage();
|
||||
$this->server->broadcastPacket($this->players, $pk);
|
||||
}else{
|
||||
$index = LevelFormat::getIndex($pos->x >> 4, $pos->z >> 4);
|
||||
if(ADVANCED_CACHE == true){
|
||||
Cache::remove("world:{$this->name}:{$index}");
|
||||
$index = LevelFormat::getIndex($pos->x >> 4, $pos->z >> 4);
|
||||
if(isset($this->usedChunks[$index]) and count($this->usedChunks[$index]) > 0){
|
||||
if($direct === true){
|
||||
$pk = new UpdateBlockPacket;
|
||||
$pk->x = $pos->x;
|
||||
$pk->y = $pos->y;
|
||||
$pk->z = $pos->z;
|
||||
$pk->block = $block->getID();
|
||||
$pk->meta = $block->getDamage();
|
||||
$this->server->broadcastPacket($this->usedChunks[$index], $pk);
|
||||
}else{
|
||||
|
||||
if(ADVANCED_CACHE == true){
|
||||
Cache::remove("world:{$this->name}:{$index}");
|
||||
}
|
||||
if(!isset($this->changedBlocks[$index])){
|
||||
$this->changedBlocks[$index] = [];
|
||||
$this->changedCount[$index] = 0;
|
||||
}
|
||||
$Y = $pos->y >> 4;
|
||||
if(!isset($this->changedBlocks[$index][$Y])){
|
||||
$this->changedBlocks[$index][$Y] = [];
|
||||
$this->changedCount[$index] |= 1 << $Y;
|
||||
}
|
||||
$this->changedBlocks[$index][$Y][] = clone $block;
|
||||
}
|
||||
if(!isset($this->changedBlocks[$index])){
|
||||
$this->changedBlocks[$index] = [];
|
||||
$this->changedCount[$index] = 0;
|
||||
}
|
||||
$Y = $pos->y >> 4;
|
||||
if(!isset($this->changedBlocks[$index][$Y])){
|
||||
$this->changedBlocks[$index][$Y] = [];
|
||||
$this->changedCount[$index] |= 1 << $Y;
|
||||
}
|
||||
$this->changedBlocks[$index][$Y][] = clone $block;
|
||||
}
|
||||
|
||||
if($update === true){
|
||||
|
@ -61,8 +61,8 @@ class WorldGenerator{
|
||||
public function generate(){
|
||||
$this->generator->init($this->level, $this->random);
|
||||
|
||||
for($Z = 7; $Z <= 9; ++$Z){
|
||||
for($X = 7; $X <= 9; ++$X){
|
||||
for($Z = 6; $Z <= 10; ++$Z){
|
||||
for($X = 6; $X <= 10; ++$X){
|
||||
$this->level->level->loadChunk($X, $Z);
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ class Ore{
|
||||
}
|
||||
|
||||
public function canPlaceObject(Level $level, $x, $y, $z){
|
||||
return ($level->level->getBlockID($x, $y, $z) !== 0);
|
||||
return ($level->level->getBlockID($x, $y, $z) === 1);
|
||||
}
|
||||
|
||||
public function placeObject(Level $level, Vector3 $pos){
|
||||
|
Loading…
x
Reference in New Issue
Block a user