mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 18:32:55 +00:00
Separated effects' MCPE ID registration from VanillaEffects
This commit is contained in:
@ -30,7 +30,7 @@ use pocketmine\entity\Living;
|
||||
class Effect{
|
||||
|
||||
/** @var int */
|
||||
protected $id;
|
||||
protected $internalRuntimeId;
|
||||
/** @var string */
|
||||
protected $name;
|
||||
/** @var Color */
|
||||
@ -41,14 +41,14 @@ class Effect{
|
||||
protected $hasBubbles;
|
||||
|
||||
/**
|
||||
* @param int $id Effect ID as per Minecraft PE
|
||||
* @param int $internalRuntimeId Internal runtime ID, unique to this effect type. Used for comparisons.
|
||||
* @param string $name Translation key used for effect name
|
||||
* @param Color $color Color of bubbles given by this effect
|
||||
* @param bool $isBad Whether the effect is harmful
|
||||
* @param bool $hasBubbles Whether the effect has potion bubbles. Some do not (e.g. Instant Damage has its own particles instead of bubbles)
|
||||
*/
|
||||
public function __construct(int $id, string $name, Color $color, bool $isBad = false, bool $hasBubbles = true){
|
||||
$this->id = $id;
|
||||
public function __construct(int $internalRuntimeId, string $name, Color $color, bool $isBad = false, bool $hasBubbles = true){
|
||||
$this->internalRuntimeId = $internalRuntimeId;
|
||||
$this->name = $name;
|
||||
$this->color = $color;
|
||||
$this->bad = $isBad;
|
||||
@ -56,10 +56,11 @@ class Effect{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the effect ID as per Minecraft PE
|
||||
* Returns a unique identifier for this effect type
|
||||
* WARNING: DO NOT STORE THIS - IT MAY CHANGE BETWEEN RESTARTS
|
||||
*/
|
||||
public function getId() : int{
|
||||
return $this->id;
|
||||
public function getRuntimeId() : int{
|
||||
return $this->internalRuntimeId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,10 +58,6 @@ class EffectInstance{
|
||||
$this->color = $overrideColor ?? $effectType->getColor();
|
||||
}
|
||||
|
||||
public function getId() : int{
|
||||
return $this->effectType->getId();
|
||||
}
|
||||
|
||||
public function getType() : Effect{
|
||||
return $this->effectType;
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ class EffectManager{
|
||||
* Removes the effect with the specified ID from the mob.
|
||||
*/
|
||||
public function remove(Effect $effectType) : void{
|
||||
$index = $effectType->getId();
|
||||
$index = $effectType->getRuntimeId();
|
||||
if(isset($this->effects[$index])){
|
||||
$effect = $this->effects[$index];
|
||||
$hasExpired = $effect->hasExpired();
|
||||
@ -113,14 +113,14 @@ class EffectManager{
|
||||
* effect.
|
||||
*/
|
||||
public function get(Effect $effect) : ?EffectInstance{
|
||||
return $this->effects[$effect->getId()] ?? null;
|
||||
return $this->effects[$effect->getRuntimeId()] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the specified effect is active on the mob.
|
||||
*/
|
||||
public function has(Effect $effect) : bool{
|
||||
return isset($this->effects[$effect->getId()]);
|
||||
return isset($this->effects[$effect->getRuntimeId()]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,7 +134,7 @@ class EffectManager{
|
||||
$oldEffect = null;
|
||||
$cancelled = false;
|
||||
|
||||
$index = $effect->getType()->getId();
|
||||
$index = $effect->getType()->getRuntimeId();
|
||||
if(isset($this->effects[$index])){
|
||||
$oldEffect = $this->effects[$index];
|
||||
if(
|
||||
|
@ -33,8 +33,8 @@ class PoisonEffect extends Effect{
|
||||
/** @var bool */
|
||||
private $fatal;
|
||||
|
||||
public function __construct(int $id, string $name, Color $color, bool $isBad = false, bool $hasBubbles = true, bool $fatal = false){
|
||||
parent::__construct($id, $name, $color, $isBad, $hasBubbles);
|
||||
public function __construct(int $internalRuntimeId, string $name, Color $color, bool $isBad = false, bool $hasBubbles = true, bool $fatal = false){
|
||||
parent::__construct($internalRuntimeId, $name, $color, $isBad, $hasBubbles);
|
||||
$this->fatal = $fatal;
|
||||
}
|
||||
|
||||
|
@ -62,9 +62,6 @@ use function assert;
|
||||
final class VanillaEffects{
|
||||
use RegistryTrait;
|
||||
|
||||
/** @var Effect[] */
|
||||
private static $mcpeIdMap = [];
|
||||
|
||||
protected static function setup() : void{
|
||||
self::register("absorption", new AbsorptionEffect(22, "%potion.absorption", new Color(0x25, 0x52, 0xa5)));
|
||||
//TODO: bad_omen
|
||||
@ -99,13 +96,6 @@ final class VanillaEffects{
|
||||
|
||||
protected static function register(string $name, Effect $member) : void{
|
||||
self::_registryRegister($name, $member);
|
||||
assert(!isset(self::$mcpeIdMap[$member->getId()]));
|
||||
self::$mcpeIdMap[$member->getId()] = $member;
|
||||
}
|
||||
|
||||
public static function byMcpeId(int $id) : ?Effect{
|
||||
self::checkInit();
|
||||
return self::$mcpeIdMap[$id] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user