Skip to content

Commit bc15fa9

Browse files
committed
add more api for ChunkLocations
1 parent 6217df5 commit bc15fa9

File tree

3 files changed

+70
-9
lines changed

3 files changed

+70
-9
lines changed

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ allprojects {
1313
apply(plugin = "com.gradleup.shadow")
1414

1515
group = "me.outspending.biomesapi"
16-
version = "0.0.10"
16+
version = "0.0.11"
1717

1818
tasks.withType<JavaCompile> {
1919
options.encoding = "UTF-8"
2020
}
2121

2222
// The file for publication.
23-
val reobfBuildFile = project.layout.buildDirectory.file("libs/reobf/${project.name}-${project.version}.jar")
23+
//val reobfBuildFile = project.layout.buildDirectory.file("libs/reobf/${project.name}-${project.version}.jar")
2424

2525
// Check if a project has the reobfJar task.
2626
fun Project.usesReobfuscatedJar() : Boolean {

main/src/main/java/me/outspending/biomesapi/packet/data/ChunkLocation.java

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
import me.outspending.biomesapi.annotations.AsOf;
44
import net.minecraft.world.level.chunk.LevelChunk;
55
import org.bukkit.Chunk;
6+
import org.jetbrains.annotations.NotNull;
67

78
/**
89
* A data class representing a chunk location.
910
* @param x the chunk x coordinate
1011
* @param z the chunk z coordinate
11-
* @version 0.0.6
12+
* @version 0.0.11
1213
* @since 0.0.6
1314
* @author Jsinco
1415
*/
15-
@AsOf("0.0.6")
16+
@AsOf("0.0.11")
1617
public record ChunkLocation(int x, int z) {
1718

1819
/**
@@ -67,4 +68,67 @@ public boolean isChunk(LevelChunk nmsChunk) {
6768
public boolean isChunk(int chunkX, int chunkZ) {
6869
return this.x == chunkX && this.z == chunkZ;
6970
}
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+
}
70134
}

test-plugin/src/main/java/me/outspending/biomesapi/BiomesAPITest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@
55
import me.outspending.biomesapi.packet.PacketHandler;
66
import me.outspending.biomesapi.packet.data.PhonyCustomBiome;
77
import me.outspending.biomesapi.packet.data.BlockReplacement;
8-
import me.outspending.biomesapi.registry.BiomeRegistry;
98
import me.outspending.biomesapi.registry.BiomeResourceKey;
109
import me.outspending.biomesapi.renderer.AmbientParticle;
1110
import me.outspending.biomesapi.renderer.ParticleRenderer;
12-
import me.outspending.biomesapi.setter.BiomeSetter;
13-
import org.bukkit.Chunk;
1411
import org.bukkit.Material;
15-
import org.bukkit.World;
1612
import org.bukkit.event.EventHandler;
1713
import org.bukkit.event.Listener;
1814
import org.bukkit.event.block.BlockBreakEvent;
@@ -51,7 +47,8 @@ public void onEnable() {
5147
.grassColor("#9D00FF")
5248
.particleRenderer(ParticleRenderer.of(AmbientParticle.WITCH, 0.01f))
5349
.blockReplacements(
54-
BlockReplacement.of(Material.GRASS_BLOCK, Material.PURPLE_CONCRETE_POWDER)
50+
BlockReplacement.of(Material.GRASS_BLOCK, Material.WATER),
51+
BlockReplacement.of(Material.STONE, Material.DIAMOND_BLOCK)
5552
)
5653
.build();
5754

0 commit comments

Comments
 (0)