Skip to content

Commit 1aeb357

Browse files
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # pom.xml
2 parents e947fe1 + c53b9e3 commit 1aeb357

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/main/java/de/codeblocksmc/codelib/locations/LocationSection.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,27 @@ public boolean contains(LocationWrapper location) {
7070
location.getZ() >= minZ && location.getZ() <= maxZ;
7171
}
7272

73+
/**
74+
* Returns a random {@link LocationWrapper} inside this {@link LocationSection}.
75+
*
76+
* @return A random location within the cuboid area.
77+
*/
78+
public LocationWrapper getRandomLocation() {
79+
double minX = Math.min(l1.getX(), l2.getX());
80+
double minY = Math.min(l1.getY(), l2.getY());
81+
double minZ = Math.min(l1.getZ(), l2.getZ());
82+
83+
double maxX = Math.max(l1.getX(), l2.getX());
84+
double maxY = Math.max(l1.getY(), l2.getY());
85+
double maxZ = Math.max(l1.getZ(), l2.getZ());
86+
87+
double x = minX + Math.random() * (maxX - minX);
88+
double y = minY + Math.random() * (maxY - minY);
89+
double z = minZ + Math.random() * (maxZ - minZ);
90+
91+
return new LocationWrapper(l1.getWorld(), x, y, z, 0f, 0f);
92+
}
93+
7394
/**
7495
* Provides a string representation of this {@link LocationSection}.
7596
*

0 commit comments

Comments
 (0)