Solved Geting block in unloaded chunks

Discussion in 'Spigot Plugin Development' started by BananaPuncher714, May 31, 2017.

  1. I need a way to fetch the highest blocks in each chunk around a location, but everytime my loop actually executes, it freezes and crashes the server. Here is my code that I think it is caught in:
    Code (Java):
    for ( int x = 0; x < 1024; x =+ 512 ) {
        for ( int z = 0; z < 1024; z =+ 512 ) {
            Material mat = w.getHighestBlockAt( cx + x - 512 + state, cz + z - 512 + state ).getLocation().clone().subtract( 0, 1, 0 ).getBlock().getType();
    I have also tried to load the chunk beforehand, but it just does not want to work.
  2. why would you need to get the highest block of an non existing chunk ?
  3. Because im trying to create a byte array for my MapRenderer so it loads the entire map faster and not cause lag, and in order to do that, I have to get the top block of the area around the player.

    EDIT: Nevermind, I solved it by changing the x =+ 512 and z =+ 512 to x = x + 512. Apparently it was stuck in an infinite loop :rolleyes:
    #3 BananaPuncher714, May 31, 2017
    Last edited: May 31, 2017
  4. I'm not certain if you can do this without loading the chunk first, is your goal to keep the chunk loaded unloaded, or is it okay to load it first, then unload it?
  5. I think the world#getHighestBlockAt() loads the chunk in, but throws errors if it hasnt been generated yet