Drop enchantment runtime IDs

This commit is contained in:
Dylan K. Taylor
2021-09-03 21:20:43 +01:00
parent ed1e7322dd
commit c062282954
6 changed files with 34 additions and 54 deletions

View File

@ -27,6 +27,7 @@ use pocketmine\item\enchantment\Enchantment;
use pocketmine\item\enchantment\VanillaEnchantments;
use pocketmine\utils\SingletonTrait;
use function array_key_exists;
use function spl_object_id;
/**
* Handles translation of internal enchantment types to and from Minecraft: Bedrock IDs.
@ -76,7 +77,7 @@ final class EnchantmentIdMap{
public function register(int $mcpeId, Enchantment $enchantment) : void{
$this->idToEnch[$mcpeId] = $enchantment;
$this->enchToId[$enchantment->getRuntimeId()] = $mcpeId;
$this->enchToId[spl_object_id($enchantment)] = $mcpeId;
}
public function fromId(int $id) : ?Enchantment{
@ -85,10 +86,10 @@ final class EnchantmentIdMap{
}
public function toId(Enchantment $enchantment) : int{
if(!array_key_exists($enchantment->getRuntimeId(), $this->enchToId)){
if(!array_key_exists(spl_object_id($enchantment), $this->enchToId)){
//this should never happen, so we treat it as an exceptional condition
throw new \InvalidArgumentException("Enchantment does not have a mapped ID");
}
return $this->enchToId[$enchantment->getRuntimeId()];
return $this->enchToId[spl_object_id($enchantment)];
}
}