# Work with chunks

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

1. Offline

### AsparancActive Member

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

### aliulyNotable MemberPlugin 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. Offline

### AsparancActive Member

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

### AsparancActive Member

Joined:
Feb 20, 2015
Posts:
210
Minecraft User:
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. Offline

### aliulyNotable MemberPlugin 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. Offline

### AsparancActive Member

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

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,294
Plugins:
11
Minecraft User:
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. Offline

### FalkStaff MemberGlobal Moderator

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

### AsparancActive Member

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

### EvolSoftNotable MemberPlugin Developer

Joined:
Sep 10, 2014
Posts:
821
Plugins:
15
Minecraft User:
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).

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)