Hi there. I’m making a plugin and I need to know how to find out the X, Y, and Z of the chunk the player is standing in. Has this even been implemented into the API?
public boolean onCommand(CommandSource source, String arguments, List<String> parents) throws CommandException {
if(!(source instanceof Player)) {
return false;
}
Player player = (Player) sender;
int chunkX, chunkY, chunkZ;
chunkX = //Get the X of the chunk that the player is standing in.
chunkY = //and so on
chunkZ = //...
return true;
}
I took a brief look at the code FerusGrim pointed to, and I believe this information could be found out by dividing the player’s getBlockX() and getBlockZ() functions by 16 and then flooring the result. I am not 100% sure, but that is how I would do it.
@MoseMister That is a really bad way to grab a chunk an entity is in. You should be passing the player’s block position to one of the following World methods
so something like
int chunkX = player.getLocation().getBlockPosition().getX() >> 4;
int chunkZ = player.getLocation().getBlockPosition().getZ() >> 4;
Optional<Chunk> chunk = world.getChunk(chunkX, 0, chunkZ);