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";
44 public const TAG_TYPE =
"Type";
46 public const TYPE_NORMAL = 0;
47 public const TYPE_OMINOUS = 1;
49 private DyeColor $baseColor = DyeColor::BLACK;
55 private array $patterns = [];
57 private int $type = self::TYPE_NORMAL;
59 public function readSaveData(
CompoundTag $nbt) :
void{
60 $colorIdMap = DyeColorIdMap::getInstance();
62 ($baseColorTag = $nbt->
getTag(self::TAG_BASE)) instanceof
IntTag &&
63 ($baseColor = $colorIdMap->fromInvertedId($baseColorTag->getValue())) !==
null
65 $this->baseColor = $baseColor;
67 $this->baseColor = DyeColor::BLACK;
70 $patternTypeIdMap = BannerPatternTypeIdMap::getInstance();
72 $patterns = $nbt->
getListTag(self::TAG_PATTERNS);
73 if($patterns !==
null){
75 foreach($patterns as $pattern){
76 $patternColor = $colorIdMap->fromInvertedId($pattern->getInt(self::TAG_PATTERN_COLOR)) ?? DyeColor::BLACK;
77 $patternType = $patternTypeIdMap->fromId($pattern->getString(self::TAG_PATTERN_NAME));
78 if($patternType ===
null){
85 $this->type = $nbt->getInt(self::TAG_TYPE);
90 $patternIdMap = BannerPatternTypeIdMap::getInstance();
91 $nbt->
setInt(self::TAG_BASE, $colorIdMap->toInvertedId($this->baseColor));
93 foreach($this->patterns as $pattern){
95 ->setString(self::TAG_PATTERN_NAME, $patternIdMap->toId($pattern->getType()))
96 ->setInt(self::TAG_PATTERN_COLOR, $colorIdMap->toInvertedId($pattern->getColor()))
99 $nbt->
setTag(self::TAG_PATTERNS, $patterns);
100 $nbt->
setInt(self::TAG_TYPE, $this->type);
105 $patternIdMap = BannerPatternTypeIdMap::getInstance();
106 $nbt->
setInt(self::TAG_BASE, $colorIdMap->toInvertedId($this->baseColor));
108 foreach($this->patterns as $pattern){
110 ->setString(self::TAG_PATTERN_NAME, $patternIdMap->toId($pattern->getType()))
111 ->setInt(self::TAG_PATTERN_COLOR, $colorIdMap->toInvertedId($pattern->getColor()))
114 $nbt->
setTag(self::TAG_PATTERNS, $patterns);
115 $nbt->
setInt(self::TAG_TYPE, $this->type);
122 return $this->baseColor;
129 $this->baseColor = $color;
137 return $this->patterns;
146 $this->patterns = $patterns;
149 public function getType() : int{ return $this->type; }
151 public function setType(
int $type) : void{ $this->type = $type; }
153 public function getDefaultName() : string{