mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-18 04:00:29 +00:00
ExperienceOrb: Require providing XP value in constructor
This commit is contained in:
@@ -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{
|
||||
|
@@ -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{
|
||||
|
Reference in New Issue
Block a user