Skip to content

Commit ddc220f

Browse files
committed
Refactor Chunk fields to final and extract coordinate utils
1 parent 365c5f8 commit ddc220f

1 file changed

Lines changed: 7 additions & 17 deletions

File tree

‎src/main/java/org/glavo/nbt/chunk/Chunk.java‎

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,37 @@
1717

1818
import org.glavo.nbt.NBTElement;
1919
import org.glavo.nbt.NBTParent;
20-
import org.glavo.nbt.internal.ChunkMetadata;
2120
import org.glavo.nbt.internal.ChunkUtils;
2221
import org.glavo.nbt.tag.CompoundTag;
2322
import org.jetbrains.annotations.Nullable;
2423

2524
public final class Chunk implements NBTParent<CompoundTag>, NBTElement {
26-
@Nullable ChunkRegion region;
27-
int localIndex = -1;
25+
final ChunkRegion region;
26+
final int localIndex;
2827

29-
CompoundTag rootTag;
28+
@Nullable CompoundTag rootTag;
3029

3130
Chunk(ChunkRegion region, int localIndex) {
3231
this.region = region;
3332
this.localIndex = localIndex;
3433
}
3534

36-
Chunk(ChunkRegion region, ChunkMetadata metadata, CompoundTag rootTag) {
37-
this.region = region;
38-
this.localIndex = metadata.localIndex();
39-
this.rootTag = rootTag;
40-
}
41-
42-
public Chunk() {
43-
}
44-
4535
/// Return the region of this chunk, or `null` if this chunk is not in any region.
46-
public @Nullable ChunkRegion getRegion() {
36+
public ChunkRegion getRegion() {
4737
return region;
4838
}
4939

5040
/// Return the local x coordinate of this chunk in its region, or -1 if this chunk is not in any region.
5141
public int getLocalX() {
52-
return localIndex >= 0 ? localIndex % ChunkUtils.CHUNKS_PER_REGION_SIDE : -1;
42+
return localIndex >= 0 ? ChunkUtils.getLocalX(localIndex) : -1;
5343
}
5444

5545
/// Return the local z coordinate of this chunk in its region, or -1 if this chunk is not in any region.
5646
public int getLocalZ() {
57-
return localIndex >= 0 ? localIndex / ChunkUtils.CHUNKS_PER_REGION_SIDE : -1;
47+
return localIndex >= 0 ? ChunkUtils.getLocalZ(localIndex) : -1;
5848
}
5949

60-
public CompoundTag getRootTag() {
50+
public @Nullable CompoundTag getRootTag() {
6151
return rootTag;
6252
}
6353
}

0 commit comments

Comments
 (0)