Block: Replace Color and WoodType magic numbers with type-safe objects

this provides automatic type safety without the need for magic number value checking everywhere.
This commit is contained in:
Dylan K. Taylor
2019-02-12 13:52:59 +00:00
parent 18440f612f
commit 7b3993730a
25 changed files with 422 additions and 250 deletions

View File

@ -38,8 +38,8 @@ class Banner extends Item{
public const TAG_PATTERN_COLOR = TileBanner::TAG_PATTERN_COLOR;
public const TAG_PATTERN_NAME = TileBanner::TAG_PATTERN_NAME;
public function __construct(int $variant){
parent::__construct(self::BANNER, $variant, "Banner");
public function __construct(int $variant, string $name){
parent::__construct(self::BANNER, $variant, $name);
}
public function getBlock() : Block{

View File

@ -27,8 +27,9 @@ use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
class Bed extends Item{
public function __construct(int $variant){
parent::__construct(self::BED, $variant, "Bed");
public function __construct(int $variant, string $name){
parent::__construct(self::BED, $variant, $name);
}
public function getBlock() : Block{

View File

@ -27,8 +27,8 @@ use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
class Dye extends Item{
public function __construct(int $variant){
parent::__construct(self::DYE, $variant, "Dye");
public function __construct(int $variant, string $name){
parent::__construct(self::DYE, $variant, $name);
}
public function getBlock() : Block{

View File

@ -25,6 +25,7 @@ namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\utils\DyeColor;
use pocketmine\entity\EntityFactory;
use pocketmine\entity\Living;
use pocketmine\nbt\tag\CompoundTag;
@ -151,11 +152,13 @@ class ItemFactory{
self::registerItem(new Item(Item::GLOWSTONE_DUST, 0, "Glowstone Dust"));
self::registerItem(new RawFish());
self::registerItem(new CookedFish());
for($i = 0; $i < 16; ++$i){
//TODO: add colour constants (this is messy)
self::registerItem(new Dye($i));
self::registerItem(new Bed($i));
self::registerItem(new Banner($i));
foreach(DyeColor::getAll() as $color){
//TODO: use colour object directly
//TODO: add interface to dye-colour objects
//TODO: new dedicated dyes
self::registerItem(new Dye($color->getInvertedMagicNumber(), $color->getDisplayName() . " Dye"));
self::registerItem(new Bed($color->getMagicNumber(), $color->getDisplayName() . " Bed"));
self::registerItem(new Banner($color->getInvertedMagicNumber(), $color->getDisplayName() . " Banner"));
}
self::registerItem(new Item(Item::BONE, 0, "Bone"));
self::registerItem(new Item(Item::SUGAR, 0, "Sugar"));