Solved Help with Experience Orbs

Discussion in 'Plugin Development' started by Orchface, Nov 21, 2017.

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

    Orchface

    Is there a Bukkit method/class that could spawn XP orbs in a straight line?

    I want to get a straight line of XP orbs that are 0.1 meters apart.

    So far, I have attempted two methods (both of which do not function in the exact way I intend)

    Method 1 - Using Bukkit's World.spawn() method (Does not work at all):
    Code:
    int lineLength = 5;
    Location loc = player.getLocation();
    for(int i = 0; i < 10 * lineLength; i++){
    player.getWorld().spawnEntity(loc,EntityType.EXPERIENCE_ORB);
    loc.setX(loc.getX()+0.1);
    }
    
    //this code spawns a rough scatter of XP orbs and does not by any means resemble
    //a straight line
    Result of Method 1:
    [​IMG]


    Method 2 - Brute force using /summon command (Works, but impractical, inefficient, and straight up stupid):
    Code:
    int lineLength = 5;
    
    for(double i = 0; i < lineLength; i+= 0.1){
    player.performCommand("summon XPOrb ~ ~-5 ~"+i);
    }
    //this spawns a perfectly straight line of XP orbs as I wish, however it is VERY slow
    //and I'm pretty sure this is not the way you're supposed to use /summon anyway...
    Result of Method 2:
    [​IMG]

    ... yeah.

    I am looking for something that has the same result as method 2, but without the inefficiency and impracticality.

    Any suggestions?

    All help is appreciated.
     
  2. Offline

    Zombie_Striker

    @Orchface
    Try setting the velocity of the orbs to be 0, and make sure that the spawn location is above the ground .

    If that does not work, you can use the Entity#teleport method as a hacky-fix to make sure all particles are in the correct location.
     
    MightyOne likes this.
  3. Offline

    Orchface


    None of these seem to work.

    It appears that Experience Orbs cannot be moved or teleported after they are spawned... But /summon evidently works. Perhaps there is a way to invoke the same function as /summon without actually running the command? I'm completely stumped.
     
  4. Offline

    Unknown123

    Please try world.spawn(location, ExperienceOrb.class).setVelocity(new Vector(0D, 0D, 0D));
     
    Orchface likes this.
  5. Offline

    Orchface

    Works! Thanks!
     
Thread Status:
Not open for further replies.

Share This Page