49 $inventory = match(
true){
50 $player->getOffHandInventory()->contains($arrow) => $player->getOffHandInventory(),
51 $player->getInventory()->contains($arrow) => $player->getInventory(),
56 return ItemUseResult::FAIL;
59 $location = $player->getLocation();
63 $baseForce = min((($p ** 2) + $p * 2) / 3, 1);
65 $entity =
new ArrowEntity(Location::fromObject(
68 ($location->yaw > 180 ? 360 : 0) - $location->yaw,
70 ), $player, $baseForce >= 1);
71 $entity->setMotion($player->getDirectionVector());
73 $infinity = $this->hasEnchantment(VanillaEnchantments::INFINITY());
75 $entity->setPickupMode(ArrowEntity::PICKUP_CREATIVE);
77 if(($punchLevel = $this->getEnchantmentLevel(VanillaEnchantments::PUNCH())) > 0){
78 $entity->setPunchKnockback($punchLevel);
81 $entity->setBaseDamage($entity->getBaseDamage() + (($powerLevel + 1) / 2));
83 if($this->hasEnchantment(VanillaEnchantments::FLAME())){
84 $entity->setOnFire(intdiv($entity->getFireTicks(), 20) + 100);
86 $ev =
new EntityShootBowEvent($player, $this, $entity, $baseForce * 3);
88 if($baseForce < 0.1 || $diff < 5 || $player->isSpectator()){
94 $entity = $ev->getProjectile();
96 if($ev->isCancelled()){
97 $entity->flagForDespawn();
98 return ItemUseResult::FAIL;
101 $entity->setMotion($entity->getMotion()->multiply($ev->getForce()));
103 if($entity instanceof Projectile){
104 $projectileEv =
new ProjectileLaunchEvent($entity);
105 $projectileEv->call();
106 if($projectileEv->isCancelled()){
107 $ev->getProjectile()->flagForDespawn();
108 return ItemUseResult::FAIL;
111 $ev->getProjectile()->spawnToAll();
112 $location->getWorld()->addSound($location,
new BowShootSound());
114 $entity->spawnToAll();
119 $inventory?->removeItem($arrow);
121 $this->applyDamage(1);
124 return ItemUseResult::SUCCESS;