PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
Anvil.php
1 <?php
2 
3 /*
4  *
5  * ____ _ _ __ __ _ __ __ ____
6  * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7  * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8  * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9  * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * @author PocketMine Team
17  * @link http://www.pocketmine.net/
18  *
19  *
20 */
21 
22 namespace pocketmine\level\format\anvil;
23 
31 
32 class Anvil extends McRegion{
33 
35  protected $regions = [];
36 
38  protected $chunks = [];
39 
40  public static function getProviderName(){
41  return "anvil";
42  }
43 
44  public static function getProviderOrder(){
45  return self::ORDER_YZX;
46  }
47 
48  public static function usesChunkSection(){
49  return true;
50  }
51 
52  public static function isValid($path){
53  $isValid = (file_exists($path . "/level.dat") and is_dir($path . "/region/"));
54 
55  if($isValid){
56  $files = glob($path . "/region/*.mc*");
57  foreach($files as $f){
58  if(strpos($f, ".mcr") !== false){ //McRegion
59  $isValid = false;
60  break;
61  }
62  }
63  }
64 
65  return $isValid;
66  }
67 
68  public function requestChunkTask($x, $z){
69  return new ChunkRequestTask($this, $this->getLevel()->getId(), $x, $z);
70  }
71 
78  protected function getRegion($x, $z){
79  return isset($this->regions[$index = Level::chunkHash($x, $z)]) ? $this->regions[$index] : null;
80  }
81 
89  public function getChunk($chunkX, $chunkZ, $create = false){
90  return parent::getChunk($chunkX, $chunkZ, $create);
91  }
92 
93  public function setChunk($chunkX, $chunkZ, FullChunk $chunk){
94  if(!($chunk instanceof Chunk)){
95  throw new ChunkException("Invalid Chunk class");
96  }
97 
98  $chunk->setProvider($this);
99 
100  self::getRegionIndex($chunkX, $chunkZ, $regionX, $regionZ);
101  $this->loadRegion($regionX, $regionZ);
102 
103  $chunk->setX($chunkX);
104  $chunk->setZ($chunkZ);
105  $this->chunks[Level::chunkHash($chunkX, $chunkZ)] = $chunk;
106  }
107 
108  public static function createChunkSection($Y){
109  return new ChunkSection(new Compound(null, [
110  "Y" => new Byte("Y", $Y),
111  "Blocks" => new ByteArray("Blocks", str_repeat("\x00", 4096)),
112  "Data" => new ByteArray("Data", str_repeat("\x00", 2048)),
113  "SkyLight" => new ByteArray("SkyLight", str_repeat("\xff", 2048)),
114  "BlockLight" => new ByteArray("BlockLight", str_repeat("\x00", 2048))
115  ]));
116  }
117 
118  public function isChunkGenerated($chunkX, $chunkZ){
119  if(($region = $this->getRegion($chunkX >> 5, $chunkZ >> 5)) instanceof RegionLoader){
120  return $region->chunkExists($chunkX - $region->getX() * 32, $chunkZ - $region->getZ() * 32) and $this->getChunk($chunkX - $region->getX() * 32, $chunkZ - $region->getZ() * 32, true)->isGenerated();
121  }
122 
123  return false;
124  }
125 
126  protected function loadRegion($x, $z){
127  if(isset($this->regions[$index = Level::chunkHash($x, $z)])){
128  return true;
129  }
130 
131  $this->regions[$index] = new RegionLoader($this, $x, $z);
132 
133  return true;
134  }
135 }
isChunkGenerated($chunkX, $chunkZ)
Definition: Anvil.php:118
getChunk($chunkX, $chunkZ, $create=false)
Definition: Anvil.php:89
setProvider(LevelProvider $provider)
static chunkHash($x, $z)
Definition: Level.php:230
setChunk($chunkX, $chunkZ, FullChunk $chunk)
Definition: Anvil.php:93