From 710e1d014de454ae1055f1d017b1ee141a7fc82c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 16 Jul 2018 12:08:13 +0100 Subject: [PATCH] Entity: fixed 0-length motion vectors being passed to move() this was an interesting bug. This was discovered by making a projectile's drag 0, making its gravity a factor of its throw force (such that force / gravity = integer value), and then throwing it directly up. At the apex, an error would occur due to trying to do a ray trace with a zero vector. This also led me to realize that there's an edge case in the current movement system - if an entity's motion reaches 0, it will stop getting movement updates. This can be undesirable when things such as gravity cause motion to become zero when throwing a projectile directly upwards. This will need to be fixed separately. --- src/pocketmine/entity/Entity.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index fd673095f..8eeb82c08 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -1346,7 +1346,6 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ if($this->hasMovementUpdate()){ $this->tryChangeMovement(); - $this->move($this->motion->x, $this->motion->y, $this->motion->z); if(abs($this->motion->x) <= self::MOTION_THRESHOLD){ $this->motion->x = 0; @@ -1358,6 +1357,10 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ $this->motion->z = 0; } + if($this->motion->x != 0 or $this->motion->y != 0 or $this->motion->z != 0){ + $this->move($this->motion->x, $this->motion->y, $this->motion->z); + } + $this->forceMovementUpdate = false; }