mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-11 05:55:33 +00:00
Merge pull request #1842 from pmmp/issues/983-interact-fix
Fix direction checking for player interactions, close #983
This commit is contained in:
commit
bf55f03a3e
@ -1743,20 +1743,19 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
*
|
*
|
||||||
* @param Vector3 $pos
|
* @param Vector3 $pos
|
||||||
* @param $maxDistance
|
* @param $maxDistance
|
||||||
* @param float $maxDiff default 0.71 (approximately sqrt(2) / 2, half of the diagonal width of a block)
|
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function canInteract(Vector3 $pos, $maxDistance, float $maxDiff = 0.71) : bool{
|
public function canInteract(Vector3 $pos, $maxDistance) : bool{
|
||||||
$eyePos = $this->getPosition()->add(0, $this->getEyeHeight(), 0);
|
$eyePos = $this->getPosition()->add(0, $this->getEyeHeight(), 0);
|
||||||
if($eyePos->distanceSquared($pos) > $maxDistance ** 2){
|
if($eyePos->distanceSquared($pos) > $maxDistance ** 2){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$dV = $this->getDirectionPlane();
|
$dV = $this->getDirectionVector();
|
||||||
$dot = $dV->dot(new Vector2($eyePos->x, $eyePos->z));
|
$eyeDot = $dV->dot($eyePos);
|
||||||
$dot1 = $dV->dot(new Vector2($pos->x, $pos->z));
|
$targetDot = $dV->dot($pos);
|
||||||
return ($dot1 - $dot) >= -$maxDiff;
|
return ($targetDot - $eyeDot) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function initHumanData(){
|
protected function initHumanData(){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user