Getting the COORDS of a certain type of nearest biome

Discussion in 'Plugin Development' started by muffinjello, Jun 18, 2013.

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

    muffinjello

    Hello!

    I am in the process of making something that when you type a command such as:
    /biome desert
    It will teleport you to the nearest biome that is a "desert"... however, I am in need of help/tips on how I should go about effectively searching out and returning the nearest specified biome...

    Any help is greatly appreciated, thanks!
     
  2. Offline

    Hedgehogs4Me

    Have you tried just guessing and checking? That is, getting a location with a modified version of the player's coordinates and checking the biome? Something like this, although I'm not known for getting it right on the first try and I'm rather new to all this, so take it with a grain of salt:

    Code:java
    1.  
    2. //There's probably an easier way to do this bit, but you should make sure they don't demand "hell" or "sky"... or "frsngurisgnr".
    3. public boolean isBiome(String mightBeBiome) {
    4. ArrayList<String> biomeList = new ArrayList<String>();
    5. biomeList.add("beach");
    6. biomeList.add("desert");
    7. biomeList.add("desert_hills");
    8. biomeList.add("forest");
    9. biomeList.add("forest_hills");
    10. biomeList.add("frozen_ocean");
    11. biomeList.add("frozen_river");
    12. biomeList.add("ice_mountains");
    13. biomeList.add("ice_plains");
    14. biomeList.add("jungle");
    15. biomeList.add("jungle_hills");
    16. biomeList.add("mushroom_island");
    17. biomeList.add("mushroom_shore");
    18. biomeList.add("ocean");
    19. biomeList.add("plains");
    20. biomeList.add("small_mountains");
    21. biomeList.add("swampland");
    22. biomeList.add("taiga");
    23. biomeList.add("taiga_hills");
    24. return biomeList.contains(mightBeBiome);
    25. }
    26.  
    27. // this next part is inside your command thingamabob
    28.  
    29. if(sender instanceof Player && args.length==1 && arg[0] && isBiome(args[0])){
    30. boolean foundBiome=false;
    31. int biomeTry=1;
    32. int biomeTryX=1;
    33. int biomeTryZ=0;
    34. if(sender.getWorld.getBiome(sender.getLocation.getBlockX(), sender.getLocation.getBlockZ()).toString().equalsIgnoreCase(args[0])){
    35. sender.sendMessage("You are already in this biome!");
    36. return true;
    37. } else {
    38. while(!foundBiome){
    39. int xLoc = biomeTryX*50+sender.getLocation.getBlockX();
    40. int zLoc = biomeTryZ*50+sender.getLocation.getBlockZ();
    41. if(sender.getWorld().getBiome(xLoc, zLoc).toString().equalsIgnoreCase(args[0])){
    42. Chunk schunk = sender.getWorld().getChunkAt(xLoc, zLoc);
    43. if(!sender.getWorld().isChunkLoaded(schunk)) world.loadChunk(schunk);
    44. sender.teleport(new Location(sender.getWorld(), xLoc, sender.getWorld().getHighestBlockYAt(xLoc, zLoc), zLoc));
    45. break; //or foundBiome=true;
    46. } else {
    47. //Red alert, initiate spiral pattern! Commander Data, start manually entering numbers!
    48. if((biomeTry>=6&&biomeTry<9)||(biomeTry>=20&&biomeTry<25)||(biomeTry>=42&&biomeTry<49)||(biomeTry>=72&&biomeTry<81)||(biomeTry>=110&&biomeTry<120)){
    49. biomeTryX++;
    50. } else if((biomeTry>=2&&biomeTry<4)||(biomeTry>=12&&biomeTry<16)||(biomeTry>=30&&biomeTry<36)||(biomeTry>=56&&biomeTry<64)||(biomeTry>=90&&biomeTry<100)){
    51. biomeTryX--;
    52. } else if((biomeTry>=4&&biomeTry<6)||(biomeTry>=16&&biomeTry<20)||(biomeTry>=36&&biomeTry<42)||(biomeTry>=64&&biomeTry<72)||(biomeTry>=100&&biomeTry<110)){
    53. biomeTryZ++;
    54. } else if(biomeTry==1||(biomeTry>=9&&biomeTry<12)||(biomeTry>=25&&biomeTry<30)||(biomeTry>=49&&biomeTry<56)||(biomeTry>=81&&biomeTry<90)){
    55. biomeTryZ--;
    56. } else {
    57. sender.sendMessage("No nearby biomes of that type! Try walking a bit.");
    58. break; //or foundBiome==true; even if that's not really the case
    59. }
    60. biomeTry++;
    61. }
    62. }
    63. return true; //No idea if I put this guy in the right place, I just eyeballed it.
    64. }
    65. } else {
    66. return false;
    67. }


    Some notes:
    - I'm not sure if you can search for a biome without loading the chunk. If you can't, god help us all, because using this method you'd have to load the chunk for every single location you check.
    - I've never used a lot of this stuff (manual chunk loading, y values, looking for biomes...) in my life, I'm basically relying on the Javadocs to tell me what's possible.
    - This is stupidly messy, inefficient code that will probably lag your server to pieces, but it's at least showing the general idea.
    - I really not that good at much of anything, and it's 6 AM. I'm probably forgetting how to multiply ints or something dumb like that. Plus, it's totally untested, as I'm not about to just go make it for you, haha.
    - It'll only search within a radius of 250 and probably won't catch really tiny biomes, but hey, I tried.
     
    muffinjello likes this.
  3. Offline

    _Filip

Thread Status:
Not open for further replies.

Share This Page