22declare(strict_types=1);
35use
function is_infinite;
40 private function __construct(){
47 private static function validateFloat(
string $tagName,
string $component,
float $value) :
void{
48 if(is_infinite($value)){
62 $yawPitch = $nbt->
getTag(Entity::TAG_ROTATION);
63 if(!($yawPitch instanceof
ListTag) || $yawPitch->getTagType() !== NBT::TAG_Float){
67 $values = $yawPitch->getValue();
68 if(count($values) !== 2){
71 self::validateFloat(Entity::TAG_ROTATION,
"yaw", $values[0]->getValue());
72 self::validateFloat(Entity::TAG_ROTATION,
"pitch", $values[1]->getValue());
81 $pos = $nbt->getTag($tagName);
82 if($pos ===
null && $optional){
83 return Vector3::zero();
85 if(!($pos instanceof
ListTag) || ($pos->getTagType() !== NBT::TAG_Double && $pos->getTagType() !== NBT::TAG_Float)){
89 $values = $pos->getValue();
90 if(count($values) !== 3){
91 throw new SavedDataLoadingException(
"Expected exactly 3 entries in '$tagName' tag");
94 $x = $values[0]->getValue();
95 $y = $values[1]->getValue();
96 $z = $values[2]->getValue();
98 self::validateFloat($tagName,
"x", $x);
99 self::validateFloat($tagName,
"y", $y);
100 self::validateFloat($tagName,
"z", $z);
102 return new Vector3($x, $y, $z);
static parseVec3(CompoundTag $nbt, string $tagName, bool $optional)
static parseLocation(CompoundTag $nbt, World $world)
static fromObject(Vector3 $pos, ?World $world, float $yaw=0.0, float $pitch=0.0)