Simplify motion handling in ProjectileItem

This commit is contained in:
Dylan K. Taylor 2020-06-19 02:38:01 +01:00
parent 6a26c0bebf
commit 3f135da704
6 changed files with 13 additions and 18 deletions

View File

@ -27,7 +27,6 @@ use pocketmine\entity\EntityFactory;
use pocketmine\entity\Location; use pocketmine\entity\Location;
use pocketmine\entity\projectile\Egg as EggEntity; use pocketmine\entity\projectile\Egg as EggEntity;
use pocketmine\entity\projectile\Throwable; use pocketmine\entity\projectile\Throwable;
use pocketmine\math\Vector3;
use pocketmine\player\Player; use pocketmine\player\Player;
class Egg extends ProjectileItem{ class Egg extends ProjectileItem{
@ -36,10 +35,10 @@ class Egg extends ProjectileItem{
return 16; return 16;
} }
protected function createEntity(Location $location, Vector3 $velocity, Player $thrower) : Throwable{ protected function createEntity(Location $location, Player $thrower) : Throwable{
return new EggEntity( return new EggEntity(
$location->getWorldNonNull(), $location->getWorldNonNull(),
EntityFactory::createBaseNBT($location, $velocity, $location->yaw, $location->pitch), EntityFactory::createBaseNBT($location, null, $location->yaw, $location->pitch),
$thrower $thrower
); );
} }

View File

@ -27,7 +27,6 @@ use pocketmine\entity\EntityFactory;
use pocketmine\entity\Location; use pocketmine\entity\Location;
use pocketmine\entity\projectile\EnderPearl as EnderPearlEntity; use pocketmine\entity\projectile\EnderPearl as EnderPearlEntity;
use pocketmine\entity\projectile\Throwable; use pocketmine\entity\projectile\Throwable;
use pocketmine\math\Vector3;
use pocketmine\player\Player; use pocketmine\player\Player;
class EnderPearl extends ProjectileItem{ class EnderPearl extends ProjectileItem{
@ -36,10 +35,10 @@ class EnderPearl extends ProjectileItem{
return 16; return 16;
} }
protected function createEntity(Location $location, Vector3 $velocity, Player $thrower) : Throwable{ protected function createEntity(Location $location, Player $thrower) : Throwable{
return new EnderPearlEntity( return new EnderPearlEntity(
$location->getWorldNonNull(), $location->getWorldNonNull(),
EntityFactory::createBaseNBT($location, $velocity, $location->yaw, $location->pitch), EntityFactory::createBaseNBT($location, null, $location->yaw, $location->pitch),
$thrower $thrower
); );
} }

View File

@ -27,15 +27,14 @@ use pocketmine\entity\EntityFactory;
use pocketmine\entity\Location; use pocketmine\entity\Location;
use pocketmine\entity\projectile\ExperienceBottle as ExperienceBottleEntity; use pocketmine\entity\projectile\ExperienceBottle as ExperienceBottleEntity;
use pocketmine\entity\projectile\Throwable; use pocketmine\entity\projectile\Throwable;
use pocketmine\math\Vector3;
use pocketmine\player\Player; use pocketmine\player\Player;
class ExperienceBottle extends ProjectileItem{ 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( return new ExperienceBottleEntity(
$location->getWorldNonNull(), $location->getWorldNonNull(),
EntityFactory::createBaseNBT($location, $velocity, $location->yaw, $location->pitch), EntityFactory::createBaseNBT($location, null, $location->yaw, $location->pitch),
$thrower $thrower
); );
} }

View File

@ -34,13 +34,13 @@ abstract class ProjectileItem extends Item{
abstract public function getThrowForce() : float; 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{ public function onClickAir(Player $player, Vector3 $directionVector) : ItemUseResult{
$location = $player->getLocation(); $location = $player->getLocation();
$projectile = $this->createEntity(Location::fromObject($player->getEyePos(), $player->getWorld(), $location->yaw, $location->pitch), $directionVector, $player); $projectile = $this->createEntity(Location::fromObject($player->getEyePos(), $player->getWorld(), $location->yaw, $location->pitch), $player);
$projectile->setMotion($projectile->getMotion()->multiply($this->getThrowForce())); $projectile->setMotion($directionVector->multiply($this->getThrowForce()));
$projectileEv = new ProjectileLaunchEvent($projectile); $projectileEv = new ProjectileLaunchEvent($projectile);
$projectileEv->call(); $projectileEv->call();

View File

@ -27,7 +27,6 @@ use pocketmine\entity\EntityFactory;
use pocketmine\entity\Location; use pocketmine\entity\Location;
use pocketmine\entity\projectile\Snowball as SnowballEntity; use pocketmine\entity\projectile\Snowball as SnowballEntity;
use pocketmine\entity\projectile\Throwable; use pocketmine\entity\projectile\Throwable;
use pocketmine\math\Vector3;
use pocketmine\player\Player; use pocketmine\player\Player;
class Snowball extends ProjectileItem{ class Snowball extends ProjectileItem{
@ -36,10 +35,10 @@ class Snowball extends ProjectileItem{
return 16; return 16;
} }
protected function createEntity(Location $location, Vector3 $velocity, Player $thrower) : Throwable{ protected function createEntity(Location $location, Player $thrower) : Throwable{
return new SnowballEntity( return new SnowballEntity(
$location->getWorldNonNull(), $location->getWorldNonNull(),
EntityFactory::createBaseNBT($location, $velocity, $location->yaw, $location->pitch), EntityFactory::createBaseNBT($location, null, $location->yaw, $location->pitch),
$thrower $thrower
); );
} }

View File

@ -27,7 +27,6 @@ use pocketmine\entity\EntityFactory;
use pocketmine\entity\Location; use pocketmine\entity\Location;
use pocketmine\entity\projectile\SplashPotion as SplashPotionEntity; use pocketmine\entity\projectile\SplashPotion as SplashPotionEntity;
use pocketmine\entity\projectile\Throwable; use pocketmine\entity\projectile\Throwable;
use pocketmine\math\Vector3;
use pocketmine\player\Player; use pocketmine\player\Player;
class SplashPotion extends ProjectileItem{ class SplashPotion extends ProjectileItem{
@ -36,10 +35,10 @@ class SplashPotion extends ProjectileItem{
return 1; return 1;
} }
protected function createEntity(Location $location, Vector3 $velocity, Player $thrower) : Throwable{ protected function createEntity(Location $location, Player $thrower) : Throwable{
$projectile = new SplashPotionEntity( $projectile = new SplashPotionEntity(
$location->getWorldNonNull(), $location->getWorldNonNull(),
EntityFactory::createBaseNBT($location, $velocity, $location->yaw, $location->pitch), EntityFactory::createBaseNBT($location, null, $location->yaw, $location->pitch),
$thrower $thrower
); );