mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
LevelAPI and pre-map r
This commit is contained in:
73
classes/API/LevelAPI.php
Normal file
73
classes/API/LevelAPI.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
|
||||
-
|
||||
/ \
|
||||
/ \
|
||||
/ POCKET \
|
||||
/ MINECRAFT PHP \
|
||||
|\ @shoghicp /|
|
||||
|. \ / .|
|
||||
| .. \ / .. |
|
||||
| .. | .. |
|
||||
| .. | .. |
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
\ | /
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class LevelAPI{
|
||||
private $server, $map, $active = false;
|
||||
function __construct($server){
|
||||
$this->server = $server;
|
||||
$this->map = $this->server->map;
|
||||
if($this->map !== false){
|
||||
$this->active = true;
|
||||
}
|
||||
}
|
||||
|
||||
private function check(){
|
||||
if($this->active === false and $this->server->map === false){
|
||||
return false;
|
||||
}
|
||||
$this->active = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getChunk($X, $Z){
|
||||
/*if($this->check() and isset($this->map->map[$X][$Z])){
|
||||
return $this->map->map[$X][$Z];
|
||||
}*/
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getOrderedChunk($X, $Z, $columnsPerPacket = 2){
|
||||
$columnsPerPacket = max(1, (int) $columnsPerPacket);
|
||||
$c = $this->getChunk($X, $Z);
|
||||
if($c === false){
|
||||
return array(str_repeat("\x00", 256));
|
||||
}
|
||||
$ordered = array();
|
||||
for($i = 0;$i < 0xff; ){
|
||||
$ordered[$i] = str_repeat("\x00", $i);
|
||||
for($j = 0; $j < $columnsPerPacket; ++$j){
|
||||
$ordered[$i] .= "\xff";
|
||||
for($k = 0; $k < 8; ++$k){
|
||||
$ordered[$i] .= substr($c[$i][0], $k << 4, 16); //Block data
|
||||
$ordered[$i] .= substr($c[$i][1], $k << 3, 8); //Meta data
|
||||
}
|
||||
++$i;
|
||||
}
|
||||
}
|
||||
return $ordered;
|
||||
}
|
||||
}
|
@ -80,6 +80,8 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
||||
$this->server->mapName = $this->getProperty("level-name");
|
||||
$this->server->mapDir = FILE_PATH."data/maps/".$this->getProperty("level-name")."/";
|
||||
$this->loadProperties();
|
||||
$this->server->loadMap();
|
||||
|
||||
//Autoload all default APIs
|
||||
console("[INFO] Loading default APIs");
|
||||
$dir = dir(FILE_PATH."classes/API/");
|
||||
|
Reference in New Issue
Block a user