38 public const TAG_PATTERNS = TileBanner::TAG_PATTERNS;
39 public const TAG_PATTERN_COLOR = TileBanner::TAG_PATTERN_COLOR;
40 public const TAG_PATTERN_NAME = TileBanner::TAG_PATTERN_NAME;
42 private DyeColor $color = DyeColor::BLACK;
48 private array $patterns = [];
50 public function getColor() : DyeColor{
55 public function setColor(DyeColor $color) : self{
56 $this->color = $color;
61 $w->enum($this->color);
69 return $this->patterns;
80 $this->patterns = $patterns;
89 parent::deserializeCompoundTag($tag);
93 $colorIdMap = DyeColorIdMap::getInstance();
94 $patternIdMap = BannerPatternTypeIdMap::getInstance();
95 $patterns = $tag->
getListTag(self::TAG_PATTERNS);
96 if($patterns !==
null && $patterns->getTagType() === NBT::TAG_Compound){
98 foreach($patterns as $t){
99 $patternColor = $colorIdMap->fromInvertedId($t->getInt(self::TAG_PATTERN_COLOR)) ?? DyeColor::BLACK;
100 $patternType = $patternIdMap->fromId($t->getString(self::TAG_PATTERN_NAME));
101 if($patternType ===
null){
109 protected function serializeCompoundTag(CompoundTag $tag) : void{
110 parent::serializeCompoundTag($tag);
112 if(count($this->patterns) > 0){
113 $patterns =
new ListTag();
114 $colorIdMap = DyeColorIdMap::getInstance();
115 $patternIdMap = BannerPatternTypeIdMap::getInstance();
116 foreach($this->patterns as $pattern){
117 $patterns->push(CompoundTag::create()
118 ->setString(self::TAG_PATTERN_NAME, $patternIdMap->toId($pattern->getType()))
119 ->setInt(self::TAG_PATTERN_COLOR, $colorIdMap->toInvertedId($pattern->getColor()))
123 $tag->setTag(self::TAG_PATTERNS, $patterns);
125 $tag->removeTag(self::TAG_PATTERNS);