GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
PMAnvil Class Reference

Public Member Functions

 nbtSerialize (Chunk $chunk)
 
 nbtDeserialize (string $data)
 
- Public Member Functions inherited from Anvil
 nbtSerialize (Chunk $chunk)
 
 nbtDeserialize (string $data)
 
 getWorldHeight ()
 
- Public Member Functions inherited from McRegion
 nbtSerialize (Chunk $chunk)
 
 nbtDeserialize (string $data)
 
 getWorldHeight ()
 
 getGenerator ()
 
 getGeneratorOptions ()
 
 getChunk (int $chunkX, int $chunkZ, bool $create=false)
 
 setChunk (int $chunkX, int $chunkZ, Chunk $chunk)
 
 saveChunk (int $chunkX, int $chunkZ)
 
 saveChunks ()
 
 loadChunk (int $chunkX, int $chunkZ, bool $create=false)
 
 unloadChunk (int $chunkX, int $chunkZ, bool $safe=true)
 
 unloadChunks ()
 
 isChunkLoaded (int $chunkX, int $chunkZ)
 
 isChunkGenerated (int $chunkX, int $chunkZ)
 
 isChunkPopulated (int $chunkX, int $chunkZ)
 
 getLoadedChunks ()
 
 doGarbageCollection ()
 
 getEmptyChunk (int $chunkX, int $chunkZ)
 
 close ()
 
- Public Member Functions inherited from BaseLevelProvider
 __construct (Level $level, string $path)
 
 getPath ()
 
 getServer ()
 
 getLevel ()
 
 getName ()
 
 getTime ()
 
 setTime ($value)
 
 getSeed ()
 
 setSeed ($value)
 
 getSpawn ()
 
 setSpawn (Vector3 $pos)
 
 doGarbageCollection ()
 
 getLevelData ()
 
 saveLevelData ()
 
 requestChunkTask (int $x, int $z)
 

Static Public Member Functions

static getProviderName ()
 
- Static Public Member Functions inherited from Anvil
static getProviderName ()
 
- Static Public Member Functions inherited from McRegion
static getProviderName ()
 
static isValid (string $path)
 
static generate (string $path, string $name, $seed, string $generator, array $options=[])
 
static getRegionIndex (int $chunkX, int $chunkZ, &$x, &$z)
 

Data Fields

const REGION_FILE_EXTENSION = "mcapm"
 
- Data Fields inherited from Anvil
const REGION_FILE_EXTENSION = "mca"
 
- Data Fields inherited from McRegion
const REGION_FILE_EXTENSION = "mcr"
 

Additional Inherited Members

- Protected Member Functions inherited from McRegion
 getRegion (int $x, int $z)
 
 loadRegion (int $x, int $z)
 
- Protected Attributes inherited from McRegion
 $regions = []
 
 $chunks = []
 
- Protected Attributes inherited from BaseLevelProvider
 $level
 
 $path
 
 $levelData
 
 $asyncChunkRequest = false
 

Detailed Description

This format is exactly the same as the PC Anvil format, with the only difference being that the stored data order is XZY instead of YZX for more performance loading and saving worlds.

Member Function Documentation

◆ getProviderName()

static getProviderName ( )
static
Returns
string

Implements LevelProvider.

163  : string{
164  return "pmanvil";
165  }

◆ nbtDeserialize()

nbtDeserialize ( string  $data)
Parameters
string$data
Returns
null|Chunk
114  {
115  $nbt = new NBT(NBT::BIG_ENDIAN);
116  try{
117  $nbt->readCompressed($data, ZLIB_ENCODING_DEFLATE);
118 
119  $chunk = $nbt->getData();
120 
121  if(!isset($chunk->Level) or !($chunk->Level instanceof CompoundTag)){
122  throw new ChunkException("Invalid NBT format");
123  }
124 
125  $chunk = $chunk->Level;
126 
127  $subChunks = [];
128  if($chunk->Sections instanceof ListTag){
129  foreach($chunk->Sections as $subChunk){
130  if($subChunk instanceof CompoundTag){
131  $subChunks[$subChunk->Y->getValue()] = new SubChunk(
132  $subChunk->Blocks->getValue(),
133  $subChunk->Data->getValue(),
134  $subChunk->SkyLight->getValue(),
135  $subChunk->BlockLight->getValue()
136  );
137  }
138  }
139  }
140 
141  $result = new Chunk(
142  $chunk["xPos"],
143  $chunk["zPos"],
144  $subChunks,
145  isset($chunk->Entities) ? $chunk->Entities->getValue() : [],
146  isset($chunk->TileEntities) ? $chunk->TileEntities->getValue() : [],
147  isset($chunk->Biomes) ? $chunk->Biomes->getValue() : "",
148  isset($chunk->HeightMap) ? $chunk->HeightMap->getValue() : []
149  );
150  $result->setLightPopulated(isset($chunk->LightPopulated) ? ((bool) $chunk->LightPopulated->getValue()) : false);
151  $result->setPopulated(isset($chunk->TerrainPopulated) ? ((bool) $chunk->TerrainPopulated->getValue()) : false);
152  $result->setGenerated(true);
153  return $result;
154  }catch(\Throwable $e){
155  MainLogger::getLogger()->logException($e);
156  return null;
157  }
158  }

◆ nbtSerialize()

nbtSerialize ( Chunk  $chunk)
Parameters
Chunk$chunk
Returns
string
49  : string{
50  $nbt = new CompoundTag("Level", []);
51  $nbt->xPos = new IntTag("xPos", $chunk->getX());
52  $nbt->zPos = new IntTag("zPos", $chunk->getZ());
53 
54  $nbt->V = new ByteTag("V", 1);
55  $nbt->LastUpdate = new LongTag("LastUpdate", 0); //TODO
56  $nbt->InhabitedTime = new LongTag("InhabitedTime", 0); //TODO
57  $nbt->TerrainPopulated = new ByteTag("TerrainPopulated", $chunk->isPopulated());
58  $nbt->LightPopulated = new ByteTag("LightPopulated", $chunk->isLightPopulated());
59 
60  $nbt->Sections = new ListTag("Sections", []);
61  $nbt->Sections->setTagType(NBT::TAG_Compound);
62  $subChunks = -1;
63  foreach($chunk->getSubChunks() as $y => $subChunk){
64  if($subChunk->isEmpty()){
65  continue;
66  }
67  $nbt->Sections[++$subChunks] = new CompoundTag(null, [
68  "Y" => new ByteTag("Y", $y),
69  "Blocks" => new ByteArrayTag("Blocks", $subChunk->getBlockIdArray()),
70  "Data" => new ByteArrayTag("Data", $subChunk->getBlockDataArray()),
71  "SkyLight" => new ByteArrayTag("SkyLight", $subChunk->getSkyLightArray()),
72  "BlockLight" => new ByteArrayTag("BlockLight", $subChunk->getBlockLightArray())
73  ]);
74  }
75 
76  $nbt->Biomes = new ByteArrayTag("Biomes", $chunk->getBiomeIdArray());
77  $nbt->HeightMap = new IntArrayTag("HeightMap", $chunk->getHeightMapArray());
78 
79  $entities = [];
80 
81  foreach($chunk->getEntities() as $entity){
82  if(!($entity instanceof Player) and !$entity->closed){
83  $entity->saveNBT();
84  $entities[] = $entity->namedtag;
85  }
86  }
87 
88  $nbt->Entities = new ListTag("Entities", $entities);
89  $nbt->Entities->setTagType(NBT::TAG_Compound);
90 
91  $tiles = [];
92  foreach($chunk->getTiles() as $tile){
93  $tile->saveNBT();
94  $tiles[] = $tile->namedtag;
95  }
96 
97  $nbt->TileEntities = new ListTag("TileEntities", $tiles);
98  $nbt->TileEntities->setTagType(NBT::TAG_Compound);
99 
100  //TODO: TileTicks
101 
102  $writer = new NBT(NBT::BIG_ENDIAN);
103  $nbt->setName("Level");
104  $writer->setData(new CompoundTag("", ["Level" => $nbt]));
105 
106  return $writer->writeCompressed(ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
107  }

Field Documentation

◆ REGION_FILE_EXTENSION

const REGION_FILE_EXTENSION = "mcapm"

The documentation for this class was generated from the following file: