mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 08:17:34 +00:00
BlockStateData: added auxiliary toVanillaNbt() helper method
toNbt() adds PM version metadata, which might not always be desired.
This commit is contained in:
parent
a2a7006878
commit
644b417d2c
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user