A problem in particles

Discussion in 'Plugin Development' started by JoltTheBolt, Dec 24, 2020.

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

    JoltTheBolt

    So I wanted to make a line of particles that will appear when I right click with an item. Previously, I have succeeded in making particles appear at one location when I right click. I did that by just getting a location of player and playing an effect there. Then I tried to make a line by using this code:
    Code:
        Location start = p.getLocation();
        Vector i1 = start.getDirection().multiply(1);
        Vector i2 = start.getDirection().multiply(2);
        Vector i3 = start.getDirection().multiply(3);
        Vector i4 = start.getDirection().multiply(4);
        Vector i5 = start.getDirection().multiply(5);
        Location l1 = start.add(i1);
        Location l2 = l1.add(i2);
        Location l3 = l2.add(i3);
        Location l4 = l3.add(i4);
        Location l5 = l4.add(i5);
        w.playEffect(l5, Effect.MOBSPAWNER_FLAMES, null);
    ;
    
    I want the line to be 5 blocks long in the direction that I am looking at. What happens is that one particle appears 15 blocks away instead. I don't understand why that happens.

    EDIT: Wait, I am multiplying it but I need to add? How will I do that?
     
    Last edited: Dec 24, 2020
  2. Offline

    CraftCreeper6

    @JoltTheBolt
    Uh.. yeah that's kinda what you told it to do.

    You've set l1 and added i1 to it, so you have a 1x multiplier of getDirection()
    Then you set l2 to be equal to l1 and then added i2 to it, so now you have a multiplier of 1 + 2 = 3
    Then you set l3 to be equal to l2 and then added i3 to it, so now you have a multiplier of 1 + 2 + 3 = 6
    So on..
    Until you have l5, which is i1 + i2 + i3 + i4 + i5, which is: 1 + 2 + 3 + 4 + 5, which, you guessed it, is 15.

    The solution? Just continuously add i1 to each location instead.
     
  3. Offline

    JoltTheBolt

    It didn't work. All the locations (l1, l2, l3, l4 , l5) turn out to be the same location (1 block, 5 blocks away from me in the direction I am looking at) and 5 particles appear on that location. I know I am doing something wrong because I just don't understand vectors that much, right now. Sorry about that.


    Code:
    Location start = p.getLocation();
        Vector i1 = start.getDirection().multiply(1);
        Location l1 = start.add(i1);
        Location l2 = l1.add(i1);
        Location l3 = l2.add(i1);
        Location l4 = l3.add(i1);
        Location l5 = l4.add(i1);
        w.playEffect(l1, Effect.MOBSPAWNER_FLAMES, null);
        w.playEffect(l2, Effect.MOBSPAWNER_FLAMES, null);
        w.playEffect(l3, Effect.MOBSPAWNER_FLAMES, null);
        w.playEffect(l4, Effect.MOBSPAWNER_FLAMES, null);
        w.playEffect(l5, Effect.MOBSPAWNER_FLAMES, null);
     
  4. Offline

    CraftCreeper6

    @JoltTheBolt
    Theoretically it works. Adding a direction to a vector will give you vector + direction so I'm not sure why that wouldn't be working. Print out the value of l1-l5 and see what it says.
     
  5. Offline

    JoltTheBolt

    @CraftCreeper6 Thanks for your help. It's not the most efficient because I simply increase the lines in code by copying and pasting but it works. I fixed it by doing this:

    Code:
    Location loc = p.getLocation();
        Vector v1 = loc.getDirection().multiply(1);
        Vector v2 = loc.getDirection().multiply(2);
        Location l1 = loc.add(v2);
        w.playEffect(l1, Effect.MOBSPAWNER_FLAMES, null);
        w.playEffect(l1, Effect.MOBSPAWNER_FLAMES, null);
        for (Entity en1 : l1.getChunk().getEntities()){
            if (en1.getLocation().distance(l1) < 1){
                en1.setFireTicks(100);
                Damageable d1 = (Damageable) en1;
                d1.damage(10);
            }
    
    }
        Location l2 = l1.add(v1);
        w.playEffect(l2, Effect.MOBSPAWNER_FLAMES, null);
        w.playEffect(l2, Effect.MOBSPAWNER_FLAMES, null);
        for (Entity en2 : l2.getChunk().getEntities()){
            if (en2.getLocation().distance(l2) < 1){
                en2.setFireTicks(100);
                Damageable d2 = (Damageable) en2;
                d2.damage(10);
            }
    
    }
        Location l3 = l2.add(v1);
        w.playEffect(l3, Effect.MOBSPAWNER_FLAMES, null);
        w.playEffect(l3, Effect.MOBSPAWNER_FLAMES, null);
        for (Entity en3 : l3.getChunk().getEntities()){
            if (en3.getLocation().distance(l3) < 1){
                en3.setFireTicks(100);
                Damageable d3 = (Damageable) en3;
                d3.damage(10);
            }
    
    }
        Location l4 = l3.add(v1);
        w.playEffect(l4, Effect.MOBSPAWNER_FLAMES, null);
        w.playEffect(l4, Effect.MOBSPAWNER_FLAMES, null);
        for (Entity en4 : l4.getChunk().getEntities()){
            if (en4.getLocation().distance(l4) < 1){
                en4.setFireTicks(100);
                Damageable d4 = (Damageable) en4;
                d4.damage(10);
            }
    
    }
    I think it is how you said I should do it but with a bit different route.
     
Thread Status:
Not open for further replies.

Share This Page