Don't explode when data contains invalid dye colour IDs

This commit is contained in:
Dylan K. Taylor
2021-04-28 13:39:03 +01:00
parent a44203a3d4
commit d5e5a81cff
6 changed files with 27 additions and 11 deletions

View File

@@ -33,7 +33,11 @@ trait ColorInMetadataTrait{
* @see Block::readStateFromData()
*/
public function readStateFromData(int $id, int $stateMeta) : void{
$this->color = DyeColorIdMap::getInstance()->fromId($stateMeta);
$color = DyeColorIdMap::getInstance()->fromId($stateMeta);
if($color === null){
throw new InvalidBlockStateException("No dye colour corresponds to ID $stateMeta");
}
$this->color = $color;
}
/**