Check if player interact with paticleEffect?

Discussion in 'Plugin Development' started by dubknights, Jul 23, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    dubknights

    so I am making an rpg plugin, and i have a spell that shoots red dust particles using this:
    Code:java
    1. public static void castFireball(Player player){
    2. Location pl = player.getEyeLocation();
    3.  
    4. double px = pl.getX();
    5. double py = pl.getY();
    6. double pz = pl.getZ();
    7.  
    8. double yaw = Math.toRadians(pl.getYaw() + 90);
    9. double pitch = Math.toRadians(pl.getPitch() + 90);
    10.  
    11. double x = Math.sin(pitch) * Math.cos(yaw);
    12. double y = Math.sin(pitch) * Math.sin(yaw);
    13. double z = Math.cos(pitch);
    14.  
    15. for(int i = 1 ; i <= 70 ; i++) {
    16. Location loc = new Location(player.getWorld(), px + i*x, py + i*z, pz + i*y);
    17. if(loc.getBlock().getType() == Material.AIR)
    18. ParticleEffect.RED_DUST.display(loc, 0, 0, 0, 0, 1);
    19. else break;
    20. }
    21. }


    how would I check if a player interacted with that particle, and damage that player? thanks.
     
  2. Offline

    ReadySetPawn

    I could be completely wrong on this but maybe check to see if the particle's location is equal to the player's location?
     
  3. Offline

    dubknights

    Never mind, i figured it out. all i did was check if there was near by living entities in a 3 block radious and damage them. here is the new code for anyone who needs it:

    Code:
    public static void castFireball(Player player){
            Location pl = player.getEyeLocation();
           
            double px = pl.getX();
            double py = pl.getY();
            double pz = pl.getZ();
           
            double yaw  = Math.toRadians(pl.getYaw() + 90);
            double pitch = Math.toRadians(pl.getPitch() + 90);
           
            double x = Math.sin(pitch) * Math.cos(yaw);
            double y = Math.sin(pitch) * Math.sin(yaw);
            double z = Math.cos(pitch);
           
            for(int i = 1 ; i <= 20 ; i++) {
                Location loc = new Location(player.getWorld(), px + i*x, py + i*z, pz + i*y);
                if(loc.getBlock().getType() == Material.AIR){
                    ParticleEffect.RED_DUST.display(loc, 0, 0, 0, 0, 1);
                    double radius = 3D;
                    List<Entity> near = loc.getWorld().getEntities();
                    for(Entity e : near) {
                        if(e.getLocation().add(0, 1, 0).distance(loc) <= radius)
                            ((CraftLivingEntity) e).damage(3);
                    }
                }else break;
            }
          }
     
Thread Status:
Not open for further replies.

Share This Page