Solved Looping thru chunks between 2 locations gets wrong chunks!

Discussion in 'Plugin Development' started by Lightspeed, Jan 24, 2016.

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

    Lightspeed

    So I have
    Code:
    for (int x = min.getBlockX(); x < max.getBlockX(); x+=16)
    {
      for (int z = min.getBlockZ(); z < max.getBlockZ(); z+=16)
      {
        chunks.add(p.getWorld().getChunkAt(x, z));
      }
    }
    This code doesen't give me the chunks im in at 124 it gives me chunk at chunk cordinated 124?!?!?
    Am I not understanding somthing?
     
  2. Offline

    teej107

    The ints required to call #getChunkAt() are Chunk coordinates rather than regular x/z values. You are getting a chunk every 16 chunks.
     
  3. Offline

    Lightspeed

    @teej107 Is there a way to get the chunk from normal coordinates?
    I fixed the problem but, is there any smaller code that I can use to get chunk inside normal coordinates?


    Code:
    Chunk minl = new Location(p.getWorld(), min.getBlockX(), min.getBlockY(), min.getBlockZ()).getChunk()
       , maxl = new Location(p.getWorld(), max.getBlockX(), max.getBlockY(), max.getBlockZ()).getChunk();
    
     
  4. Offline

    teej107

  5. Offline

    Lightspeed

    @teej107 Thanks I tried auto completing min/max.to and nothing popped up like to Location.
    OFFTOPIC: Do you have a quick awnser/link on how to serialize a NBTtag?
     
  6. Offline

    teej107

    Don't rely on your IDE too much. Actually searching the JavaDocs is way better than the IDE for reasons like what happened to you.

    Minecraft already serializes NBTTags.
     
  7. Offline

    Lightspeed

    Last edited: Jan 25, 2016
Thread Status:
Not open for further replies.

Share This Page