From 3f135da7040844e65433fa203eb9176a602e195a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 19 Jun 2020 02:38:01 +0100 Subject: [PATCH] Simplify motion handling in ProjectileItem --- src/item/Egg.php | 5 ++--- src/item/EnderPearl.php | 5 ++--- src/item/ExperienceBottle.php | 5 ++--- src/item/ProjectileItem.php | 6 +++--- src/item/Snowball.php | 5 ++--- src/item/SplashPotion.php | 5 ++--- 6 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/item/Egg.php b/src/item/Egg.php index f9657ee95..6ad22172e 100644 --- a/src/item/Egg.php +++ b/src/item/Egg.php @@ -27,7 +27,6 @@ use pocketmine\entity\EntityFactory; use pocketmine\entity\Location; use pocketmine\entity\projectile\Egg as EggEntity; use pocketmine\entity\projectile\Throwable; -use pocketmine\math\Vector3; use pocketmine\player\Player; class Egg extends ProjectileItem{ @@ -36,10 +35,10 @@ class Egg extends ProjectileItem{ return 16; } - protected function createEntity(Location $location, Vector3 $velocity, Player $thrower) : Throwable{ + protected function createEntity(Location $location, Player $thrower) : Throwable{ return new EggEntity( $location->getWorldNonNull(), - EntityFactory::createBaseNBT($location, $velocity, $location->yaw, $location->pitch), + EntityFactory::createBaseNBT($location, null, $location->yaw, $location->pitch), $thrower ); } diff --git a/src/item/EnderPearl.php b/src/item/EnderPearl.php index 19d62da58..4c865cbdc 100644 --- a/src/item/EnderPearl.php +++ b/src/item/EnderPearl.php @@ -27,7 +27,6 @@ use pocketmine\entity\EntityFactory; use pocketmine\entity\Location; use pocketmine\entity\projectile\EnderPearl as EnderPearlEntity; use pocketmine\entity\projectile\Throwable; -use pocketmine\math\Vector3; use pocketmine\player\Player; class EnderPearl extends ProjectileItem{ @@ -36,10 +35,10 @@ class EnderPearl extends ProjectileItem{ return 16; } - protected function createEntity(Location $location, Vector3 $velocity, Player $thrower) : Throwable{ + protected function createEntity(Location $location, Player $thrower) : Throwable{ return new EnderPearlEntity( $location->getWorldNonNull(), - EntityFactory::createBaseNBT($location, $velocity, $location->yaw, $location->pitch), + EntityFactory::createBaseNBT($location, null, $location->yaw, $location->pitch), $thrower ); } diff --git a/src/item/ExperienceBottle.php b/src/item/ExperienceBottle.php index 8d1225bb5..20af8b56a 100644 --- a/src/item/ExperienceBottle.php +++ b/src/item/ExperienceBottle.php @@ -27,15 +27,14 @@ use pocketmine\entity\EntityFactory; use pocketmine\entity\Location; use pocketmine\entity\projectile\ExperienceBottle as ExperienceBottleEntity; use pocketmine\entity\projectile\Throwable; -use pocketmine\math\Vector3; use pocketmine\player\Player; class ExperienceBottle extends ProjectileItem{ - protected function createEntity(Location $location, Vector3 $velocity, Player $thrower) : Throwable{ + protected function createEntity(Location $location, Player $thrower) : Throwable{ return new ExperienceBottleEntity( $location->getWorldNonNull(), - EntityFactory::createBaseNBT($location, $velocity, $location->yaw, $location->pitch), + EntityFactory::createBaseNBT($location, null, $location->yaw, $location->pitch), $thrower ); } diff --git a/src/item/ProjectileItem.php b/src/item/ProjectileItem.php index 90ac91315..8ac5fedc1 100644 --- a/src/item/ProjectileItem.php +++ b/src/item/ProjectileItem.php @@ -34,13 +34,13 @@ abstract class ProjectileItem extends Item{ abstract public function getThrowForce() : float; - abstract protected function createEntity(Location $location, Vector3 $velocity, Player $thrower) : Throwable; + abstract protected function createEntity(Location $location, Player $thrower) : Throwable; public function onClickAir(Player $player, Vector3 $directionVector) : ItemUseResult{ $location = $player->getLocation(); - $projectile = $this->createEntity(Location::fromObject($player->getEyePos(), $player->getWorld(), $location->yaw, $location->pitch), $directionVector, $player); - $projectile->setMotion($projectile->getMotion()->multiply($this->getThrowForce())); + $projectile = $this->createEntity(Location::fromObject($player->getEyePos(), $player->getWorld(), $location->yaw, $location->pitch), $player); + $projectile->setMotion($directionVector->multiply($this->getThrowForce())); $projectileEv = new ProjectileLaunchEvent($projectile); $projectileEv->call(); diff --git a/src/item/Snowball.php b/src/item/Snowball.php index c0f1b0f32..5dd6856a2 100644 --- a/src/item/Snowball.php +++ b/src/item/Snowball.php @@ -27,7 +27,6 @@ use pocketmine\entity\EntityFactory; use pocketmine\entity\Location; use pocketmine\entity\projectile\Snowball as SnowballEntity; use pocketmine\entity\projectile\Throwable; -use pocketmine\math\Vector3; use pocketmine\player\Player; class Snowball extends ProjectileItem{ @@ -36,10 +35,10 @@ class Snowball extends ProjectileItem{ return 16; } - protected function createEntity(Location $location, Vector3 $velocity, Player $thrower) : Throwable{ + protected function createEntity(Location $location, Player $thrower) : Throwable{ return new SnowballEntity( $location->getWorldNonNull(), - EntityFactory::createBaseNBT($location, $velocity, $location->yaw, $location->pitch), + EntityFactory::createBaseNBT($location, null, $location->yaw, $location->pitch), $thrower ); } diff --git a/src/item/SplashPotion.php b/src/item/SplashPotion.php index 8a658843c..9ad5106bc 100644 --- a/src/item/SplashPotion.php +++ b/src/item/SplashPotion.php @@ -27,7 +27,6 @@ use pocketmine\entity\EntityFactory; use pocketmine\entity\Location; use pocketmine\entity\projectile\SplashPotion as SplashPotionEntity; use pocketmine\entity\projectile\Throwable; -use pocketmine\math\Vector3; use pocketmine\player\Player; class SplashPotion extends ProjectileItem{ @@ -36,10 +35,10 @@ class SplashPotion extends ProjectileItem{ return 1; } - protected function createEntity(Location $location, Vector3 $velocity, Player $thrower) : Throwable{ + protected function createEntity(Location $location, Player $thrower) : Throwable{ $projectile = new SplashPotionEntity( $location->getWorldNonNull(), - EntityFactory::createBaseNBT($location, $velocity, $location->yaw, $location->pitch), + EntityFactory::createBaseNBT($location, null, $location->yaw, $location->pitch), $thrower );