Progblem with getChunk


#1

This is my code:

Chunk chunk = player.getLocation().getExtent().getChunk(player.getLocation().getBlockPosition()).get();
Location chunkLocation = chunk.getLocation(player.getLocation().getPosition()).sub(chunk.getBlockMin().toDouble());

but it always turn in a “No value preset” error, what am I doing wrong?


#2

What are you trying to do ?
The best equivalent of your code which should be working (I’ve not tested) is:

Location<World> locationInWorld = player.getLocation();
Chunk chunk = locationInWorld.getExtent().getChunk(locationInWorld.getChunkPosition()).get();
Location<Chunk> locationInChunk = chunk.getLocation(locationInWorld.getPosition());
Location<Chunk> relativeLocationInChunk = locationInChunk.sub(chunk.getBlockMin());

But it’s nearly useless because locationInWorld and locationInChunk hold the same positions and relativeLocationInChunk is almost unusable.


#3

I want to know the chunk where the player is on, because I want to create a code of conquer terrain


#4

Then the two first lines of the code I have given should be enough unless you need something else. :slight_smile: