|
3 | 3 | import me.outspending.biomesapi.annotations.AsOf; |
4 | 4 | import net.minecraft.world.level.chunk.LevelChunk; |
5 | 5 | import org.bukkit.Chunk; |
| 6 | +import org.jetbrains.annotations.NotNull; |
6 | 7 |
|
7 | 8 | /** |
8 | 9 | * A data class representing a chunk location. |
9 | 10 | * @param x the chunk x coordinate |
10 | 11 | * @param z the chunk z coordinate |
11 | | - * @version 0.0.6 |
| 12 | + * @version 0.0.11 |
12 | 13 | * @since 0.0.6 |
13 | 14 | * @author Jsinco |
14 | 15 | */ |
15 | | -@AsOf("0.0.6") |
| 16 | +@AsOf("0.0.11") |
16 | 17 | public record ChunkLocation(int x, int z) { |
17 | 18 |
|
18 | 19 | /** |
@@ -67,4 +68,67 @@ public boolean isChunk(LevelChunk nmsChunk) { |
67 | 68 | public boolean isChunk(int chunkX, int chunkZ) { |
68 | 69 | return this.x == chunkX && this.z == chunkZ; |
69 | 70 | } |
| 71 | + |
| 72 | + |
| 73 | + /** |
| 74 | + * Checks if this ChunkLocation is within a certain radius of another ChunkLocation. |
| 75 | + * @param other the other ChunkLocation to compare |
| 76 | + * @param radius the radius to check within |
| 77 | + * @return true if this ChunkLocation is within the radius of the other, false otherwise |
| 78 | + */ |
| 79 | + @AsOf("0.0.11") |
| 80 | + public boolean isWithinRadius(ChunkLocation other, int radius) { |
| 81 | + int deltaX = this.x - other.x; |
| 82 | + int deltaZ = this.z - other.z; |
| 83 | + return (deltaX * deltaX + deltaZ * deltaZ) <= (radius * radius); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Offsets this ChunkLocation by the given x and z offsets. |
| 88 | + * @param offsetX the x offset |
| 89 | + * @param offsetZ the z offset |
| 90 | + * @return a new ChunkLocation with the offset applied |
| 91 | + */ |
| 92 | + @AsOf("0.0.11") |
| 93 | + public @NotNull ChunkLocation offset(int offsetX, int offsetZ) { |
| 94 | + return new ChunkLocation(this.x + offsetX, this.z + offsetZ); |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Offsets this ChunkLocation by another ChunkLocation. |
| 99 | + * @param offset the ChunkLocation to offset by |
| 100 | + * @return a new ChunkLocation with the offset applied |
| 101 | + */ |
| 102 | + @AsOf("0.0.11") |
| 103 | + public @NotNull ChunkLocation offset(@NotNull ChunkLocation offset) { |
| 104 | + return new ChunkLocation(this.x + offset.x, this.z + offset.z); |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Negates the chunk coordinates. |
| 109 | + * @return a new ChunkLocation with negated x and z coordinates |
| 110 | + */ |
| 111 | + @AsOf("0.0.11") |
| 112 | + public @NotNull ChunkLocation negate() { |
| 113 | + return new ChunkLocation(-this.x, -this.z); |
| 114 | + } |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + @Override |
| 119 | + public boolean equals(Object obj) { |
| 120 | + if (this == obj) return true; |
| 121 | + if (obj == null || getClass() != obj.getClass()) return false; |
| 122 | + ChunkLocation that = (ChunkLocation) obj; |
| 123 | + return x == that.x && z == that.z; |
| 124 | + } |
| 125 | + |
| 126 | + @Override |
| 127 | + public int hashCode() { |
| 128 | + return 31 * x + z; |
| 129 | + } |
| 130 | + |
| 131 | + public @NotNull String toString() { |
| 132 | + return "ChunkLocation{x=" + x + ", z=" + z + "}"; |
| 133 | + } |
70 | 134 | } |
0 commit comments