dropItem projectile not working properly

Discussion in 'Plugin Development' started by Blackwing_Forged, Mar 14, 2018.

Thread Status:
Not open for further replies.
  1. I don't know if im doing something wrong but when i fire the "gun" the projectile launches, but goes straight through the mob, sometimes damaging them but sometimes not. Also how do i make the projectile not bounce on the ground, like if it hits a block it stays at that location. If anyone knows how to fix this or a better way of doing it please let me know, thanks.

    Code:
    Item items =  p.getWorld().dropItem(p.getEyeLocation(), clone);
    items.setVelocity(p.getLocation().getDirection().multiply(1.5));
    Bukkit.getScheduler().runTaskTimer(main, new BukkitRunnable(){
            @Override
            public void run()
            {
              if(!items.isOnGround())
              {
                  for(Entity en : items.getNearbyEntities(1, 1, 1))
                  {
                       if(en instanceof Damageable && en != p)
                       {
                            ((Damageable) en).damage(.5);
                        }
                   }
               }
               this.cancel();
              }            
    }, 0L, 10L);
     
  2. Offline

    CommonSenze

    @Blackwing_Forged
    You cancel the bukkit runnable after the first check. I recommend doing a Projectile Hit event and save the projectile in an ArrayList and if that projectile that was in the Projectile Hit Event is in the array list than do the damage.
     
  3. @CommonSenze
    Will that event fire? Its not technically a projectile is it?
     
  4. Offline

    CommonSenze

    @Blackwing_Forged just move the:
    Code:java
    1. this.cancel();

    to the else statement:
    Code:java
    1. Bukkit.getScheduler().runTaskTimer(main, new BukkitRunnable(){
    2. @Override
    3. public void run() {
    4. if(!items.isOnGround()){
    5. for(Entity en : items.getNearbyEntities(1, 1, 1)){
    6. if(en instanceof Damageable && en != p){
    7. ((Damageable) en).damage(.5);
    8. }
    9. }
    10. } else {
    11. this.cancel();
    12. }
    13. }
    14. }, 0L, 10L);
     
  5. @CommonSenze
    Still doesn't work properly, never damages mobs when i hit them and just goes right through them, i want it to when it hits a mob or block stops right where it is
     
Thread Status:
Not open for further replies.

Share This Page