*/ private $patterns; public function __construct(ItemIdentifier $identifier, Block $floorVariant, Block $wallVariant){ parent::__construct($identifier, $floorVariant, $wallVariant); $this->color = DyeColor::BLACK(); $this->patterns = new Deque(); } public function getColor() : DyeColor{ return $this->color; } /** @return $this */ public function setColor(DyeColor $color) : self{ $this->color = $color; return $this; } public function getMeta() : int{ return DyeColorIdMap::getInstance()->toInvertedId($this->color); } public function getMaxStackSize() : int{ return 16; } /** * @return Deque|BannerPattern[] * @phpstan-return Deque */ public function getPatterns() : Deque{ return $this->patterns; } /** * @param Deque|BannerPattern[] $patterns * @phpstan-param Deque $patterns * * @return $this */ public function setPatterns(Deque $patterns) : self{ $this->patterns = $patterns; return $this; } public function getFuelTime() : int{ return 300; } protected function deserializeCompoundTag(CompoundTag $tag) : void{ parent::deserializeCompoundTag($tag); $this->patterns = new Deque(); $colorIdMap = DyeColorIdMap::getInstance(); $patterns = $tag->getListTag(self::TAG_PATTERNS); if($patterns !== null){ /** @var CompoundTag $t */ foreach($patterns as $t){ $this->patterns->push(new BannerPattern($t->getString(self::TAG_PATTERN_NAME), $colorIdMap->fromInvertedId($t->getInt(self::TAG_PATTERN_COLOR)))); } } } protected function serializeCompoundTag(CompoundTag $tag) : void{ parent::serializeCompoundTag($tag); if(!$this->patterns->isEmpty()){ $patterns = new ListTag(); $colorIdMap = DyeColorIdMap::getInstance(); /** @var BannerPattern $pattern */ foreach($this->patterns as $pattern){ $patterns->push(CompoundTag::create() ->setString(self::TAG_PATTERN_NAME, $pattern->getId()) ->setInt(self::TAG_PATTERN_COLOR, $colorIdMap->toInvertedId($pattern->getColor())) ); } $tag->setTag(self::TAG_PATTERNS, $patterns); }else{ $tag->removeTag(self::TAG_PATTERNS); } } public function __clone(){ parent::__clone(); //we don't need to duplicate the individual patterns because they are immutable $this->patterns = $this->patterns->copy(); } }