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

View File

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

View File

@ -32,9 +32,13 @@ final class MedicineTypeIdMap{
use IntSaveIdMapTrait;
private function __construct(){
$this->register(MedicineTypeIds::ANTIDOTE, MedicineType::ANTIDOTE);
$this->register(MedicineTypeIds::ELIXIR, MedicineType::ELIXIR);
$this->register(MedicineTypeIds::EYE_DROPS, MedicineType::EYE_DROPS);
$this->register(MedicineTypeIds::TONIC, MedicineType::TONIC);
foreach(MedicineType::cases() as $case){
$this->register(match($case){
MedicineType::ANTIDOTE => MedicineTypeIds::ANTIDOTE,
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;
private function __construct(){
$this->register(0, MobHeadType::SKELETON);
$this->register(1, MobHeadType::WITHER_SKELETON);
$this->register(2, MobHeadType::ZOMBIE);
$this->register(3, MobHeadType::PLAYER);
$this->register(4, MobHeadType::CREEPER);
$this->register(5, MobHeadType::DRAGON);
$this->register(6, MobHeadType::PIGLIN);
foreach(MobHeadType::cases() as $case){
$this->register(match($case){
MobHeadType::SKELETON => 0,
MobHeadType::WITHER_SKELETON => 1,
MobHeadType::ZOMBIE => 2,
MobHeadType::PLAYER => 3,
MobHeadType::CREEPER => 4,
MobHeadType::DRAGON => 5,
MobHeadType::PIGLIN => 6,
}, $case);
}
}
}

View File

@ -33,16 +33,20 @@ final class MushroomBlockTypeIdMap{
use IntSaveIdMapTrait;
public function __construct(){
$this->register(LegacyMeta::MUSHROOM_BLOCK_ALL_PORES, MushroomBlockType::PORES);
$this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_NORTHWEST_CORNER, MushroomBlockType::CAP_NORTHWEST);
$this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_NORTH_SIDE, MushroomBlockType::CAP_NORTH);
$this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_NORTHEAST_CORNER, MushroomBlockType::CAP_NORTHEAST);
$this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_WEST_SIDE, MushroomBlockType::CAP_WEST);
$this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_TOP_ONLY, MushroomBlockType::CAP_MIDDLE);
$this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_EAST_SIDE, MushroomBlockType::CAP_EAST);
$this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTHWEST_CORNER, MushroomBlockType::CAP_SOUTHWEST);
$this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTH_SIDE, MushroomBlockType::CAP_SOUTH);
$this->register(LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTHEAST_CORNER, MushroomBlockType::CAP_SOUTHEAST);
$this->register(LegacyMeta::MUSHROOM_BLOCK_ALL_CAP, MushroomBlockType::ALL_CAP);
foreach(MushroomBlockType::cases() as $case){
$this->register(match($case){
MushroomBlockType::PORES => LegacyMeta::MUSHROOM_BLOCK_ALL_PORES,
MushroomBlockType::CAP_NORTHWEST => LegacyMeta::MUSHROOM_BLOCK_CAP_NORTHWEST_CORNER,
MushroomBlockType::CAP_NORTH => LegacyMeta::MUSHROOM_BLOCK_CAP_NORTH_SIDE,
MushroomBlockType::CAP_NORTHEAST => LegacyMeta::MUSHROOM_BLOCK_CAP_NORTHEAST_CORNER,
MushroomBlockType::CAP_WEST => LegacyMeta::MUSHROOM_BLOCK_CAP_WEST_SIDE,
MushroomBlockType::CAP_MIDDLE => LegacyMeta::MUSHROOM_BLOCK_CAP_TOP_ONLY,
MushroomBlockType::CAP_EAST => LegacyMeta::MUSHROOM_BLOCK_CAP_EAST_SIDE,
MushroomBlockType::CAP_SOUTHWEST => LegacyMeta::MUSHROOM_BLOCK_CAP_SOUTHWEST_CORNER,
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;
private function __construct(){
$this->register(0, NoteInstrument::PIANO);
$this->register(1, NoteInstrument::BASS_DRUM);
$this->register(2, NoteInstrument::SNARE);
$this->register(3, NoteInstrument::CLICKS_AND_STICKS);
$this->register(4, NoteInstrument::DOUBLE_BASS);
$this->register(5, NoteInstrument::BELL);
$this->register(6, NoteInstrument::FLUTE);
$this->register(7, NoteInstrument::CHIME);
$this->register(8, NoteInstrument::GUITAR);
$this->register(9, NoteInstrument::XYLOPHONE);
$this->register(10, NoteInstrument::IRON_XYLOPHONE);
$this->register(11, NoteInstrument::COW_BELL);
$this->register(12, NoteInstrument::DIDGERIDOO);
$this->register(13, NoteInstrument::BIT);
$this->register(14, NoteInstrument::BANJO);
$this->register(15, NoteInstrument::PLING);
foreach(NoteInstrument::cases() as $case){
$this->register(match($case){
NoteInstrument::PIANO => 0,
NoteInstrument::BASS_DRUM => 1,
NoteInstrument::SNARE => 2,
NoteInstrument::CLICKS_AND_STICKS => 3,
NoteInstrument::DOUBLE_BASS => 4,
NoteInstrument::BELL => 5,
NoteInstrument::FLUTE => 6,
NoteInstrument::CHIME => 7,
NoteInstrument::GUITAR => 8,
NoteInstrument::XYLOPHONE => 9,
NoteInstrument::IRON_XYLOPHONE => 10,
NoteInstrument::COW_BELL => 11,
NoteInstrument::DIDGERIDOO => 12,
NoteInstrument::BIT => 13,
NoteInstrument::BANJO => 14,
NoteInstrument::PLING => 15,
}, $case);
}
}
}

View File

@ -32,48 +32,52 @@ final class PotionTypeIdMap{
use IntSaveIdMapTrait;
private function __construct(){
$this->register(PotionTypeIds::WATER, PotionType::WATER);
$this->register(PotionTypeIds::MUNDANE, PotionType::MUNDANE);
$this->register(PotionTypeIds::LONG_MUNDANE, PotionType::LONG_MUNDANE);
$this->register(PotionTypeIds::THICK, PotionType::THICK);
$this->register(PotionTypeIds::AWKWARD, PotionType::AWKWARD);
$this->register(PotionTypeIds::NIGHT_VISION, PotionType::NIGHT_VISION);
$this->register(PotionTypeIds::LONG_NIGHT_VISION, PotionType::LONG_NIGHT_VISION);
$this->register(PotionTypeIds::INVISIBILITY, PotionType::INVISIBILITY);
$this->register(PotionTypeIds::LONG_INVISIBILITY, PotionType::LONG_INVISIBILITY);
$this->register(PotionTypeIds::LEAPING, PotionType::LEAPING);
$this->register(PotionTypeIds::LONG_LEAPING, PotionType::LONG_LEAPING);
$this->register(PotionTypeIds::STRONG_LEAPING, PotionType::STRONG_LEAPING);
$this->register(PotionTypeIds::FIRE_RESISTANCE, PotionType::FIRE_RESISTANCE);
$this->register(PotionTypeIds::LONG_FIRE_RESISTANCE, PotionType::LONG_FIRE_RESISTANCE);
$this->register(PotionTypeIds::SWIFTNESS, PotionType::SWIFTNESS);
$this->register(PotionTypeIds::LONG_SWIFTNESS, PotionType::LONG_SWIFTNESS);
$this->register(PotionTypeIds::STRONG_SWIFTNESS, PotionType::STRONG_SWIFTNESS);
$this->register(PotionTypeIds::SLOWNESS, PotionType::SLOWNESS);
$this->register(PotionTypeIds::LONG_SLOWNESS, PotionType::LONG_SLOWNESS);
$this->register(PotionTypeIds::WATER_BREATHING, PotionType::WATER_BREATHING);
$this->register(PotionTypeIds::LONG_WATER_BREATHING, PotionType::LONG_WATER_BREATHING);
$this->register(PotionTypeIds::HEALING, PotionType::HEALING);
$this->register(PotionTypeIds::STRONG_HEALING, PotionType::STRONG_HEALING);
$this->register(PotionTypeIds::HARMING, PotionType::HARMING);
$this->register(PotionTypeIds::STRONG_HARMING, PotionType::STRONG_HARMING);
$this->register(PotionTypeIds::POISON, PotionType::POISON);
$this->register(PotionTypeIds::LONG_POISON, PotionType::LONG_POISON);
$this->register(PotionTypeIds::STRONG_POISON, PotionType::STRONG_POISON);
$this->register(PotionTypeIds::REGENERATION, PotionType::REGENERATION);
$this->register(PotionTypeIds::LONG_REGENERATION, PotionType::LONG_REGENERATION);
$this->register(PotionTypeIds::STRONG_REGENERATION, PotionType::STRONG_REGENERATION);
$this->register(PotionTypeIds::STRENGTH, PotionType::STRENGTH);
$this->register(PotionTypeIds::LONG_STRENGTH, PotionType::LONG_STRENGTH);
$this->register(PotionTypeIds::STRONG_STRENGTH, PotionType::STRONG_STRENGTH);
$this->register(PotionTypeIds::WEAKNESS, PotionType::WEAKNESS);
$this->register(PotionTypeIds::LONG_WEAKNESS, PotionType::LONG_WEAKNESS);
$this->register(PotionTypeIds::WITHER, PotionType::WITHER);
$this->register(PotionTypeIds::TURTLE_MASTER, PotionType::TURTLE_MASTER);
$this->register(PotionTypeIds::LONG_TURTLE_MASTER, PotionType::LONG_TURTLE_MASTER);
$this->register(PotionTypeIds::STRONG_TURTLE_MASTER, PotionType::STRONG_TURTLE_MASTER);
$this->register(PotionTypeIds::SLOW_FALLING, PotionType::SLOW_FALLING);
$this->register(PotionTypeIds::LONG_SLOW_FALLING, PotionType::LONG_SLOW_FALLING);
$this->register(PotionTypeIds::STRONG_SLOWNESS, PotionType::STRONG_SLOWNESS);
foreach(PotionType::cases() as $case){
$this->register(match($case){
PotionType::WATER => PotionTypeIds::WATER,
PotionType::MUNDANE => PotionTypeIds::MUNDANE,
PotionType::LONG_MUNDANE => PotionTypeIds::LONG_MUNDANE,
PotionType::THICK => PotionTypeIds::THICK,
PotionType::AWKWARD => PotionTypeIds::AWKWARD,
PotionType::NIGHT_VISION => PotionTypeIds::NIGHT_VISION,
PotionType::LONG_NIGHT_VISION => PotionTypeIds::LONG_NIGHT_VISION,
PotionType::INVISIBILITY => PotionTypeIds::INVISIBILITY,
PotionType::LONG_INVISIBILITY => PotionTypeIds::LONG_INVISIBILITY,
PotionType::LEAPING => PotionTypeIds::LEAPING,
PotionType::LONG_LEAPING => PotionTypeIds::LONG_LEAPING,
PotionType::STRONG_LEAPING => PotionTypeIds::STRONG_LEAPING,
PotionType::FIRE_RESISTANCE => PotionTypeIds::FIRE_RESISTANCE,
PotionType::LONG_FIRE_RESISTANCE => PotionTypeIds::LONG_FIRE_RESISTANCE,
PotionType::SWIFTNESS => PotionTypeIds::SWIFTNESS,
PotionType::LONG_SWIFTNESS => PotionTypeIds::LONG_SWIFTNESS,
PotionType::STRONG_SWIFTNESS => PotionTypeIds::STRONG_SWIFTNESS,
PotionType::SLOWNESS => PotionTypeIds::SLOWNESS,
PotionType::LONG_SLOWNESS => PotionTypeIds::LONG_SLOWNESS,
PotionType::WATER_BREATHING => PotionTypeIds::WATER_BREATHING,
PotionType::LONG_WATER_BREATHING => PotionTypeIds::LONG_WATER_BREATHING,
PotionType::HEALING => PotionTypeIds::HEALING,
PotionType::STRONG_HEALING => PotionTypeIds::STRONG_HEALING,
PotionType::HARMING => PotionTypeIds::HARMING,
PotionType::STRONG_HARMING => PotionTypeIds::STRONG_HARMING,
PotionType::POISON => PotionTypeIds::POISON,
PotionType::LONG_POISON => PotionTypeIds::LONG_POISON,
PotionType::STRONG_POISON => PotionTypeIds::STRONG_POISON,
PotionType::REGENERATION => PotionTypeIds::REGENERATION,
PotionType::LONG_REGENERATION => PotionTypeIds::LONG_REGENERATION,
PotionType::STRONG_REGENERATION => PotionTypeIds::STRONG_REGENERATION,
PotionType::STRENGTH => PotionTypeIds::STRENGTH,
PotionType::LONG_STRENGTH => PotionTypeIds::LONG_STRENGTH,
PotionType::STRONG_STRENGTH => PotionTypeIds::STRONG_STRENGTH,
PotionType::WEAKNESS => PotionTypeIds::WEAKNESS,
PotionType::LONG_WEAKNESS => PotionTypeIds::LONG_WEAKNESS,
PotionType::WITHER => PotionTypeIds::WITHER,
PotionType::TURTLE_MASTER => PotionTypeIds::TURTLE_MASTER,
PotionType::LONG_TURTLE_MASTER => PotionTypeIds::LONG_TURTLE_MASTER,
PotionType::STRONG_TURTLE_MASTER => PotionTypeIds::STRONG_TURTLE_MASTER,
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;
private function __construct(){
$this->register(SuspiciousStewTypeIds::POPPY, SuspiciousStewType::POPPY);
$this->register(SuspiciousStewTypeIds::CORNFLOWER, SuspiciousStewType::CORNFLOWER);
$this->register(SuspiciousStewTypeIds::TULIP, SuspiciousStewType::TULIP);
$this->register(SuspiciousStewTypeIds::AZURE_BLUET, SuspiciousStewType::AZURE_BLUET);
$this->register(SuspiciousStewTypeIds::LILY_OF_THE_VALLEY, SuspiciousStewType::LILY_OF_THE_VALLEY);
$this->register(SuspiciousStewTypeIds::DANDELION, SuspiciousStewType::DANDELION);
$this->register(SuspiciousStewTypeIds::BLUE_ORCHID, SuspiciousStewType::BLUE_ORCHID);
$this->register(SuspiciousStewTypeIds::ALLIUM, SuspiciousStewType::ALLIUM);
$this->register(SuspiciousStewTypeIds::OXEYE_DAISY, SuspiciousStewType::OXEYE_DAISY);
$this->register(SuspiciousStewTypeIds::WITHER_ROSE, SuspiciousStewType::WITHER_ROSE);
foreach(SuspiciousStewType::cases() as $case){
$this->register(match($case){
SuspiciousStewType::POPPY => SuspiciousStewTypeIds::POPPY,
SuspiciousStewType::CORNFLOWER => SuspiciousStewTypeIds::CORNFLOWER,
SuspiciousStewType::TULIP => SuspiciousStewTypeIds::TULIP,
SuspiciousStewType::AZURE_BLUET => SuspiciousStewTypeIds::AZURE_BLUET,
SuspiciousStewType::LILY_OF_THE_VALLEY => SuspiciousStewTypeIds::LILY_OF_THE_VALLEY,
SuspiciousStewType::DANDELION => SuspiciousStewTypeIds::DANDELION,
SuspiciousStewType::BLUE_ORCHID => SuspiciousStewTypeIds::BLUE_ORCHID,
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 = [];
public function __construct(){
$this->register(0, GameMode::SURVIVAL);
$this->register(1, GameMode::CREATIVE);
$this->register(2, GameMode::ADVENTURE);
$this->register(3, GameMode::SPECTATOR);
foreach(GameMode::cases() as $case){
$this->register(match($case){
GameMode::SURVIVAL => 0,
GameMode::CREATIVE => 1,
GameMode::ADVENTURE => 2,
GameMode::SPECTATOR => 3,
}, $case);
}
}
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);
}
}
}