mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 16:24:05 +00:00
XpManager: add APIs to prevent owning Human from attracting XP orbs (#4623)
Fixes #4589 The following API methods are added: - `XpManager->canAttractXpOrbs()` - `XpManager->setCanAttractXpOrbs()` Possible future scope: flip this on its head to allow spectator players to attract XP orbs, in case someone wants that for some reason ??? Co-authored-by: Dylan K. Taylor <dktapps@pmmp.io>
This commit is contained in:
parent
d487e43766
commit
de82424fb2
@ -49,6 +49,9 @@ class ExperienceManager{
|
||||
/** @var int */
|
||||
private $totalXp = 0;
|
||||
|
||||
/** @var bool */
|
||||
private $canAttractXpOrbs = true;
|
||||
|
||||
/** @var int */
|
||||
private $xpCooldown = 0;
|
||||
|
||||
@ -294,4 +297,12 @@ class ExperienceManager{
|
||||
$this->xpCooldown = max(0, $this->xpCooldown - $tickDiff);
|
||||
}
|
||||
}
|
||||
|
||||
public function canAttractXpOrbs() : bool{
|
||||
return $this->canAttractXpOrbs;
|
||||
}
|
||||
|
||||
public function setCanAttractXpOrbs(bool $v = true) : void{
|
||||
$this->canAttractXpOrbs = $v;
|
||||
}
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ class ExperienceOrb extends Entity{
|
||||
}
|
||||
|
||||
$currentTarget = $this->getTargetPlayer();
|
||||
if($currentTarget !== null and (!$currentTarget->isAlive() or $currentTarget->location->distanceSquared($this->location) > self::MAX_TARGET_DISTANCE ** 2)){
|
||||
if($currentTarget !== null and (!$currentTarget->isAlive() or !$currentTarget->getXpManager()->canAttractXpOrbs() or $currentTarget->location->distanceSquared($this->location) > self::MAX_TARGET_DISTANCE ** 2)){
|
||||
$currentTarget = null;
|
||||
}
|
||||
|
||||
@ -174,7 +174,7 @@ class ExperienceOrb extends Entity{
|
||||
if($currentTarget === null){
|
||||
$newTarget = $this->getWorld()->getNearestEntity($this->location, self::MAX_TARGET_DISTANCE, Human::class);
|
||||
|
||||
if($newTarget instanceof Human and !($newTarget instanceof Player and $newTarget->isSpectator())){
|
||||
if($newTarget instanceof Human and !($newTarget instanceof Player and $newTarget->isSpectator()) and $newTarget->getXpManager()->canAttractXpOrbs()){
|
||||
$currentTarget = $newTarget;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user