40 public const TAG_BASE =
"Base";
41 public const TAG_PATTERNS =
"Patterns";
42 public const TAG_PATTERN_COLOR =
"Color";
43 public const TAG_PATTERN_NAME =
"Pattern";
45 private DyeColor $baseColor = DyeColor::BLACK;
51 private array $patterns = [];
53 public function readSaveData(
CompoundTag $nbt) :
void{
54 $colorIdMap = DyeColorIdMap::getInstance();
56 ($baseColorTag = $nbt->
getTag(self::TAG_BASE)) instanceof
IntTag &&
57 ($baseColor = $colorIdMap->fromInvertedId($baseColorTag->getValue())) !==
null
59 $this->baseColor = $baseColor;
61 $this->baseColor = DyeColor::BLACK;
64 $patternTypeIdMap = BannerPatternTypeIdMap::getInstance();
66 $patterns = $nbt->
getListTag(self::TAG_PATTERNS);
67 if($patterns !==
null){
69 foreach($patterns as $pattern){
70 $patternColor = $colorIdMap->fromInvertedId($pattern->getInt(self::TAG_PATTERN_COLOR)) ?? DyeColor::BLACK;
71 $patternType = $patternTypeIdMap->fromId($pattern->getString(self::TAG_PATTERN_NAME));
72 if($patternType ===
null){
82 $patternIdMap = BannerPatternTypeIdMap::getInstance();
83 $nbt->
setInt(self::TAG_BASE, $colorIdMap->toInvertedId($this->baseColor));
85 foreach($this->patterns as $pattern){
87 ->setString(self::TAG_PATTERN_NAME, $patternIdMap->toId($pattern->getType()))
88 ->setInt(self::TAG_PATTERN_COLOR, $colorIdMap->toInvertedId($pattern->getColor()))
91 $nbt->
setTag(self::TAG_PATTERNS, $patterns);
96 $patternIdMap = BannerPatternTypeIdMap::getInstance();
97 $nbt->
setInt(self::TAG_BASE, $colorIdMap->toInvertedId($this->baseColor));
99 foreach($this->patterns as $pattern){
101 ->setString(self::TAG_PATTERN_NAME, $patternIdMap->toId($pattern->getType()))
102 ->setInt(self::TAG_PATTERN_COLOR, $colorIdMap->toInvertedId($pattern->getColor()))
105 $nbt->
setTag(self::TAG_PATTERNS, $patterns);
112 return $this->baseColor;
119 $this->baseColor = $color;
127 return $this->patterns;
136 $this->patterns = $patterns;
139 public function getDefaultName() : string{