44 private const TAG_ITEM =
"item";
45 private const TAG_ITEM_DATA =
"mData";
46 private const TAG_PLANT_BLOCK =
"PlantBlock";
48 private ?
Block $plant =
null;
50 public function readSaveData(
CompoundTag $nbt) :
void{
51 $blockStateData =
null;
53 $blockDataUpgrader = GlobalBlockStateHandlers::getUpgrader();
54 if(($itemIdTag = $nbt->
getTag(self::TAG_ITEM)) instanceof
ShortTag && ($itemMetaTag = $nbt->
getTag(self::TAG_ITEM_DATA)) instanceof
IntTag){
56 $blockStateData = $blockDataUpgrader->upgradeIntIdMeta($itemIdTag->getValue(), $itemMetaTag->getValue());
60 }elseif(($plantBlockTag = $nbt->
getCompoundTag(self::TAG_PLANT_BLOCK)) !==
null){
62 $blockStateData = $blockDataUpgrader->upgradeBlockStateNbt($plantBlockTag);
64 throw new SavedDataLoadingException(
"Error loading " . self::TAG_PLANT_BLOCK .
" tag for flower pot: " . $e->getMessage(), 0, $e);
68 if($blockStateData !==
null){
70 $blockStateId = GlobalBlockStateHandlers::getDeserializer()->deserialize($blockStateData);
74 $this->setPlant(RuntimeBlockStateRegistry::getInstance()->fromStateId($blockStateId));
79 if($this->plant !== null){
80 $nbt->
setTag(self::TAG_PLANT_BLOCK, GlobalBlockStateHandlers::getSerializer()->serialize($this->plant->getStateId())->toNbt());
84 public function getPlant() : ?
Block{
85 return $this->plant !== null ? clone $this->plant : null;
88 public function setPlant(?Block $plant) : void{
89 if($plant === null || $plant instanceof Air){
92 $this->plant = clone $plant;
97 if($this->plant !== null){
98 $nbt->
setTag(self::TAG_PLANT_BLOCK, TypeConverter::getInstance()->getBlockTranslator()->internalIdToNetworkStateData($this->plant->getStateId())->toNbt());