mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-11 05:55:33 +00:00
Entity: Require declaration of gravity and drag via abstract methods
this guarantees that subclasses will actually declare them. [bc break]
This commit is contained in:
parent
f3c9b59856
commit
b7e2b3e94a
@ -222,6 +222,8 @@ abstract class Entity{
|
|||||||
$this->timings = Timings::getEntityTimings($this);
|
$this->timings = Timings::getEntityTimings($this);
|
||||||
|
|
||||||
$this->size = $this->getInitialSizeInfo();
|
$this->size = $this->getInitialSizeInfo();
|
||||||
|
$this->drag = $this->getInitialDragMultiplier();
|
||||||
|
$this->gravity = $this->getInitialGravity();
|
||||||
|
|
||||||
$this->id = self::nextRuntimeId();
|
$this->id = self::nextRuntimeId();
|
||||||
$this->server = $location->getWorld()->getServer();
|
$this->server = $location->getWorld()->getServer();
|
||||||
@ -257,6 +259,21 @@ abstract class Entity{
|
|||||||
|
|
||||||
abstract protected function getInitialSizeInfo() : EntitySizeInfo;
|
abstract protected function getInitialSizeInfo() : EntitySizeInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the percentage by which the entity's velocity is reduced per tick when moving through air.
|
||||||
|
* The entity's velocity is multiplied by 1 minus this value.
|
||||||
|
*
|
||||||
|
* @return float 0-1
|
||||||
|
*/
|
||||||
|
abstract protected function getInitialDragMultiplier() : float;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the downwards acceleration of the entity when falling, in blocks/tick².
|
||||||
|
*
|
||||||
|
* @return float minimum 0
|
||||||
|
*/
|
||||||
|
abstract protected function getInitialGravity() : float;
|
||||||
|
|
||||||
public function getNameTag() : string{
|
public function getNameTag() : string{
|
||||||
return $this->nameTag;
|
return $this->nameTag;
|
||||||
}
|
}
|
||||||
|
@ -76,9 +76,6 @@ use const M_PI;
|
|||||||
abstract class Living extends Entity{
|
abstract class Living extends Entity{
|
||||||
protected const DEFAULT_BREATH_TICKS = 300;
|
protected const DEFAULT_BREATH_TICKS = 300;
|
||||||
|
|
||||||
protected $gravity = 0.08;
|
|
||||||
protected $drag = 0.02;
|
|
||||||
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
protected $attackTime = 0;
|
protected $attackTime = 0;
|
||||||
|
|
||||||
@ -121,6 +118,10 @@ abstract class Living extends Entity{
|
|||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $swimming = false;
|
protected $swimming = false;
|
||||||
|
|
||||||
|
protected function getInitialDragMultiplier() : float{ return 0.02; }
|
||||||
|
|
||||||
|
protected function getInitialGravity() : float{ return 0.08; }
|
||||||
|
|
||||||
abstract public function getName() : string;
|
abstract public function getName() : string;
|
||||||
|
|
||||||
protected function initEntity(CompoundTag $nbt) : void{
|
protected function initEntity(CompoundTag $nbt) : void{
|
||||||
|
@ -78,9 +78,6 @@ class ExperienceOrb extends Entity{
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public $gravity = 0.04;
|
|
||||||
public $drag = 0.02;
|
|
||||||
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
protected $age = 0;
|
protected $age = 0;
|
||||||
|
|
||||||
@ -106,6 +103,10 @@ class ExperienceOrb extends Entity{
|
|||||||
|
|
||||||
protected function getInitialSizeInfo() : EntitySizeInfo{ return new EntitySizeInfo(0.25, 0.25); }
|
protected function getInitialSizeInfo() : EntitySizeInfo{ return new EntitySizeInfo(0.25, 0.25); }
|
||||||
|
|
||||||
|
protected function getInitialDragMultiplier() : float{ return 0.02; }
|
||||||
|
|
||||||
|
protected function getInitialGravity() : float{ return 0.04; }
|
||||||
|
|
||||||
protected function initEntity(CompoundTag $nbt) : void{
|
protected function initEntity(CompoundTag $nbt) : void{
|
||||||
parent::initEntity($nbt);
|
parent::initEntity($nbt);
|
||||||
|
|
||||||
|
@ -46,9 +46,6 @@ class FallingBlock extends Entity{
|
|||||||
|
|
||||||
public static function getNetworkTypeId() : string{ return EntityIds::FALLING_BLOCK; }
|
public static function getNetworkTypeId() : string{ return EntityIds::FALLING_BLOCK; }
|
||||||
|
|
||||||
protected $gravity = 0.04;
|
|
||||||
protected $drag = 0.02;
|
|
||||||
|
|
||||||
/** @var Block */
|
/** @var Block */
|
||||||
protected $block;
|
protected $block;
|
||||||
|
|
||||||
@ -61,6 +58,10 @@ class FallingBlock extends Entity{
|
|||||||
|
|
||||||
protected function getInitialSizeInfo() : EntitySizeInfo{ return new EntitySizeInfo(0.98, 0.98); }
|
protected function getInitialSizeInfo() : EntitySizeInfo{ return new EntitySizeInfo(0.98, 0.98); }
|
||||||
|
|
||||||
|
protected function getInitialDragMultiplier() : float{ return 0.02; }
|
||||||
|
|
||||||
|
protected function getInitialGravity() : float{ return 0.04; }
|
||||||
|
|
||||||
public static function parseBlockNBT(BlockFactory $factory, CompoundTag $nbt) : Block{
|
public static function parseBlockNBT(BlockFactory $factory, CompoundTag $nbt) : Block{
|
||||||
$blockId = 0;
|
$blockId = 0;
|
||||||
|
|
||||||
|
@ -59,9 +59,6 @@ class ItemEntity extends Entity{
|
|||||||
/** @var Item */
|
/** @var Item */
|
||||||
protected $item;
|
protected $item;
|
||||||
|
|
||||||
protected $gravity = 0.04;
|
|
||||||
protected $drag = 0.02;
|
|
||||||
|
|
||||||
public $canCollide = false;
|
public $canCollide = false;
|
||||||
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
@ -77,6 +74,10 @@ class ItemEntity extends Entity{
|
|||||||
|
|
||||||
protected function getInitialSizeInfo() : EntitySizeInfo{ return new EntitySizeInfo(0.25, 0.25); }
|
protected function getInitialSizeInfo() : EntitySizeInfo{ return new EntitySizeInfo(0.25, 0.25); }
|
||||||
|
|
||||||
|
protected function getInitialDragMultiplier() : float{ return 0.02; }
|
||||||
|
|
||||||
|
protected function getInitialGravity() : float{ return 0.04; }
|
||||||
|
|
||||||
protected function initEntity(CompoundTag $nbt) : void{
|
protected function initEntity(CompoundTag $nbt) : void{
|
||||||
parent::initEntity($nbt);
|
parent::initEntity($nbt);
|
||||||
|
|
||||||
|
@ -56,11 +56,6 @@ class Painting extends Entity{
|
|||||||
Facing::EAST => 3
|
Facing::EAST => 3
|
||||||
];
|
];
|
||||||
|
|
||||||
/** @var float */
|
|
||||||
protected $gravity = 0.0;
|
|
||||||
/** @var float */
|
|
||||||
protected $drag = 1.0;
|
|
||||||
|
|
||||||
/** @var Vector3 */
|
/** @var Vector3 */
|
||||||
protected $blockIn;
|
protected $blockIn;
|
||||||
/** @var int */
|
/** @var int */
|
||||||
@ -80,6 +75,10 @@ class Painting extends Entity{
|
|||||||
return new EntitySizeInfo(0.5, 0.5);
|
return new EntitySizeInfo(0.5, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getInitialDragMultiplier() : float{ return 1.0; }
|
||||||
|
|
||||||
|
protected function getInitialGravity() : float{ return 0.0; }
|
||||||
|
|
||||||
protected function initEntity(CompoundTag $nbt) : void{
|
protected function initEntity(CompoundTag $nbt) : void{
|
||||||
$this->setMaxHealth(1);
|
$this->setMaxHealth(1);
|
||||||
$this->setHealth(1);
|
$this->setHealth(1);
|
||||||
|
@ -41,9 +41,6 @@ class PrimedTNT extends Entity implements Explosive{
|
|||||||
|
|
||||||
public static function getNetworkTypeId() : string{ return EntityIds::TNT; }
|
public static function getNetworkTypeId() : string{ return EntityIds::TNT; }
|
||||||
|
|
||||||
protected $gravity = 0.04;
|
|
||||||
protected $drag = 0.02;
|
|
||||||
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
protected $fuse;
|
protected $fuse;
|
||||||
|
|
||||||
@ -53,6 +50,10 @@ class PrimedTNT extends Entity implements Explosive{
|
|||||||
|
|
||||||
protected function getInitialSizeInfo() : EntitySizeInfo{ return new EntitySizeInfo(0.98, 0.98); }
|
protected function getInitialSizeInfo() : EntitySizeInfo{ return new EntitySizeInfo(0.98, 0.98); }
|
||||||
|
|
||||||
|
protected function getInitialDragMultiplier() : float{ return 0.02; }
|
||||||
|
|
||||||
|
protected function getInitialGravity() : float{ return 0.04; }
|
||||||
|
|
||||||
public function getFuse() : int{
|
public function getFuse() : int{
|
||||||
return $this->fuse;
|
return $this->fuse;
|
||||||
}
|
}
|
||||||
|
@ -52,9 +52,6 @@ class Arrow extends Projectile{
|
|||||||
private const TAG_PICKUP = "pickup"; //TAG_Byte
|
private const TAG_PICKUP = "pickup"; //TAG_Byte
|
||||||
public const TAG_CRIT = "crit"; //TAG_Byte
|
public const TAG_CRIT = "crit"; //TAG_Byte
|
||||||
|
|
||||||
protected $gravity = 0.05;
|
|
||||||
protected $drag = 0.01;
|
|
||||||
|
|
||||||
/** @var float */
|
/** @var float */
|
||||||
protected $damage = 2.0;
|
protected $damage = 2.0;
|
||||||
|
|
||||||
@ -77,6 +74,10 @@ class Arrow extends Projectile{
|
|||||||
|
|
||||||
protected function getInitialSizeInfo() : EntitySizeInfo{ return new EntitySizeInfo(0.25, 0.25); }
|
protected function getInitialSizeInfo() : EntitySizeInfo{ return new EntitySizeInfo(0.25, 0.25); }
|
||||||
|
|
||||||
|
protected function getInitialDragMultiplier() : float{ return 0.01; }
|
||||||
|
|
||||||
|
protected function getInitialGravity() : float{ return 0.05; }
|
||||||
|
|
||||||
protected function initEntity(CompoundTag $nbt) : void{
|
protected function initEntity(CompoundTag $nbt) : void{
|
||||||
parent::initEntity($nbt);
|
parent::initEntity($nbt);
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ use function mt_rand;
|
|||||||
class ExperienceBottle extends Throwable{
|
class ExperienceBottle extends Throwable{
|
||||||
public static function getNetworkTypeId() : string{ return EntityIds::XP_BOTTLE; }
|
public static function getNetworkTypeId() : string{ return EntityIds::XP_BOTTLE; }
|
||||||
|
|
||||||
protected $gravity = 0.07;
|
protected function getInitialGravity() : float{ return 0.07; }
|
||||||
|
|
||||||
public function getResultDamage() : int{
|
public function getResultDamage() : int{
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -52,9 +52,6 @@ class SplashPotion extends Throwable{
|
|||||||
|
|
||||||
public static function getNetworkTypeId() : string{ return EntityIds::SPLASH_POTION; }
|
public static function getNetworkTypeId() : string{ return EntityIds::SPLASH_POTION; }
|
||||||
|
|
||||||
protected $gravity = 0.05;
|
|
||||||
protected $drag = 0.01;
|
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $linger = false;
|
protected $linger = false;
|
||||||
protected PotionType $potionType;
|
protected PotionType $potionType;
|
||||||
@ -64,6 +61,8 @@ class SplashPotion extends Throwable{
|
|||||||
parent::__construct($location, $shootingEntity, $nbt);
|
parent::__construct($location, $shootingEntity, $nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getInitialGravity() : float{ return 0.05; }
|
||||||
|
|
||||||
public function saveNBT() : CompoundTag{
|
public function saveNBT() : CompoundTag{
|
||||||
$nbt = parent::saveNBT();
|
$nbt = parent::saveNBT();
|
||||||
$nbt->setShort("PotionId", PotionTypeIdMap::getInstance()->toId($this->getPotionType()));
|
$nbt->setShort("PotionId", PotionTypeIdMap::getInstance()->toId($this->getPotionType()));
|
||||||
|
@ -29,11 +29,12 @@ use pocketmine\math\RayTraceResult;
|
|||||||
|
|
||||||
abstract class Throwable extends Projectile{
|
abstract class Throwable extends Projectile{
|
||||||
|
|
||||||
protected $gravity = 0.03;
|
|
||||||
protected $drag = 0.01;
|
|
||||||
|
|
||||||
protected function getInitialSizeInfo() : EntitySizeInfo{ return new EntitySizeInfo(0.25, 0.25); }
|
protected function getInitialSizeInfo() : EntitySizeInfo{ return new EntitySizeInfo(0.25, 0.25); }
|
||||||
|
|
||||||
|
protected function getInitialDragMultiplier() : float{ return 0.01; }
|
||||||
|
|
||||||
|
protected function getInitialGravity() : float{ return 0.03; }
|
||||||
|
|
||||||
protected function onHitBlock(Block $blockHit, RayTraceResult $hitResult) : void{
|
protected function onHitBlock(Block $blockHit, RayTraceResult $hitResult) : void{
|
||||||
parent::onHitBlock($blockHit, $hitResult);
|
parent::onHitBlock($blockHit, $hitResult);
|
||||||
$this->flagForDespawn();
|
$this->flagForDespawn();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user