Filled [Req] Discover Bar

Discussion in 'Archived: Plugin Requests' started by wowzersam, May 24, 2014.

  1. Offline

    IvanTheForth

  2. Offline

    wowzersam

  3. Offline

    wowzersam

  4. Offline

    Etsijä

    IvanTheForth Can you tell us where exactly do things go wrong with negative values? Trigonometric functions can be tricky sometimes. :) Have you isolated the problem to the BarUtils class?
     
  5. Offline

    IvanTheForth

    Etsijä
    The problem is when there are negatives entered, it throws my method a wrench. It still produces a result, but the result is not correct and could lead to players walking in the wrong direction.
     
  6. Offline

    Etsijä

    Which method is it? I could have a look at it.
     
  7. Offline

    IvanTheForth

    Etsijä
    There are two methods that do pretty much the same thing. I have two of them because I wanted to test in my IDE without having to start up my server.
     
  8. Offline

    iRamboxC4x

    Sounds look good idea [diamond]
     
  9. Offline

    whitehooder

  10. Offline

    wowzersam

  11. Offline

    15987632

    IvanTheForth i don't know if this will do anything but when the yaw goes negative can you add the amount equal to a full rotation of yaw so it goes positive and its in the same direction. Idk just thought of the idea from trig in school
     
  12. Offline

    IvanTheForth

  13. Offline

    15987632

  14. Offline

    whitehooder

    I'll try to write a method for it. I only had a 20 minute look so I didn't really figure out much, other than how it was supposed to work. I'm quite busy with other stuff on and off, which is why I haven't been on Bukkit lately. Anyway, lets get this over with, shall we? :3
     
  15. Offline

    Harrison015

    Any progress updates on the problem?
     
  16. Offline

    whitehooder

    I'm sorry about this. There's been too much going on lately.

    Anyway, @IvanTheFort , I hope you can continue the plugin with this snippet:
    Code:java
    1. public static String addWaypoint(String bar, WaypointData wpd, Location pLoc) {
    2. return addWaypoint(bar, wpd.getLocation(), pLoc, wpd.getIcon());
    3. }
    4.  
    5. public static String addWaypoint(String bar, Location wpLoc, Location pLoc, char icon) {
    6. double dx = pLoc.getX() - (wpLoc.getBlockX()+0.5);
    7. double dz = pLoc.getZ() - (wpLoc.getBlockZ()+0.5);
    8.  
    9. double yaw = Math.toDegrees(Math.atan2(dz, dx));
    10. double pYaw = pLoc.getYaw();
    11. yaw = (yaw<0?180+(180+yaw):yaw);
    12. pYaw = (pYaw<0?180+(180+pYaw):pYaw);
    13. pYaw -= 90;
    14.  
    15. double offset;
    16. if (Math.max(yaw, pYaw) - Math.min(yaw, pYaw) > 180) {
    17. if (pYaw > yaw) {
    18. offset = 360-pYaw + yaw;
    19. } else {
    20. offset = -(360-yaw + pYaw);
    21. }
    22. } else {
    23. offset = -(pYaw - yaw);
    24. }
    25.  
    26. if (Math.abs(offset) > 90) {
    27. return bar;
    28. }
    29.  
    30. // System.out.println("yaw: " + yaw + ", pYaw: " + pYaw + ", offset: " + offset);
    31.  
    32. StringBuilder sb = new StringBuilder(bar);
    33.  
    34. for(int i = 0; i < 29; i++){
    35. float increment = 180F/29F;
    36. float min = -90+(i*increment);
    37. float max = -90+((i+1)*increment);
    38. if (offset >= min && offset < max) {
    39. sb.setCharAt(i, icon);
    40. }
    41. }
    42.  
    43. return sb.toString();
    44. }

    It seems to be working great ;)

    Edit: Oh, and here's the main method I used to try it out, in case you don't want to fire up a server ;)
    Code:java
    1. public static void main(String[] args){
    2. Location wpLoc = new Location(null, -10, 0, 0); //x
    3. Location wpLoc2 = new Location(null, -10, 0, -10); //y
    4. Location wpLoc3 = new Location(null, -10, 0, 10); //z
    5. Location pLoc = new Location(null, 0.5, 0.5, 0.5, 0, 0);
    6.  
    7. String bar = "----------------------------- Forward";
    8. bar = BarUtils.addWaypoint(bar, wpLoc, pLoc, 'X');
    9. bar = BarUtils.addWaypoint(bar, wpLoc2, pLoc, 'Y');
    10. bar = BarUtils.addWaypoint(bar, wpLoc3, pLoc, 'Z');
    11.  
    12. System.out.println(bar);
    13.  
    14. pLoc = new Location(null, 0.5, 0.5, 0.5, 90, 0);
    15. bar = "----------------------------- Right";
    16. bar = BarUtils.addWaypoint(bar, wpLoc, pLoc, 'X');
    17. bar = BarUtils.addWaypoint(bar, wpLoc2, pLoc, 'Y');
    18. bar = BarUtils.addWaypoint(bar, wpLoc3, pLoc, 'Z');
    19.  
    20. System.out.println(bar);
    21.  
    22. pLoc = new Location(null, 0.5, 0.5, 0.5, -90, 0);
    23. bar = "----------------------------- Left";
    24. bar = BarUtils.addWaypoint(bar, wpLoc, pLoc, 'X');
    25. bar = BarUtils.addWaypoint(bar, wpLoc2, pLoc, 'Y');
    26. bar = BarUtils.addWaypoint(bar, wpLoc3, pLoc, 'Z');
    27.  
    28. System.out.println(bar);
    29.  
    30. pLoc = new Location(null, 0.5, 0.5, 0.5, 180, 0);
    31. bar = "----------------------------- Behind";
    32. bar = BarUtils.addWaypoint(bar, wpLoc, pLoc, 'X');
    33. bar = BarUtils.addWaypoint(bar, wpLoc2, pLoc, 'Y');
    34. bar = BarUtils.addWaypoint(bar, wpLoc3, pLoc, 'Z');
    35.  
    36. System.out.println(bar);
    37. }


    IvanTheForth Don't know why the tahg didn't work...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  17. Offline

    15987632

  18. Offline

    whitehooder

    Damn it! :3
    Anyway, I thought I'd post a link to a test jar ;)
     
  19. Offline

    Harrison015

    whitehooder
    I'll test soon ;)

    whitehooder
    Works perfect until I have two waypoints near me.

    Suggestions: Commands to manage and set waypoints, and another command to set navigation to a certain waypoint on the bar with the health being how close you are to that waypoint

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  20. Offline

    whitehooder

    It's not my project, but I'm curious as to what happens when you're near two. Do the second one show up or are the directions messed up?
     
  21. Offline

    Harrison015

    None show up, for some reason
     
  22. Offline

    whitehooder

    I doubt it has anything to do with the code I posted above. We could either wait for IvanTheForth to come back or I could have a look at it when I've got time for it.
     
  23. Offline

    wowzersam

    I've been gone for 2 weeks. Hows this plugin coming along?
     
  24. Offline

    whitehooder

    The problem is solved, but the plugin coder is gone (it seems). I could take on the project and give him the source later, but I figured it's best to wait just a few more days to see if he gets back any time soon. Tell me if you'd like me to do it ;)
     
  25. Offline

    wowzersam

    whitehooder I'd say it would be better to wait just a few more days, like you said. If there is no response in a few days then I'd like you to do it :)
     

Share This Page