-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
# Conflicts: # build.gradle.kts
- Loading branch information
Showing
4 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ plugins { | |
} | ||
|
||
group = "gg.flyte" | ||
version = "1.0.19" | ||
version = "1.0.22" | ||
|
||
repositories { | ||
mavenCentral() | ||
|
87 changes: 87 additions & 0 deletions
87
src/main/kotlin/gg/flyte/twilight/extension/BoundingBox.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package gg.flyte.twilight.extension | ||
|
||
import org.bukkit.Location | ||
import org.bukkit.World | ||
import org.bukkit.block.Block | ||
import org.bukkit.util.BoundingBox | ||
|
||
/** | ||
* Retrieves all the blocks within the bounding box in the specified world. | ||
* | ||
* This extension function for BoundingBox iterates through all x, y, and z | ||
* coordinates that the bounding box encompasses and collects the corresponding | ||
* blocks from the world. | ||
* | ||
* Note: This function can be performance-intensive for large bounding boxes, | ||
* as it iterates over every single block within the bounding box. | ||
* | ||
* @param world The world from which to retrieve the blocks. | ||
* @return A list of Block objects within the bounding box in the given world. | ||
*/ | ||
fun BoundingBox.getBlocks(world: World): List<Block> { | ||
val blocks = mutableListOf<Block>() | ||
|
||
val minX = minX.toInt() | ||
val minY = minY.toInt() | ||
val minZ = minZ.toInt() | ||
val maxX = maxX.toInt() | ||
val maxY = maxY.toInt() | ||
val maxZ = maxZ.toInt() | ||
|
||
for (x in minX..maxX) { | ||
for (y in minY..maxY) { | ||
for (z in minZ..maxZ) { | ||
blocks.add(world.getBlockAt(x, y, z)) | ||
} | ||
} | ||
} | ||
|
||
return blocks | ||
} | ||
|
||
/** | ||
* Retrieves all the locations within the bounding box in the specified world. | ||
* | ||
* This extension function for BoundingBox iterates through all x, y, and z | ||
* coordinates that the bounding box encompasses and collects the corresponding | ||
* locations from the world. | ||
* | ||
* Note: This function can be performance-intensive for large bounding boxes, | ||
* as it iterates over every single location within the bounding box. | ||
* | ||
* @param world The world in which the bounding box is defined. | ||
* @return A list of Location objects representing each block position within the bounding box. | ||
*/ | ||
fun BoundingBox.getLocations(world: World): List<Location> { | ||
val locations = mutableListOf<Location>() | ||
|
||
val minX = minX.toInt() | ||
val minY = minY.toInt() | ||
val minZ = minZ.toInt() | ||
val maxX = maxX.toInt() | ||
val maxY = maxY.toInt() | ||
val maxZ = maxZ.toInt() | ||
|
||
for (x in minX..maxX) { | ||
for (y in minY..maxY) { | ||
for (z in minZ..maxZ) { | ||
locations.add(Location(world, x.toDouble(), y.toDouble(), z.toDouble())) | ||
} | ||
} | ||
} | ||
|
||
return locations | ||
} | ||
|
||
/** | ||
* Checks if the specified Location is within the boundaries of this BoundingBox. | ||
* | ||
* This extension function provides a simple way to determine if a Location is contained | ||
* within the BoundingBox using its x, y, and z coordinates. | ||
* | ||
* @param location The Location to check for containment within this BoundingBox. | ||
* @return Boolean true if the Location is within the BoundingBox; false otherwise. | ||
*/ | ||
fun BoundingBox.contains(location: Location): Boolean { | ||
return contains(location.x, location.y, location.z) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters