mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-18 20:14:31 +00:00
Added Inventory interfaces and types, updated long array() to []
This commit is contained in:
@@ -46,7 +46,7 @@ class Explosion{
|
||||
/**
|
||||
* @var Block[]
|
||||
*/
|
||||
public $affectedBlocks = array();
|
||||
public $affectedBlocks = [];
|
||||
public $stepLen = 0.3;
|
||||
private $what;
|
||||
|
||||
@@ -95,7 +95,7 @@ class Explosion{
|
||||
}
|
||||
}
|
||||
|
||||
$send = array();
|
||||
$send = [];
|
||||
$source = $this->source->floor();
|
||||
$radius = 2 * $this->size;
|
||||
$yield = (1 / $this->size) * 100;
|
||||
|
@@ -64,19 +64,19 @@ class Level{
|
||||
const BLOCK_UPDATE_TOUCH = 5;
|
||||
|
||||
/** @var Player[] */
|
||||
public $players = array();
|
||||
public $players = [];
|
||||
|
||||
/** @var Entity[] */
|
||||
public $entities = array();
|
||||
public $entities = [];
|
||||
|
||||
/** @var Entity[][] */
|
||||
public $chunkEntities = array();
|
||||
public $chunkEntities = [];
|
||||
|
||||
/** @var Tile[] */
|
||||
public $tiles = array();
|
||||
public $tiles = [];
|
||||
|
||||
/** @var Tile[][] */
|
||||
public $chunkTiles = array();
|
||||
public $chunkTiles = [];
|
||||
|
||||
public $nextSave;
|
||||
|
||||
@@ -116,9 +116,9 @@ class Level{
|
||||
$this->nextSave += 90;
|
||||
$this->stopTime = false;
|
||||
$this->name = $name;
|
||||
$this->usedChunks = array();
|
||||
$this->changedBlocks = array();
|
||||
$this->changedCount = array();
|
||||
$this->usedChunks = [];
|
||||
$this->changedBlocks = [];
|
||||
$this->changedCount = [];
|
||||
$gen = Generator::getGenerator($this->level->levelData["generator"]);
|
||||
$this->generator = new $gen((array) $this->level->levelData["generatorSettings"]);
|
||||
$this->generator->init($this, new Random($this->level->levelData["seed"]));
|
||||
@@ -184,7 +184,7 @@ class Level{
|
||||
public function getUsingChunk($X, $Z){
|
||||
$index = LevelFormat::getIndex($X, $Z);
|
||||
|
||||
return isset($this->usedChunks[$index]) ? $this->usedChunks[$index] : array();
|
||||
return isset($this->usedChunks[$index]) ? $this->usedChunks[$index] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -292,7 +292,7 @@ class Level{
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->changedCount = array();
|
||||
$this->changedCount = [];
|
||||
|
||||
if(count($this->changedBlocks) > 0){
|
||||
foreach($this->changedBlocks as $index => $mini){
|
||||
@@ -308,7 +308,7 @@ class Level{
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->changedBlocks = array();
|
||||
$this->changedBlocks = [];
|
||||
}
|
||||
|
||||
$X = null;
|
||||
@@ -429,8 +429,8 @@ class Level{
|
||||
foreach($this->usedChunks as $index => $d){
|
||||
LevelFormat::getXZ($index, $X, $Z);
|
||||
$nbt = new Compound("", array(
|
||||
new Enum("Entities", array()),
|
||||
new Enum("TileEntities", array()),
|
||||
new Enum("Entities", []),
|
||||
new Enum("TileEntities", []),
|
||||
));
|
||||
$nbt->Entities->setTagType(NBT::TAG_Compound);
|
||||
$nbt->TileEntities->setTagType(NBT::TAG_Compound);
|
||||
@@ -531,12 +531,12 @@ class Level{
|
||||
Cache::remove("world:{$this->name}:{$index}");
|
||||
}
|
||||
if(!isset($this->changedBlocks[$index])){
|
||||
$this->changedBlocks[$index] = array();
|
||||
$this->changedBlocks[$index] = [];
|
||||
$this->changedCount[$index] = 0;
|
||||
}
|
||||
$Y = $pos->y >> 4;
|
||||
if(!isset($this->changedBlocks[$index][$Y])){
|
||||
$this->changedBlocks[$index][$Y] = array();
|
||||
$this->changedBlocks[$index][$Y] = [];
|
||||
$this->changedCount[$index] |= 1 << $Y;
|
||||
}
|
||||
$this->changedBlocks[$index][$Y][] = clone $block;
|
||||
@@ -581,12 +581,12 @@ class Level{
|
||||
Cache::remove("world:{$this->name}:{$index}");
|
||||
}
|
||||
if(!isset($this->changedBlocks[$index])){
|
||||
$this->changedBlocks[$index] = array();
|
||||
$this->changedBlocks[$index] = [];
|
||||
$this->changedCount[$index] = 0;
|
||||
}
|
||||
$Y = $pos->y >> 4;
|
||||
if(!isset($this->changedBlocks[$index][$Y])){
|
||||
$this->changedBlocks[$index][$Y] = array();
|
||||
$this->changedBlocks[$index][$Y] = [];
|
||||
$this->changedCount[$index] |= 1 << $Y;
|
||||
}
|
||||
$this->changedBlocks[$index][$Y][] = clone $block;
|
||||
@@ -896,7 +896,7 @@ class Level{
|
||||
return $this->chunkEntities[$index];
|
||||
}
|
||||
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -913,7 +913,7 @@ class Level{
|
||||
return $this->chunkTiles[$index];
|
||||
}
|
||||
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -929,9 +929,9 @@ class Level{
|
||||
if(isset($this->usedChunks[$index])){
|
||||
return true;
|
||||
}elseif($this->level->loadChunk($X, $Z) !== false){
|
||||
$this->usedChunks[$index] = array();
|
||||
$this->chunkTiles[$index] = array();
|
||||
$this->chunkEntities[$index] = array();
|
||||
$this->usedChunks[$index] = [];
|
||||
$this->chunkTiles[$index] = [];
|
||||
$this->chunkEntities[$index] = [];
|
||||
$tags = $this->level->getChunkNBT($X, $Z);
|
||||
if(isset($tags->Entities)){
|
||||
foreach($tags->Entities as $nbt){
|
||||
@@ -1027,7 +1027,7 @@ class Level{
|
||||
}
|
||||
|
||||
|
||||
$raw = array();
|
||||
$raw = [];
|
||||
for($Y = 0; $Y < 8; ++$Y){
|
||||
if(($Yndex & (1 << $Y)) !== 0){
|
||||
$raw[$Y] = $this->level->getMiniChunk($X, $Z, $Y);
|
||||
|
@@ -53,7 +53,7 @@ class LevelImport{
|
||||
$nbt->read(substr(file_get_contents($this->path . "entities.dat"), 12));
|
||||
$entities = $nbt->getData();
|
||||
if(!isset($entities->TileEntities)){
|
||||
$entities->TileEntities = array();
|
||||
$entities->TileEntities = [];
|
||||
}
|
||||
$tiles = $entities->TileEntities;
|
||||
$entities = $entities->Entities;
|
||||
|
@@ -35,13 +35,13 @@ class PocketChunkParser{
|
||||
private $file;
|
||||
public $sectorLength = 4096; //16 * 16 * 16
|
||||
public $chunkLength = 86016; //21 * $sectorLength
|
||||
public $map = array();
|
||||
public $map = [];
|
||||
|
||||
public function __construct(){
|
||||
}
|
||||
|
||||
private function loadLocationTable(){
|
||||
$this->location = array();
|
||||
$this->location = [];
|
||||
console("[DEBUG] Loading Chunk Location table...", true, true, 2);
|
||||
for($offset = 0; $offset < 0x1000; $offset += 4){
|
||||
$data = Binary::readLInt(substr($this->raw, $offset, 4));
|
||||
@@ -116,10 +116,10 @@ class PocketChunkParser{
|
||||
$len = Binary::readLInt(substr($this->raw, $offset, 4));
|
||||
$offset += 4;
|
||||
$chunk = array(
|
||||
0 => array(), //Block
|
||||
1 => array(), //Data
|
||||
2 => array(), //SkyLight
|
||||
3 => array(), //BlockLight
|
||||
0 => [], //Block
|
||||
1 => [], //Data
|
||||
2 => [], //SkyLight
|
||||
3 => [], //BlockLight
|
||||
);
|
||||
foreach($chunk as $section => &$data){
|
||||
$l = $section === 0 ? 128 : 64;
|
||||
@@ -139,7 +139,7 @@ class PocketChunkParser{
|
||||
$this->loadLocationTable();
|
||||
console("[DEBUG] Loading chunks...", true, true, 2);
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
$this->map[$x] = array();
|
||||
$this->map[$x] = [];
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
$this->map[$x][$z] = $this->parseChunk($x, $z);
|
||||
}
|
||||
|
@@ -38,32 +38,32 @@ class Chunk extends BaseChunk{
|
||||
if($this->nbt->Entities instanceof Enum){
|
||||
$this->nbt->Entities->setTagType(NBT::TAG_Compound);
|
||||
}else{
|
||||
$this->nbt->Entities = new Enum("Entities", array());
|
||||
$this->nbt->Entities = new Enum("Entities", []);
|
||||
$this->nbt->Entities->setTagType(NBT::TAG_Compound);
|
||||
}
|
||||
|
||||
if($this->nbt->TileEntities instanceof Enum){
|
||||
$this->nbt->TileEntities->setTagType(NBT::TAG_Compound);
|
||||
}else{
|
||||
$this->nbt->TileEntities = new Enum("TileEntities", array());
|
||||
$this->nbt->TileEntities = new Enum("TileEntities", []);
|
||||
$this->nbt->TileEntities->setTagType(NBT::TAG_Compound);
|
||||
}
|
||||
|
||||
if($this->nbt->TileTicks instanceof Enum){
|
||||
$this->nbt->TileTicks->setTagType(NBT::TAG_Compound);
|
||||
}else{
|
||||
$this->nbt->TileTicks = new Enum("TileTicks", array());
|
||||
$this->nbt->TileTicks = new Enum("TileTicks", []);
|
||||
$this->nbt->TileTicks->setTagType(NBT::TAG_Compound);
|
||||
}
|
||||
|
||||
if($this->nbt->Sections instanceof Enum){
|
||||
$this->nbt->Sections->setTagType(NBT::TAG_Compound);
|
||||
}else{
|
||||
$this->nbt->Sections = new Enum("Sections", array());
|
||||
$this->nbt->Sections = new Enum("Sections", []);
|
||||
$this->nbt->Sections->setTagType(NBT::TAG_Compound);
|
||||
}
|
||||
|
||||
$sections = array();
|
||||
$sections = [];
|
||||
foreach($this->nbt->Sections as $section){
|
||||
if($section instanceof Compound){
|
||||
$sections[(int) $section["Y"]] = new ChunkSection($section);
|
||||
|
@@ -43,7 +43,7 @@ class RegionLoader{
|
||||
protected $filePath;
|
||||
protected $filePointer;
|
||||
protected $lastSector;
|
||||
protected $locationTable = array();
|
||||
protected $locationTable = [];
|
||||
|
||||
public function __construct($path,/*Level $level, */$regionX, $regionZ){
|
||||
$this->x = $regionX;
|
||||
@@ -118,7 +118,7 @@ class RegionLoader{
|
||||
}
|
||||
|
||||
public function generateChunk($x, $z){
|
||||
$nbt = new Compound("Level", array());
|
||||
$nbt = new Compound("Level", []);
|
||||
$nbt->xPos = new Int("xPos", ($this->getX() * 32) + $x);
|
||||
$nbt->zPos = new Int("xPos", ($this->getZ() * 32) + $z);
|
||||
$nbt->LastUpdate = new Long("LastUpdate", 0);
|
||||
@@ -128,13 +128,13 @@ class RegionLoader{
|
||||
$nbt->InhabitedTime = new Long("InhabitedTime", 0);
|
||||
$nbt->Biomes = new ByteArray("Biomes", str_repeat(Binary::writeByte(-1), 256));
|
||||
$nbt->HeightMap = new IntArray("HeightMap", array_fill(0, 256, 127));
|
||||
$nbt->Sections = new Enum("Sections", array());
|
||||
$nbt->Sections = new Enum("Sections", []);
|
||||
$nbt->Sections->setTagType(NBT::TAG_Compound);
|
||||
$nbt->Entities = new Enum("Entities", array());
|
||||
$nbt->Entities = new Enum("Entities", []);
|
||||
$nbt->Entities->setTagType(NBT::TAG_Compound);
|
||||
$nbt->TileEntities = new Enum("TileEntities", array());
|
||||
$nbt->TileEntities = new Enum("TileEntities", []);
|
||||
$nbt->TileEntities->setTagType(NBT::TAG_Compound);
|
||||
$nbt->TileTicks = new Enum("TileTicks", array());
|
||||
$nbt->TileTicks = new Enum("TileTicks", []);
|
||||
$nbt->TileTicks->setTagType(NBT::TAG_Compound);
|
||||
$writer = new NBT(NBT::BIG_ENDIAN);
|
||||
$writer->setData(new Compound("", array($nbt)));
|
||||
@@ -187,7 +187,7 @@ class RegionLoader{
|
||||
}
|
||||
|
||||
private function cleanGarbage(){
|
||||
$sectors = array();
|
||||
$sectors = [];
|
||||
foreach($this->locationTable as $index => $data){ //Calculate file usage
|
||||
if($data[0] === 0 or $data[1] === 0){
|
||||
$this->locationTable[$index] = array(0, 0, 0);
|
||||
|
@@ -27,7 +27,7 @@ use pocketmine\level\Level;
|
||||
abstract class BaseChunk implements Chunk{
|
||||
|
||||
/** @var ChunkSection[] */
|
||||
protected $sections = array();
|
||||
protected $sections = [];
|
||||
protected $level;
|
||||
|
||||
protected $x;
|
||||
|
@@ -34,11 +34,11 @@ class LevelFormat extends PMF{
|
||||
const ZLIB_ENCODING = 15; //15 = zlib, -15 = raw deflate, 31 = gzip
|
||||
|
||||
public $level;
|
||||
public $levelData = array();
|
||||
public $levelData = [];
|
||||
public $isLoaded = true;
|
||||
private $chunks = array();
|
||||
private $chunkChange = array();
|
||||
private $chunkInfo = array();
|
||||
private $chunks = [];
|
||||
private $chunkChange = [];
|
||||
private $chunkInfo = [];
|
||||
public $isGenerating = 0;
|
||||
|
||||
public function getData($index){
|
||||
@@ -69,9 +69,9 @@ class LevelFormat extends PMF{
|
||||
* @param bool|array $blank default false
|
||||
*/
|
||||
public function __construct($file, $blank = false){
|
||||
$this->chunks = array();
|
||||
$this->chunkChange = array();
|
||||
$this->chunkInfo = array();
|
||||
$this->chunks = [];
|
||||
$this->chunkChange = [];
|
||||
$this->chunkInfo = [];
|
||||
if(is_array($blank)){
|
||||
$this->create($file, 0);
|
||||
$this->levelData = $blank;
|
||||
@@ -189,8 +189,8 @@ class LevelFormat extends PMF{
|
||||
private function upgrade_From1_To2(){
|
||||
console("[NOTICE] Old PMF Level format version #1 detected, upgrading to version #2");
|
||||
$nbt = new Compound("", array(
|
||||
new Enum("Entities", array()),
|
||||
new Enum("TileEntities", array())
|
||||
new Enum("Entities", []),
|
||||
new Enum("TileEntities", [])
|
||||
));
|
||||
$nbt->Entities->setTagType(NBT::TAG_Compound);
|
||||
$nbt->TileEntities->setTagType(NBT::TAG_Compound);
|
||||
@@ -301,7 +301,7 @@ class LevelFormat extends PMF{
|
||||
$nbt->read(substr($chunk, $offset, $len));
|
||||
$this->chunkInfo[$index][2] = $nbt->getData();
|
||||
$offset += $len;
|
||||
$this->chunks[$index] = array();
|
||||
$this->chunks[$index] = [];
|
||||
$this->chunkChange[$index] = array(-1 => false);
|
||||
$this->chunkInfo[$index][3] = substr($chunk, $offset, 256); //Biome data
|
||||
$offset += 256;
|
||||
@@ -421,8 +421,8 @@ class LevelFormat extends PMF{
|
||||
7 => 8192,
|
||||
);
|
||||
$nbt = new Compound("", array(
|
||||
new Enum("Entities", array()),
|
||||
new Enum("TileEntities", array())
|
||||
new Enum("Entities", []),
|
||||
new Enum("TileEntities", [])
|
||||
));
|
||||
$nbt->Entities->setTagType(NBT::TAG_Compound);
|
||||
$nbt->TileEntities->setTagType(NBT::TAG_Compound);
|
||||
|
@@ -37,7 +37,7 @@ use pocketmine\math\Vector3 as Vector3;
|
||||
use pocketmine\utils\Random;
|
||||
|
||||
class Flat extends Generator{
|
||||
private $level, $random, $structure, $chunks, $options, $floorLevel, $preset, $populators = array();
|
||||
private $level, $random, $structure, $chunks, $options, $floorLevel, $preset, $populators = [];
|
||||
|
||||
public function getSettings(){
|
||||
return $this->options;
|
||||
@@ -47,7 +47,7 @@ class Flat extends Generator{
|
||||
return "flat";
|
||||
}
|
||||
|
||||
public function __construct(array $options = array()){
|
||||
public function __construct(array $options = []){
|
||||
$this->preset = "2;7,59x1,3x3,2;1;spawn(radius=10 block=89),decoration(treecount=80 grasscount=45)";
|
||||
$this->options = $options;
|
||||
if(isset($options["preset"])){
|
||||
@@ -84,8 +84,8 @@ class Flat extends Generator{
|
||||
$options = isset($preset[3]) ? $preset[3] : "";
|
||||
preg_match_all('#(([0-9]{0,})x?([0-9]{1,3}:?[0-9]{0,2})),?#', $blocks, $matches);
|
||||
$y = 0;
|
||||
$this->structure = array();
|
||||
$this->chunks = array();
|
||||
$this->structure = [];
|
||||
$this->chunks = [];
|
||||
foreach($matches[3] as $i => $b){
|
||||
$b = Item::fromString($b);
|
||||
$cnt = $matches[2][$i] === "" ? 1 : intval($matches[2][$i]);
|
||||
@@ -122,7 +122,7 @@ class Flat extends Generator{
|
||||
foreach($matches[2] as $i => $option){
|
||||
$params = true;
|
||||
if($matches[3][$i] !== ""){
|
||||
$params = array();
|
||||
$params = [];
|
||||
$p = explode(" ", $matches[3][$i]);
|
||||
foreach($p as $k){
|
||||
$k = explode("=", $k);
|
||||
|
@@ -28,7 +28,7 @@ use pocketmine\level\Level;
|
||||
use pocketmine\utils\Random;
|
||||
|
||||
abstract class Generator{
|
||||
private static $list = array();
|
||||
private static $list = [];
|
||||
|
||||
public static function addGenerator($object, $name){
|
||||
if(is_subclass_of($object, "pocketmine\\level\\generator\\Generator") and !isset(Generator::$list[$name])){
|
||||
@@ -48,7 +48,7 @@ abstract class Generator{
|
||||
return "pocketmine\\level\\generator\\Normal";
|
||||
}
|
||||
|
||||
public abstract function __construct(array $settings = array());
|
||||
public abstract function __construct(array $settings = []);
|
||||
|
||||
public abstract function init(Level $level, Random $random);
|
||||
|
||||
|
@@ -40,7 +40,7 @@ use pocketmine\utils\Random;
|
||||
|
||||
class Normal extends Generator{
|
||||
|
||||
private $populators = array();
|
||||
private $populators = [];
|
||||
private $level;
|
||||
private $random;
|
||||
private $worldHeight = 65;
|
||||
@@ -50,7 +50,7 @@ class Normal extends Generator{
|
||||
private $noisePatchesSmall;
|
||||
private $noiseBase;
|
||||
|
||||
public function __construct(array $options = array()){
|
||||
public function __construct(array $options = []){
|
||||
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class Normal extends Generator{
|
||||
}
|
||||
|
||||
public function getSettings(){
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
public function init(Level $level, Random $random){
|
||||
@@ -98,10 +98,10 @@ class Normal extends Generator{
|
||||
|
||||
public function generateChunk($chunkX, $chunkZ){
|
||||
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
|
||||
$hills = array();
|
||||
$patches = array();
|
||||
$patchesSmall = array();
|
||||
$base = array();
|
||||
$hills = [];
|
||||
$patches = [];
|
||||
$patchesSmall = [];
|
||||
$base = [];
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
$i = ($z << 4) + $x;
|
||||
|
@@ -29,7 +29,7 @@ namespace pocketmine\level\generator\noise;
|
||||
|
||||
|
||||
abstract class Generator{
|
||||
protected $perm = array();
|
||||
protected $perm = [];
|
||||
protected $offsetX = 0;
|
||||
protected $offsetY = 0;
|
||||
protected $offsetZ = 0;
|
||||
|
@@ -27,7 +27,7 @@ use pocketmine\math\Vector3 as Vector3;
|
||||
use pocketmine\utils\Random;
|
||||
|
||||
class Ore extends Populator{
|
||||
private $oreTypes = array();
|
||||
private $oreTypes = [];
|
||||
|
||||
public function populate(Level $level, $chunkX, $chunkZ, Random $random){
|
||||
foreach($this->oreTypes as $type){
|
||||
|
Reference in New Issue
Block a user