mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-18 11:45:30 +00:00
Dye, banner and bed items now store DyeColor objects instead of using magic meta values
This commit is contained in:
parent
0bd1c1529e
commit
97687f2236
@ -25,6 +25,7 @@ namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\BlockDataValidator;
|
||||
use pocketmine\block\utils\DyeColor;
|
||||
use pocketmine\item\Bed as ItemBed;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\ItemFactory;
|
||||
use pocketmine\lang\TranslationContainer;
|
||||
@ -175,7 +176,9 @@ class Bed extends Transparent{
|
||||
}
|
||||
|
||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||
$this->color = DyeColor::fromMagicNumber($item->getDamage()); //TODO: replace this with a proper colour getter
|
||||
if($item instanceof ItemBed){ //TODO: the item should do this
|
||||
$this->color = $item->getColor();
|
||||
}
|
||||
$down = $this->getSide(Facing::DOWN);
|
||||
if(!$down->isTransparent()){
|
||||
$this->facing = $player !== null ? $player->getHorizontalFacing() : Facing::NORTH;
|
||||
|
@ -34,13 +34,23 @@ use pocketmine\tile\Banner as TileBanner;
|
||||
use function assert;
|
||||
|
||||
class Banner extends Item{
|
||||
public const TAG_BASE = TileBanner::TAG_BASE;
|
||||
public const TAG_PATTERNS = TileBanner::TAG_PATTERNS;
|
||||
public const TAG_PATTERN_COLOR = TileBanner::TAG_PATTERN_COLOR;
|
||||
public const TAG_PATTERN_NAME = TileBanner::TAG_PATTERN_NAME;
|
||||
|
||||
public function __construct(int $variant, string $name){
|
||||
/** @var DyeColor */
|
||||
private $color;
|
||||
|
||||
public function __construct(int $variant, string $name, DyeColor $color){
|
||||
parent::__construct(self::BANNER, $variant, $name);
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DyeColor
|
||||
*/
|
||||
public function getColor() : DyeColor{
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
public function getBlock() : Block{
|
||||
@ -51,27 +61,6 @@ class Banner extends Item{
|
||||
return 16;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the color of the banner base.
|
||||
*
|
||||
* @return DyeColor
|
||||
*/
|
||||
public function getBaseColor() : DyeColor{
|
||||
return DyeColor::fromMagicNumber($this->getNamedTag()->getInt(self::TAG_BASE, $this->getDamage()), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color of the banner base.
|
||||
* Banner items have to be resent to see the changes in the inventory.
|
||||
*
|
||||
* @param DyeColor $color
|
||||
*/
|
||||
public function setBaseColor(DyeColor $color) : void{
|
||||
$namedTag = $this->getNamedTag();
|
||||
$namedTag->setInt(self::TAG_BASE, $color->getInvertedMagicNumber());
|
||||
$this->setNamedTag($namedTag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies a new pattern on the banner with the given color.
|
||||
* Banner items have to be resent to see the changes in the inventory.
|
||||
@ -224,9 +213,6 @@ class Banner extends Item{
|
||||
|
||||
public function correctNBT() : void{
|
||||
$tag = $this->getNamedTag();
|
||||
if(!$tag->hasTag(self::TAG_BASE, IntTag::class)){
|
||||
$tag->setInt(self::TAG_BASE, DyeColor::BLACK()->getInvertedMagicNumber());
|
||||
}
|
||||
|
||||
if(!$tag->hasTag(self::TAG_PATTERNS, ListTag::class)){
|
||||
$tag->setTag(new ListTag(self::TAG_PATTERNS));
|
||||
|
@ -25,11 +25,23 @@ namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\block\utils\DyeColor;
|
||||
|
||||
class Bed extends Item{
|
||||
|
||||
public function __construct(int $variant, string $name){
|
||||
/** @var DyeColor */
|
||||
private $color;
|
||||
|
||||
public function __construct(int $variant, string $name, DyeColor $color){
|
||||
parent::__construct(self::BED, $variant, $name);
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DyeColor
|
||||
*/
|
||||
public function getColor() : DyeColor{
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
public function getBlock() : Block{
|
||||
|
@ -23,8 +23,22 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\utils\DyeColor;
|
||||
|
||||
class Dye extends Item{
|
||||
public function __construct(int $variant, string $name){
|
||||
|
||||
/** @var DyeColor */
|
||||
private $color;
|
||||
|
||||
public function __construct(int $variant, string $name, DyeColor $color){
|
||||
parent::__construct(self::DYE, $variant, $name);
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DyeColor
|
||||
*/
|
||||
public function getColor() : DyeColor{
|
||||
return $this->color;
|
||||
}
|
||||
}
|
||||
|
@ -245,9 +245,9 @@ class ItemFactory{
|
||||
foreach(DyeColor::getAll() as $color){
|
||||
//TODO: use colour object directly
|
||||
//TODO: add interface to dye-colour objects
|
||||
self::register(new Dye($dyeMap[$color] ?? $color->getInvertedMagicNumber(), $color->getDisplayName() . " Dye"));
|
||||
self::register(new Bed($color->getMagicNumber(), $color->getDisplayName() . " Bed"));
|
||||
self::register(new Banner($color->getInvertedMagicNumber(), $color->getDisplayName() . " Banner"));
|
||||
self::register(new Dye($dyeMap[$color] ?? $color->getInvertedMagicNumber(), $color->getDisplayName() . " Dye", $color));
|
||||
self::register(new Bed($color->getMagicNumber(), $color->getDisplayName() . " Bed", $color));
|
||||
self::register(new Banner($color->getInvertedMagicNumber(), $color->getDisplayName() . " Banner", $color));
|
||||
}
|
||||
|
||||
foreach(Potion::ALL as $type){
|
||||
|
@ -123,7 +123,7 @@ class Banner extends Spawnable implements Nameable{
|
||||
parent::copyDataFromItem($item);
|
||||
$this->copyNameFromItem($item);
|
||||
if($item instanceof ItemBanner){
|
||||
$this->setBaseColor($item->getBaseColor());
|
||||
$this->setBaseColor($item->getColor());
|
||||
if(($patterns = $item->getPatterns()) !== null){
|
||||
$this->setPatterns($patterns);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user