BlockStateData: added auxiliary toVanillaNbt() helper method

toNbt() adds PM version metadata, which might not always be desired.
This commit is contained in:
Dylan K. Taylor 2023-07-03 14:05:17 +01:00
parent a2a7006878
commit 644b417d2c
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -111,7 +111,10 @@ final class BlockStateData{
return new self($name, $states->getValue(), $version);
}
public function toNbt() : CompoundTag{
/**
* Encodes the blockstate as a TAG_Compound, exactly as it would be in vanilla Bedrock.
*/
public function toVanillaNbt() : CompoundTag{
$statesTag = CompoundTag::create();
foreach(Utils::stringifyKeys($this->states) as $key => $value){
$statesTag->setTag($key, $value);
@ -119,7 +122,15 @@ final class BlockStateData{
return CompoundTag::create()
->setString(self::TAG_NAME, $this->name)
->setInt(self::TAG_VERSION, $this->version)
->setTag(self::TAG_STATES, $statesTag)
->setTag(self::TAG_STATES, $statesTag);
}
/**
* Encodes the blockstate as a TAG_Compound, but with extra PM-specific metadata, used for fixing bugs in old saved
* data. This should be used for anything saved to disk.
*/
public function toNbt() : CompoundTag{
return $this->toVanillaNbt()
->setLong(VersionInfo::TAG_WORLD_DATA_VERSION, VersionInfo::WORLD_DATA_VERSION);
}