Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Work with chunks

Comments in 'Plugin Development' started by Asparanc, Aug 7, 2015.

  1. Asparanc
    Offline

    Asparanc Active Member

    Joined:
    Feb 20, 2015
    Posts:
    210
    Minecraft User:
    Asparanc
    How to get chunkX and chunckY from player position ? It's for a claim system.
  2. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    I assume you mean chunk x,z as there is no y.

    PosX >> 4
    PosZ >> 4

    You could also divide by 16.
    EvolSoft, PEMapModder and Falk like this.
  3. Asparanc
    Offline

    Asparanc Active Member

    Joined:
    Feb 20, 2015
    Posts:
    210
    Minecraft User:
    Asparanc
    Okay thx and yes Z not Y it's a fail x)
    EvolSoft likes this.
  4. Asparanc
    Offline

    Asparanc Active Member

    Joined:
    Feb 20, 2015
    Posts:
    210
    Minecraft User:
    Asparanc
    But if the player is in x = 158 z = 115 (not multiple of 16) ot will give the correct
    he correct chunkX and chunkZ where the playzr stand ? And all players in the same chunk will get the same chunkX and ChunkZ with :
    X >> 4
    Z >> 4
    ?
  5. aliuly
    Offline

    aliuly Notable Member Plugin Developer

    Joined:
    Feb 8, 2014
    Posts:
    1,086
    Plugins:
    17
    >> is a bit shift so it automatically rounds down. It would be slightly faster than a division which may do a float conversion which you then need to cast to int.
    PEMapModder likes this.
  6. Asparanc
    Offline

    Asparanc Active Member

    Joined:
    Feb 20, 2015
    Posts:
    210
    Minecraft User:
    Asparanc
    Ok i've ask it because it look like so easy ^^ just >> 4 and you have chunkX (or Z) ^^
    Falk likes this.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Exactly because it is easy, that's why they made it 16 blocks per chunk instead of 20 blocks per chunk. Because you can't achieve the same thing with 20. You'll have to divide by 20 and cast to int in that case.
    Asparanc likes this.
  8. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Unless you were using a base-20 computer :)
  9. Asparanc
    Offline

    Asparanc Active Member

    Joined:
    Feb 20, 2015
    Posts:
    210
    Minecraft User:
    Asparanc
    Right :)
  10. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    You didn't fail at all. Any Voxel based game has 16x16x16 render chunks. Don't forget that Minecraft has a build height of 256 blocks so there are also 16 chunks vertically (Render Chunks).
    upload_2015-8-11_9-54-44.png
    See the green part. It's an entire chunk. As you can see it has only X and Z coordinates. But if you see in the Hierarchy the chunk has 16 subitems: they are Render Chunks and they are 16x16x16 in size and they have only the Y coordinate (from 0 to 15)

Share This Page

Advertisement