Extract mandatory parameters into constructor parameters

the goal is obviously to ditch NBT entirely here, but there's more work to be done before that becomes possible.
This commit is contained in:
Dylan K. Taylor
2020-06-19 02:49:24 +01:00
parent 3f135da704
commit 1205432c34
22 changed files with 192 additions and 180 deletions

View File

@ -23,12 +23,13 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\entity\EntityFactory;
use pocketmine\entity\Location;
use pocketmine\entity\projectile\Arrow as ArrowEntity;
use pocketmine\entity\projectile\Projectile;
use pocketmine\event\entity\EntityShootBowEvent;
use pocketmine\event\entity\ProjectileLaunchEvent;
use pocketmine\item\enchantment\Enchantment;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\player\Player;
use pocketmine\world\sound\BowShootSound;
use function intdiv;
@ -51,18 +52,18 @@ class Bow extends Tool{
}
$location = $player->getLocation();
$nbt = EntityFactory::createBaseNBT(
$player->getEyePos(),
$player->getDirectionVector(),
($location->yaw > 180 ? 360 : 0) - $location->yaw,
-$location->pitch
);
$diff = $player->getItemUseDuration();
$p = $diff / 20;
$baseForce = min((($p ** 2) + $p * 2) / 3, 1);
$entity = new ArrowEntity($location->getWorldNonNull(), $nbt, $player, $baseForce >= 1);
$entity = new ArrowEntity(Location::fromObject(
$player->getEyePos(),
$player->getWorld(),
($location->yaw > 180 ? 360 : 0) - $location->yaw,
-$location->pitch
), $player, $baseForce >= 1, new CompoundTag());
$entity->setMotion($player->getDirectionVector());
$infinity = $this->hasEnchantment(Enchantment::INFINITY());
if($infinity){