Added API methods for getting & setting armour dye colours

This commit is contained in:
Dylan K. Taylor 2017-11-21 14:10:33 +00:00
parent 78d24b9183
commit 9da19b5f15

View File

@ -24,9 +24,35 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\nbt\tag\IntTag;
use pocketmine\utils\Binary;
use pocketmine\utils\Color;
abstract class Armor extends Item{
public const TAG_CUSTOM_COLOR = "customColor"; //TAG_Int
public function getMaxStackSize() : int{
return 1;
}
/**
* Returns the dyed colour of this armour piece. This generally only applies to leather armour.
* @return Color|null
*/
public function getCustomColor() : ?Color{
if($this->getNamedTag()->hasTag(self::TAG_CUSTOM_COLOR, IntTag::class)){
return Color::fromARGB(Binary::unsignInt($this->getNamedTag()->getInt(self::TAG_CUSTOM_COLOR)));
}
return null;
}
/**
* Sets the dyed colour of this armour piece. This generally only applies to leather armour.
* @param Color $color
*/
public function setCustomColor(Color $color) : void{
$this->setNamedTagEntry(new IntTag(self::TAG_CUSTOM_COLOR, Binary::signInt($color->toARGB())));
}
}