*/ private array $idToEffect = []; /** * @var int[] * @phpstan-var array */ private array $effectToId = []; private function __construct(){ $this->register(EffectIds::SPEED, VanillaEffects::SPEED()); $this->register(EffectIds::SLOWNESS, VanillaEffects::SLOWNESS()); $this->register(EffectIds::HASTE, VanillaEffects::HASTE()); $this->register(EffectIds::MINING_FATIGUE, VanillaEffects::MINING_FATIGUE()); $this->register(EffectIds::STRENGTH, VanillaEffects::STRENGTH()); $this->register(EffectIds::INSTANT_HEALTH, VanillaEffects::INSTANT_HEALTH()); $this->register(EffectIds::INSTANT_DAMAGE, VanillaEffects::INSTANT_DAMAGE()); $this->register(EffectIds::JUMP_BOOST, VanillaEffects::JUMP_BOOST()); $this->register(EffectIds::NAUSEA, VanillaEffects::NAUSEA()); $this->register(EffectIds::REGENERATION, VanillaEffects::REGENERATION()); $this->register(EffectIds::RESISTANCE, VanillaEffects::RESISTANCE()); $this->register(EffectIds::FIRE_RESISTANCE, VanillaEffects::FIRE_RESISTANCE()); $this->register(EffectIds::WATER_BREATHING, VanillaEffects::WATER_BREATHING()); $this->register(EffectIds::INVISIBILITY, VanillaEffects::INVISIBILITY()); $this->register(EffectIds::BLINDNESS, VanillaEffects::BLINDNESS()); $this->register(EffectIds::NIGHT_VISION, VanillaEffects::NIGHT_VISION()); $this->register(EffectIds::HUNGER, VanillaEffects::HUNGER()); $this->register(EffectIds::WEAKNESS, VanillaEffects::WEAKNESS()); $this->register(EffectIds::POISON, VanillaEffects::POISON()); $this->register(EffectIds::WITHER, VanillaEffects::WITHER()); $this->register(EffectIds::HEALTH_BOOST, VanillaEffects::HEALTH_BOOST()); $this->register(EffectIds::ABSORPTION, VanillaEffects::ABSORPTION()); $this->register(EffectIds::SATURATION, VanillaEffects::SATURATION()); $this->register(EffectIds::LEVITATION, VanillaEffects::LEVITATION()); $this->register(EffectIds::FATAL_POISON, VanillaEffects::FATAL_POISON()); $this->register(EffectIds::CONDUIT_POWER, VanillaEffects::CONDUIT_POWER()); //TODO: SLOW_FALLING //TODO: BAD_OMEN //TODO: VILLAGE_HERO $this->register(EffectIds::DARKNESS, VanillaEffects::DARKNESS()); } //TODO: not a big fan of the code duplication here :( public function register(int $mcpeId, Effect $effect) : void{ $this->idToEffect[$mcpeId] = $effect; $this->effectToId[spl_object_id($effect)] = $mcpeId; } public function fromId(int $id) : ?Effect{ //we might not have all the effect IDs registered return $this->idToEffect[$id] ?? null; } public function toId(Effect $effect) : int{ if(!array_key_exists(spl_object_id($effect), $this->effectToId)){ //this should never happen, so we treat it as an exceptional condition throw new \InvalidArgumentException("Effect does not have a mapped ID"); } return $this->effectToId[spl_object_id($effect)]; } }