Skip to content

Commit 0ce35d7

Browse files
committed
Filter pointer passes the index
1 parent f8a89bf commit 0ce35d7

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

common/src/main/kotlin/com/lambda/module/modules/movement/EntityControl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ object EntityControl : Module(
3030

3131
init {
3232
listener<TickEvent.Pre> {
33-
getEntities(player.pos, 8.0, theHonses, { horse -> horse.setHorseFlag(4, true) })
33+
getEntities(player.pos, 8.0, theHonses, { horse, _ -> horse.setHorseFlag(4, true) })
3434
}
3535

3636
/*listener<MovementEvent.Pre> {

common/src/main/kotlin/com/lambda/module/modules/movement/RocketExtend.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ object RocketExtend : Module(
2828

2929
if (event.packet is EntitiesDestroyS2CPacket) {
3030
event.packet.entityIds.map(world::getEntityById)
31-
.filterPointer(extendedRockets, { event.packet.entityIds.removeInt(it.id) }) { rocket -> rocket.shooter == player }
31+
.filterPointer(extendedRockets, { _, id -> event.packet.entityIds.removeInt(id) }) { rocket -> rocket.shooter == player }
3232
}
3333
}
3434

common/src/main/kotlin/com/lambda/util/collections/Extensions.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ package com.lambda.util.collections
1111
* @param R The target type to filter elements to.
1212
* @param C The type of the destination mutable collection.
1313
* @param destination The mutable collection to which the filtered elements will be added.
14+
* @param iterator The iterator function that processes the filtered elements and their index.
1415
* @param predicate The predicate function that determines whether an element should be included based on its type and other criteria.
1516
*/
1617
inline fun <reified R, C : MutableCollection<in R>> Iterable<*>.filterPointer(
1718
destination: C?,
18-
iterator: (R) -> Unit,
19+
iterator: (R, Int) -> Unit,
1920
predicate: (R) -> Boolean,
2021
) {
21-
for (element in this) if (element is R && predicate(element)) { iterator(element); destination?.add(element) }
22+
var index = 0
23+
for (element in this) if (element is R && predicate(element)) { iterator(element, index++); destination?.add(element) }
2224
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ object WorldUtils {
5858
var closest: T? = null
5959
var closestDistance = Double.MAX_VALUE
6060

61-
val comparator = { entity: T ->
61+
val comparator = { entity: T, _: Int ->
6262
val distance = pos.squaredDistanceTo(entity.pos)
6363
if (distance < closestDistance) {
6464
closest = entity
@@ -103,7 +103,7 @@ object WorldUtils {
103103
pos: Vec3d,
104104
distance: Double,
105105
pointer: MutableList<T>? = null,
106-
iterator: (T) -> Unit = {},
106+
iterator: (T, Int) -> Unit = { _, _ -> },
107107
predicate: (T) -> Boolean = { true },
108108
) {
109109
val chunks = ceil(distance / 16).toInt()
@@ -144,7 +144,7 @@ object WorldUtils {
144144
pos: Vec3d,
145145
distance: Double,
146146
pointer: MutableList<T>? = null,
147-
iterator: (T) -> Unit = {},
147+
iterator: (T, Int) -> Unit = { _, _ -> },
148148
predicate: (T) -> Boolean = { true },
149149
) {
150150
world.entities.filterPointer(pointer, iterator) { entity ->
@@ -171,7 +171,7 @@ object WorldUtils {
171171
rangeY: Int,
172172
rangeZ: Int,
173173
pointer: MutableList<Block>? = null,
174-
iterator: (Block) -> Unit = {},
174+
iterator: (Block, Int) -> Unit = { _, _ -> },
175175
predicate: (Block) -> Boolean = { true },
176176
) = searchBlock(pos, Vec3i(rangeX, rangeY, rangeZ), pointer, iterator, predicate)
177177

@@ -188,7 +188,7 @@ object WorldUtils {
188188
pos: Vec3i,
189189
range: Vec3i,
190190
pointer: MutableList<Block>? = null,
191-
iterator: (Block) -> Unit = {},
191+
iterator: (Block, Int) -> Unit = { _, _ -> },
192192
predicate: (Block) -> Boolean = { true },
193193
) {
194194
// TODO: Implement O(1) pointer mapping
@@ -212,7 +212,7 @@ object WorldUtils {
212212
pos: Vec3i,
213213
range: Vec3i,
214214
pointer: MutableList<T>? = null,
215-
iterator: (T) -> Unit = {},
215+
iterator: (T, Int) -> Unit = { _, _ -> },
216216
predicate: (T) -> Boolean = { true },
217217
) {
218218
// TODO: Implement O(1) pointer mapping

0 commit comments

Comments
 (0)