ArrayOutOfBounds in Biomegrid

Discussion in 'Plugin Development' started by whereisthemonkey, Apr 13, 2016.

Thread Status:
Not open for further replies.
  1. Hey together, I am currently trying to generate chunk data with the following code:

    Code:java
    1.  
    2. @Override
    3. public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, BiomeGrid biome) {
    4. //ChunkData data = createChunkData(world);
    5. System.out.println(chunkX);
    6. System.out.println(chunkZ);
    7. switch (random.nextInt(11)) {
    8. case 0:
    9. biome.setBiome(chunkX, chunkZ, Biome.BIRCH_FOREST);
    10. break;
    11. case 1:
    12. biome.setBiome(chunkX, chunkZ, Biome.COLD_TAIGA);
    13. break;
    14. case 2:
    15. biome.setBiome(chunkX, chunkZ, Biome.DESERT);
    16. break;
    17. case 3:
    18. biome.setBiome(chunkX, chunkZ, Biome.EXTREME_HILLS);
    19. break;
    20. case 4:
    21. biome.setBiome(chunkX, chunkZ, Biome.FLOWER_FOREST);
    22. break;
    23. case 5:
    24. biome.setBiome(chunkX, chunkZ, Biome.FOREST);
    25. break;
    26. case 6:
    27. biome.setBiome(chunkX, chunkZ, Biome.JUNGLE);
    28. break;
    29. case 7:
    30. biome.setBiome(chunkX, chunkZ, Biome.PLAINS);
    31. break;
    32. case 8:
    33. biome.setBiome(chunkX, chunkZ, Biome.SAVANNA);
    34. break;
    35. case 9:
    36. biome.setBiome(chunkX, chunkZ, Biome.SUNFLOWER_PLAINS);
    37. break;
    38. case 10:
    39. biome.setBiome(chunkX, chunkZ, Biome.TAIGA);
    40. break;
    41. default:
    42. biome.setBiome(chunkX, chunkZ, Biome.PLAINS);
    43. break;
    44. }
    45. return (ChunkData) world.getChunkAt(chunkX, chunkZ).getChunkSnapshot();
    46. }
    47.  


    I looked at the Biomegrid class and saw that it is an array of 256 length. My question now is, how can I fix this error:

    Code:java
    1.  
    2. Error occurred while enabling ProsperityRush v1.0 (Is it up to date?)
    3. net.minecraft.server.v1_8_R3.ReportedException: Exception generating new chunk
    4. at net.minecraft.server.v1_8_R3.ChunkProviderServer.originalGetChunkAt(ChunkProviderServer.java:150) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    5. at net.minecraft.server.v1_8_R3.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:118) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    6. at net.minecraft.server.v1_8_R3.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:97) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    7. at org.bukkit.craftbukkit.v1_8_R3.CraftServer.createWorld(CraftServer.java:929) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    8. at org.bukkit.Bukkit.createWorld(Bukkit.java:464) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    9. at org.bukkit.WorldCreator.createWorld(WorldCreator.java:261) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    10. at me.whereisthemonkey.ProsperityRush.Parcel.ParcelWorld.<init>(ParcelWorld.java:24) ~[?:?]
    11. at me.whereisthemonkey.ProsperityRush.ProsperityRush.onEnable(ProsperityRush.java:35) ~[?:?]
    12. at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    13. at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-db6de12-18fbb24]
    14. at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-db6de12-18fbb24]
    15. at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot.jar:git-Spigot-db6de12-18fbb24]
    16. at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot.jar:git-Spigot-db6de12-18fbb24]
    17. at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414) [spigot.jar:git-Spigot-db6de12-18fbb24]
    18. at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378) [spigot.jar:git-Spigot-db6de12-18fbb24]
    19. at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333) [spigot.jar:git-Spigot-db6de12-18fbb24]
    20. at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) [spigot.jar:git-Spigot-db6de12-18fbb24]
    21. at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [spigot.jar:git-Spigot-db6de12-18fbb24]
    22. at java.lang.Thread.run(Unknown Source) [?:1.8.0_65]
    23. Caused by: java.lang.ArrayIndexOutOfBoundsException: -13
    24. at org.bukkit.craftbukkit.v1_8_R3.generator.CustomChunkGenerator$CustomBiomeGrid.setBiome(CustomChunkGenerator.java:27) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    25. at me.whereisthemonkey.ProsperityRush.Parcel.Generators.HillParcelGenerator.generateChunkData(HillParcelGenerator.java:73) ~[?:?]
    26. at org.bukkit.craftbukkit.v1_8_R3.generator.CustomChunkGenerator.getOrCreateChunk(CustomChunkGenerator.java:53) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    27. at net.minecraft.server.v1_8_R3.ChunkProviderServer.originalGetChunkAt(ChunkProviderServer.java:142) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    28. ... 18 more
    29.  


    Which x and y should I use and could anyone please help me out?

    Thank you very much,
    Whereisthemonkey
     
  2. Offline

    Zombie_Striker

    What is line 73 from call HillParcelGenerator? It seems you are trying to get a negitive index at that line.
     
  3. I know what I am doing, line 73 is setBiome which calls an Array. The Out of Bounds is called because an Array can't as we both know be called ad a negative value like Array[-13]. My question was what could i possibly do wrong and how can I do it right?
     
  4. Offline

    Zombie_Striker

    @whereisthemonkey
    Print out what the random is equal to, and what each Biome value is equal to.
     
  5. @Zombie_Striker Hey, the random works fine I already did all you do ;)
    What I guess is that I am using the generateChunkData function wrong, but there is no tutorial so I was hoping somebody could help me out
     
  6. Offline

    mcdorli

  7. Last edited by a moderator: Apr 15, 2016
  8. Offline

    MisterErwin

    @whereisthemonkey Did you really read it?

    Have a look at the parameters of ChunkGenerator#generateChunkData and the ones from BiomeGrid.
     
  9. Offline

    Jero

    ArrayOutOfBound means the element you are asking for does not exist.

    Can you show me the class and this line:

    me.whereisthemonkey.ProsperityRush.Parcel.Generators.HillParcelGenerator.generateChunkData(HillParcelGenerator.java:73)
     
  10. @Jero
    Code:java
    1.  
    2. biome.setBiome(chunkX, chunkZ, Biome.JUNGLE);
    3.  


    I know that the problem is cause by calling the element -13 from the ArrayList biomes[256]

    Thanks for your quick reply!

    @mcdorli If you did it so many times I would highly appreciate it if you share your knowledge with me! Thank you!
     
  11. Offline

    mcdorli

    Yeah, BiomeGrid#setBiome takes in arguments relative to the chunk, and not the chunk's coordinates. You need to give it a value between 0 and 15.

    And oohhh...look at it what i says on the 2nd method declaration https://hub.spigotmc.org/javadocs/spigot/org/bukkit/generator/ChunkGenerator.BiomeGrid.html
     
    MisterErwin likes this.
Thread Status:
Not open for further replies.

Share This Page