How to get the item which was held in hand when a projectile was launched? i wanna make an explosion when the arrow hits the ground but only if the bow has a custom name, can't find a way to get the item's custom name which was held on launch of the arrow in PorjectileHitEvent because players can change the item in hand by the time projectile hit something, can anyone help?
try this on projectile shoot: if get item get NBT has custom tag named is explosive true get shooted projectile add custom tag named isexplosive true on projectile hit: get projectile if is arrow and has custom name tag named is explosive with true do explosion
you can try if you wish, but i dont know if it works that why i didnt mention it, meantime doe... let me anvil my arrows
PHP: public function onLaunch(ProjectileLaunchEvent $event){ $projectile = $event->getEntity(); $shootingEntity = $projectile->shootingEntity; if($shootingEntity instanceof Player){ $isExplosive = strpos("Explosive", $shootingEntity->getInventory()->getItemInHand()->getName()); if($isExplosive){ $this->explosivearrows[spl_object_hash($projectile)] = $projectile; // Make sure $this->explosivearrows starts as an array at onEnable() function } }}public function onHit(ProjectileHitEvent $event){ if(isset($this->explosivearrows[spl_object_hash($event->getEntity())])){ unset($this->explosivearrows[spl_object_hash($event->getEntity())]); // Do your stuff }}