Solved Can I Access Chunk Information?

Discussion in 'Plugin Development' started by Rellac, Oct 10, 2015.

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

    Rellac

    I have something in mind that I would like to develop and I need to gain an understanding of chunks.

    I'm having trouble with googling, as I seem to just be finding lots and lots of plugins that have something to do with chunks.

    Anyhoo, before starting my full blown plugin and confusing myself with stuff too complex for learning a single thing, I'd like to make the following plugin:

    Command: /replace <x, y> <x, y,z> <block>

    This will grab chunk x,y and replace block x,y,z with the defined block.

    Do chunks have a way to access via coordinates, or would I need to create a 0,0 reference myself? How could I begin to access them and do they contain a list of contained blocks within for this functionality?

    Any help would be great and I could also use any docs links you may have for me as I seem to be having trouble finding any reference to chunks with bukkit.

    Thanks.
     
  2. https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/World.html#getChunkAt(int, int)
    https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/World.html#getChunkAt(org.bukkit.Location)

    This will be a bit server intensive:
    Code:
    for (int y = 0; y <= world.getMaxHeight(); y++) { // Loop through every 'y' coordinate until the maximum world height.
        for (int x = 0; x <= 16; x++) { // Every chunk has a size of 16.
            for (int z = 0; z <= 16; z++) { // ^ Same here.
                Block blockAt = chunk.getBlock(x, y, z); // Get the block. I'm not sure if this requires world coordinates or chunk coordinates, but here I'm using chunk coordinates.
                // Do something.
            }
        }
    }
    
     
    Last edited: Oct 10, 2015
    Rellac likes this.
  3. Offline

    Rellac

  4. No problem, please mark this thread as solved.
     
  5. Offline

    Rellac

  6. Offline

    stefvanschie

    @Rellac

    Go above the OP and click Thread Tools > Edit title > Change prefix to solved
     
    Rellac likes this.
  7. Offline

    Rellac

    @stefvanschie Thanks! Done :)

    @KingFaris11 Sorry, I just noticed something.

    Your x/z loops are written as (int x = 0; x <= 16; x++)

    Unless my maths is failing me, should this not be (int x = 0; x < 16; x++) or (int x = 0; x <= 15; x++)? Each chunk is 16x16, so therefore, should I not be getting 0-15 rather than 0-16?

    I don't seem to be getting issues at the moment, but would this cause me issues further down the line?

    edit: same for y too?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
  8. Oops my mistake, yes it is < but for the max height, no, I believe it is <=.
     
    Rellac likes this.
Thread Status:
Not open for further replies.

Share This Page