### Communities

tag:snake search within a tag
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
created:<1w created < 1 week ago
post_type:xxxx type of post
Q&A

Post

# How would I go about chunk loading around player in a 3 dimensional cartesian coordinate space [closed]

+0
−3

Closed as unclear by cuzzo‭ on Nov 7, 2022 at 17:26

This question cannot be answered in its current form, because critical information is missing.

This question was closed; new answers can no longer be added. Users with the reopen privilege may vote to reopen this question if it has been improved or closed incorrectly.

So I am in the process of creating a voxel sandbox survival game (minecraft clone) in javaFX. I am at a point where I need to come up with a way to load the chunks in my surrounding given a render distance setting.

At first I thought this was a simple as iterating through the chunk coordinates in the players vicinity and adding them to the world if they did not already exist (done by initializing new chunk) or adding a pre-existing chunk if they did (done by `manager`) such as this:

``````public ArrayList<Chunk> getChunksToRender() {
//Defines the starting chunk to begin iteration. This chunk is in the corner of the area that should be rendered
//playerChunk is the chunk that the player is currently in.
//Chunks are at locations divisible by 16, e.x 0,0,0 |16,16,0 | 16,32,0
Point3D start = new Point3D(playerChunk.getLocation().getX() + (renderDistance * bounds),
playerChunk.getLocation().getY() + (renderDistance * bounds), playerChunk.getLocation().getZ());

chunks = new ArrayList<>();
for (int i = (int) start.getX(); i < start.getX() + (renderDistance * bounds); i+= bounds) {
for (int j = (int) start.getY(); j < start.getY() + (renderDistance * bounds); j+= bounds) {
if (manager.containsChunkWithLocation(new Point3D(i, j, 0))) {
//Gets pre existing chunk from chunk manager and adds it to chunks to be rendered
}
else {
//Creates new Chunk at location (i, j, 0) xyz coords
}
}
}
//Returns chunks to be added to world by chunk manager
return chunks;
}
``````

`bounds` is the chunk width and height (Same number, 16x16 in this case). All chunks are at the same Z coordinate (vertical). However as chunks are created and loaded around a player, they eventually cross the x and y axis. I am trying to think of a solution that accounts for the eventual transition from a negative coordinate to a positive and from positive to negative.

A visual example of what I was going for below. The green arrow represents the order in which the chunks would load, iterating through each one in the players vicinity and loading it:

But I quickly remembered that this 3D space is cartesian and this method quickly falls apart when an axis is encountered.

How would I go about implementing something that accounts for axis? I'm not necessarily looking for code, but I am just not sure how to go about doing this. Any help would be appreciated!

Why does this post require moderator attention?
Why should this post be closed?

"Falls apart" in what way? (3 comments)
"Falls apart" in what way?
Peter Taylor‭ wrote 7 months ago

"Falls apart" in what way?

cuzzo‭ wrote 7 months ago

It will only load the chunks with positive coordinates since at some point it will encounter an axis and go negative.

Peter Taylor‭ wrote 7 months ago

I can't see anything in this code which treats positive and negative numbers differently. Is the problem elsewhere? And can you just avoid it by starting at Integer.MAX_VALUE / 2 ?