mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
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:
@ -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{
|
||||
|
@ -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{
|
||||
|
@ -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{
|
||||
|
@ -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"));
|
||||
|
Reference in New Issue
Block a user