From 8ea03524ffaeee7a84cd73fa42fa013fe92c1a86 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 14 Jan 2017 14:21:28 +0000 Subject: [PATCH] Fixed most movement-check false-positives (finally!) Removed ySize hack, fixes ladders, fixed original autojump and dropdown issues. These were due to a tiny, tiny tiny margin for error when decoding network floats (usually less than 0.000001, but enough to cause issues. Added Binary floating-point decode accuracy option to combat this. Network Vector3s are now rounded to 4 decimal places. --- src/pocketmine/Player.php | 5 ----- src/pocketmine/utils/Binary.php | 18 ++++++++++++++---- src/pocketmine/utils/BinaryStream.php | 14 +++++++------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 54206905a..163076d38 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1387,11 +1387,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade $diffY = $this->y - $newPos->y; $diffZ = $this->z - $newPos->z; - $yS = 0.5 + $this->ySize; - if($diffY >= -$yS or $diffY <= $yS){ - $diffY = 0; - } - $diff = ($diffX ** 2 + $diffY ** 2 + $diffZ ** 2) / ($tickDiff ** 2); if($this->isSurvival()){ diff --git a/src/pocketmine/utils/Binary.php b/src/pocketmine/utils/Binary.php index e3a7cd528..95330abca 100644 --- a/src/pocketmine/utils/Binary.php +++ b/src/pocketmine/utils/Binary.php @@ -354,18 +354,28 @@ class Binary{ return pack("V", $value); } - public static function readFloat($str){ + public static function readFloat($str, int $accuracy = -1){ self::checkLength($str, 4); - return ENDIANNESS === self::BIG_ENDIAN ? unpack("f", $str)[1] : unpack("f", strrev($str))[1]; + $value = ENDIANNESS === self::BIG_ENDIAN ? unpack("f", $str)[1] : unpack("f", strrev($str))[1]; + if($accuracy > -1){ + return round($value, $accuracy); + }else{ + return $value; + } } public static function writeFloat($value){ return ENDIANNESS === self::BIG_ENDIAN ? pack("f", $value) : strrev(pack("f", $value)); } - public static function readLFloat($str){ + public static function readLFloat($str, int $accuracy = -1){ self::checkLength($str, 4); - return ENDIANNESS === self::BIG_ENDIAN ? unpack("f", strrev($str))[1] : unpack("f", $str)[1]; + $value = ENDIANNESS === self::BIG_ENDIAN ? unpack("f", strrev($str))[1] : unpack("f", $str)[1]; + if($accuracy > -1){ + return round($value, $accuracy); + }else{ + return $value; + } } public static function writeLFloat($value){ diff --git a/src/pocketmine/utils/BinaryStream.php b/src/pocketmine/utils/BinaryStream.php index 0c1f4b534..6d4ae6bbf 100644 --- a/src/pocketmine/utils/BinaryStream.php +++ b/src/pocketmine/utils/BinaryStream.php @@ -126,8 +126,8 @@ class BinaryStream extends \stdClass{ $this->buffer .= Binary::writeShort($v); } - public function getFloat(){ - return Binary::readFloat($this->get(4)); + public function getFloat(int $accuracy = -1){ + return Binary::readFloat($this->get(4), $accuracy); } public function putFloat($v){ @@ -142,8 +142,8 @@ class BinaryStream extends \stdClass{ $this->buffer .= Binary::writeLShort($v); } - public function getLFloat(){ - return Binary::readLFloat($this->get(4)); + public function getLFloat(int $accuracy = -1){ + return Binary::readLFloat($this->get(4), $accuracy); } public function putLFloat($v){ @@ -300,9 +300,9 @@ class BinaryStream extends \stdClass{ } public function getVector3f(&$x, &$y, &$z){ - $x = $this->getLFloat(); - $y = $this->getLFloat(); - $z = $this->getLFloat(); + $x = $this->getLFloat(4); + $y = $this->getLFloat(4); + $z = $this->getLFloat(4); } public function putVector3f($x, $y, $z){