name; } public function getStates() : CompoundTag{ return $this->states; } public function getVersion() : int{ return $this->version; } /** * @throws BlockStateDeserializeException */ public static function fromNbt(CompoundTag $nbt) : self{ try{ $name = $nbt->getString(self::TAG_NAME); $states = $nbt->getCompoundTag(self::TAG_STATES) ?? throw new BlockStateDeserializeException("Missing tag \"" . self::TAG_STATES . "\""); $version = $nbt->getInt(self::TAG_VERSION, 0); }catch(NbtException $e){ throw new BlockStateDeserializeException($e->getMessage(), 0, $e); } $allKeys = $nbt->getValue(); unset($allKeys[self::TAG_NAME], $allKeys[self::TAG_STATES], $allKeys[self::TAG_VERSION]); if(count($allKeys) !== 0){ throw new BlockStateDeserializeException("Unexpected extra keys: " . implode(", ", array_keys($allKeys))); } return new self($name, $states, $version); } public function toNbt() : CompoundTag{ return CompoundTag::create() ->setString(self::TAG_NAME, $this->name) ->setInt(self::TAG_VERSION, $this->version) ->setTag(self::TAG_STATES, $this->states); } public function equals(self $that) : bool{ return $this->name === $that->name && $this->states->equals($that->states) && $this->version === $that->version; } }