34 use IntSaveIdMapTrait {
35 register as registerInt;
42 private array $itemIdToEnum = [];
48 private array $enumToItemId = [];
50 private function __construct(){
51 foreach(DyeColor::cases() as $case){
52 [$colorId, $dyeItemId] = match($case){
53 DyeColor::WHITE => [0, ItemTypeNames::WHITE_DYE],
54 DyeColor::ORANGE => [1, ItemTypeNames::ORANGE_DYE],
55 DyeColor::MAGENTA => [2, ItemTypeNames::MAGENTA_DYE],
56 DyeColor::LIGHT_BLUE => [3, ItemTypeNames::LIGHT_BLUE_DYE],
57 DyeColor::YELLOW => [4, ItemTypeNames::YELLOW_DYE],
58 DyeColor::LIME => [5, ItemTypeNames::LIME_DYE],
59 DyeColor::PINK => [6, ItemTypeNames::PINK_DYE],
60 DyeColor::GRAY => [7, ItemTypeNames::GRAY_DYE],
61 DyeColor::LIGHT_GRAY => [8, ItemTypeNames::LIGHT_GRAY_DYE],
62 DyeColor::CYAN => [9, ItemTypeNames::CYAN_DYE],
63 DyeColor::PURPLE => [10, ItemTypeNames::PURPLE_DYE],
64 DyeColor::BLUE => [11, ItemTypeNames::BLUE_DYE],
65 DyeColor::BROWN => [12, ItemTypeNames::BROWN_DYE],
66 DyeColor::GREEN => [13, ItemTypeNames::GREEN_DYE],
67 DyeColor::RED => [14, ItemTypeNames::RED_DYE],
68 DyeColor::BLACK => [15, ItemTypeNames::BLACK_DYE],
71 $this->
register($colorId, $dyeItemId, $case);
75 private function register(
int $id,
string $itemId, DyeColor $color) :
void{
76 $this->registerInt($id, $color);
77 $this->itemIdToEnum[$itemId] = $color;
78 $this->enumToItemId[spl_object_id($color)] = $itemId;
81 public function toInvertedId(DyeColor $color) :
int{
82 return ~$this->toId($color) & 0xf;
85 public function toItemId(DyeColor $color) :
string{
86 return $this->enumToItemId[spl_object_id($color)];
89 public function fromInvertedId(
int $id) : ?DyeColor{
90 return $this->fromId(~$id & 0xf);
93 public function fromItemId(
string $itemId) : ?DyeColor{
94 return $this->itemIdToEnum[$itemId] ??
null;