mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
ExperienceOrb: Require providing XP value in constructor
This commit is contained in:
parent
981b0285d1
commit
fc70b625b3
@ -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{
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user