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.
This commit is contained in:
Dylan K. Taylor 2017-01-14 14:21:28 +00:00
parent e4aa3d72fe
commit 8ea03524ff
3 changed files with 21 additions and 16 deletions

View File

@ -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()){

View File

@ -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){

View File

@ -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){