data: Use statically analyzable ways of ensuring all cases are registered

PHPStan will verify that these matches cover all cases, which guarantees that all cases will be covered.
In addition, if PHPStan is not used, the constructors will immediately bail out when they hit a case that isn't covered.
The only downside is the extra indentation :(
This commit is contained in:
Dylan K. Taylor 2023-12-20 16:06:54 +00:00
parent c51b1b2812
commit 57f3a04bc5
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
10 changed files with 188 additions and 187 deletions

View File

@ -43,44 +43,48 @@ final class BannerPatternTypeIdMap{
private array $enumToId = []; private array $enumToId = [];
public function __construct(){ public function __construct(){
$this->register("bo", BannerPatternType::BORDER); foreach(BannerPatternType::cases() as $case){
$this->register("bri", BannerPatternType::BRICKS); $this->register(match($case){
$this->register("mc", BannerPatternType::CIRCLE); BannerPatternType::BORDER => "bo",
$this->register("cre", BannerPatternType::CREEPER); BannerPatternType::BRICKS => "bri",
$this->register("cr", BannerPatternType::CROSS); BannerPatternType::CIRCLE => "mc",
$this->register("cbo", BannerPatternType::CURLY_BORDER); BannerPatternType::CREEPER => "cre",
$this->register("lud", BannerPatternType::DIAGONAL_LEFT); BannerPatternType::CROSS => "cr",
$this->register("rd", BannerPatternType::DIAGONAL_RIGHT); BannerPatternType::CURLY_BORDER => "cbo",
$this->register("ld", BannerPatternType::DIAGONAL_UP_LEFT); BannerPatternType::DIAGONAL_LEFT => "lud",
$this->register("rud", BannerPatternType::DIAGONAL_UP_RIGHT); BannerPatternType::DIAGONAL_RIGHT => "rd",
$this->register("flo", BannerPatternType::FLOWER); BannerPatternType::DIAGONAL_UP_LEFT => "ld",
$this->register("gra", BannerPatternType::GRADIENT); BannerPatternType::DIAGONAL_UP_RIGHT => "rud",
$this->register("gru", BannerPatternType::GRADIENT_UP); BannerPatternType::FLOWER => "flo",
$this->register("hh", BannerPatternType::HALF_HORIZONTAL); BannerPatternType::GRADIENT => "gra",
$this->register("hhb", BannerPatternType::HALF_HORIZONTAL_BOTTOM); BannerPatternType::GRADIENT_UP => "gru",
$this->register("vh", BannerPatternType::HALF_VERTICAL); BannerPatternType::HALF_HORIZONTAL => "hh",
$this->register("vhr", BannerPatternType::HALF_VERTICAL_RIGHT); BannerPatternType::HALF_HORIZONTAL_BOTTOM => "hhb",
$this->register("moj", BannerPatternType::MOJANG); BannerPatternType::HALF_VERTICAL => "vh",
$this->register("mr", BannerPatternType::RHOMBUS); BannerPatternType::HALF_VERTICAL_RIGHT => "vhr",
$this->register("sku", BannerPatternType::SKULL); BannerPatternType::MOJANG => "moj",
$this->register("ss", BannerPatternType::SMALL_STRIPES); BannerPatternType::RHOMBUS => "mr",
$this->register("bl", BannerPatternType::SQUARE_BOTTOM_LEFT); BannerPatternType::SKULL => "sku",
$this->register("br", BannerPatternType::SQUARE_BOTTOM_RIGHT); BannerPatternType::SMALL_STRIPES => "ss",
$this->register("tl", BannerPatternType::SQUARE_TOP_LEFT); BannerPatternType::SQUARE_BOTTOM_LEFT => "bl",
$this->register("tr", BannerPatternType::SQUARE_TOP_RIGHT); BannerPatternType::SQUARE_BOTTOM_RIGHT => "br",
$this->register("sc", BannerPatternType::STRAIGHT_CROSS); BannerPatternType::SQUARE_TOP_LEFT => "tl",
$this->register("bs", BannerPatternType::STRIPE_BOTTOM); BannerPatternType::SQUARE_TOP_RIGHT => "tr",
$this->register("cs", BannerPatternType::STRIPE_CENTER); BannerPatternType::STRAIGHT_CROSS => "sc",
$this->register("dls", BannerPatternType::STRIPE_DOWNLEFT); BannerPatternType::STRIPE_BOTTOM => "bs",
$this->register("drs", BannerPatternType::STRIPE_DOWNRIGHT); BannerPatternType::STRIPE_CENTER => "cs",
$this->register("ls", BannerPatternType::STRIPE_LEFT); BannerPatternType::STRIPE_DOWNLEFT => "dls",
$this->register("ms", BannerPatternType::STRIPE_MIDDLE); BannerPatternType::STRIPE_DOWNRIGHT => "drs",
$this->register("rs", BannerPatternType::STRIPE_RIGHT); BannerPatternType::STRIPE_LEFT => "ls",
$this->register("ts", BannerPatternType::STRIPE_TOP); BannerPatternType::STRIPE_MIDDLE => "ms",
$this->register("bt", BannerPatternType::TRIANGLE_BOTTOM); BannerPatternType::STRIPE_RIGHT => "rs",
$this->register("tt", BannerPatternType::TRIANGLE_TOP); BannerPatternType::STRIPE_TOP => "ts",
$this->register("bts", BannerPatternType::TRIANGLES_BOTTOM); BannerPatternType::TRIANGLE_BOTTOM => "bt",
$this->register("tts", BannerPatternType::TRIANGLES_TOP); BannerPatternType::TRIANGLE_TOP => "tt",
BannerPatternType::TRIANGLES_BOTTOM => "bts",
BannerPatternType::TRIANGLES_TOP => "tts",
}, $case);
}
} }
public function register(string $stringId, BannerPatternType $type) : void{ public function register(string $stringId, BannerPatternType $type) : void{

View File

@ -48,22 +48,28 @@ final class DyeColorIdMap{
private array $enumToItemId = []; private array $enumToItemId = [];
private function __construct(){ private function __construct(){
$this->register(0, ItemTypeNames::WHITE_DYE, DyeColor::WHITE); foreach(DyeColor::cases() as $case){
$this->register(1, ItemTypeNames::ORANGE_DYE, DyeColor::ORANGE); [$colorId, $dyeItemId] = match($case){
$this->register(2, ItemTypeNames::MAGENTA_DYE, DyeColor::MAGENTA); DyeColor::WHITE => [0, ItemTypeNames::WHITE_DYE],
$this->register(3, ItemTypeNames::LIGHT_BLUE_DYE, DyeColor::LIGHT_BLUE); DyeColor::ORANGE => [1, ItemTypeNames::ORANGE_DYE],
$this->register(4, ItemTypeNames::YELLOW_DYE, DyeColor::YELLOW); DyeColor::MAGENTA => [2, ItemTypeNames::MAGENTA_DYE],
$this->register(5, ItemTypeNames::LIME_DYE, DyeColor::LIME); DyeColor::LIGHT_BLUE => [3, ItemTypeNames::LIGHT_BLUE_DYE],
$this->register(6, ItemTypeNames::PINK_DYE, DyeColor::PINK); DyeColor::YELLOW => [4, ItemTypeNames::YELLOW_DYE],
$this->register(7, ItemTypeNames::GRAY_DYE, DyeColor::GRAY); DyeColor::LIME => [5, ItemTypeNames::LIME_DYE],
$this->register(8, ItemTypeNames::LIGHT_GRAY_DYE, DyeColor::LIGHT_GRAY); DyeColor::PINK => [6, ItemTypeNames::PINK_DYE],
$this->register(9, ItemTypeNames::CYAN_DYE, DyeColor::CYAN); DyeColor::GRAY => [7, ItemTypeNames::GRAY_DYE],
$this->register(10, ItemTypeNames::PURPLE_DYE, DyeColor::PURPLE); DyeColor::LIGHT_GRAY => [8, ItemTypeNames::LIGHT_GRAY_DYE],
$this->register(11, ItemTypeNames::BLUE_DYE, DyeColor::BLUE); DyeColor::CYAN => [9, ItemTypeNames::CYAN_DYE],
$this->register(12, ItemTypeNames::BROWN_DYE, DyeColor::BROWN); DyeColor::PURPLE => [10, ItemTypeNames::PURPLE_DYE],
$this->register(13, ItemTypeNames::GREEN_DYE, DyeColor::GREEN); DyeColor::BLUE => [11, ItemTypeNames::BLUE_DYE],
$this->register(14, ItemTypeNames::RED_DYE, DyeColor::RED); DyeColor::BROWN => [12, ItemTypeNames::BROWN_DYE],
$this->register(15, ItemTypeNames::BLACK_DYE, DyeColor::BLACK); DyeColor::GREEN => [13, ItemTypeNames::GREEN_DYE],
DyeColor::RED => [14, ItemTypeNames::RED_DYE],
DyeColor::BLACK => [15, ItemTypeNames::BLACK_DYE],
};
$this->register($colorId, $dyeItemId, $case);
}
} }
private function register(int $id, string $itemId, DyeColor $color) : void{ private function register(int $id, string $itemId, DyeColor $color) : void{

View File

@ -32,9 +32,13 @@ final class MedicineTypeIdMap{
use IntSaveIdMapTrait; use IntSaveIdMapTrait;
private function __construct(){ private function __construct(){
$this->register(MedicineTypeIds::ANTIDOTE, MedicineType::ANTIDOTE); foreach(MedicineType::cases() as $case){
$this->register(MedicineTypeIds::ELIXIR, MedicineType::ELIXIR); $this->register(match($case){
$this->register(MedicineTypeIds::EYE_DROPS, MedicineType::EYE_DROPS); MedicineType::ANTIDOTE => MedicineTypeIds::ANTIDOTE,
$this->register(MedicineTypeIds::TONIC, MedicineType::TONIC); MedicineType::ELIXIR => MedicineTypeIds::ELIXIR,
MedicineType::EYE_DROPS => MedicineTypeIds::EYE_DROPS,
MedicineType::TONIC => MedicineTypeIds::TONIC,
}, $case);
}
} }
} }

View File

@ -32,12 +32,16 @@ final class MobHeadTypeIdMap{
use IntSaveIdMapTrait; use IntSaveIdMapTrait;
private function __construct(){ private function __construct(){
$this->register(0, MobHeadType::SKELETON); foreach(MobHeadType::cases() as $case){
$this->register(1, MobHeadType::WITHER_SKELETON); $this->register(match($case){
$this->register(2, MobHeadType::ZOMBIE); MobHeadType::SKELETON => 0,
$this->register(3, MobHeadType::PLAYER); MobHeadType::WITHER_SKELETON => 1,
$this->register(4, MobHeadType::CREEPER); MobHeadType::ZOMBIE => 2,
$this->register(5, MobHeadType::DRAGON); MobHeadType::PLAYER => 3,
$this->register(6, MobHeadType::PIGLIN); MobHeadType::CREEPER => 4,
MobHeadType::DRAGON => 5,
MobHeadType::PIGLIN => 6,
}, $case);
}
} }
} }

View File

@ -33,16 +33,20 @@ final class MushroomBlockTypeIdMap{
use IntSaveIdMapTrait; use IntSaveIdMapTrait;
public function __construct(){ public function __construct(){
$this->register(LegacyMeta::MUSHROOM_BLOCK_ALL_PORES, MushroomBlockType::PORES); foreach(MushroomBlockType::cases() as $case){
$this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_NORTHWEST_CORNER, MushroomBlockType::CAP_NORTHWEST); $this->register(match($case){
$this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_NORTH_SIDE, MushroomBlockType::CAP_NORTH); MushroomBlockType::PORES => LegacyMeta::MUSHROOM_BLOCK_ALL_PORES,
$this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_NORTHEAST_CORNER, MushroomBlockType::CAP_NORTHEAST); MushroomBlockType::CAP_NORTHWEST => LegacyMeta::MUSHROOM_BLOCK_CAP_NORTHWEST_CORNER,
$this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_WEST_SIDE, MushroomBlockType::CAP_WEST); MushroomBlockType::CAP_NORTH => LegacyMeta::MUSHROOM_BLOCK_CAP_NORTH_SIDE,
$this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_TOP_ONLY, MushroomBlockType::CAP_MIDDLE); MushroomBlockType::CAP_NORTHEAST => LegacyMeta::MUSHROOM_BLOCK_CAP_NORTHEAST_CORNER,
$this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_EAST_SIDE, MushroomBlockType::CAP_EAST); MushroomBlockType::CAP_WEST => LegacyMeta::MUSHROOM_BLOCK_CAP_WEST_SIDE,
$this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTHWEST_CORNER, MushroomBlockType::CAP_SOUTHWEST); MushroomBlockType::CAP_MIDDLE => LegacyMeta::MUSHROOM_BLOCK_CAP_TOP_ONLY,
$this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTH_SIDE, MushroomBlockType::CAP_SOUTH); MushroomBlockType::CAP_EAST => LegacyMeta::MUSHROOM_BLOCK_CAP_EAST_SIDE,
$this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTHEAST_CORNER, MushroomBlockType::CAP_SOUTHEAST); MushroomBlockType::CAP_SOUTHWEST => LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTHWEST_CORNER,
$this->register(LegacyMeta::MUSHROOM_BLOCK_ALL_CAP, MushroomBlockType::ALL_CAP); MushroomBlockType::CAP_SOUTH => LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTH_SIDE,
MushroomBlockType::CAP_SOUTHEAST => LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTHEAST_CORNER,
MushroomBlockType::ALL_CAP => LegacyMeta::MUSHROOM_BLOCK_ALL_CAP,
}, $case);
}
} }
} }

View File

@ -32,21 +32,25 @@ final class NoteInstrumentIdMap{
use IntSaveIdMapTrait; use IntSaveIdMapTrait;
private function __construct(){ private function __construct(){
$this->register(0, NoteInstrument::PIANO); foreach(NoteInstrument::cases() as $case){
$this->register(1, NoteInstrument::BASS_DRUM); $this->register(match($case){
$this->register(2, NoteInstrument::SNARE); NoteInstrument::PIANO => 0,
$this->register(3, NoteInstrument::CLICKS_AND_STICKS); NoteInstrument::BASS_DRUM => 1,
$this->register(4, NoteInstrument::DOUBLE_BASS); NoteInstrument::SNARE => 2,
$this->register(5, NoteInstrument::BELL); NoteInstrument::CLICKS_AND_STICKS => 3,
$this->register(6, NoteInstrument::FLUTE); NoteInstrument::DOUBLE_BASS => 4,
$this->register(7, NoteInstrument::CHIME); NoteInstrument::BELL => 5,
$this->register(8, NoteInstrument::GUITAR); NoteInstrument::FLUTE => 6,
$this->register(9, NoteInstrument::XYLOPHONE); NoteInstrument::CHIME => 7,
$this->register(10, NoteInstrument::IRON_XYLOPHONE); NoteInstrument::GUITAR => 8,
$this->register(11, NoteInstrument::COW_BELL); NoteInstrument::XYLOPHONE => 9,
$this->register(12, NoteInstrument::DIDGERIDOO); NoteInstrument::IRON_XYLOPHONE => 10,
$this->register(13, NoteInstrument::BIT); NoteInstrument::COW_BELL => 11,
$this->register(14, NoteInstrument::BANJO); NoteInstrument::DIDGERIDOO => 12,
$this->register(15, NoteInstrument::PLING); NoteInstrument::BIT => 13,
NoteInstrument::BANJO => 14,
NoteInstrument::PLING => 15,
}, $case);
}
} }
} }

View File

@ -32,48 +32,52 @@ final class PotionTypeIdMap{
use IntSaveIdMapTrait; use IntSaveIdMapTrait;
private function __construct(){ private function __construct(){
$this->register(PotionTypeIds::WATER, PotionType::WATER); foreach(PotionType::cases() as $case){
$this->register(PotionTypeIds::MUNDANE, PotionType::MUNDANE); $this->register(match($case){
$this->register(PotionTypeIds::LONG_MUNDANE, PotionType::LONG_MUNDANE); PotionType::WATER => PotionTypeIds::WATER,
$this->register(PotionTypeIds::THICK, PotionType::THICK); PotionType::MUNDANE => PotionTypeIds::MUNDANE,
$this->register(PotionTypeIds::AWKWARD, PotionType::AWKWARD); PotionType::LONG_MUNDANE => PotionTypeIds::LONG_MUNDANE,
$this->register(PotionTypeIds::NIGHT_VISION, PotionType::NIGHT_VISION); PotionType::THICK => PotionTypeIds::THICK,
$this->register(PotionTypeIds::LONG_NIGHT_VISION, PotionType::LONG_NIGHT_VISION); PotionType::AWKWARD => PotionTypeIds::AWKWARD,
$this->register(PotionTypeIds::INVISIBILITY, PotionType::INVISIBILITY); PotionType::NIGHT_VISION => PotionTypeIds::NIGHT_VISION,
$this->register(PotionTypeIds::LONG_INVISIBILITY, PotionType::LONG_INVISIBILITY); PotionType::LONG_NIGHT_VISION => PotionTypeIds::LONG_NIGHT_VISION,
$this->register(PotionTypeIds::LEAPING, PotionType::LEAPING); PotionType::INVISIBILITY => PotionTypeIds::INVISIBILITY,
$this->register(PotionTypeIds::LONG_LEAPING, PotionType::LONG_LEAPING); PotionType::LONG_INVISIBILITY => PotionTypeIds::LONG_INVISIBILITY,
$this->register(PotionTypeIds::STRONG_LEAPING, PotionType::STRONG_LEAPING); PotionType::LEAPING => PotionTypeIds::LEAPING,
$this->register(PotionTypeIds::FIRE_RESISTANCE, PotionType::FIRE_RESISTANCE); PotionType::LONG_LEAPING => PotionTypeIds::LONG_LEAPING,
$this->register(PotionTypeIds::LONG_FIRE_RESISTANCE, PotionType::LONG_FIRE_RESISTANCE); PotionType::STRONG_LEAPING => PotionTypeIds::STRONG_LEAPING,
$this->register(PotionTypeIds::SWIFTNESS, PotionType::SWIFTNESS); PotionType::FIRE_RESISTANCE => PotionTypeIds::FIRE_RESISTANCE,
$this->register(PotionTypeIds::LONG_SWIFTNESS, PotionType::LONG_SWIFTNESS); PotionType::LONG_FIRE_RESISTANCE => PotionTypeIds::LONG_FIRE_RESISTANCE,
$this->register(PotionTypeIds::STRONG_SWIFTNESS, PotionType::STRONG_SWIFTNESS); PotionType::SWIFTNESS => PotionTypeIds::SWIFTNESS,
$this->register(PotionTypeIds::SLOWNESS, PotionType::SLOWNESS); PotionType::LONG_SWIFTNESS => PotionTypeIds::LONG_SWIFTNESS,
$this->register(PotionTypeIds::LONG_SLOWNESS, PotionType::LONG_SLOWNESS); PotionType::STRONG_SWIFTNESS => PotionTypeIds::STRONG_SWIFTNESS,
$this->register(PotionTypeIds::WATER_BREATHING, PotionType::WATER_BREATHING); PotionType::SLOWNESS => PotionTypeIds::SLOWNESS,
$this->register(PotionTypeIds::LONG_WATER_BREATHING, PotionType::LONG_WATER_BREATHING); PotionType::LONG_SLOWNESS => PotionTypeIds::LONG_SLOWNESS,
$this->register(PotionTypeIds::HEALING, PotionType::HEALING); PotionType::WATER_BREATHING => PotionTypeIds::WATER_BREATHING,
$this->register(PotionTypeIds::STRONG_HEALING, PotionType::STRONG_HEALING); PotionType::LONG_WATER_BREATHING => PotionTypeIds::LONG_WATER_BREATHING,
$this->register(PotionTypeIds::HARMING, PotionType::HARMING); PotionType::HEALING => PotionTypeIds::HEALING,
$this->register(PotionTypeIds::STRONG_HARMING, PotionType::STRONG_HARMING); PotionType::STRONG_HEALING => PotionTypeIds::STRONG_HEALING,
$this->register(PotionTypeIds::POISON, PotionType::POISON); PotionType::HARMING => PotionTypeIds::HARMING,
$this->register(PotionTypeIds::LONG_POISON, PotionType::LONG_POISON); PotionType::STRONG_HARMING => PotionTypeIds::STRONG_HARMING,
$this->register(PotionTypeIds::STRONG_POISON, PotionType::STRONG_POISON); PotionType::POISON => PotionTypeIds::POISON,
$this->register(PotionTypeIds::REGENERATION, PotionType::REGENERATION); PotionType::LONG_POISON => PotionTypeIds::LONG_POISON,
$this->register(PotionTypeIds::LONG_REGENERATION, PotionType::LONG_REGENERATION); PotionType::STRONG_POISON => PotionTypeIds::STRONG_POISON,
$this->register(PotionTypeIds::STRONG_REGENERATION, PotionType::STRONG_REGENERATION); PotionType::REGENERATION => PotionTypeIds::REGENERATION,
$this->register(PotionTypeIds::STRENGTH, PotionType::STRENGTH); PotionType::LONG_REGENERATION => PotionTypeIds::LONG_REGENERATION,
$this->register(PotionTypeIds::LONG_STRENGTH, PotionType::LONG_STRENGTH); PotionType::STRONG_REGENERATION => PotionTypeIds::STRONG_REGENERATION,
$this->register(PotionTypeIds::STRONG_STRENGTH, PotionType::STRONG_STRENGTH); PotionType::STRENGTH => PotionTypeIds::STRENGTH,
$this->register(PotionTypeIds::WEAKNESS, PotionType::WEAKNESS); PotionType::LONG_STRENGTH => PotionTypeIds::LONG_STRENGTH,
$this->register(PotionTypeIds::LONG_WEAKNESS, PotionType::LONG_WEAKNESS); PotionType::STRONG_STRENGTH => PotionTypeIds::STRONG_STRENGTH,
$this->register(PotionTypeIds::WITHER, PotionType::WITHER); PotionType::WEAKNESS => PotionTypeIds::WEAKNESS,
$this->register(PotionTypeIds::TURTLE_MASTER, PotionType::TURTLE_MASTER); PotionType::LONG_WEAKNESS => PotionTypeIds::LONG_WEAKNESS,
$this->register(PotionTypeIds::LONG_TURTLE_MASTER, PotionType::LONG_TURTLE_MASTER); PotionType::WITHER => PotionTypeIds::WITHER,
$this->register(PotionTypeIds::STRONG_TURTLE_MASTER, PotionType::STRONG_TURTLE_MASTER); PotionType::TURTLE_MASTER => PotionTypeIds::TURTLE_MASTER,
$this->register(PotionTypeIds::SLOW_FALLING, PotionType::SLOW_FALLING); PotionType::LONG_TURTLE_MASTER => PotionTypeIds::LONG_TURTLE_MASTER,
$this->register(PotionTypeIds::LONG_SLOW_FALLING, PotionType::LONG_SLOW_FALLING); PotionType::STRONG_TURTLE_MASTER => PotionTypeIds::STRONG_TURTLE_MASTER,
$this->register(PotionTypeIds::STRONG_SLOWNESS, PotionType::STRONG_SLOWNESS); PotionType::SLOW_FALLING => PotionTypeIds::SLOW_FALLING,
PotionType::LONG_SLOW_FALLING => PotionTypeIds::LONG_SLOW_FALLING,
PotionType::STRONG_SLOWNESS => PotionTypeIds::STRONG_SLOWNESS,
}, $case);
}
} }
} }

View File

@ -32,15 +32,20 @@ final class SuspiciousStewTypeIdMap{
use IntSaveIdMapTrait; use IntSaveIdMapTrait;
private function __construct(){ private function __construct(){
$this->register(SuspiciousStewTypeIds::POPPY, SuspiciousStewType::POPPY); foreach(SuspiciousStewType::cases() as $case){
$this->register(SuspiciousStewTypeIds::CORNFLOWER, SuspiciousStewType::CORNFLOWER); $this->register(match($case){
$this->register(SuspiciousStewTypeIds::TULIP, SuspiciousStewType::TULIP); SuspiciousStewType::POPPY => SuspiciousStewTypeIds::POPPY,
$this->register(SuspiciousStewTypeIds::AZURE_BLUET, SuspiciousStewType::AZURE_BLUET); SuspiciousStewType::CORNFLOWER => SuspiciousStewTypeIds::CORNFLOWER,
$this->register(SuspiciousStewTypeIds::LILY_OF_THE_VALLEY, SuspiciousStewType::LILY_OF_THE_VALLEY); SuspiciousStewType::TULIP => SuspiciousStewTypeIds::TULIP,
$this->register(SuspiciousStewTypeIds::DANDELION, SuspiciousStewType::DANDELION); SuspiciousStewType::AZURE_BLUET => SuspiciousStewTypeIds::AZURE_BLUET,
$this->register(SuspiciousStewTypeIds::BLUE_ORCHID, SuspiciousStewType::BLUE_ORCHID); SuspiciousStewType::LILY_OF_THE_VALLEY => SuspiciousStewTypeIds::LILY_OF_THE_VALLEY,
$this->register(SuspiciousStewTypeIds::ALLIUM, SuspiciousStewType::ALLIUM); SuspiciousStewType::DANDELION => SuspiciousStewTypeIds::DANDELION,
$this->register(SuspiciousStewTypeIds::OXEYE_DAISY, SuspiciousStewType::OXEYE_DAISY); SuspiciousStewType::BLUE_ORCHID => SuspiciousStewTypeIds::BLUE_ORCHID,
$this->register(SuspiciousStewTypeIds::WITHER_ROSE, SuspiciousStewType::WITHER_ROSE); SuspiciousStewType::ALLIUM => SuspiciousStewTypeIds::ALLIUM,
SuspiciousStewType::OXEYE_DAISY => SuspiciousStewTypeIds::OXEYE_DAISY,
SuspiciousStewType::WITHER_ROSE => SuspiciousStewTypeIds::WITHER_ROSE,
}, $case);
}
} }
} }

View File

@ -44,10 +44,14 @@ final class GameModeIdMap{
private array $enumToId = []; private array $enumToId = [];
public function __construct(){ public function __construct(){
$this->register(0, GameMode::SURVIVAL); foreach(GameMode::cases() as $case){
$this->register(1, GameMode::CREATIVE); $this->register(match($case){
$this->register(2, GameMode::ADVENTURE); GameMode::SURVIVAL => 0,
$this->register(3, GameMode::SPECTATOR); GameMode::CREATIVE => 1,
GameMode::ADVENTURE => 2,
GameMode::SPECTATOR => 3,
}, $case);
}
} }
private function register(int $id, GameMode $type) : void{ private function register(int $id, GameMode $type) : void{

View File

@ -1,38 +0,0 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\data\bedrock;
use PHPUnit\Framework\TestCase;
use pocketmine\block\utils\DyeColor;
class DyeColorIdMapTest extends TestCase{
public function testAllColorsMapped() : void{
foreach(DyeColor::cases() as $color){
$id = DyeColorIdMap::getInstance()->toId($color);
$color2 = DyeColorIdMap::getInstance()->fromId($id);
self::assertTrue($color === $color2);
}
}
}