Skip to content

Commit 6f56847

Browse files
committed
Temporary functions for type reference
1 parent a709d54 commit 6f56847

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

common/src/main/kotlin/com/lambda/util/world/WorldUtils.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ import kotlin.math.ceil
4040
*
4141
*/
4242
object WorldUtils {
43+
/**
44+
* Gets the closest entity of type [T] within a specified range.
45+
*/
46+
inline fun <reified T : Entity> SafeContext.getClosestEntity(
47+
type: Class<T>, // This is a class reference, not an instance of the class.
48+
pos: Vec3d,
49+
range: Double,
50+
predicate: (T) -> Boolean = { true },
51+
): T? {
52+
return getClosestEntity(pos, range, predicate)
53+
}
54+
4355
/**
4456
* Gets the closest entity of type [T] within a specified range.
4557
*
@@ -72,6 +84,20 @@ object WorldUtils {
7284
return closest
7385
}
7486

87+
/**
88+
* Gets all entities of type [T] within a specified distance from a position.
89+
*/
90+
inline fun <reified T : Entity> SafeContext.getFastEntities(
91+
type: Class<T>, // This is a class reference, not an instance of the class.
92+
pos: Vec3d,
93+
distance: Double,
94+
pointer: MutableList<Entity>? = null,
95+
iterator: (Entity, Int) -> Unit = { _, _ -> },
96+
predicate: (Entity) -> Boolean = { true },
97+
) {
98+
return getFastEntities(pos, distance, pointer, iterator, predicate)
99+
}
100+
75101
/**
76102
* Gets all entities of type [T] within a specified distance from a position.
77103
*
@@ -131,6 +157,20 @@ object WorldUtils {
131157
}
132158
}
133159

160+
/**
161+
* Gets all entities of type [T] within a specified distance from a position.
162+
*/
163+
inline fun <reified T : Entity> SafeContext.getEntities(
164+
type: Class<T>, // This is a class reference, not an instance of the class.
165+
pos: Vec3d,
166+
distance: Double,
167+
pointer: MutableList<Entity>? = null,
168+
iterator: (Entity, Int) -> Unit = { _, _ -> },
169+
predicate: (Entity) -> Boolean = { true },
170+
) {
171+
return getEntities(pos, distance, pointer, iterator, predicate)
172+
}
173+
134174
/**
135175
* Gets all entities of type [T] within a specified distance from a position.
136176
*

0 commit comments

Comments
 (0)