Renamed NBT tags to have Tag in the name

This commit is contained in:
Shoghi Cervantes
2015-08-12 21:30:15 +02:00
parent 34dc6ea0d6
commit 7f8b39a63c
58 changed files with 791 additions and 791 deletions

View File

@ -32,11 +32,11 @@ use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Math;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\Byte;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Double;
use pocketmine\nbt\tag\Enum;
use pocketmine\nbt\tag\Float;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\DoubleTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\FloatTag;
use pocketmine\network\Network;
use pocketmine\network\protocol\ExplodePacket;
@ -186,22 +186,22 @@ class Explosion{
foreach($this->affectedBlocks as $block){
if($block->getId() === Block::TNT){
$mot = (new Random())->nextSignedFloat() * M_PI * 2;
$tnt = Entity::createEntity("PrimedTNT", $this->level->getChunk($block->x >> 4, $block->z >> 4), new Compound("", [
"Pos" => new Enum("Pos", [
new Double("", $block->x + 0.5),
new Double("", $block->y),
new Double("", $block->z + 0.5)
$tnt = Entity::createEntity("PrimedTNT", $this->level->getChunk($block->x >> 4, $block->z >> 4), new CompoundTag("", [
"Pos" => new ListTag("Pos", [
new DoubleTag("", $block->x + 0.5),
new DoubleTag("", $block->y),
new DoubleTag("", $block->z + 0.5)
]),
"Motion" => new Enum("Motion", [
new Double("", -sin($mot) * 0.02),
new Double("", 0.2),
new Double("", -cos($mot) * 0.02)
"Motion" => new ListTag("Motion", [
new DoubleTag("", -sin($mot) * 0.02),
new DoubleTag("", 0.2),
new DoubleTag("", -cos($mot) * 0.02)
]),
"Rotation" => new Enum("Rotation", [
new Float("", 0),
new Float("", 0)
"Rotation" => new ListTag("Rotation", [
new FloatTag("", 0),
new FloatTag("", 0)
]),
"Fuse" => new Byte("Fuse", mt_rand(10, 30))
"Fuse" => new ByteTag("Fuse", mt_rand(10, 30))
]));
$tnt->spawnToAll();
}elseif(mt_rand(0, 100) < $yield){

View File

@ -81,13 +81,13 @@ use pocketmine\metadata\Metadatable;
use pocketmine\metadata\MetadataValue;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Double;
use pocketmine\nbt\tag\Enum;
use pocketmine\nbt\tag\Float;
use pocketmine\nbt\tag\Int;
use pocketmine\nbt\tag\Short;
use pocketmine\nbt\tag\String;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\DoubleTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\FloatTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\ShortTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\network\Network;
use pocketmine\network\protocol\DataPacket;
use pocketmine\network\protocol\FullChunkDataPacket;
@ -1466,25 +1466,25 @@ class Level implements ChunkManager, Metadatable{
$itemTag->setName("Item");
if($item->getId() > 0 and $item->getCount() > 0){
$itemEntity = Entity::createEntity("Item", $this->getChunk($source->getX() >> 4, $source->getZ() >> 4, true), new Compound("", [
"Pos" => new Enum("Pos", [
new Double("", $source->getX()),
new Double("", $source->getY()),
new Double("", $source->getZ())
$itemEntity = Entity::createEntity("Item", $this->getChunk($source->getX() >> 4, $source->getZ() >> 4, true), new CompoundTag("", [
"Pos" => new ListTag("Pos", [
new DoubleTag("", $source->getX()),
new DoubleTag("", $source->getY()),
new DoubleTag("", $source->getZ())
]),
"Motion" => new Enum("Motion", [
new Double("", $motion->x),
new Double("", $motion->y),
new Double("", $motion->z)
"Motion" => new ListTag("Motion", [
new DoubleTag("", $motion->x),
new DoubleTag("", $motion->y),
new DoubleTag("", $motion->z)
]),
"Rotation" => new Enum("Rotation", [
new Float("", lcg_value() * 360),
new Float("", 0)
"Rotation" => new ListTag("Rotation", [
new FloatTag("", lcg_value() * 360),
new FloatTag("", 0)
]),
"Health" => new Short("Health", 5),
"Health" => new ShortTag("Health", 5),
"Item" => $itemTag,
"PickupDelay" => new Short("PickupDelay", $delay)
"PickupDelay" => new ShortTag("PickupDelay", $delay)
]));
$itemEntity->spawnToAll();
@ -1568,10 +1568,10 @@ class Level implements ChunkManager, Metadatable{
}
$tag = $item->getNamedTagEntry("CanDestroy");
if($tag instanceof Enum){
if($tag instanceof ListTag){
$canBreak = false;
foreach($tag as $v){
if($v instanceof String){
if($v instanceof StringTag){
$entry = Item::fromString($v->getValue());
if($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()){
$canBreak = true;
@ -1730,10 +1730,10 @@ class Level implements ChunkManager, Metadatable{
}
$tag = $item->getNamedTagEntry("CanPlaceOn");
if($tag instanceof Enum){
if($tag instanceof ListTag){
$canPlace = false;
foreach($tag as $v){
if($v instanceof String){
if($v instanceof StringTag){
$entry = Item::fromString($v->getValue());
if($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()){
$canPlace = true;
@ -1769,19 +1769,19 @@ class Level implements ChunkManager, Metadatable{
if($hand->getId() === Item::SIGN_POST or $hand->getId() === Item::WALL_SIGN){
$nbt = new Compound("", [
"id" => new String("id", Tile::SIGN),
"x" => new Int("x", $block->x),
"y" => new Int("y", $block->y),
"z" => new Int("z", $block->z),
"Text1" => new String("Text1", ""),
"Text2" => new String("Text2", ""),
"Text3" => new String("Text3", ""),
"Text4" => new String("Text4", "")
$nbt = new CompoundTag("", [
"id" => new StringTag("id", Tile::SIGN),
"x" => new IntTag("x", $block->x),
"y" => new IntTag("y", $block->y),
"z" => new IntTag("z", $block->z),
"Text1" => new StringTag("Text1", ""),
"Text2" => new StringTag("Text2", ""),
"Text3" => new StringTag("Text3", ""),
"Text4" => new StringTag("Text4", "")
]);
if($player !== null){
$nbt->Creator = new String("Creator", $player->getRawUniqueId());
$nbt->Creator = new StringTag("Creator", $player->getRawUniqueId());
}
if($item->hasCustomBlockData()){

View File

@ -25,9 +25,9 @@ use pocketmine\level\format\FullChunk;
use pocketmine\level\format\mcregion\McRegion;
use pocketmine\level\Level;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\Byte;
use pocketmine\nbt\tag\ByteArray;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\ByteArrayTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\protocol\FullChunkDataPacket;
use pocketmine\tile\Spawnable;
use pocketmine\utils\BinaryStream;
@ -152,12 +152,12 @@ class Anvil extends McRegion{
}
public static function createChunkSection($Y){
return new ChunkSection(new Compound("", [
"Y" => new Byte("Y", $Y),
"Blocks" => new ByteArray("Blocks", str_repeat("\x00", 4096)),
"Data" => new ByteArray("Data", str_repeat("\x00", 2048)),
"SkyLight" => new ByteArray("SkyLight", str_repeat("\xff", 2048)),
"BlockLight" => new ByteArray("BlockLight", str_repeat("\x00", 2048))
return new ChunkSection(new CompoundTag("", [
"Y" => new ByteTag("Y", $Y),
"Blocks" => new ByteArrayTag("Blocks", str_repeat("\x00", 4096)),
"Data" => new ByteArrayTag("Data", str_repeat("\x00", 2048)),
"SkyLight" => new ByteArrayTag("SkyLight", str_repeat("\xff", 2048)),
"BlockLight" => new ByteArrayTag("BlockLight", str_repeat("\x00", 2048))
]));
}

View File

@ -25,62 +25,62 @@ use pocketmine\level\format\generic\BaseChunk;
use pocketmine\level\format\generic\EmptyChunkSection;
use pocketmine\level\format\LevelProvider;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\Byte;
use pocketmine\nbt\tag\ByteArray;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Enum;
use pocketmine\nbt\tag\Int;
use pocketmine\nbt\tag\IntArray;
use pocketmine\nbt\tag\Long;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\ByteArrayTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\IntArrayTag;
use pocketmine\nbt\tag\LongTag;
use pocketmine\Player;
use pocketmine\utils\Binary;
use pocketmine\utils\BinaryStream;
class Chunk extends BaseChunk{
/** @var Compound */
/** @var CompoundTag */
protected $nbt;
public function __construct($level, Compound $nbt = null){
public function __construct($level, CompoundTag $nbt = null){
if($nbt === null){
$this->provider = $level;
$this->nbt = new Compound("Level", []);
$this->nbt = new CompoundTag("Level", []);
return;
}
$this->nbt = $nbt;
if(!isset($this->nbt->Entities) or !($this->nbt->Entities instanceof Enum)){
$this->nbt->Entities = new Enum("Entities", []);
if(!isset($this->nbt->Entities) or !($this->nbt->Entities instanceof ListTag)){
$this->nbt->Entities = new ListTag("Entities", []);
$this->nbt->Entities->setTagType(NBT::TAG_Compound);
}
if(!isset($this->nbt->TileEntities) or !($this->nbt->TileEntities instanceof Enum)){
$this->nbt->TileEntities = new Enum("TileEntities", []);
if(!isset($this->nbt->TileEntities) or !($this->nbt->TileEntities instanceof ListTag)){
$this->nbt->TileEntities = new ListTag("TileEntities", []);
$this->nbt->TileEntities->setTagType(NBT::TAG_Compound);
}
if(!isset($this->nbt->TileTicks) or !($this->nbt->TileTicks instanceof Enum)){
$this->nbt->TileTicks = new Enum("TileTicks", []);
if(!isset($this->nbt->TileTicks) or !($this->nbt->TileTicks instanceof ListTag)){
$this->nbt->TileTicks = new ListTag("TileTicks", []);
$this->nbt->TileTicks->setTagType(NBT::TAG_Compound);
}
if(!isset($this->nbt->Sections) or !($this->nbt->Sections instanceof Enum)){
$this->nbt->Sections = new Enum("Sections", []);
if(!isset($this->nbt->Sections) or !($this->nbt->Sections instanceof ListTag)){
$this->nbt->Sections = new ListTag("Sections", []);
$this->nbt->Sections->setTagType(NBT::TAG_Compound);
}
if(!isset($this->nbt->BiomeColors) or !($this->nbt->BiomeColors instanceof IntArray)){
$this->nbt->BiomeColors = new IntArray("BiomeColors", array_fill(0, 256, 0));
if(!isset($this->nbt->BiomeColors) or !($this->nbt->BiomeColors instanceof IntArrayTag)){
$this->nbt->BiomeColors = new IntArrayTag("BiomeColors", array_fill(0, 256, 0));
}
if(!isset($this->nbt->HeightMap) or !($this->nbt->HeightMap instanceof IntArray)){
$this->nbt->HeightMap = new IntArray("HeightMap", array_fill(0, 256, 0));
if(!isset($this->nbt->HeightMap) or !($this->nbt->HeightMap instanceof IntArrayTag)){
$this->nbt->HeightMap = new IntArrayTag("HeightMap", array_fill(0, 256, 0));
}
$sections = [];
foreach($this->nbt->Sections as $section){
if($section instanceof Compound){
if($section instanceof CompoundTag){
$y = (int) $section["Y"];
if($y < 8){
$sections[$y] = new ChunkSection($section);
@ -95,8 +95,8 @@ class Chunk extends BaseChunk{
$extraData = [];
if(!isset($this->nbt->ExtraData) or !($this->nbt->ExtraData instanceof ByteArray)){
$this->nbt->ExtraData = new ByteArray("ExtraData", Binary::writeInt(0));
if(!isset($this->nbt->ExtraData) or !($this->nbt->ExtraData instanceof ByteArrayTag)){
$this->nbt->ExtraData = new ByteArrayTag("ExtraData", Binary::writeInt(0));
}else{
$stream = new BinaryStream($this->nbt->ExtraData->getValue());
$count = $stream->getInt();
@ -121,7 +121,7 @@ class Chunk extends BaseChunk{
}
public function setLightPopulated($value = 1){
$this->nbt->LightPopulated = new Byte("LightPopulated", $value);
$this->nbt->LightPopulated = new ByteTag("LightPopulated", $value);
$this->hasChanged = true;
}
@ -136,7 +136,7 @@ class Chunk extends BaseChunk{
* @param int $value
*/
public function setPopulated($value = 1){
$this->nbt->TerrainPopulated = new Byte("TerrainPopulated", $value);
$this->nbt->TerrainPopulated = new ByteTag("TerrainPopulated", $value);
$this->hasChanged = true;
}
@ -151,12 +151,12 @@ class Chunk extends BaseChunk{
* @param int $value
*/
public function setGenerated($value = 1){
$this->nbt->TerrainGenerated = new Byte("TerrainGenerated", $value);
$this->nbt->TerrainGenerated = new ByteTag("TerrainGenerated", $value);
$this->hasChanged = true;
}
/**
* @return Compound
* @return CompoundTag
*/
public function getNBT(){
return $this->nbt;
@ -175,7 +175,7 @@ class Chunk extends BaseChunk{
$nbt->readCompressed($data, ZLIB_ENCODING_DEFLATE);
$chunk = $nbt->getData();
if(!isset($chunk->Level) or !($chunk->Level instanceof Compound)){
if(!isset($chunk->Level) or !($chunk->Level instanceof CompoundTag)){
return null;
}
@ -198,7 +198,7 @@ class Chunk extends BaseChunk{
$nbt->read($data);
$chunk = $nbt->getData();
if(!isset($chunk->Level) or !($chunk->Level instanceof Compound)){
if(!isset($chunk->Level) or !($chunk->Level instanceof CompoundTag)){
return null;
}
@ -211,27 +211,27 @@ class Chunk extends BaseChunk{
public function toFastBinary(){
$nbt = clone $this->getNBT();
$nbt->xPos = new Int("xPos", $this->x);
$nbt->zPos = new Int("zPos", $this->z);
$nbt->xPos = new IntTag("xPos", $this->x);
$nbt->zPos = new IntTag("zPos", $this->z);
$nbt->Sections = new Enum("Sections", []);
$nbt->Sections = new ListTag("Sections", []);
$nbt->Sections->setTagType(NBT::TAG_Compound);
foreach($this->getSections() as $section){
if($section instanceof EmptyChunkSection){
continue;
}
$nbt->Sections[$section->getY()] = new Compound(null, [
"Y" => new Byte("Y", $section->getY()),
"Blocks" => new ByteArray("Blocks", $section->getIdArray()),
"Data" => new ByteArray("Data", $section->getDataArray()),
"BlockLight" => new ByteArray("BlockLight", $section->getLightArray()),
"SkyLight" => new ByteArray("SkyLight", $section->getSkyLightArray())
$nbt->Sections[$section->getY()] = new CompoundTag(null, [
"Y" => new ByteTag("Y", $section->getY()),
"Blocks" => new ByteArrayTag("Blocks", $section->getIdArray()),
"Data" => new ByteArrayTag("Data", $section->getDataArray()),
"BlockLight" => new ByteArrayTag("BlockLight", $section->getLightArray()),
"SkyLight" => new ByteArrayTag("SkyLight", $section->getSkyLightArray())
]);
}
$nbt->BiomeColors = new IntArray("BiomeColors", $this->getBiomeColorArray());
$nbt->BiomeColors = new IntArrayTag("BiomeColors", $this->getBiomeColorArray());
$nbt->HeightMap = new IntArray("HeightMap", $this->getHeightMapArray());
$nbt->HeightMap = new IntArrayTag("HeightMap", $this->getHeightMapArray());
$entities = [];
@ -242,7 +242,7 @@ class Chunk extends BaseChunk{
}
}
$nbt->Entities = new Enum("Entities", $entities);
$nbt->Entities = new ListTag("Entities", $entities);
$nbt->Entities->setTagType(NBT::TAG_Compound);
@ -252,7 +252,7 @@ class Chunk extends BaseChunk{
$tiles[] = $tile->namedtag;
}
$nbt->TileEntities = new Enum("TileEntities", $tiles);
$nbt->TileEntities = new ListTag("TileEntities", $tiles);
$nbt->TileEntities->setTagType(NBT::TAG_Compound);
$extraData = new BinaryStream();
@ -262,11 +262,11 @@ class Chunk extends BaseChunk{
$extraData->putShort($value);
}
$nbt->ExtraData = new ByteArray("ExtraData", $extraData->getBuffer());
$nbt->ExtraData = new ByteArrayTag("ExtraData", $extraData->getBuffer());
$writer = new NBT(NBT::BIG_ENDIAN);
$nbt->setName("Level");
$writer->setData(new Compound("", ["Level" => $nbt]));
$writer->setData(new CompoundTag("", ["Level" => $nbt]));
return $writer->write();
}
@ -274,27 +274,27 @@ class Chunk extends BaseChunk{
public function toBinary(){
$nbt = clone $this->getNBT();
$nbt->xPos = new Int("xPos", $this->x);
$nbt->zPos = new Int("zPos", $this->z);
$nbt->xPos = new IntTag("xPos", $this->x);
$nbt->zPos = new IntTag("zPos", $this->z);
$nbt->Sections = new Enum("Sections", []);
$nbt->Sections = new ListTag("Sections", []);
$nbt->Sections->setTagType(NBT::TAG_Compound);
foreach($this->getSections() as $section){
if($section instanceof EmptyChunkSection){
continue;
}
$nbt->Sections[$section->getY()] = new Compound(null, [
"Y" => new Byte("Y", $section->getY()),
"Blocks" => new ByteArray("Blocks", $section->getIdArray()),
"Data" => new ByteArray("Data", $section->getDataArray()),
"BlockLight" => new ByteArray("BlockLight", $section->getLightArray()),
"SkyLight" => new ByteArray("SkyLight", $section->getSkyLightArray())
$nbt->Sections[$section->getY()] = new CompoundTag(null, [
"Y" => new ByteTag("Y", $section->getY()),
"Blocks" => new ByteArrayTag("Blocks", $section->getIdArray()),
"Data" => new ByteArrayTag("Data", $section->getDataArray()),
"BlockLight" => new ByteArrayTag("BlockLight", $section->getLightArray()),
"SkyLight" => new ByteArrayTag("SkyLight", $section->getSkyLightArray())
]);
}
$nbt->BiomeColors = new IntArray("BiomeColors", $this->getBiomeColorArray());
$nbt->BiomeColors = new IntArrayTag("BiomeColors", $this->getBiomeColorArray());
$nbt->HeightMap = new IntArray("HeightMap", $this->getHeightMapArray());
$nbt->HeightMap = new IntArrayTag("HeightMap", $this->getHeightMapArray());
$entities = [];
@ -305,7 +305,7 @@ class Chunk extends BaseChunk{
}
}
$nbt->Entities = new Enum("Entities", $entities);
$nbt->Entities = new ListTag("Entities", $entities);
$nbt->Entities->setTagType(NBT::TAG_Compound);
@ -315,7 +315,7 @@ class Chunk extends BaseChunk{
$tiles[] = $tile->namedtag;
}
$nbt->TileEntities = new Enum("TileEntities", $tiles);
$nbt->TileEntities = new ListTag("TileEntities", $tiles);
$nbt->TileEntities->setTagType(NBT::TAG_Compound);
$extraData = new BinaryStream();
@ -325,11 +325,11 @@ class Chunk extends BaseChunk{
$extraData->putShort($value);
}
$nbt->ExtraData = new ByteArray("ExtraData", $extraData->getBuffer());
$nbt->ExtraData = new ByteArrayTag("ExtraData", $extraData->getBuffer());
$writer = new NBT(NBT::BIG_ENDIAN);
$nbt->setName("Level");
$writer->setData(new Compound("", ["Level" => $nbt]));
$writer->setData(new CompoundTag("", ["Level" => $nbt]));
return $writer->writeCompressed(ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
}
@ -354,11 +354,11 @@ class Chunk extends BaseChunk{
$chunk->heightMap = array_fill(0, 256, 0);
$chunk->biomeColors = array_fill(0, 256, 0);
$chunk->nbt->V = new Byte("V", 1);
$chunk->nbt->InhabitedTime = new Long("InhabitedTime", 0);
$chunk->nbt->TerrainGenerated = new Byte("TerrainGenerated", 0);
$chunk->nbt->TerrainPopulated = new Byte("TerrainPopulated", 0);
$chunk->nbt->LightPopulated = new Byte("LightPopulated", 0);
$chunk->nbt->V = new ByteTag("V", 1);
$chunk->nbt->InhabitedTime = new LongTag("InhabitedTime", 0);
$chunk->nbt->TerrainGenerated = new ByteTag("TerrainGenerated", 0);
$chunk->nbt->TerrainPopulated = new ByteTag("TerrainPopulated", 0);
$chunk->nbt->LightPopulated = new ByteTag("LightPopulated", 0);
return $chunk;
}catch(\Exception $e){

View File

@ -21,7 +21,7 @@
namespace pocketmine\level\format\anvil;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\CompoundTag;
class ChunkSection implements \pocketmine\level\format\ChunkSection{
@ -31,7 +31,7 @@ class ChunkSection implements \pocketmine\level\format\ChunkSection{
private $blockLight;
private $skyLight;
public function __construct(Compound $nbt){
public function __construct(CompoundTag $nbt){
$this->y = (int) $nbt["Y"];
$this->blocks = (string) $nbt["Blocks"];
$this->data = (string) $nbt["Data"];

View File

@ -24,7 +24,7 @@ namespace pocketmine\level\format\generic;
use pocketmine\level\format\Chunk;
use pocketmine\level\format\ChunkSection;
use pocketmine\level\format\LevelProvider;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\utils\Binary;
use pocketmine\utils\ChunkException;
@ -40,8 +40,8 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{
* @param ChunkSection[] $sections
* @param int[] $biomeColors
* @param int[] $heightMap
* @param Compound[] $entities
* @param Compound[] $tiles
* @param CompoundTag[] $entities
* @param CompoundTag[] $tiles
*
* @throws ChunkException
*/

View File

@ -27,7 +27,7 @@ use pocketmine\level\format\FullChunk;
use pocketmine\level\format\LevelProvider;
use pocketmine\level\generator\biome\Biome;
use pocketmine\level\Level;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\Player;
use pocketmine\tile\Tile;
@ -82,8 +82,8 @@ abstract class BaseFullChunk implements FullChunk{
* @param string $blockLight
* @param int[] $biomeColors
* @param int[] $heightMap
* @param Compound[] $entities
* @param Compound[] $tiles
* @param CompoundTag[] $entities
* @param CompoundTag[] $tiles
*/
protected function __construct($provider, $x, $z, $blocks, $data, $skyLight, $blockLight, array $biomeColors = [], array $heightMap = [], array $entities = [], array $tiles = [], array $extraData = []){
$this->provider = $provider;
@ -134,7 +134,7 @@ abstract class BaseFullChunk implements FullChunk{
if($this->NBTentities !== null){
$this->getProvider()->getLevel()->timings->syncChunkLoadEntitiesTimer->startTiming();
foreach($this->NBTentities as $nbt){
if($nbt instanceof Compound){
if($nbt instanceof CompoundTag){
if(!isset($nbt->id)){
$this->setChanged();
continue;
@ -157,7 +157,7 @@ abstract class BaseFullChunk implements FullChunk{
$this->getProvider()->getLevel()->timings->syncChunkLoadTileEntitiesTimer->startTiming();
foreach($this->NBTtiles as $nbt){
if($nbt instanceof Compound){
if($nbt instanceof CompoundTag){
if(!isset($nbt->id)){
$changed = true;
continue;

View File

@ -26,9 +26,9 @@ use pocketmine\level\generator\Generator;
use pocketmine\level\Level;
use pocketmine\math\Vector3;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Int;
use pocketmine\nbt\tag\String;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\utils\LevelException;
abstract class BaseLevelProvider implements LevelProvider{
@ -36,7 +36,7 @@ abstract class BaseLevelProvider implements LevelProvider{
protected $level;
/** @var string */
protected $path;
/** @var Compound */
/** @var CompoundTag */
protected $levelData;
public function __construct(Level $level, $path){
@ -48,18 +48,18 @@ abstract class BaseLevelProvider implements LevelProvider{
$nbt = new NBT(NBT::BIG_ENDIAN);
$nbt->readCompressed(file_get_contents($this->getPath() . "level.dat"));
$levelData = $nbt->getData();
if($levelData->Data instanceof Compound){
if($levelData->Data instanceof CompoundTag){
$this->levelData = $levelData->Data;
}else{
throw new LevelException("Invalid level.dat");
}
if(!isset($this->levelData->generatorName)){
$this->levelData->generatorName = new String("generatorName", Generator::getGenerator("DEFAULT"));
$this->levelData->generatorName = new StringTag("generatorName", Generator::getGenerator("DEFAULT"));
}
if(!isset($this->levelData->generatorOptions)){
$this->levelData->generatorOptions = new String("generatorOptions", "");
$this->levelData->generatorOptions = new StringTag("generatorOptions", "");
}
}
@ -84,7 +84,7 @@ abstract class BaseLevelProvider implements LevelProvider{
}
public function setTime($value){
$this->levelData->Time = new Int("Time", (int) $value);
$this->levelData->Time = new IntTag("Time", (int) $value);
}
public function getSeed(){
@ -92,7 +92,7 @@ abstract class BaseLevelProvider implements LevelProvider{
}
public function setSeed($value){
$this->levelData->RandomSeed = new Int("RandomSeed", (int) $value);
$this->levelData->RandomSeed = new IntTag("RandomSeed", (int) $value);
}
public function getSpawn(){
@ -100,9 +100,9 @@ abstract class BaseLevelProvider implements LevelProvider{
}
public function setSpawn(Vector3 $pos){
$this->levelData->SpawnX = new Int("SpawnX", (int) $pos->x);
$this->levelData->SpawnY = new Int("SpawnY", (int) $pos->y);
$this->levelData->SpawnZ = new Int("SpawnZ", (int) $pos->z);
$this->levelData->SpawnX = new IntTag("SpawnX", (int) $pos->x);
$this->levelData->SpawnY = new IntTag("SpawnY", (int) $pos->y);
$this->levelData->SpawnZ = new IntTag("SpawnZ", (int) $pos->z);
}
public function doGarbageCollection(){
@ -110,7 +110,7 @@ abstract class BaseLevelProvider implements LevelProvider{
}
/**
* @return Compound
* @return CompoundTag
*/
public function getLevelData(){
return $this->levelData;
@ -118,7 +118,7 @@ abstract class BaseLevelProvider implements LevelProvider{
public function saveLevelData(){
$nbt = new NBT(NBT::BIG_ENDIAN);
$nbt->setData(new Compound("", [
$nbt->setData(new CompoundTag("", [
"Data" => $this->levelData
]));
$buffer = $nbt->writeCompressed();

View File

@ -26,11 +26,11 @@ use pocketmine\level\format\generic\BaseLevelProvider;
use pocketmine\level\generator\Generator;
use pocketmine\level\Level;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\Byte;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Int;
use pocketmine\nbt\tag\Long;
use pocketmine\nbt\tag\String;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\LongTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\tile\Spawnable;
use pocketmine\utils\Binary;
use pocketmine\utils\BinaryStream;
@ -62,18 +62,18 @@ class LevelDB extends BaseLevelProvider{
$nbt = new NBT(NBT::LITTLE_ENDIAN);
$nbt->read(substr(file_get_contents($this->getPath() . "level.dat"), 8));
$levelData = $nbt->getData();
if($levelData instanceof Compound){
if($levelData instanceof CompoundTag){
$this->levelData = $levelData;
}else{
throw new LevelException("Invalid level.dat");
}
if(!isset($this->levelData->generatorName)){
$this->levelData->generatorName = new String("generatorName", Generator::getGenerator("DEFAULT"));
$this->levelData->generatorName = new StringTag("generatorName", Generator::getGenerator("DEFAULT"));
}
if(!isset($this->levelData->generatorOptions)){
$this->levelData->generatorOptions = new String("generatorOptions", "");
$this->levelData->generatorOptions = new StringTag("generatorOptions", "");
}
$this->db = new \LevelDB($this->path . "/db", [
@ -105,24 +105,24 @@ class LevelDB extends BaseLevelProvider{
mkdir($path . "/db", 0777, true);
}
//TODO, add extra details
$levelData = new Compound("", [
"hardcore" => new Byte("hardcore", 0),
"initialized" => new Byte("initialized", 1),
"GameType" => new Int("GameType", 0),
"generatorVersion" => new Int("generatorVersion", 1), //2 in MCPE
"SpawnX" => new Int("SpawnX", 128),
"SpawnY" => new Int("SpawnY", 70),
"SpawnZ" => new Int("SpawnZ", 128),
"version" => new Int("version", 19133),
"DayTime" => new Int("DayTime", 0),
"LastPlayed" => new Long("LastPlayed", microtime(true) * 1000),
"RandomSeed" => new Long("RandomSeed", $seed),
"SizeOnDisk" => new Long("SizeOnDisk", 0),
"Time" => new Long("Time", 0),
"generatorName" => new String("generatorName", Generator::getGeneratorName($generator)),
"generatorOptions" => new String("generatorOptions", isset($options["preset"]) ? $options["preset"] : ""),
"LevelName" => new String("LevelName", $name),
"GameRules" => new Compound("GameRules", [])
$levelData = new CompoundTag("", [
"hardcore" => new ByteTag("hardcore", 0),
"initialized" => new ByteTag("initialized", 1),
"GameType" => new IntTag("GameType", 0),
"generatorVersion" => new IntTag("generatorVersion", 1), //2 in MCPE
"SpawnX" => new IntTag("SpawnX", 128),
"SpawnY" => new IntTag("SpawnY", 70),
"SpawnZ" => new IntTag("SpawnZ", 128),
"version" => new IntTag("version", 19133),
"DayTime" => new IntTag("DayTime", 0),
"LastPlayed" => new LongTag("LastPlayed", microtime(true) * 1000),
"RandomSeed" => new LongTag("RandomSeed", $seed),
"SizeOnDisk" => new LongTag("SizeOnDisk", 0),
"Time" => new LongTag("Time", 0),
"generatorName" => new StringTag("generatorName", Generator::getGeneratorName($generator)),
"generatorOptions" => new StringTag("generatorOptions", isset($options["preset"]) ? $options["preset"] : ""),
"LevelName" => new StringTag("LevelName", $name),
"GameRules" => new CompoundTag("GameRules", [])
]);
$nbt = new NBT(NBT::LITTLE_ENDIAN);
$nbt->setData($levelData);

View File

@ -24,74 +24,74 @@ namespace pocketmine\level\format\mcregion;
use pocketmine\level\format\generic\BaseFullChunk;
use pocketmine\level\format\LevelProvider;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\Byte;
use pocketmine\nbt\tag\ByteArray;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Enum;
use pocketmine\nbt\tag\Int;
use pocketmine\nbt\tag\IntArray;
use pocketmine\nbt\tag\Long;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\ByteArrayTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\IntArrayTag;
use pocketmine\nbt\tag\LongTag;
use pocketmine\Player;
use pocketmine\utils\Binary;
use pocketmine\utils\BinaryStream;
class Chunk extends BaseFullChunk{
/** @var Compound */
/** @var CompoundTag */
protected $nbt;
public function __construct($level, Compound $nbt = null){
public function __construct($level, CompoundTag $nbt = null){
if($nbt === null){
$this->provider = $level;
$this->nbt = new Compound("Level", []);
$this->nbt = new CompoundTag("Level", []);
return;
}
$this->nbt = $nbt;
if(isset($this->nbt->Entities) and $this->nbt->Entities instanceof Enum){
if(isset($this->nbt->Entities) and $this->nbt->Entities instanceof ListTag){
$this->nbt->Entities->setTagType(NBT::TAG_Compound);
}else{
$this->nbt->Entities = new Enum("Entities", []);
$this->nbt->Entities = new ListTag("Entities", []);
$this->nbt->Entities->setTagType(NBT::TAG_Compound);
}
if(isset($this->nbt->TileEntities) and $this->nbt->TileEntities instanceof Enum){
if(isset($this->nbt->TileEntities) and $this->nbt->TileEntities instanceof ListTag){
$this->nbt->TileEntities->setTagType(NBT::TAG_Compound);
}else{
$this->nbt->TileEntities = new Enum("TileEntities", []);
$this->nbt->TileEntities = new ListTag("TileEntities", []);
$this->nbt->TileEntities->setTagType(NBT::TAG_Compound);
}
if(isset($this->nbt->TileTicks) and $this->nbt->TileTicks instanceof Enum){
if(isset($this->nbt->TileTicks) and $this->nbt->TileTicks instanceof ListTag){
$this->nbt->TileTicks->setTagType(NBT::TAG_Compound);
}else{
$this->nbt->TileTicks = new Enum("TileTicks", []);
$this->nbt->TileTicks = new ListTag("TileTicks", []);
$this->nbt->TileTicks->setTagType(NBT::TAG_Compound);
}
if(!isset($this->nbt->BiomeColors) or !($this->nbt->BiomeColors instanceof IntArray)){
$this->nbt->BiomeColors = new IntArray("BiomeColors", array_fill(0, 256, 0));
if(!isset($this->nbt->BiomeColors) or !($this->nbt->BiomeColors instanceof IntArrayTag)){
$this->nbt->BiomeColors = new IntArrayTag("BiomeColors", array_fill(0, 256, 0));
}
if(!isset($this->nbt->HeightMap) or !($this->nbt->HeightMap instanceof IntArray)){
$this->nbt->HeightMap = new IntArray("HeightMap", array_fill(0, 256, 0));
if(!isset($this->nbt->HeightMap) or !($this->nbt->HeightMap instanceof IntArrayTag)){
$this->nbt->HeightMap = new IntArrayTag("HeightMap", array_fill(0, 256, 0));
}
if(!isset($this->nbt->Blocks)){
$this->nbt->Blocks = new ByteArray("Blocks", str_repeat("\x00", 32768));
$this->nbt->Blocks = new ByteArrayTag("Blocks", str_repeat("\x00", 32768));
}
if(!isset($this->nbt->Data)){
$this->nbt->Data = new ByteArray("Data", $half = str_repeat("\x00", 16384));
$this->nbt->SkyLight = new ByteArray("SkyLight", $half);
$this->nbt->BlockLight = new ByteArray("BlockLight", $half);
$this->nbt->Data = new ByteArrayTag("Data", $half = str_repeat("\x00", 16384));
$this->nbt->SkyLight = new ByteArrayTag("SkyLight", $half);
$this->nbt->BlockLight = new ByteArrayTag("BlockLight", $half);
}
$extraData = [];
if(!isset($this->nbt->ExtraData) or !($this->nbt->ExtraData instanceof ByteArray)){
$this->nbt->ExtraData = new ByteArray("ExtraData", Binary::writeInt(0));
if(!isset($this->nbt->ExtraData) or !($this->nbt->ExtraData instanceof ByteArrayTag)){
$this->nbt->ExtraData = new ByteArrayTag("ExtraData", Binary::writeInt(0));
}else{
$stream = new BinaryStream($this->nbt->ExtraData->getValue());
$count = $stream->getInt();
@ -258,7 +258,7 @@ class Chunk extends BaseFullChunk{
}
public function setLightPopulated($value = 1){
$this->nbt->LightPopulated = new Byte("LightPopulated", $value ? 1 : 0);
$this->nbt->LightPopulated = new ByteTag("LightPopulated", $value ? 1 : 0);
$this->hasChanged = true;
}
@ -273,7 +273,7 @@ class Chunk extends BaseFullChunk{
* @param int $value
*/
public function setPopulated($value = 1){
$this->nbt->TerrainPopulated = new Byte("TerrainPopulated", $value ? 1 : 0);
$this->nbt->TerrainPopulated = new ByteTag("TerrainPopulated", $value ? 1 : 0);
$this->hasChanged = true;
}
@ -293,7 +293,7 @@ class Chunk extends BaseFullChunk{
* @param int $value
*/
public function setGenerated($value = 1){
$this->nbt->TerrainGenerated = new Byte("TerrainGenerated", (int) $value);
$this->nbt->TerrainGenerated = new ByteTag("TerrainGenerated", (int) $value);
$this->hasChanged = true;
}
@ -310,7 +310,7 @@ class Chunk extends BaseFullChunk{
$nbt->readCompressed($data, ZLIB_ENCODING_DEFLATE);
$chunk = $nbt->getData();
if(!isset($chunk->Level) or !($chunk->Level instanceof Compound)){
if(!isset($chunk->Level) or !($chunk->Level instanceof CompoundTag)){
return null;
}
@ -348,9 +348,9 @@ class Chunk extends BaseFullChunk{
$flags = ord($data{$offset++});
$chunk->nbt->TerrainGenerated = new Byte("TerrainGenerated", $flags & 0b1);
$chunk->nbt->TerrainPopulated = new Byte("TerrainPopulated", ($flags >> 1) & 0b1);
$chunk->nbt->LightPopulated = new Byte("LightPopulated", ($flags >> 2) & 0b1);
$chunk->nbt->TerrainGenerated = new ByteTag("TerrainGenerated", $flags & 0b1);
$chunk->nbt->TerrainPopulated = new ByteTag("TerrainPopulated", ($flags >> 1) & 0b1);
$chunk->nbt->LightPopulated = new ByteTag("LightPopulated", ($flags >> 2) & 0b1);
return $chunk;
}catch(\Exception $e){
@ -374,18 +374,18 @@ class Chunk extends BaseFullChunk{
public function toBinary(){
$nbt = clone $this->getNBT();
$nbt->xPos = new Int("xPos", $this->x);
$nbt->zPos = new Int("zPos", $this->z);
$nbt->xPos = new IntTag("xPos", $this->x);
$nbt->zPos = new IntTag("zPos", $this->z);
if($this->isGenerated()){
$nbt->Blocks = new ByteArray("Blocks", $this->getBlockIdArray());
$nbt->Data = new ByteArray("Data", $this->getBlockDataArray());
$nbt->SkyLight = new ByteArray("SkyLight", $this->getBlockSkyLightArray());
$nbt->BlockLight = new ByteArray("BlockLight", $this->getBlockLightArray());
$nbt->Blocks = new ByteArrayTag("Blocks", $this->getBlockIdArray());
$nbt->Data = new ByteArrayTag("Data", $this->getBlockDataArray());
$nbt->SkyLight = new ByteArrayTag("SkyLight", $this->getBlockSkyLightArray());
$nbt->BlockLight = new ByteArrayTag("BlockLight", $this->getBlockLightArray());
$nbt->BiomeColors = new IntArray("BiomeColors", $this->getBiomeColorArray());
$nbt->BiomeColors = new IntArrayTag("BiomeColors", $this->getBiomeColorArray());
$nbt->HeightMap = new IntArray("HeightMap", $this->getHeightMapArray());
$nbt->HeightMap = new IntArrayTag("HeightMap", $this->getHeightMapArray());
}
$entities = [];
@ -397,7 +397,7 @@ class Chunk extends BaseFullChunk{
}
}
$nbt->Entities = new Enum("Entities", $entities);
$nbt->Entities = new ListTag("Entities", $entities);
$nbt->Entities->setTagType(NBT::TAG_Compound);
@ -407,7 +407,7 @@ class Chunk extends BaseFullChunk{
$tiles[] = $tile->namedtag;
}
$nbt->TileEntities = new Enum("TileEntities", $tiles);
$nbt->TileEntities = new ListTag("TileEntities", $tiles);
$nbt->TileEntities->setTagType(NBT::TAG_Compound);
$extraData = new BinaryStream();
@ -417,17 +417,17 @@ class Chunk extends BaseFullChunk{
$extraData->putShort($value);
}
$nbt->ExtraData = new ByteArray("ExtraData", $extraData->getBuffer());
$nbt->ExtraData = new ByteArrayTag("ExtraData", $extraData->getBuffer());
$writer = new NBT(NBT::BIG_ENDIAN);
$nbt->setName("Level");
$writer->setData(new Compound("", ["Level" => $nbt]));
$writer->setData(new CompoundTag("", ["Level" => $nbt]));
return $writer->writeCompressed(ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
}
/**
* @return Compound
* @return CompoundTag
*/
public function getNBT(){
return $this->nbt;
@ -454,11 +454,11 @@ class Chunk extends BaseFullChunk{
$chunk->heightMap = array_fill(0, 256, 0);
$chunk->biomeColors = array_fill(0, 256, 0);
$chunk->nbt->V = new Byte("V", 1);
$chunk->nbt->InhabitedTime = new Long("InhabitedTime", 0);
$chunk->nbt->TerrainGenerated = new Byte("TerrainGenerated", 0);
$chunk->nbt->TerrainPopulated = new Byte("TerrainPopulated", 0);
$chunk->nbt->LightPopulated = new Byte("LightPopulated", 0);
$chunk->nbt->V = new ByteTag("V", 1);
$chunk->nbt->InhabitedTime = new LongTag("InhabitedTime", 0);
$chunk->nbt->TerrainGenerated = new ByteTag("TerrainGenerated", 0);
$chunk->nbt->TerrainPopulated = new ByteTag("TerrainPopulated", 0);
$chunk->nbt->LightPopulated = new ByteTag("LightPopulated", 0);
return $chunk;
}catch(\Exception $e){

View File

@ -26,11 +26,11 @@ use pocketmine\level\format\generic\BaseLevelProvider;
use pocketmine\level\generator\Generator;
use pocketmine\level\Level;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\Byte;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\Int;
use pocketmine\nbt\tag\Long;
use pocketmine\nbt\tag\String;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\LongTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\tile\Spawnable;
use pocketmine\utils\BinaryStream;
@ -81,27 +81,27 @@ class McRegion extends BaseLevelProvider{
mkdir($path . "/region", 0777);
}
//TODO, add extra details
$levelData = new Compound("Data", [
"hardcore" => new Byte("hardcore", 0),
"initialized" => new Byte("initialized", 1),
"GameType" => new Int("GameType", 0),
"generatorVersion" => new Int("generatorVersion", 1), //2 in MCPE
"SpawnX" => new Int("SpawnX", 128),
"SpawnY" => new Int("SpawnY", 70),
"SpawnZ" => new Int("SpawnZ", 128),
"version" => new Int("version", 19133),
"DayTime" => new Int("DayTime", 0),
"LastPlayed" => new Long("LastPlayed", microtime(true) * 1000),
"RandomSeed" => new Long("RandomSeed", $seed),
"SizeOnDisk" => new Long("SizeOnDisk", 0),
"Time" => new Long("Time", 0),
"generatorName" => new String("generatorName", Generator::getGeneratorName($generator)),
"generatorOptions" => new String("generatorOptions", isset($options["preset"]) ? $options["preset"] : ""),
"LevelName" => new String("LevelName", $name),
"GameRules" => new Compound("GameRules", [])
$levelData = new CompoundTag("Data", [
"hardcore" => new ByteTag("hardcore", 0),
"initialized" => new ByteTag("initialized", 1),
"GameType" => new IntTag("GameType", 0),
"generatorVersion" => new IntTag("generatorVersion", 1), //2 in MCPE
"SpawnX" => new IntTag("SpawnX", 128),
"SpawnY" => new IntTag("SpawnY", 70),
"SpawnZ" => new IntTag("SpawnZ", 128),
"version" => new IntTag("version", 19133),
"DayTime" => new IntTag("DayTime", 0),
"LastPlayed" => new LongTag("LastPlayed", microtime(true) * 1000),
"RandomSeed" => new LongTag("RandomSeed", $seed),
"SizeOnDisk" => new LongTag("SizeOnDisk", 0),
"Time" => new LongTag("Time", 0),
"generatorName" => new StringTag("generatorName", Generator::getGeneratorName($generator)),
"generatorOptions" => new StringTag("generatorOptions", isset($options["preset"]) ? $options["preset"] : ""),
"LevelName" => new StringTag("LevelName", $name),
"GameRules" => new CompoundTag("GameRules", [])
]);
$nbt = new NBT(NBT::BIG_ENDIAN);
$nbt->setData(new Compound("", [
$nbt->setData(new CompoundTag("", [
"Data" => $levelData
]));
$buffer = $nbt->writeCompressed();