Fixed entity move performance issue and a ton of entity movement bugs

- fixed zombies and villagers movement not updating
- fixed dropped items "movement" lagging the living **** out of the server when not actually moving
- fixed arrows not falling when the supporting block is removed
- fixed knockback
- fixed zombies + villagers being un-attackable after hitting them

... the list goes on
This commit is contained in:
Dylan K. Taylor
2017-08-20 20:31:09 +01:00
parent 02f42eba48
commit 2f3c77c68a
10 changed files with 122 additions and 162 deletions

View File

@ -108,28 +108,20 @@ abstract class Projectile extends Entity{
$this->namedtag->Age = new ShortTag("Age", $this->age);
}
public function onUpdate(int $currentTick) : bool{
protected function applyDragBeforeGravity() : bool{
return true;
}
public function entityBaseTick(int $tickDiff = 1) : bool{
if($this->closed){
return false;
}
$tickDiff = $currentTick - $this->lastUpdate;
if($tickDiff <= 0 and !$this->justCreated){
return true;
}
$this->lastUpdate = $currentTick;
$hasUpdate = $this->entityBaseTick($tickDiff);
$hasUpdate = parent::entityBaseTick($tickDiff);
if($this->isAlive()){
$movingObjectPosition = null;
if(!$this->isCollided){
$this->motionY -= $this->gravity;
}
$moveVector = new Vector3($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ);
$list = $this->getLevel()->getCollidingEntities($this->boundingBox->addCoord($this->motionX, $this->motionY, $this->motionZ)->expand(1, 1, 1), $this);
@ -170,8 +162,6 @@ abstract class Projectile extends Entity{
}
}
$this->move($this->motionX, $this->motionY, $this->motionZ);
if($this->isCollided and !$this->hadCollision){ //Collided with a block
$this->hadCollision = true;
@ -181,20 +171,16 @@ abstract class Projectile extends Entity{
$this->server->getPluginManager()->callEvent(new ProjectileHitEvent($this));
return false;
}elseif(!$this->isCollided and $this->hadCollision){ //Collided with block, but block later removed
//This currently doesn't work because the arrow's motion is all zeros when it's hit a block, so move() doesn't do any collision checks.
//TODO: fix this
}elseif(!$this->isCollided and $this->hadCollision){ //Previously collided with block, but block later removed
$this->hadCollision = false;
}
if(!$this->hadCollision or abs($this->motionX) > 0.00001 or abs($this->motionY) > 0.00001 or abs($this->motionZ) > 0.00001){
if(!$this->hadCollision or abs($this->motionX) > self::MOTION_THRESHOLD or abs($this->motionY) > self::MOTION_THRESHOLD or abs($this->motionZ) > self::MOTION_THRESHOLD){
$f = sqrt(($this->motionX ** 2) + ($this->motionZ ** 2));
$this->yaw = (atan2($this->motionX, $this->motionZ) * 180 / M_PI);
$this->pitch = (atan2($this->motionY, $f) * 180 / M_PI);
$hasUpdate = true;
}
$this->updateMovement();
}
return $hasUpdate;