Entity: Allow disabling gravity for a mob

This commit is contained in:
Dylan K. Taylor 2019-01-27 15:42:46 +00:00
parent 6f9c4eb8e8
commit bccc07633c
2 changed files with 14 additions and 7 deletions

View File

@ -359,6 +359,8 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
protected $gravity; protected $gravity;
/** @var float */ /** @var float */
protected $drag; protected $drag;
/** @var bool */
protected $gravityEnabled = true;
/** @var Server */ /** @var Server */
protected $server; protected $server;
@ -1046,6 +1048,14 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->level->broadcastPacketToViewers($this, $pk); $this->level->broadcastPacketToViewers($this, $pk);
} }
public function hasGravity() : bool{
return $this->gravityEnabled;
}
public function setHasGravity(bool $v = true) : void{
$this->gravityEnabled = $v;
}
protected function applyDragBeforeGravity() : bool{ protected function applyDragBeforeGravity() : bool{
return false; return false;
} }
@ -1061,7 +1071,9 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->motion->y *= $friction; $this->motion->y *= $friction;
} }
$this->applyGravity(); if($this->gravityEnabled){
$this->applyGravity();
}
if(!$this->applyDragBeforeGravity()){ if(!$this->applyDragBeforeGravity()){
$this->motion->y *= $friction; $this->motion->y *= $friction;

View File

@ -99,6 +99,7 @@ class Squid extends WaterAnimal{
} }
$inWater = $this->isUnderwater(); $inWater = $this->isUnderwater();
$this->setHasGravity(!$inWater);
if(!$inWater){ if(!$inWater){
$this->swimDirection = null; $this->swimDirection = null;
}elseif($this->swimDirection !== null){ }elseif($this->swimDirection !== null){
@ -118,12 +119,6 @@ class Squid extends WaterAnimal{
return $hasUpdate; return $hasUpdate;
} }
protected function applyGravity() : void{
if(!$this->isUnderwater()){
parent::applyGravity();
}
}
public function getDrops() : array{ public function getDrops() : array{
return [ return [
ItemFactory::get(Item::DYE, 0, mt_rand(1, 3)) ItemFactory::get(Item::DYE, 0, mt_rand(1, 3))