diff --git a/src/pocketmine/item/Armor.php b/src/pocketmine/item/Armor.php index 340f647be..48c6b727c 100644 --- a/src/pocketmine/item/Armor.php +++ b/src/pocketmine/item/Armor.php @@ -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()))); + } } \ No newline at end of file