Player: Changed canInteract() default max diff to sqrt(3) / 2

This is needed because players can break blocks that are outside of their field of view. A player can be inside a block and be able to break that block, while looking up, which places its centre (which is where the interact check is done from) actually behind the player's field of view. This causes anti-cheat to be triggered and makes it impossible to break blocks one is inside.

This commit changes the max negative diff to be half of the distance between a block's centre and its corners (M_SQRT_3 / 2).
This commit is contained in:
Dylan K. Taylor 2018-01-04 15:46:49 +00:00
parent 3ca162f23f
commit 5c37d298a6

View File

@ -1743,11 +1743,11 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
*
* @param Vector3 $pos
* @param float $maxDistance
* @param float $maxDiff default 0.71 (approximately sqrt(2) / 2, half of the diagonal width of a block)
* @param float $maxDiff defaults to half of the 3D diagonal width of a block
*
* @return bool
*/
public function canInteract(Vector3 $pos, float $maxDistance, float $maxDiff = 0.71) : bool{
public function canInteract(Vector3 $pos, float $maxDistance, float $maxDiff = M_SQRT3 / 2) : bool{
$eyePos = $this->getPosition()->add(0, $this->getEyeHeight(), 0);
if($eyePos->distanceSquared($pos) > $maxDistance ** 2){
return false;