mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 16:51:42 +00:00
Added tagType parameter to ListTag constructor, remove some boilerplate code
This commit is contained in:
parent
69e29236aa
commit
8fafef2f7f
@ -764,25 +764,25 @@ class Server{
|
||||
new DoubleTag("", $spawn->x),
|
||||
new DoubleTag("", $spawn->y),
|
||||
new DoubleTag("", $spawn->z)
|
||||
]),
|
||||
], NBT::TAG_Double),
|
||||
new StringTag("Level", $this->getDefaultLevel()->getName()),
|
||||
//new StringTag("SpawnLevel", $this->getDefaultLevel()->getName()),
|
||||
//new IntTag("SpawnX", (int) $spawn->x),
|
||||
//new IntTag("SpawnY", (int) $spawn->y),
|
||||
//new IntTag("SpawnZ", (int) $spawn->z),
|
||||
//new ByteTag("SpawnForced", 1), //TODO
|
||||
new ListTag("Inventory", []),
|
||||
new ListTag("Inventory", [], NBT::TAG_Compound),
|
||||
new CompoundTag("Achievements", []),
|
||||
new IntTag("playerGameType", $this->getGamemode()),
|
||||
new ListTag("Motion", [
|
||||
new DoubleTag("", 0.0),
|
||||
new DoubleTag("", 0.0),
|
||||
new DoubleTag("", 0.0)
|
||||
]),
|
||||
], NBT::TAG_Double),
|
||||
new ListTag("Rotation", [
|
||||
new FloatTag("", 0.0),
|
||||
new FloatTag("", 0.0)
|
||||
]),
|
||||
], NBT::TAG_Float),
|
||||
new FloatTag("FallDistance", 0.0),
|
||||
new ShortTag("Fire", 0),
|
||||
new ShortTag("Air", 300),
|
||||
@ -790,10 +790,6 @@ class Server{
|
||||
new ByteTag("Invulnerable", 0),
|
||||
new StringTag("NameTag", $name)
|
||||
]);
|
||||
$nbt->Pos->setTagType(NBT::TAG_Double);
|
||||
$nbt->Inventory->setTagType(NBT::TAG_Compound);
|
||||
$nbt->Motion->setTagType(NBT::TAG_Double);
|
||||
$nbt->Rotation->setTagType(NBT::TAG_Float);
|
||||
|
||||
return $nbt;
|
||||
|
||||
|
@ -69,13 +69,12 @@ class BurningFurnace extends Solid{
|
||||
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0];
|
||||
$this->getLevel()->setBlock($blockReplace, $this, true, true);
|
||||
$nbt = new CompoundTag("", [
|
||||
new ListTag("Items", []),
|
||||
new ListTag("Items", [], NBT::TAG_Compound),
|
||||
new StringTag("id", Tile::FURNACE),
|
||||
new IntTag("x", $this->x),
|
||||
new IntTag("y", $this->y),
|
||||
new IntTag("z", $this->z)
|
||||
]);
|
||||
$nbt->Items->setTagType(NBT::TAG_Compound);
|
||||
|
||||
if($item->hasCustomName()){
|
||||
$nbt->CustomName = new StringTag("CustomName", $item->getCustomName());
|
||||
@ -97,13 +96,13 @@ class BurningFurnace extends Solid{
|
||||
$furnace = $this->getLevel()->getTile($this);
|
||||
if(!($furnace instanceof TileFurnace)){
|
||||
$nbt = new CompoundTag("", [
|
||||
new ListTag("Items", []),
|
||||
new ListTag("Items", [], NBT::TAG_Compound),
|
||||
new StringTag("id", Tile::FURNACE),
|
||||
new IntTag("x", $this->x),
|
||||
new IntTag("y", $this->y),
|
||||
new IntTag("z", $this->z)
|
||||
]);
|
||||
$nbt->Items->setTagType(NBT::TAG_Compound);
|
||||
|
||||
$furnace = Tile::createTile("Furnace", $this->getLevel(), $nbt);
|
||||
}
|
||||
|
||||
|
@ -96,13 +96,12 @@ class Chest extends Transparent{
|
||||
|
||||
$this->getLevel()->setBlock($blockReplace, $this, true, true);
|
||||
$nbt = new CompoundTag("", [
|
||||
new ListTag("Items", []),
|
||||
new ListTag("Items", [], NBT::TAG_Compound),
|
||||
new StringTag("id", Tile::CHEST),
|
||||
new IntTag("x", $this->x),
|
||||
new IntTag("y", $this->y),
|
||||
new IntTag("z", $this->z)
|
||||
]);
|
||||
$nbt->Items->setTagType(NBT::TAG_Compound);
|
||||
|
||||
if($item->hasCustomName()){
|
||||
$nbt->CustomName = new StringTag("CustomName", $item->getCustomName());
|
||||
@ -143,13 +142,12 @@ class Chest extends Transparent{
|
||||
$chest = $t;
|
||||
}else{
|
||||
$nbt = new CompoundTag("", [
|
||||
new ListTag("Items", []),
|
||||
new ListTag("Items", [], NBT::TAG_Compound),
|
||||
new StringTag("id", Tile::CHEST),
|
||||
new IntTag("x", $this->x),
|
||||
new IntTag("y", $this->y),
|
||||
new IntTag("z", $this->z)
|
||||
]);
|
||||
$nbt->Items->setTagType(NBT::TAG_Compound);
|
||||
$chest = Tile::createTile("Chest", $this->getLevel(), $nbt);
|
||||
}
|
||||
|
||||
|
@ -470,8 +470,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
$this->namedtag->foodSaturationLevel = new FloatTag("foodSaturationLevel", $this->getSaturation());
|
||||
$this->namedtag->foodTickTimer = new IntTag("foodTickTimer", $this->foodTickTimer);
|
||||
|
||||
$this->namedtag->Inventory = new ListTag("Inventory", []);
|
||||
$this->namedtag->Inventory->setTagType(NBT::TAG_Compound);
|
||||
$this->namedtag->Inventory = new ListTag("Inventory", [], NBT::TAG_Compound);
|
||||
if($this->inventory !== null){
|
||||
//Normal inventory
|
||||
$slotCount = $this->inventory->getSize() + $this->inventory->getHotbarSize();
|
||||
|
@ -376,8 +376,7 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
$found = false;
|
||||
|
||||
if(!isset($tag->ench)){
|
||||
$tag->ench = new ListTag("ench", []);
|
||||
$tag->ench->setTagType(NBT::TAG_Compound);
|
||||
$tag->ench = new ListTag("ench", [], NBT::TAG_Compound);
|
||||
}else{
|
||||
foreach($tag->ench as $k => $entry){
|
||||
if($entry["id"] === $ench->getId()){
|
||||
@ -517,8 +516,7 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
if(!isset($tag->display)){
|
||||
$tag->display = new CompoundTag("display", []);
|
||||
}
|
||||
$tag->display->Lore = new ListTag("Lore");
|
||||
$tag->display->Lore->setTagType(NBT::TAG_String);
|
||||
$tag->display->Lore = new ListTag("Lore", [], NBT::TAG_String);
|
||||
$count = 0;
|
||||
foreach($lines as $line){
|
||||
$tag->display->Lore[$count++] = new StringTag("", $line);
|
||||
|
@ -49,8 +49,7 @@ class Anvil extends McRegion{
|
||||
$nbt->TerrainPopulated = new ByteTag("TerrainPopulated", $chunk->isPopulated() ? 1 : 0);
|
||||
$nbt->LightPopulated = new ByteTag("LightPopulated", $chunk->isLightPopulated() ? 1 : 0);
|
||||
|
||||
$nbt->Sections = new ListTag("Sections", []);
|
||||
$nbt->Sections->setTagType(NBT::TAG_Compound);
|
||||
$nbt->Sections = new ListTag("Sections", [], NBT::TAG_Compound);
|
||||
$subChunks = -1;
|
||||
foreach($chunk->getSubChunks() as $y => $subChunk){
|
||||
if($subChunk->isEmpty()){
|
||||
@ -77,8 +76,7 @@ class Anvil extends McRegion{
|
||||
}
|
||||
}
|
||||
|
||||
$nbt->Entities = new ListTag("Entities", $entities);
|
||||
$nbt->Entities->setTagType(NBT::TAG_Compound);
|
||||
$nbt->Entities = new ListTag("Entities", $entities, NBT::TAG_Compound);
|
||||
|
||||
$tiles = [];
|
||||
foreach($chunk->getTiles() as $tile){
|
||||
@ -86,8 +84,7 @@ class Anvil extends McRegion{
|
||||
$tiles[] = $tile->namedtag;
|
||||
}
|
||||
|
||||
$nbt->TileEntities = new ListTag("TileEntities", $tiles);
|
||||
$nbt->TileEntities->setTagType(NBT::TAG_Compound);
|
||||
$nbt->TileEntities = new ListTag("TileEntities", $tiles, NBT::TAG_Compound);
|
||||
|
||||
//TODO: TileTicks
|
||||
|
||||
|
@ -95,8 +95,7 @@ class McRegion extends BaseLevelProvider{
|
||||
}
|
||||
}
|
||||
|
||||
$nbt->Entities = new ListTag("Entities", $entities);
|
||||
$nbt->Entities->setTagType(NBT::TAG_Compound);
|
||||
$nbt->Entities = new ListTag("Entities", $entities, NBT::TAG_Compound);
|
||||
|
||||
$tiles = [];
|
||||
foreach($chunk->getTiles() as $tile){
|
||||
@ -104,8 +103,7 @@ class McRegion extends BaseLevelProvider{
|
||||
$tiles[] = $tile->namedtag;
|
||||
}
|
||||
|
||||
$nbt->TileEntities = new ListTag("TileEntities", $tiles);
|
||||
$nbt->TileEntities->setTagType(NBT::TAG_Compound);
|
||||
$nbt->TileEntities = new ListTag("TileEntities", $tiles, NBT::TAG_Compound);
|
||||
|
||||
$writer = new NBT(NBT::BIG_ENDIAN);
|
||||
$nbt->setName("Level");
|
||||
|
@ -52,8 +52,8 @@ class PMAnvil extends Anvil{
|
||||
$nbt->TerrainPopulated = new ByteTag("TerrainPopulated", $chunk->isPopulated() ? 1 : 0);
|
||||
$nbt->LightPopulated = new ByteTag("LightPopulated", $chunk->isLightPopulated() ? 1 : 0);
|
||||
|
||||
$nbt->Sections = new ListTag("Sections", []);
|
||||
$nbt->Sections->setTagType(NBT::TAG_Compound);
|
||||
$nbt->Sections = new ListTag("Sections", [], NBT::TAG_Compound);
|
||||
|
||||
$subChunks = -1;
|
||||
foreach($chunk->getSubChunks() as $y => $subChunk){
|
||||
if($subChunk->isEmpty()){
|
||||
@ -80,8 +80,7 @@ class PMAnvil extends Anvil{
|
||||
}
|
||||
}
|
||||
|
||||
$nbt->Entities = new ListTag("Entities", $entities);
|
||||
$nbt->Entities->setTagType(NBT::TAG_Compound);
|
||||
$nbt->Entities = new ListTag("Entities", $entities, NBT::TAG_Compound);
|
||||
|
||||
$tiles = [];
|
||||
foreach($chunk->getTiles() as $tile){
|
||||
@ -89,8 +88,7 @@ class PMAnvil extends Anvil{
|
||||
$tiles[] = $tile->namedtag;
|
||||
}
|
||||
|
||||
$nbt->TileEntities = new ListTag("TileEntities", $tiles);
|
||||
$nbt->TileEntities->setTagType(NBT::TAG_Compound);
|
||||
$nbt->TileEntities = new ListTag("TileEntities", $tiles, NBT::TAG_Compound);
|
||||
|
||||
//TODO: TileTicks
|
||||
|
||||
|
@ -29,16 +29,18 @@ use pocketmine\nbt\NBT;
|
||||
|
||||
class ListTag extends NamedTag implements \ArrayAccess, \Countable{
|
||||
|
||||
private $tagType = NBT::TAG_End;
|
||||
private $tagType;
|
||||
|
||||
/**
|
||||
* ListTag constructor.
|
||||
*
|
||||
* @param string $name
|
||||
* @param NamedTag[] $value
|
||||
* @param int $tagType
|
||||
*/
|
||||
public function __construct(string $name = "", array $value = []){
|
||||
public function __construct(string $name = "", array $value = [], int $tagType = NBT::TAG_End){
|
||||
parent::__construct($name, $value);
|
||||
$this->tagType = $tagType;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user