diff --git a/src/entity/EntityFactory.php b/src/entity/EntityFactory.php index d33dc442d..4724e4ebc 100644 --- a/src/entity/EntityFactory.php +++ b/src/entity/EntityFactory.php @@ -47,6 +47,7 @@ use pocketmine\nbt\NbtDataException; use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; +use pocketmine\nbt\tag\ShortTag; use pocketmine\nbt\tag\StringTag; use pocketmine\utils\SingletonTrait; use pocketmine\utils\Utils; @@ -93,7 +94,14 @@ final class EntityFactory{ }, ['ThrownExpBottle', 'minecraft:xp_bottle'], EntityLegacyIds::XP_BOTTLE); $this->register(ExperienceOrb::class, function(World $world, CompoundTag $nbt) : ExperienceOrb{ - return new ExperienceOrb(EntityDataHelper::parseLocation($nbt, $world), $nbt); + $value = 1; + if(($valuePcTag = $nbt->getTag(ExperienceOrb::TAG_VALUE_PC)) instanceof ShortTag){ //PC + $value = $valuePcTag->getValue(); + }elseif(($valuePeTag = $nbt->getTag(ExperienceOrb::TAG_VALUE_PE)) instanceof IntTag){ //PE save format + $value = $valuePeTag->getValue(); + } + + return new ExperienceOrb(EntityDataHelper::parseLocation($nbt, $world), $value, $nbt); }, ['XPOrb', 'minecraft:xp_orb'], EntityLegacyIds::XP_ORB); $this->register(FallingBlock::class, function(World $world, CompoundTag $nbt) : FallingBlock{ diff --git a/src/entity/object/ExperienceOrb.php b/src/entity/object/ExperienceOrb.php index c3f0b6382..8076dd9e7 100644 --- a/src/entity/object/ExperienceOrb.php +++ b/src/entity/object/ExperienceOrb.php @@ -26,6 +26,7 @@ namespace pocketmine\entity\object; use pocketmine\entity\Entity; use pocketmine\entity\EntitySizeInfo; use pocketmine\entity\Human; +use pocketmine\entity\Location; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; use pocketmine\nbt\tag\ShortTag; @@ -98,7 +99,12 @@ class ExperienceOrb extends Entity{ protected $targetPlayerRuntimeId = null; /** @var int */ - protected $xpValue = 1; + protected $xpValue; + + public function __construct(Location $location, int $xpValue, ?CompoundTag $nbt = null){ + $this->xpValue = $xpValue; + parent::__construct($location, $nbt); + } protected function getInitialSizeInfo() : EntitySizeInfo{ return new EntitySizeInfo(0.25, 0.25); } @@ -106,15 +112,6 @@ class ExperienceOrb extends Entity{ parent::initEntity($nbt); $this->age = $nbt->getShort("Age", 0); - - $value = 1; - if(($valuePcTag = $nbt->getTag(self::TAG_VALUE_PC)) instanceof ShortTag){ //PC - $value = $valuePcTag->getValue(); - }elseif(($valuePeTag = $nbt->getTag(self::TAG_VALUE_PE)) instanceof IntTag){ //PE save format - $value = $valuePeTag->getValue(); - } - - $this->setXpValue($value); } public function saveNBT() : CompoundTag{ diff --git a/src/world/World.php b/src/world/World.php index 06acb4871..acaf2866b 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -1616,9 +1616,8 @@ class World implements ChunkManager{ $orbs = []; foreach(ExperienceOrb::splitIntoOrbSizes($amount) as $split){ - $orb = new ExperienceOrb(Location::fromObject($pos, $this, lcg_value() * 360, 0)); + $orb = new ExperienceOrb(Location::fromObject($pos, $this, lcg_value() * 360, 0), $split); - $orb->setXpValue($split); $orb->setMotion(new Vector3((lcg_value() * 0.2 - 0.1) * 2, lcg_value() * 0.4, (lcg_value() * 0.2 - 0.1) * 2)); $orb->spawnToAll();