Get location of an entity

Discussion in 'Plugin Development' started by thorvaldemar, Nov 23, 2015.

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

    thorvaldemar

    Hey guys. I just want one little thing. How can i get the location of a snowball when it is in air??
     
  2. entity.getLocation()
     
  3. Offline

    thorvaldemar

    @FisheyLP If i did that woulden i get all the entitys??
     
  4. Offline

    q8minecraft

    @thorvaldemar unless you're looping through all the entities in the world, then no.
     
  5. Offline

    thorvaldemar

    @q8minecraft Okay i don't think i understand. Okay what i wanted to do is every time there is a snowball. The game will execute the snowball and then summon a firework at it every single tick. Do you know how that can be done??
     
  6. Offline

    q8minecraft

  7. Offline

    CraftCreeper6

    @thorvaldemar
    Every single tick?!?!?

    Repeating task with 1 as the delay and repeats as however many. Don't know what it is? Look it up.

    As for firework, you need to create the item stack and manipulate the object itself, I don't remember exactly how you do it, but you can look that up too.
     
  8. Offline

    EvilWitchdoctor

    I would suggest adding the snowball to a Set on ProjectileLaunchEvent and then having a scheduler run ever 1 tick to do the firework effect. If you need to see some code I can whip it up
     
  9. Offline

    thorvaldemar

  10. Offline

    RoboticPlayer

  11. Offline

    thorvaldemar

    @henderry2019 I'm sure you are trying to help me, but i'm actully learning best by getting a code and the experince with it and this is something i've tryed to do in a long time and i was about to give up, but i would give it one more chance. Thank you for the website. I think i will find i very useful :)
     
  12. Offline

    mcdorli

    wrong, no one learns like that. Do you know java?
     
    Zombie_Striker likes this.
  13. Offline

    EvilWitchdoctor

    Woah slow down people let's not get into a fight.
    @thorvaldemar If you've never used schedulers before, here's something to look at to get you started. Obviously it will need tweaking but something generally like this ought to work to help you solve your problem
    Code:
        @EventHandler
        public void onSnowballLaunch(ProjectileLaunchEvent evt){
            if(evt.getEntityType() == EntityType.SNOWBALL /*&& any other conditions*/){
                snowballList.add(evt.getEntity());
                if(snowballList.getSize() == 1) runEffectLoop();
            }
        }
       
        //somwhere else in your code
        public void runEffectLoop(){
            getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
                @Override
                public void run(){
                    for(Entity entity : snowballList) playFireworkEffect(entity.getLocation());
                    if(!snowballList.isEmpty()) runEffectLoop();
                }
            }, 1);//runs every 1 tick
        }
     
  14. Offline

    LemonCoder

    You would do this by, Entity.getLocation();
     
  15. Offline

    RoboticPlayer

    If you are going to spoonfeed, at least do it right. This code makes no sense at all. Are you seriously trying to call a method within itself?

    Edit: My last post got cut off, I was going to say look at this for events: http://wiki.bukkit.org/Event_API_Reference
    And this for schedulers: http://wiki.bukkit.org/Scheduler_Programming
     
  16. Offline

    EvilWitchdoctor

    @henderry2019 Methods can indeed call themselves-> e.g., recursive methods. Not always the best idea to, but sometimes very useful.
    Good idea posting the API refs, here's another to add to that handy list related to the topic:
    https://hub.spigotmc.org/javadocs/bukkit/
     
  17. Offline

    Scimiguy

    You posted a recursive method inside a recursive method inside a for loop.

    I'd be amazed if the server didn't instantly crash
     
  18. Offline

    Lordloss

    Lol, selfown.
    You flame people because you just cant understand what this really simple method does. Maybe you are the one who should take some java beginner lessons, instead of talking like a smart guy.
     
  19. Offline

    Xerox262

    What? It wasn't inside a for loop. It was after one. It is still the wrong way to do it as he's creating a new runnable every tick rather than running a/many BukkitRunnable timer.
     
  20. Offline

    Scimiguy

    @Xerox262
    Ah you're right, my mistake

    Still, terrible
     
  21. Offline

    thorvaldemar

    Yes i read a book.

    Thanks for all the help... And yes i'm not the best to java, but i can all ways learn and not every body learns the same way. XD
     
    Last edited: Nov 24, 2015
Thread Status:
Not open for further replies.

Share This Page