FlowerPot (tile): Allow BlockFactory to determine id/data validity

This commit is contained in:
Dylan K. Taylor 2019-06-08 17:55:50 +01:00
parent 1b629d7ac0
commit f84040a7ad

View File

@ -43,9 +43,10 @@ class FlowerPot extends Spawnable{
public function readSaveData(CompoundTag $nbt) : void{ public function readSaveData(CompoundTag $nbt) : void{
if($nbt->hasTag(self::TAG_ITEM, ShortTag::class) and $nbt->hasTag(self::TAG_ITEM_DATA, IntTag::class)){ if($nbt->hasTag(self::TAG_ITEM, ShortTag::class) and $nbt->hasTag(self::TAG_ITEM_DATA, IntTag::class)){
//prevent stupidity with wrong items try{
if(($id = $nbt->getShort(self::TAG_ITEM)) >= 0 and $id <= 255 and ($data = $nbt->getInt(self::TAG_ITEM_DATA)) >= 0 and $data <= 15){ $this->setPlant(BlockFactory::get($nbt->getShort(self::TAG_ITEM), $nbt->getInt(self::TAG_ITEM_DATA)));
$this->setPlant(BlockFactory::get($id, $data)); }catch(\InvalidArgumentException $e){
//noop
} }
}else{ }else{
//TODO: new PlantBlock tag //TODO: new PlantBlock tag