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

Public Member Functions

 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 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 = "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
 

Member Function Documentation

◆ getProviderName()

static getProviderName ( )
static
Returns
string

Implements LevelProvider.

170  : string{
171  return "anvil";
172  }

◆ getWorldHeight()

getWorldHeight ( )
Returns
int

Implements LevelProvider.

177  : int{
178  //TODO: add world height options
179  return 256;
180  }

◆ nbtDeserialize()

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

◆ nbtSerialize()

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

Field Documentation

◆ REGION_FILE_EXTENSION

const REGION_FILE_EXTENSION = "mca"

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