Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow empty chunks to be selected if their region exists #1593

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions chunky/src/java/se/llbit/chunky/map/MapTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void draw(MapBuffer buffer, WorldMapLoader mapLoader, ChunkView view,
if (scale >= 16) {
Chunk chunk = mapLoader.getWorld().currentDimension().getChunk(pos);
renderChunk(chunk);
if (!(chunk instanceof EmptyChunk) && selection.isSelected(pos)) {
if (!(chunk instanceof EmptyRegionChunk) && selection.isSelected(pos)) {
for (int i = 0; i < tileWidth * tileWidth; ++i) {
pixels[i] = selectionTint(pixels[i]);
}
Expand All @@ -76,8 +76,11 @@ public void draw(MapBuffer buffer, WorldMapLoader mapLoader, ChunkView view,
for (int z = 0; z < 32; ++z) {
for (int x = 0; x < 32; ++x) {
Chunk chunk = region.getChunk(x, z);
//Calculate the chunk position as empty chunks are (0, 0)
ChunkPosition pos = region.getPosition().chunkPositionFromRegion(x, z);

pixels[pixelOffset] = chunk.biomeColor();
if (isValid && !(chunk instanceof EmptyChunk) && selection.isSelected(chunk.getPosition())) {
if (isValid && !(chunk instanceof EmptyRegionChunk) && selection.isSelected(pos)) {
pixels[pixelOffset] = selectionTint(pixels[pixelOffset]);
}
pixelOffset += 1;
Expand Down
4 changes: 4 additions & 0 deletions chunky/src/java/se/llbit/chunky/world/ChunkPosition.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public ChunkPosition getRegionPosition() {
return new ChunkPosition(x >> 5, z >> 5);
}

public ChunkPosition chunkPositionFromRegion(int localX, int localZ) {
return new ChunkPosition((this.x << 5) | (localX & 0x1f), (this.z << 5) | (localZ & 0x1f));
}

/**
* @return The packed {@code long} chunk position for the x and z
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private boolean setChunk(ChunkPosition pos, boolean selected) {
private boolean setChunk(Dimension dimension, ChunkPosition pos, boolean selected) {
//Only need to check if the chunk isn't empty on selecting a chunk, as it must exist if it's already selected
Chunk chunk = dimension.getChunk(pos);
if(selected && (chunk == EmptyRegionChunk.INSTANCE || chunk == EmptyChunk.INSTANCE)) {
if(selected && (chunk == EmptyRegionChunk.INSTANCE)) {
return false;
}
return setChunk(pos, selected);
Expand All @@ -87,7 +87,7 @@ private boolean setChunksWithinRegion(Dimension dimension, ChunkPosition regionP
if(previousValue != selected) {
ChunkPosition chunkPos = new ChunkPosition(chunkX, chunkZ);
Chunk chunk = dimension.getChunk(chunkPos);
if(chunk != EmptyRegionChunk.INSTANCE && chunk != EmptyChunk.INSTANCE) {
if(chunk != EmptyRegionChunk.INSTANCE) {
selectionChanged = true;
selectedChunksForRegion.set(bitIndex, selected);

Expand Down
Loading