51 public const TAG_NAME =
"name";
52 public const TAG_STATES =
"states";
53 public const TAG_VERSION =
"version";
61 private array $states,
69 public static function current(
string $name, array $states) : self{
73 public function getName() : string{ return $this->name; }
79 public function getStates() : array{ return $this->states; }
81 public function getState(
string $name) : ?
Tag{
82 return $this->states[$name] ?? null;
85 public function getVersion() : int{ return $this->version; }
87 public function getVersionAsString() : string{
88 $major = ($this->version >> 24) & 0xff;
89 $minor = ($this->version >> 16) & 0xff;
90 $patch = ($this->version >> 8) & 0xff;
91 $revision = $this->version & 0xff;
92 return "$major.$minor.$patch.$revision";
100 $name = $nbt->getString(self::TAG_NAME);
102 $version = $nbt->getInt(self::TAG_VERSION, 0);
109 unset($allKeys[self::TAG_NAME], $allKeys[self::TAG_STATES], $allKeys[self::TAG_VERSION], $allKeys[VersionInfo::TAG_WORLD_DATA_VERSION]);
110 if(count($allKeys) !== 0){
111 throw new BlockStateDeserializeException(
"Unexpected extra keys: " . implode(
", ", array_keys($allKeys)));
114 return new self($name, $states->getValue(), $version);
122 foreach(Utils::stringifyKeys($this->states) as $key => $value){
123 $statesTag->setTag($key, $value);
125 return CompoundTag::create()
127 ->setInt(self::TAG_VERSION, $this->version)
128 ->setTag(self::TAG_STATES, $statesTag);
136 return $this->toVanillaNbt()
140 public function equals(
self $that) : bool{
141 if($this->name !== $that->name || count($this->states) !== count($that->states)){
144 foreach(Utils::stringifyKeys($this->states) as $k => $v){
145 if(!isset($that->states[$k]) || !$that->states[$k]->equals($v)){