https://bukkit.org/threads/solved-get-the-entity-a-player-is-looking-at.40592/#post-793498 Try porting it from this.
Try Player->getTargetEntity(); PHP: public function check(Player $player) { $entity = $player->getTargetEntity(); if($entity instanceof Player) { return true; } return false; }
PHP: <?phpdeclare(strict_types=1);namespace blablabla; //todo: do not forget change thisuse pocketmine\event\Listener;use pocketmine\event\server\DataPacketReceiveEvent;use pocketmine\network\mcpe\protocol\InteractPacket;use pocketmine\Player;use pocketmine\plugin\PluginBase;class Main extends PluginBase implements Listener{ public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onLooking(DataPacketReceiveEvent $e){ $pk = $e->getPacket(); if($pk instanceof InteractPacket){ $player = $this->getServer()->findEntity($pk->target); if($player === null){ return; } if($player instanceof Player){ var_dump($player->getName()); } } }}
there is some maths calculs to get the exact view im sure of that and @samjmckenzie you linked me Java/Bukkit codes .-.
i like how you added the "//todo: do not forget change this" and also made the whole code XD, man im doing these things since 2016