Moved glazed-terracotta ID-mapping table to BlockLegacyIdHelper

This commit is contained in:
Dylan K. Taylor 2020-07-05 18:20:41 +01:00
parent eddb2b7fdd
commit 79d8bf898a
2 changed files with 40 additions and 23 deletions

View File

@ -451,35 +451,13 @@ class BlockFactory{
$this->register(new Opaque(new BID(Ids::RED_SANDSTONE, $variant), $prefix . "Red Sandstone", $sandstoneBreakInfo));
}
//region ugly glazed-terracotta colour -> ID mapping table
/** @var int[] */
$glazedTerracottaIds = [
DyeColor::WHITE()->id() => Ids::WHITE_GLAZED_TERRACOTTA,
DyeColor::ORANGE()->id() => Ids::ORANGE_GLAZED_TERRACOTTA,
DyeColor::MAGENTA()->id() => Ids::MAGENTA_GLAZED_TERRACOTTA,
DyeColor::LIGHT_BLUE()->id() => Ids::LIGHT_BLUE_GLAZED_TERRACOTTA,
DyeColor::YELLOW()->id() => Ids::YELLOW_GLAZED_TERRACOTTA,
DyeColor::LIME()->id() => Ids::LIME_GLAZED_TERRACOTTA,
DyeColor::PINK()->id() => Ids::PINK_GLAZED_TERRACOTTA,
DyeColor::GRAY()->id() => Ids::GRAY_GLAZED_TERRACOTTA,
DyeColor::LIGHT_GRAY()->id() => Ids::SILVER_GLAZED_TERRACOTTA,
DyeColor::CYAN()->id() => Ids::CYAN_GLAZED_TERRACOTTA,
DyeColor::PURPLE()->id() => Ids::PURPLE_GLAZED_TERRACOTTA,
DyeColor::BLUE()->id() => Ids::BLUE_GLAZED_TERRACOTTA,
DyeColor::BROWN()->id() => Ids::BROWN_GLAZED_TERRACOTTA,
DyeColor::GREEN()->id() => Ids::GREEN_GLAZED_TERRACOTTA,
DyeColor::RED()->id() => Ids::RED_GLAZED_TERRACOTTA,
DyeColor::BLACK()->id() => Ids::BLACK_GLAZED_TERRACOTTA
];
//endregion
foreach(DyeColor::getAll() as $color){
$this->register(new Carpet(new BID(Ids::CARPET, $color->getMagicNumber()), $color->getDisplayName() . " Carpet"));
$this->register(new Concrete(new BID(Ids::CONCRETE, $color->getMagicNumber()), $color->getDisplayName() . " Concrete"));
$this->register(new ConcretePowder(new BID(Ids::CONCRETE_POWDER, $color->getMagicNumber()), $color->getDisplayName() . " Concrete Powder"));
$this->register(new Glass(new BID(Ids::STAINED_GLASS, $color->getMagicNumber()), $color->getDisplayName() . " Stained Glass"));
$this->register(new GlassPane(new BID(Ids::STAINED_GLASS_PANE, $color->getMagicNumber()), $color->getDisplayName() . " Stained Glass Pane"));
$this->register(new GlazedTerracotta(new BID($glazedTerracottaIds[$color->id()]), $color->getDisplayName() . " Glazed Terracotta"));
$this->register(new GlazedTerracotta(BlockLegacyIdHelper::getGlazedTerracottaIdentifier($color), $color->getDisplayName() . " Glazed Terracotta"));
$this->register(new HardenedClay(new BID(Ids::STAINED_CLAY, $color->getMagicNumber()), $color->getDisplayName() . " Stained Clay"));
$this->register(new HardenedGlass(new BID(Ids::HARD_STAINED_GLASS, $color->getMagicNumber()), "Hardened " . $color->getDisplayName() . " Stained Glass"));
$this->register(new HardenedGlassPane(new BID(Ids::HARD_STAINED_GLASS_PANE, $color->getMagicNumber()), "Hardened " . $color->getDisplayName() . " Stained Glass Pane"));

View File

@ -27,6 +27,7 @@ use pocketmine\block\BlockIdentifier as BID;
use pocketmine\block\BlockIdentifierFlattened as BIDFlattened;
use pocketmine\block\BlockLegacyIds as Ids;
use pocketmine\block\tile\Sign as TileSign;
use pocketmine\block\utils\DyeColor;
use pocketmine\block\utils\TreeType;
use pocketmine\item\ItemIds;
use pocketmine\utils\AssumptionFailedError;
@ -158,4 +159,42 @@ final class BlockLegacyIdHelper{
}
throw new AssumptionFailedError("Switch should cover all wood types");
}
public static function getGlazedTerracottaIdentifier(DyeColor $color) : BlockIdentifier{
switch($color->id()){
case DyeColor::WHITE()->id():
return new BlockIdentifier(Ids::WHITE_GLAZED_TERRACOTTA);
case DyeColor::ORANGE()->id():
return new BlockIdentifier(Ids::ORANGE_GLAZED_TERRACOTTA);
case DyeColor::MAGENTA()->id():
return new BlockIdentifier(Ids::MAGENTA_GLAZED_TERRACOTTA);
case DyeColor::LIGHT_BLUE()->id():
return new BlockIdentifier(Ids::LIGHT_BLUE_GLAZED_TERRACOTTA);
case DyeColor::YELLOW()->id():
return new BlockIdentifier(Ids::YELLOW_GLAZED_TERRACOTTA);
case DyeColor::LIME()->id():
return new BlockIdentifier(Ids::LIME_GLAZED_TERRACOTTA);
case DyeColor::PINK()->id():
return new BlockIdentifier(Ids::PINK_GLAZED_TERRACOTTA);
case DyeColor::GRAY()->id():
return new BlockIdentifier(Ids::GRAY_GLAZED_TERRACOTTA);
case DyeColor::LIGHT_GRAY()->id():
return new BlockIdentifier(Ids::SILVER_GLAZED_TERRACOTTA);
case DyeColor::CYAN()->id():
return new BlockIdentifier(Ids::CYAN_GLAZED_TERRACOTTA);
case DyeColor::PURPLE()->id():
return new BlockIdentifier(Ids::PURPLE_GLAZED_TERRACOTTA);
case DyeColor::BLUE()->id():
return new BlockIdentifier(Ids::BLUE_GLAZED_TERRACOTTA);
case DyeColor::BROWN()->id():
return new BlockIdentifier(Ids::BROWN_GLAZED_TERRACOTTA);
case DyeColor::GREEN()->id():
return new BlockIdentifier(Ids::GREEN_GLAZED_TERRACOTTA);
case DyeColor::RED()->id():
return new BlockIdentifier(Ids::RED_GLAZED_TERRACOTTA);
case DyeColor::BLACK()->id():
return new BlockIdentifier(Ids::BLACK_GLAZED_TERRACOTTA);
}
throw new AssumptionFailedError("Switch should cover all wood types");
}
}