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:
Dylan K. Taylor
2022-06-01 20:51:18 +01:00
parent f3c9b59856
commit b7e2b3e94a
11 changed files with 52 additions and 30 deletions

View File

@ -52,9 +52,6 @@ class Arrow extends Projectile{
private const TAG_PICKUP = "pickup"; //TAG_Byte
public const TAG_CRIT = "crit"; //TAG_Byte
protected $gravity = 0.05;
protected $drag = 0.01;
/** @var float */
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 getInitialDragMultiplier() : float{ return 0.01; }
protected function getInitialGravity() : float{ return 0.05; }
protected function initEntity(CompoundTag $nbt) : void{
parent::initEntity($nbt);

View File

@ -32,7 +32,7 @@ use function mt_rand;
class ExperienceBottle extends Throwable{
public static function getNetworkTypeId() : string{ return EntityIds::XP_BOTTLE; }
protected $gravity = 0.07;
protected function getInitialGravity() : float{ return 0.07; }
public function getResultDamage() : int{
return -1;

View File

@ -52,9 +52,6 @@ class SplashPotion extends Throwable{
public static function getNetworkTypeId() : string{ return EntityIds::SPLASH_POTION; }
protected $gravity = 0.05;
protected $drag = 0.01;
/** @var bool */
protected $linger = false;
protected PotionType $potionType;
@ -64,6 +61,8 @@ class SplashPotion extends Throwable{
parent::__construct($location, $shootingEntity, $nbt);
}
protected function getInitialGravity() : float{ return 0.05; }
public function saveNBT() : CompoundTag{
$nbt = parent::saveNBT();
$nbt->setShort("PotionId", PotionTypeIdMap::getInstance()->toId($this->getPotionType()));

View File

@ -29,11 +29,12 @@ use pocketmine\math\RayTraceResult;
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 getInitialDragMultiplier() : float{ return 0.01; }
protected function getInitialGravity() : float{ return 0.03; }
protected function onHitBlock(Block $blockHit, RayTraceResult $hitResult) : void{
parent::onHitBlock($blockHit, $hitResult);
$this->flagForDespawn();