Updating for latest PocketMine-NBT changes

This commit is contained in:
Dylan K. Taylor
2019-03-21 15:58:22 +00:00
parent 1ac255f955
commit 8c536c248d
24 changed files with 237 additions and 266 deletions

View File

@ -715,7 +715,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
}
public function saveNBT() : CompoundTag{
$nbt = new CompoundTag("");
$nbt = new CompoundTag();
if(!($this instanceof Player)){
$nbt->setString("id", EntityFactory::getSaveId(get_class($this)));
@ -725,21 +725,21 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
}
}
$nbt->setTag(new ListTag("Pos", [
new DoubleTag("", $this->x),
new DoubleTag("", $this->y),
new DoubleTag("", $this->z)
$nbt->setTag("Pos", new ListTag([
new DoubleTag($this->x),
new DoubleTag($this->y),
new DoubleTag($this->z)
]));
$nbt->setTag(new ListTag("Motion", [
new DoubleTag("", $this->motion->x),
new DoubleTag("", $this->motion->y),
new DoubleTag("", $this->motion->z)
$nbt->setTag("Motion", new ListTag([
new DoubleTag($this->motion->x),
new DoubleTag($this->motion->y),
new DoubleTag($this->motion->z)
]));
$nbt->setTag(new ListTag("Rotation", [
new FloatTag("", $this->yaw),
new FloatTag("", $this->pitch)
$nbt->setTag("Rotation", new ListTag([
new FloatTag($this->yaw),
new FloatTag($this->pitch)
]));
$nbt->setFloat("FallDistance", $this->fallDistance);

View File

@ -246,21 +246,20 @@ final class EntityFactory{
* @return CompoundTag
*/
public static function createBaseNBT(Vector3 $pos, ?Vector3 $motion = null, float $yaw = 0.0, float $pitch = 0.0) : CompoundTag{
return new CompoundTag("", [
new ListTag("Pos", [
new DoubleTag("", $pos->x),
new DoubleTag("", $pos->y),
new DoubleTag("", $pos->z)
]),
new ListTag("Motion", [
new DoubleTag("", $motion ? $motion->x : 0.0),
new DoubleTag("", $motion ? $motion->y : 0.0),
new DoubleTag("", $motion ? $motion->z : 0.0)
]),
new ListTag("Rotation", [
new FloatTag("", $yaw),
new FloatTag("", $pitch)
])
]);
return CompoundTag::create()
->setTag("Pos", new ListTag([
new DoubleTag($pos->x),
new DoubleTag($pos->y),
new DoubleTag($pos->z)
]))
->setTag("Motion", new ListTag([
new DoubleTag($motion ? $motion->x : 0.0),
new DoubleTag($motion ? $motion->y : 0.0),
new DoubleTag($motion ? $motion->z : 0.0)
]))
->setTag("Rotation", new ListTag([
new FloatTag($yaw),
new FloatTag($pitch)
]));
}
}

View File

@ -800,8 +800,8 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$nbt->setInt("XpTotal", $this->totalXp);
$nbt->setInt("XpSeed", $this->xpSeed);
$inventoryTag = new ListTag("Inventory", [], NBT::TAG_Compound);
$nbt->setTag($inventoryTag);
$inventoryTag = new ListTag([], NBT::TAG_Compound);
$nbt->setTag("Inventory", $inventoryTag);
if($this->inventory !== null){
//Normal inventory
$slotCount = $this->inventory->getSize() + $this->inventory->getHotbarSize();
@ -835,17 +835,17 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
}
}
$nbt->setTag(new ListTag("EnderChestInventory", $items, NBT::TAG_Compound));
$nbt->setTag("EnderChestInventory", new ListTag($items, NBT::TAG_Compound));
}
if($this->skin !== null){
$nbt->setTag(new CompoundTag("Skin", [
new StringTag("Name", $this->skin->getSkinId()),
new ByteArrayTag("Data", $this->skin->getSkinData()),
new ByteArrayTag("CapeData", $this->skin->getCapeData()),
new StringTag("GeometryName", $this->skin->getGeometryName()),
new ByteArrayTag("GeometryData", $this->skin->getGeometryData())
]));
$nbt->setTag("Skin", CompoundTag::create()
->setString("Name", $this->skin->getSkinId())
->setByteArray("Data", $this->skin->getSkinData())
->setByteArray("CapeData", $this->skin->getCapeData())
->setString("GeometryName", $this->skin->getGeometryName())
->setByteArray("GeometryData", $this->skin->getGeometryData())
);
}
return $nbt;

View File

@ -42,10 +42,8 @@ use pocketmine\item\enchantment\Enchantment;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\math\VoxelRayTrace;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\FloatTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\network\mcpe\protocol\EntityEventPacket;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
@ -178,16 +176,15 @@ abstract class Living extends Entity implements Damageable{
if(count($this->effects) > 0){
$effects = [];
foreach($this->effects as $effect){
$effects[] = new CompoundTag("", [
new ByteTag("Id", $effect->getId()),
new ByteTag("Amplifier", Binary::signByte($effect->getAmplifier())),
new IntTag("Duration", $effect->getDuration()),
new ByteTag("Ambient", $effect->isAmbient() ? 1 : 0),
new ByteTag("ShowParticles", $effect->isVisible() ? 1 : 0)
]);
$effects[] = CompoundTag::create()
->setByte("Id", $effect->getId())
->setByte("Amplifier", Binary::signByte($effect->getAmplifier()))
->setInt("Duration", $effect->getDuration())
->setByte("Ambient", $effect->isAmbient() ? 1 : 0)
->setByte("ShowParticles", $effect->isVisible() ? 1 : 0);
}
$nbt->setTag(new ListTag("ActiveEffects", $effects));
$nbt->setTag("ActiveEffects", new ListTag($effects));
}
return $nbt;

View File

@ -134,7 +134,7 @@ class ItemEntity extends Entity{
public function saveNBT() : CompoundTag{
$nbt = parent::saveNBT();
$nbt->setTag($this->item->nbtSerialize(-1, "Item"));
$nbt->setTag("Item", $this->item->nbtSerialize());
$nbt->setShort("Health", (int) $this->getHealth());
if($this->despawnDelay === self::NEVER_DESPAWN){
$age = -32768;