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

@ -78,21 +78,19 @@ class Squid extends WaterAnimal{
}
public function onUpdate(int $currentTick) : bool{
public function entityBaseTick(int $tickDiff = 1) : bool{
if($this->closed !== false){
return false;
}
if(++$this->switchDirectionTicker === 100){
if(++$this->switchDirectionTicker === 100 or $this->isCollided){
$this->switchDirectionTicker = 0;
if(mt_rand(0, 100) < 50){
$this->swimDirection = null;
}
}
$this->timings->startTiming();
$hasUpdate = parent::onUpdate($currentTick);
$hasUpdate = parent::entityBaseTick($tickDiff);
if($this->isAlive()){
@ -102,7 +100,6 @@ class Squid extends WaterAnimal{
$inWater = $this->isInsideOfWater();
if(!$inWater){
$this->motionY -= $this->gravity;
$this->swimDirection = null;
}elseif($this->swimDirection !== null){
if($this->motionX ** 2 + $this->motionY ** 2 + $this->motionZ ** 2 <= $this->swimDirection->lengthSquared()){
@ -115,34 +112,18 @@ class Squid extends WaterAnimal{
$this->swimSpeed = mt_rand(50, 100) / 2000;
}
$expectedPos = new Vector3($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ);
$this->move($this->motionX, $this->motionY, $this->motionZ);
if($expectedPos->distanceSquared($this) > 0){
$this->swimDirection = $this->generateRandomDirection();
$this->swimSpeed = mt_rand(50, 100) / 2000;
}
$friction = 1 - $this->drag;
$this->motionX *= $friction;
$this->motionY *= 1 - $this->drag;
$this->motionZ *= $friction;
$f = sqrt(($this->motionX ** 2) + ($this->motionZ ** 2));
$this->yaw = (-atan2($this->motionX, $this->motionZ) * 180 / M_PI);
$this->pitch = (-atan2($f, $this->motionY) * 180 / M_PI);
if($this->onGround){
$this->motionY *= -0.5;
}
}
$this->timings->stopTiming();
return $hasUpdate;
}
return $hasUpdate or !$this->onGround or abs($this->motionX) > 0.00001 or abs($this->motionY) > 0.00001 or abs($this->motionZ) > 0.00001;
protected function applyGravity(){
if(!$this->isInsideOfWater()){
parent::applyGravity();
}
}