Help with retrieving locations

Discussion in 'Spigot Plugin Development' started by Drakonn, Jun 14, 2018.

  1. I am trying to create a /wild plugin that allows users to select a biome as well as a teleport range and they will only be teleported to a location that is in the that biome and is somewhere in the selected range. The name problem with this is obviously finding the location so to attempt and make the plugin more efficient I have decided to add a option in config to use previous location x% of the time. My problem however is with storing and retrieving the previous locations efficiently. My initial idea was to use a key system where a list of locations would be stored in a hashmap (lists would have a max size of 10 to prevent excessive memory usage) and each list would corrospond to a String that is a combination of the target world, target biome and the selected max and min ranges. My problem with this is that it is insanely inefficient as if I required a teleportation to any biome in the overworld with a range of 7500-10000 it would ignore a location that was a teleportation to a forest 7500-10000 blocks away. Similarly if I wanted to teleport a player 1000-10000 blocks away my current system would ignore 1000-5000, 5000-7500 and 7500-10000 locations which still all fit the required range. So my question is can anybody think of a better method to do this? Or does anyone have a more efficient of getting a random location that fits a set of requirements other than using a repeating task and the math.random to get the co-ordinates.
     
  2. wow, okay, that's a lot of information, I'm not sure what you're asking.
    I'm going to try to reformat this as bullet points.
    • users select a biome
    • they are teleported to a random location within one of said biome
    • there should be a preference to already loaded biomes / already used locations to save space and processing power
    • have an equal bias toward any range as long as it is within a hard limit?...
    • find an efficient way to store this information
    Is this correct? Is there something I'm missing?
     
  3. thats correct. The best bet for this problem is surely generating the locations algorithmic-ally because saving them will be insanely worse on performance in the long run.
     
    • Winner Winner x 1
  4. I've seen it done before with good results so decided to see if I could get it to work well myself, However at the moment I can't think of any effective ways to do this so going to leave it as is.
     
    • Friendly Friendly x 1
  5. make a plugin that scans the world every 100 or 200 blocks in 2 dimensions, in a determined range for example 20,000 blocks, and saves the coordinates and the biome in a database, you will have approximately 20,000 data rows, which could be distributed In the following way {"biome", "x", "z"}, then when you need a biome you just select everything that has the required biome and then you select a random point.

    the scan just need to be made one time
     
    • Creative Creative x 1
  6. Do yourself a favor and use Random#nextInt(int) as an offset to the min X/Z coordinates and you can just use the max Y at that location to get an XYZ. Most players also can't tell the difference between Random and a lower quality random, so also do yourself a favor and use ThreadLocalRandom while you're at it. If you're intent on getting the incremental thing to work, use it as it is and have a counter of some sort to calculate the min/max random range instead of storing everything. If you're doing this right, I see no reason to have a for loop at all.
     

Share This Page