mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-08 19:11:47 +00:00
Chunk loading based on X,Y,Z (+1 dimension)
This commit is contained in:
parent
7312c57123
commit
abf52079fc
@ -84,19 +84,22 @@ class Player{
|
|||||||
console("[DEBUG] New Session started with ".$ip.":".$port.". MTU ".$this->MTU.", Client ID ".$this->clientID, true, true, 2);
|
console("[DEBUG] New Session started with ".$ip.":".$port.". MTU ".$this->MTU.", Client ID ".$this->clientID, true, true, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function orderChunks(){
|
public function orderChunks(){
|
||||||
if(!($this->entity instanceof Entity)){
|
if(!($this->entity instanceof Entity)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$X = $this->entity->x / 16;
|
$X = $this->entity->x / 16;
|
||||||
$Z = $this->entity->z / 16;
|
$Z = $this->entity->z / 16;
|
||||||
$v = new Vector2($X, $Z);
|
$Y = $this->entity->y / 16;
|
||||||
|
$v = new Vector3($X, $Y, $Z);
|
||||||
$this->chunksOrder = array();
|
$this->chunksOrder = array();
|
||||||
for($x = 0; $x < 16; ++$x){
|
for($x = 0; $x < 16; ++$x){
|
||||||
for($z = 0; $z < 16; ++$z){
|
for($z = 0; $z < 16; ++$z){
|
||||||
$d = $x.":".$z;
|
for($y = 0; $y < 8; ++$y){
|
||||||
|
$d = $x.":".$y.":".$z;
|
||||||
if(!isset($this->chunksLoaded[$d])){
|
if(!isset($this->chunksLoaded[$d])){
|
||||||
$this->chunksOrder[$d] = $v->distance(new Vector2($x + 0.5, $z + 0.5));
|
$this->chunksOrder[$d] = $v->distance(new Vector3($x + 0.5, $y, $z + 0.5));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,7 +107,6 @@ class Player{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getNextChunk(){
|
public function getNextChunk(){
|
||||||
$this->orderChunks();
|
|
||||||
$c = key($this->chunksOrder);
|
$c = key($this->chunksOrder);
|
||||||
$d = $this->chunksOrder[$c];
|
$d = $this->chunksOrder[$c];
|
||||||
if($c === null or $d > 6){
|
if($c === null or $d > 6){
|
||||||
@ -115,20 +117,14 @@ class Player{
|
|||||||
$this->chunksLoaded[$c] = true;
|
$this->chunksLoaded[$c] = true;
|
||||||
$id = explode(":", $c);
|
$id = explode(":", $c);
|
||||||
$X = $id[0];
|
$X = $id[0];
|
||||||
$Z = $id[1];
|
$Z = $id[2];
|
||||||
$x = $X * 16;
|
$Y = $id[1];
|
||||||
$z = $Z * 16;
|
$x = $X << 4;
|
||||||
|
$z = $Z << 4;
|
||||||
|
$y = $Y << 4;
|
||||||
/*
|
/*
|
||||||
$MTU = $this->MTU - 16;
|
$MTU = $this->MTU - 16;
|
||||||
$y = $this->entity->y / 16;
|
$chunk = $this->level->getMiniChunk('.$X.', '.$Z.', '.$Y.', $MTU);
|
||||||
$order = array();
|
|
||||||
|
|
||||||
for($Y = 0; $Y < 8; ++$Y){
|
|
||||||
$order[$Y] = abs($y - ($Y + 0.5));
|
|
||||||
}
|
|
||||||
asort($order);
|
|
||||||
foreach($order as $Y => $distance){
|
|
||||||
$chunk = $this->level->getMiniChunk('.$X.', '.$Z.', $Y, $MTU);
|
|
||||||
foreach($chunk as $d){
|
foreach($chunk as $d){
|
||||||
$this->dataPacket(MC_CHUNK_DATA, array(
|
$this->dataPacket(MC_CHUNK_DATA, array(
|
||||||
"x" => '.$X.',
|
"x" => '.$X.',
|
||||||
@ -136,9 +132,8 @@ class Player{
|
|||||||
"data" => $d,
|
"data" => $d,
|
||||||
), true);
|
), true);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$tiles = $this->server->query("SELECT * FROM tileentities WHERE spawnable = 1 AND x >= '.$x.' AND x < '.($x + 16).' AND z >= '.$z.' AND z < '.($z + 16).';");
|
$tiles = $this->server->query("SELECT * FROM tileentities WHERE spawnable = 1 AND x >= '.$x.' AND x < '.($x + 16).' AND z >= '.$z.' AND z < '.($z + 16).' AND y >= '.$y.' AND y < '.($y + 16).';");
|
||||||
if($tiles !== false and $tiles !== true){
|
if($tiles !== false and $tiles !== true){
|
||||||
while(($tile = $tiles->fetchArray(SQLITE3_ASSOC)) !== false){
|
while(($tile = $tiles->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||||
$this->server->api->tileentity->spawnTo($tile["ID"], "'.$this->username.'", true);
|
$this->server->api->tileentity->spawnTo($tile["ID"], "'.$this->username.'", true);
|
||||||
@ -146,7 +141,7 @@ class Player{
|
|||||||
}
|
}
|
||||||
$this->actionQueue(\'$this->getNextChunk();\');
|
$this->actionQueue(\'$this->getNextChunk();\');
|
||||||
*/
|
*/
|
||||||
$this->actionQueue('$MTU = $this->MTU - 16;$y = $this->entity->y / 16;$order = array();for($Y = 0; $Y < 8; ++$Y){$order[$Y] = abs($y - ($Y + 0.5));}asort($order);foreach($order as $Y => $distance){$chunk = $this->level->getMiniChunk('.$X.', '.$Z.', $Y, $MTU);foreach($chunk as $d){$this->dataPacket(MC_CHUNK_DATA, array("x" => '.$X.',"z" => '.$Z.',"data" => $d,), true);}}$tiles = $this->server->query("SELECT * FROM tileentities WHERE spawnable = 1 AND x >= '.$x.' AND x < '.($x + 16).' AND z >= '.$z.' AND z < '.($z + 16).';");if($tiles !== false and $tiles !== true){while(($tile = $tiles->fetchArray(SQLITE3_ASSOC)) !== false){$this->server->api->tileentity->spawnTo($tile["ID"], "'.$this->username.'", true);}}$this->actionQueue(\'$this->getNextChunk();\');');
|
$this->actionQueue('$MTU = $this->MTU - 16;$chunk = $this->level->getMiniChunk('.$X.', '.$Z.', '.$Y.', $MTU);foreach($chunk as $d){$this->dataPacket(MC_CHUNK_DATA, array("x" => '.$X.',"z" => '.$Z.',"data" => $d,), true);}$tiles = $this->server->query("SELECT * FROM tileentities WHERE spawnable = 1 AND x >= '.$x.' AND x < '.($x + 16).' AND z >= '.$z.' AND z < '.($z + 16).' AND y >= '.$y.' AND y < '.($y + 16).';");if($tiles !== false and $tiles !== true){while(($tile = $tiles->fetchArray(SQLITE3_ASSOC)) !== false){$this->server->api->tileentity->spawnTo($tile["ID"], "'.$this->username.'", true);}}$this->actionQueue(\'$this->getNextChunk();\');');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -754,6 +749,8 @@ class Player{
|
|||||||
$this->sendInventory();
|
$this->sendInventory();
|
||||||
$this->teleport(new Vector3($this->data->get("position")["x"], $this->data->get("position")["y"], $this->data->get("position")["z"]));
|
$this->teleport(new Vector3($this->data->get("position")["x"], $this->data->get("position")["y"], $this->data->get("position")["z"]));
|
||||||
$this->sendSettings();
|
$this->sendSettings();
|
||||||
|
$this->orderChunks();
|
||||||
|
$this->server->schedule(50, array($this, "orderChunks"), array(), true);
|
||||||
$this->getNextChunk();
|
$this->getNextChunk();
|
||||||
$this->blocked = false;
|
$this->blocked = false;
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user