getTag(Entity::TAG_ROTATION); if(!($yawPitch instanceof ListTag) || $yawPitch->getTagType() !== NBT::TAG_Float){ throw new SavedDataLoadingException("'" . Entity::TAG_ROTATION . "' should be a List"); } /** @var FloatTag[] $values */ $values = $yawPitch->getValue(); if(count($values) !== 2){ throw new SavedDataLoadingException("Expected exactly 2 entries for 'Rotation'"); } self::validateFloat(Entity::TAG_ROTATION, "yaw", $values[0]->getValue()); self::validateFloat(Entity::TAG_ROTATION, "pitch", $values[1]->getValue()); return Location::fromObject($pos, $world, $values[0]->getValue(), $values[1]->getValue()); } /** * @throws SavedDataLoadingException */ public static function parseVec3(CompoundTag $nbt, string $tagName, bool $optional) : Vector3{ $pos = $nbt->getTag($tagName); if($pos === null && $optional){ return Vector3::zero(); } if(!($pos instanceof ListTag) || ($pos->getTagType() !== NBT::TAG_Double && $pos->getTagType() !== NBT::TAG_Float)){ throw new SavedDataLoadingException("'$tagName' should be a List or List"); } /** @var DoubleTag[]|FloatTag[] $values */ $values = $pos->getValue(); if(count($values) !== 3){ throw new SavedDataLoadingException("Expected exactly 3 entries in '$tagName' tag"); } $x = $values[0]->getValue(); $y = $values[1]->getValue(); $z = $values[2]->getValue(); self::validateFloat($tagName, "x", $x); self::validateFloat($tagName, "y", $y); self::validateFloat($tagName, "z", $z); return new Vector3($x, $y, $z); } }