mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 07:54:19 +00:00
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:
parent
e4aa3d72fe
commit
8ea03524ff
@ -1387,11 +1387,6 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
|||||||
$diffY = $this->y - $newPos->y;
|
$diffY = $this->y - $newPos->y;
|
||||||
$diffZ = $this->z - $newPos->z;
|
$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);
|
$diff = ($diffX ** 2 + $diffY ** 2 + $diffZ ** 2) / ($tickDiff ** 2);
|
||||||
|
|
||||||
if($this->isSurvival()){
|
if($this->isSurvival()){
|
||||||
|
@ -354,18 +354,28 @@ class Binary{
|
|||||||
return pack("V", $value);
|
return pack("V", $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function readFloat($str){
|
public static function readFloat($str, int $accuracy = -1){
|
||||||
self::checkLength($str, 4);
|
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){
|
public static function writeFloat($value){
|
||||||
return ENDIANNESS === self::BIG_ENDIAN ? pack("f", $value) : strrev(pack("f", $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);
|
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){
|
public static function writeLFloat($value){
|
||||||
|
@ -126,8 +126,8 @@ class BinaryStream extends \stdClass{
|
|||||||
$this->buffer .= Binary::writeShort($v);
|
$this->buffer .= Binary::writeShort($v);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFloat(){
|
public function getFloat(int $accuracy = -1){
|
||||||
return Binary::readFloat($this->get(4));
|
return Binary::readFloat($this->get(4), $accuracy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function putFloat($v){
|
public function putFloat($v){
|
||||||
@ -142,8 +142,8 @@ class BinaryStream extends \stdClass{
|
|||||||
$this->buffer .= Binary::writeLShort($v);
|
$this->buffer .= Binary::writeLShort($v);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLFloat(){
|
public function getLFloat(int $accuracy = -1){
|
||||||
return Binary::readLFloat($this->get(4));
|
return Binary::readLFloat($this->get(4), $accuracy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function putLFloat($v){
|
public function putLFloat($v){
|
||||||
@ -300,9 +300,9 @@ class BinaryStream extends \stdClass{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getVector3f(&$x, &$y, &$z){
|
public function getVector3f(&$x, &$y, &$z){
|
||||||
$x = $this->getLFloat();
|
$x = $this->getLFloat(4);
|
||||||
$y = $this->getLFloat();
|
$y = $this->getLFloat(4);
|
||||||
$z = $this->getLFloat();
|
$z = $this->getLFloat(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function putVector3f($x, $y, $z){
|
public function putVector3f($x, $y, $z){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user