migrate to new CompoundTag API (#1515)

This commit is contained in:
Dylan K. Taylor
2017-11-10 15:38:21 +00:00
committed by GitHub
parent d4494687d1
commit aa399a1109
20 changed files with 305 additions and 370 deletions

View File

@ -51,12 +51,10 @@ use pocketmine\math\Vector2;
use pocketmine\math\Vector3;
use pocketmine\metadata\Metadatable;
use pocketmine\metadata\MetadataValue;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\DoubleTag;
use pocketmine\nbt\tag\FloatTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\ShortTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\network\mcpe\protocol\AddEntityPacket;
use pocketmine\network\mcpe\protocol\EntityEventPacket;
@ -504,53 +502,36 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->server = $level->getServer();
$this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
$this->setPositionAndRotation(
$this->temporalVector->setComponents(
$this->namedtag["Pos"][0],
$this->namedtag["Pos"][1],
$this->namedtag["Pos"][2]
),
$this->namedtag->Rotation[0],
$this->namedtag->Rotation[1]
);
if(isset($this->namedtag->Motion)){
$this->setMotion($this->temporalVector->setComponents($this->namedtag["Motion"][0], $this->namedtag["Motion"][1], $this->namedtag["Motion"][2]));
}else{
$this->setMotion($this->temporalVector->setComponents(0, 0, 0));
/** @var float[] $pos */
$pos = $this->namedtag->getListTag("Pos")->getAllValues();
/** @var float[] $rotation */
$rotation = $this->namedtag->getListTag("Rotation")->getAllValues();
$this->setPositionAndRotation($this->temporalVector->setComponents(...$pos), ...$rotation);
/** @var float[] $motion */
$motion = [0, 0, 0];
if($this->namedtag->hasTag("Motion", ListTag::class)){
$motion = $this->namedtag->getListTag("Motion")->getAllValues();
}
$this->setMotion($this->temporalVector->setComponents(...$motion));
$this->resetLastMovements();
assert(!is_nan($this->x) and !is_infinite($this->x) and !is_nan($this->y) and !is_infinite($this->y) and !is_nan($this->z) and !is_infinite($this->z));
if(!isset($this->namedtag->FallDistance)){
$this->namedtag->FallDistance = new FloatTag("FallDistance", 0);
}
$this->fallDistance = $this->namedtag["FallDistance"];
$this->fallDistance = $this->namedtag->getFloat("FallDistance", 0);
if(!isset($this->namedtag->Fire)){
$this->namedtag->Fire = new ShortTag("Fire", 0);
}
$this->fireTicks = (int) $this->namedtag["Fire"];
$this->fireTicks = $this->namedtag->getShort("Fire", 0);
if($this->isOnFire()){
$this->setGenericFlag(self::DATA_FLAG_ONFIRE);
}
if(!isset($this->namedtag->Air)){
$this->namedtag->Air = new ShortTag("Air", 300);
}
$this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $this->namedtag["Air"], false);
if(!isset($this->namedtag->OnGround)){
$this->namedtag->OnGround = new ByteTag("OnGround", 0);
}
$this->onGround = $this->namedtag["OnGround"] !== 0;
if(!isset($this->namedtag->Invulnerable)){
$this->namedtag->Invulnerable = new ByteTag("Invulnerable", 0);
}
$this->invulnerable = $this->namedtag["Invulnerable"] !== 0;
$this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $this->namedtag->getShort("Air", 300), false);
$this->onGround = $this->namedtag->getByte("OnGround", 0) !== 0;
$this->invulnerable = $this->namedtag->getByte("Invulnerable", 0) !== 0;
$this->attributeMap = new AttributeMap();
$this->addAttributes();
@ -816,49 +797,46 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
public function saveNBT(){
if(!($this instanceof Player)){
$this->namedtag->id = new StringTag("id", $this->getSaveId());
$this->namedtag->setString("id", $this->getSaveId(), true);
if($this->getNameTag() !== ""){
$this->namedtag->CustomName = new StringTag("CustomName", $this->getNameTag());
$this->namedtag->CustomNameVisible = new ByteTag("CustomNameVisible", $this->isNameTagVisible() ? 1 : 0);
$this->namedtag->setString("CustomName", $this->getNameTag());
$this->namedtag->setByte("CustomNameVisible", $this->isNameTagVisible() ? 1 : 0);
}else{
unset($this->namedtag->CustomName);
unset($this->namedtag->CustomNameVisible);
$this->namedtag->removeTag("CustomName", "CustomNameVisible");
}
}
$this->namedtag->Pos = new ListTag("Pos", [
$this->namedtag->setTag(new ListTag("Pos", [
new DoubleTag("", $this->x),
new DoubleTag("", $this->y),
new DoubleTag("", $this->z)
]);
]));
$this->namedtag->Motion = new ListTag("Motion", [
$this->namedtag->setTag(new ListTag("Motion", [
new DoubleTag("", $this->motionX),
new DoubleTag("", $this->motionY),
new DoubleTag("", $this->motionZ)
]);
]));
$this->namedtag->Rotation = new ListTag("Rotation", [
$this->namedtag->setTag(new ListTag("Rotation", [
new FloatTag("", $this->yaw),
new FloatTag("", $this->pitch)
]);
]));
$this->namedtag->FallDistance = new FloatTag("FallDistance", $this->fallDistance);
$this->namedtag->Fire = new ShortTag("Fire", $this->fireTicks);
$this->namedtag->Air = new ShortTag("Air", $this->getDataProperty(self::DATA_AIR));
$this->namedtag->OnGround = new ByteTag("OnGround", $this->onGround ? 1 : 0);
$this->namedtag->Invulnerable = new ByteTag("Invulnerable", $this->invulnerable ? 1 : 0);
$this->namedtag->setFloat("FallDistance", $this->fallDistance);
$this->namedtag->setShort("Fire", $this->fireTicks);
$this->namedtag->setShort("Air", $this->getDataProperty(self::DATA_AIR));
$this->namedtag->setByte("OnGround", $this->onGround ? 1 : 0);
$this->namedtag->setByte("Invulnerable", $this->invulnerable ? 1 : 0);
}
protected function initEntity(){
assert($this->namedtag instanceof CompoundTag);
if(isset($this->namedtag->CustomName)){
$this->setNameTag($this->namedtag["CustomName"]);
if(isset($this->namedtag->CustomNameVisible)){
$this->setNameTagVisible($this->namedtag["CustomNameVisible"] > 0);
}
if($this->namedtag->hasTag("CustomName", StringTag::class)){
$this->setNameTag($this->namedtag->getString("CustomName"));
$this->setNameTagVisible($this->namedtag->getByte("CustomNameVisible", 1) !== 0);
}
$this->scheduleUpdate();

View File

@ -53,17 +53,13 @@ class FallingSand extends Entity{
parent::initEntity();
$blockId = 0;
$damage = 0;
if(isset($this->namedtag->TileID)){
$blockId = (int) $this->namedtag["TileID"];
}elseif(isset($this->namedtag->Tile)){
$blockId = (int) $this->namedtag["Tile"];
$this->namedtag["TileID"] = new IntTag("TileID", $blockId);
}
if(isset($this->namedtag->Data)){
$damage = (int) $this->namedtag["Data"];
//TODO: 1.8+ save format
if($this->namedtag->hasTag("TileID", IntTag::class)){
$blockId = $this->namedtag->getInt("TileID");
}elseif($this->namedtag->hasTag("Tile", ByteTag::class)){
$blockId = $this->namedtag->getByte("Tile");
$this->namedtag->removeTag("Tile");
}
if($blockId === 0){
@ -71,6 +67,8 @@ class FallingSand extends Entity{
return;
}
$damage = $this->namedtag->getByte("Data", 0);
$this->block = BlockFactory::get($blockId, $damage);
$this->setDataProperty(self::DATA_VARIANT, self::DATA_TYPE_INT, $this->block->getId() | ($this->block->getDamage() << 8));
@ -132,7 +130,7 @@ class FallingSand extends Entity{
}
public function saveNBT(){
$this->namedtag->TileID = new IntTag("TileID", $this->block->getId());
$this->namedtag->Data = new ByteTag("Data", $this->block->getDamage());
$this->namedtag->setInt("TileID", $this->block->getId(), true);
$this->namedtag->setByte("Data", $this->block->getDamage());
}
}

View File

@ -34,7 +34,6 @@ use pocketmine\item\Item as ItemItem;
use pocketmine\level\Level;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\FloatTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\StringTag;
@ -311,14 +310,15 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
* For Human entities which are not players, sets their properties such as nametag, skin and UUID from NBT.
*/
protected function initHumanData(){
if(isset($this->namedtag->NameTag)){
$this->setNameTag($this->namedtag["NameTag"]);
if($this->namedtag->hasTag("NameTag", StringTag::class)){
$this->setNameTag($this->namedtag->getString("NameTag"));
}
if(isset($this->namedtag->Skin) and $this->namedtag->Skin instanceof CompoundTag){
$skin = $this->namedtag->getCompoundTag("Skin");
if($skin !== null){
$this->setSkin(new Skin(
$this->namedtag->Skin["Name"],
$this->namedtag->Skin["Data"]
$skin->getString("Name"),
$skin->getString("Data")
));
}
@ -333,71 +333,39 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$this->inventory = new PlayerInventory($this);
$this->initHumanData();
if(isset($this->namedtag->Inventory) and $this->namedtag->Inventory instanceof ListTag){
foreach($this->namedtag->Inventory as $i => $item){
if($item["Slot"] >= 0 and $item["Slot"] < 9){ //Hotbar
$inventoryTag = $this->namedtag->getListTag("Inventory");
if($inventoryTag !== null){
/** @var CompoundTag $item */
foreach($inventoryTag as $i => $item){
$slot = $item->getByte("Slot");
if($slot >= 0 and $slot < 9){ //Hotbar
//Old hotbar saving stuff, remove it (useless now)
unset($this->namedtag->Inventory->{$i});
}elseif($item["Slot"] >= 100 and $item["Slot"] < 104){ //Armor
$this->inventory->setItem($this->inventory->getSize() + $item["Slot"] - 100, ItemItem::nbtDeserialize($item));
unset($inventoryTag[$i]);
}elseif($slot >= 100 and $slot < 104){ //Armor
$this->inventory->setItem($this->inventory->getSize() + $slot - 100, ItemItem::nbtDeserialize($item));
}else{
$this->inventory->setItem($item["Slot"] - 9, ItemItem::nbtDeserialize($item));
$this->inventory->setItem($slot - 9, ItemItem::nbtDeserialize($item));
}
}
}
if(isset($this->namedtag->SelectedInventorySlot) and $this->namedtag->SelectedInventorySlot instanceof IntTag){
$this->inventory->setHeldItemIndex($this->namedtag->SelectedInventorySlot->getValue(), false);
}else{
$this->inventory->setHeldItemIndex(0, false);
}
$this->inventory->setHeldItemIndex($this->namedtag->getInt("SelectedInventorySlot", 0), false);
parent::initEntity();
if(!isset($this->namedtag->foodLevel) or !($this->namedtag->foodLevel instanceof IntTag)){
$this->namedtag->foodLevel = new IntTag("foodLevel", (int) $this->getFood());
}else{
$this->setFood((float) $this->namedtag["foodLevel"]);
}
$this->setFood((float) $this->namedtag->getInt("foodLevel", (int) $this->getFood(), true));
$this->setExhaustion($this->namedtag->getFloat("foodExhaustionLevel", $this->getExhaustion(), true));
$this->setSaturation($this->namedtag->getFloat("foodSaturationLevel", $this->getSaturation(), true));
$this->foodTickTimer = $this->namedtag->getInt("foodTickTimer", $this->foodTickTimer, true);
if(!isset($this->namedtag->foodExhaustionLevel) or !($this->namedtag->foodExhaustionLevel instanceof FloatTag)){
$this->namedtag->foodExhaustionLevel = new FloatTag("foodExhaustionLevel", $this->getExhaustion());
}else{
$this->setExhaustion((float) $this->namedtag["foodExhaustionLevel"]);
}
$this->setXpLevel($this->namedtag->getInt("XpLevel", $this->getXpLevel(), true));
$this->setXpProgress($this->namedtag->getFloat("XpP", $this->getXpProgress(), true));
$this->totalXp = $this->namedtag->getInt("XpTotal", $this->totalXp, true);
if(!isset($this->namedtag->foodSaturationLevel) or !($this->namedtag->foodSaturationLevel instanceof FloatTag)){
$this->namedtag->foodSaturationLevel = new FloatTag("foodSaturationLevel", $this->getSaturation());
if($this->namedtag->hasTag("XpSeed", IntTag::class)){
$this->xpSeed = $this->namedtag->getInt("XpSeed");
}else{
$this->setSaturation((float) $this->namedtag["foodSaturationLevel"]);
}
if(!isset($this->namedtag->foodTickTimer) or !($this->namedtag->foodTickTimer instanceof IntTag)){
$this->namedtag->foodTickTimer = new IntTag("foodTickTimer", $this->foodTickTimer);
}else{
$this->foodTickTimer = $this->namedtag["foodTickTimer"];
}
if(!isset($this->namedtag->XpLevel) or !($this->namedtag->XpLevel instanceof IntTag)){
$this->namedtag->XpLevel = new IntTag("XpLevel", $this->getXpLevel());
}else{
$this->setXpLevel((int) $this->namedtag["XpLevel"]);
}
if(!isset($this->namedtag->XpP) or !($this->namedtag->XpP instanceof FloatTag)){
$this->namedtag->XpP = new FloatTag("XpP", $this->getXpProgress());
}
if(!isset($this->namedtag->XpTotal) or !($this->namedtag->XpTotal instanceof IntTag)){
$this->namedtag->XpTotal = new IntTag("XpTotal", $this->totalXp);
}else{
$this->totalXp = $this->namedtag["XpTotal"];
}
if(!isset($this->namedtag->XpSeed) or !($this->namedtag->XpSeed instanceof IntTag)){
$this->namedtag->XpSeed = new IntTag("XpSeed", $this->xpSeed ?? ($this->xpSeed = mt_rand(-0x80000000, 0x7fffffff)));
}else{
$this->xpSeed = $this->namedtag["XpSeed"];
$this->xpSeed = random_int(INT32_MIN, INT32_MAX);
}
}
@ -479,19 +447,25 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
public function saveNBT(){
parent::saveNBT();
$this->namedtag->foodLevel = new IntTag("foodLevel", (int) $this->getFood());
$this->namedtag->foodExhaustionLevel = new FloatTag("foodExhaustionLevel", $this->getExhaustion());
$this->namedtag->foodSaturationLevel = new FloatTag("foodSaturationLevel", $this->getSaturation());
$this->namedtag->foodTickTimer = new IntTag("foodTickTimer", $this->foodTickTimer);
$this->namedtag->setInt("foodLevel", (int) $this->getFood(), true);
$this->namedtag->setFloat("foodExhaustionLevel", $this->getExhaustion(), true);
$this->namedtag->setFloat("foodSaturationLevel", $this->getSaturation(), true);
$this->namedtag->setInt("foodTickTimer", $this->foodTickTimer);
$this->namedtag->Inventory = new ListTag("Inventory", [], NBT::TAG_Compound);
$this->namedtag->setInt("XpLevel", $this->getXpLevel());
$this->namedtag->setFloat("XpP", $this->getXpProgress());
$this->namedtag->setInt("XpTotal", $this->totalXp);
$this->namedtag->setInt("XpSeed", $this->xpSeed);
$inventoryTag = new ListTag("Inventory", [], NBT::TAG_Compound);
$this->namedtag->setTag($inventoryTag);
if($this->inventory !== null){
//Normal inventory
$slotCount = $this->inventory->getSize() + $this->inventory->getHotbarSize();
for($slot = $this->inventory->getHotbarSize(); $slot < $slotCount; ++$slot){
$item = $this->inventory->getItem($slot - 9);
if(!$item->isNull()){
$this->namedtag->Inventory[$slot] = $item->nbtSerialize($slot);
$inventoryTag[$slot] = $item->nbtSerialize($slot);
}
}
@ -499,19 +473,19 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
for($slot = 100; $slot < 104; ++$slot){
$item = $this->inventory->getItem($this->inventory->getSize() + $slot - 100);
if(!$item->isNull()){
$this->namedtag->Inventory[$slot] = $item->nbtSerialize($slot);
$inventoryTag[$slot] = $item->nbtSerialize($slot);
}
}
$this->namedtag->SelectedInventorySlot = new IntTag("SelectedInventorySlot", $this->inventory->getHeldItemIndex());
$this->namedtag->setInt("SelectedInventorySlot", $this->inventory->getHeldItemIndex());
}
if($this->skin !== null){
$this->namedtag->Skin = new CompoundTag("Skin", [
$this->namedtag->setTag(new CompoundTag("Skin", [
//TODO: save cape & geometry
new StringTag("Data", $this->skin->getSkinData()),
new StringTag("Name", $this->skin->getSkinId())
]);
]));
}
}

View File

@ -27,9 +27,6 @@ use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\ItemDespawnEvent;
use pocketmine\event\entity\ItemSpawnEvent;
use pocketmine\item\Item as ItemItem;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\ShortTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\network\mcpe\protocol\AddItemEntityPacket;
use pocketmine\Player;
@ -59,28 +56,19 @@ class Item extends Entity{
$this->setMaxHealth(5);
$this->setHealth((int) $this->namedtag["Health"]);
if(isset($this->namedtag->Age)){
$this->age = $this->namedtag["Age"];
}
if(isset($this->namedtag->PickupDelay)){
$this->pickupDelay = $this->namedtag["PickupDelay"];
}
if(isset($this->namedtag->Owner)){
$this->owner = $this->namedtag["Owner"];
}
if(isset($this->namedtag->Thrower)){
$this->thrower = $this->namedtag["Thrower"];
}
$this->age = $this->namedtag->getShort("Age", $this->age);
$this->pickupDelay = $this->namedtag->getShort("PickupDelay", $this->pickupDelay);
$this->owner = $this->namedtag->getString("Owner", $this->owner);
$this->thrower = $this->namedtag->getString("Thrower", $this->thrower);
if(!isset($this->namedtag->Item)){
$itemTag = $this->namedtag->getCompoundTag("Item");
if($itemTag === null){
$this->close();
return;
}
assert($this->namedtag->Item instanceof CompoundTag);
$this->item = ItemItem::nbtDeserialize($this->namedtag->Item);
$this->item = ItemItem::nbtDeserialize($itemTag);
$this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this));
@ -139,15 +127,15 @@ class Item extends Entity{
public function saveNBT(){
parent::saveNBT();
$this->namedtag->Item = $this->item->nbtSerialize(-1, "Item");
$this->namedtag->Health = new ShortTag("Health", (int) $this->getHealth());
$this->namedtag->Age = new ShortTag("Age", $this->age);
$this->namedtag->PickupDelay = new ShortTag("PickupDelay", $this->pickupDelay);
$this->namedtag->setTag($this->item->nbtSerialize(-1, "Item"));
$this->namedtag->setShort("Health", (int) $this->getHealth());
$this->namedtag->setShort("Age", $this->age);
$this->namedtag->setShort("PickupDelay", $this->pickupDelay);
if($this->owner !== null){
$this->namedtag->Owner = new StringTag("Owner", $this->owner);
$this->namedtag->setString("Owner", $this->owner);
}
if($this->thrower !== null){
$this->namedtag->Thrower = new StringTag("Thrower", $this->thrower);
$this->namedtag->setString("Thrower", $this->thrower);
}
}

View File

@ -65,29 +65,33 @@ abstract class Living extends Entity implements Damageable{
protected function initEntity(){
parent::initEntity();
if(isset($this->namedtag->HealF)){
$this->namedtag->Health = new FloatTag("Health", (float) $this->namedtag["HealF"]);
unset($this->namedtag->HealF);
}elseif(isset($this->namedtag->Health)){
if(!($this->namedtag->Health instanceof FloatTag)){
$this->namedtag->Health = new FloatTag("Health", (float) $this->namedtag->Health->getValue());
$health = $this->getMaxHealth();
if($this->namedtag->hasTag("HealF", FloatTag::class)){
$health = new FloatTag("Health", (float) $this->namedtag["HealF"]);
$this->namedtag->removeTag("HealF");
}elseif($this->namedtag->hasTag("Health")){
$healthTag = $this->namedtag->getTag("Health");
$health = (float) $healthTag->getValue(); //Older versions of PocketMine-MP incorrectly saved this as a short instead of a float
if(!($healthTag instanceof FloatTag)){
$this->namedtag->removeTag("Health");
}
}else{
$this->namedtag->Health = new FloatTag("Health", (float) $this->getMaxHealth());
}
$this->setHealth((float) $this->namedtag["Health"]);
$this->setHealth($health);
if(isset($this->namedtag->ActiveEffects)){
foreach($this->namedtag->ActiveEffects->getValue() as $e){
$amplifier = Binary::unsignByte($e->Amplifier->getValue()); //0-255 only
/** @var CompoundTag[]|ListTag $activeEffectsTag */
$activeEffectsTag = $this->namedtag->getListTag("ActiveEffects");
if($activeEffectsTag !== null){
foreach($activeEffectsTag as $e){
$amplifier = Binary::unsignByte($e->getByte("Amplifier")); //0-255 only
$effect = Effect::getEffect($e["Id"]);
$effect = Effect::getEffect($e->getByte("Id"));
if($effect === null){
continue;
}
$effect->setAmplifier($amplifier)->setDuration($e["Duration"])->setVisible($e["ShowParticles"] > 0);
$effect->setAmplifier($amplifier)->setDuration($e->getInt("Duration"))->setVisible($e->getByte("ShowParticles", 1) > 0);
$this->addEffect($effect);
}
@ -130,7 +134,7 @@ abstract class Living extends Entity implements Damageable{
public function saveNBT(){
parent::saveNBT();
$this->namedtag->Health = new FloatTag("Health", $this->getHealth());
$this->namedtag->setFloat("Health", $this->getHealth(), true);
if(count($this->effects) > 0){
$effects = [];
@ -144,9 +148,9 @@ abstract class Living extends Entity implements Damageable{
]);
}
$this->namedtag->ActiveEffects = new ListTag("ActiveEffects", $effects);
$this->namedtag->setTag(new ListTag("ActiveEffects", $effects));
}else{
unset($this->namedtag->ActiveEffects);
$this->namedtag->removeTag("ActiveEffects");
}
}

View File

@ -26,7 +26,7 @@ namespace pocketmine\entity;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\ExplosionPrimeEvent;
use pocketmine\level\Explosion;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\ShortTag;
use pocketmine\network\mcpe\protocol\LevelEventPacket;
class PrimedTNT extends Entity implements Explosive{
@ -54,8 +54,8 @@ class PrimedTNT extends Entity implements Explosive{
protected function initEntity(){
parent::initEntity();
if(isset($this->namedtag->Fuse)){
$this->fuse = $this->namedtag["Fuse"];
if($this->namedtag->hasTag("Fuse", ShortTag::class)){
$this->fuse = $this->namedtag->getShort("Fuse");
}else{
$this->fuse = 80;
}
@ -73,7 +73,7 @@ class PrimedTNT extends Entity implements Explosive{
public function saveNBT(){
parent::saveNBT();
$this->namedtag->Fuse = new ByteTag("Fuse", $this->fuse);
$this->namedtag->setShort("Fuse", $this->fuse, true); //older versions incorrectly saved this as a byte
}
public function entityBaseTick(int $tickDiff = 1) : bool{

View File

@ -23,8 +23,6 @@ declare(strict_types=1);
namespace pocketmine\entity;
use pocketmine\nbt\tag\IntTag;
class Villager extends Creature implements NPC, Ageable{
const PROFESSION_FARMER = 0;
const PROFESSION_LIBRARIAN = 1;
@ -45,7 +43,7 @@ class Villager extends Creature implements NPC, Ageable{
parent::initEntity();
/** @var int $profession */
$profession = $this->namedtag["Profession"] ?? self::PROFESSION_FARMER;
$profession = $this->namedtag->getInt("Profession", self::PROFESSION_FARMER);
if($profession > 4 or $profession < 0){
$profession = self::PROFESSION_FARMER;
@ -56,7 +54,7 @@ class Villager extends Creature implements NPC, Ageable{
public function saveNBT(){
parent::saveNBT();
$this->namedtag->Profession = new IntTag("Profession", $this->getProfession());
$this->namedtag->setInt("Profession", $this->getProfession());
}
/**

View File

@ -34,7 +34,6 @@ use pocketmine\level\Level;
use pocketmine\level\MovingObjectPosition;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\ShortTag;
abstract class Projectile extends Entity{
@ -62,9 +61,7 @@ abstract class Projectile extends Entity{
$this->setMaxHealth(1);
$this->setHealth(1);
if(isset($this->namedtag->Age)){
$this->age = $this->namedtag["Age"];
}
$this->age = $this->namedtag->getShort("Age", $this->age);
}
public function canCollideWith(Entity $entity) : bool{
@ -107,7 +104,7 @@ abstract class Projectile extends Entity{
public function saveNBT(){
parent::saveNBT();
$this->namedtag->Age = new ShortTag("Age", $this->age);
$this->namedtag->setShort("Age", $this->age);
}
protected function applyDragBeforeGravity() : bool{