From 1cd955c216dee303976248451a1f87db140787ed Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 2 Aug 2019 17:29:32 +0100 Subject: [PATCH] Entity: added getEyePos() --- src/entity/Entity.php | 4 ++++ src/entity/projectile/SplashPotion.php | 2 +- src/item/Bow.php | 2 +- src/item/ProjectileItem.php | 2 +- src/player/Player.php | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 8f19b3151..f1df17228 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -1171,6 +1171,10 @@ abstract class Entity extends Location{ return $this->eyeHeight; } + public function getEyePos() : Vector3{ + return new Vector3($this->x, $this->y + $this->getEyeHeight(), $this->z); + } + public function onCollideWithPlayer(Player $player) : void{ } diff --git a/src/entity/projectile/SplashPotion.php b/src/entity/projectile/SplashPotion.php index 5c4aff1fd..fccc8f02e 100644 --- a/src/entity/projectile/SplashPotion.php +++ b/src/entity/projectile/SplashPotion.php @@ -96,7 +96,7 @@ class SplashPotion extends Throwable{ if(!$this->willLinger()){ foreach($this->world->getNearbyEntities($this->boundingBox->expandedCopy(4.125, 2.125, 4.125), $this) as $entity){ if($entity instanceof Living and $entity->isAlive()){ - $distanceSquared = $entity->add(0, $entity->getEyeHeight(), 0)->distanceSquared($this); + $distanceSquared = $entity->getEyePos()->distanceSquared($this); if($distanceSquared > 16){ //4 blocks continue; } diff --git a/src/item/Bow.php b/src/item/Bow.php index 0cc6b4f9a..9aabc9a87 100644 --- a/src/item/Bow.php +++ b/src/item/Bow.php @@ -51,7 +51,7 @@ class Bow extends Tool{ } $nbt = EntityFactory::createBaseNBT( - $player->add(0, $player->getEyeHeight(), 0), + $player->getEyePos(), $player->getDirectionVector(), ($player->yaw > 180 ? 360 : 0) - $player->yaw, -$player->pitch diff --git a/src/item/ProjectileItem.php b/src/item/ProjectileItem.php index b0a939a89..ecbc0fdc6 100644 --- a/src/item/ProjectileItem.php +++ b/src/item/ProjectileItem.php @@ -53,7 +53,7 @@ abstract class ProjectileItem extends Item{ } public function onClickAir(Player $player, Vector3 $directionVector) : ItemUseResult{ - $nbt = EntityFactory::createBaseNBT($player->add(0, $player->getEyeHeight(), 0), $directionVector, $player->yaw, $player->pitch); + $nbt = EntityFactory::createBaseNBT($player->getEyePos(), $directionVector, $player->yaw, $player->pitch); $this->addExtraTags($nbt); $class = $this->getProjectileEntityClass(); diff --git a/src/player/Player.php b/src/player/Player.php index 0c66e50c1..85d03c506 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -1463,7 +1463,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, * @return bool */ public function canInteract(Vector3 $pos, float $maxDistance, float $maxDiff = M_SQRT3 / 2) : bool{ - $eyePos = $this->getPosition()->add(0, $this->getEyeHeight(), 0); + $eyePos = $this->getEyePos(); if($eyePos->distanceSquared($pos) > $maxDistance ** 2){ return false; }