How to get hasLineOfSight() with a projectile or projectile source

Discussion in 'Plugin Development' started by BananaPuncher714, Feb 12, 2017.

Thread Status:
Not open for further replies.
  1. So I have a projectile source that fires a projectile, and I need to determine whether the projectile source or the projectile can see the entity with hasLineOfSight(). Only LivingEntity has that method, and I can't cast projectile or projectile source to a LivingEntity object. What should I do?
     
  2. Offline

    MattTheBeast

    Are you trying to see if the shooter can see the target?
     
  3. @MattTheBeast
    Yes, I'm trying to get a target that a dispenser can see an entity when it fires an arrow, but in order to do that, I need a LivingEntity because dispensers and arrows do not have the hasLineOfSight() method.
     
  4. Offline

    Rayzr522

    @BananaPuncher714 You'll have to write this yourself. Figure out the direction the dispenser is facing, and use the getNearbyEntities method in the World class to get entities in a certain radius of the dispenser. I can think of a few ways to implement this... but that's up to you :)
     
  5. @Rayzr522
    Ok, thanks, but do you know the coding for the hasLineOfSightMethod()? Or is it simply a for loop checking for blocks to the entity?
     
  6. @BananaPuncher714
    Essentially yes. Bukkit uses the NMS rayTrace system which is a more complex version of what you're describing.
     
  7. Ok, thanks.
     
Thread Status:
Not open for further replies.

Share This Page