Skip to content

Commit 04c476c

Browse files
committed
ref: world dsl utils
1 parent d82087c commit 04c476c

File tree

8 files changed

+352
-437
lines changed

8 files changed

+352
-437
lines changed

common/src/main/kotlin/com/lambda/module/modules/debug/BlockTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ object BlockTest : Module(
5050

5151
init {
5252
listen<RenderEvent.StaticESP> {
53-
blockSearch(range, step) { _, state ->
53+
blockSearch(range, step = step) { _, state ->
5454
state.isOf(Blocks.DIAMOND_BLOCK)
5555
}.forEach { (pos, state) ->
5656
state.getOutlineShape(world, pos).boundingBoxes.forEach { box ->

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import com.lambda.event.events.PacketEvent
2222
import com.lambda.event.listener.SafeListener.Companion.listen
2323
import com.lambda.module.Module
2424
import com.lambda.module.tag.ModuleTag
25-
import com.lambda.util.extension.filterPointer
2625
import net.minecraft.entity.projectile.FireworkRocketEntity
2726
import net.minecraft.network.packet.c2s.common.CommonPongC2SPacket
2827
import net.minecraft.network.packet.s2c.play.EntitiesDestroyS2CPacket
@@ -41,12 +40,8 @@ object RocketExtend : Module(
4140
init {
4241
listen<PacketEvent.Receive.Pre> { event ->
4342
if (event.packet is PlayerPositionLookS2CPacket) reset()
44-
4543
if (event.packet is EntitiesDestroyS2CPacket) {
46-
event.packet.entityIds.map(world::getEntityById)
47-
.filterPointer(extendedRockets, { _, id -> event.packet.entityIds.removeInt(id) }) { rocket ->
48-
rocket.shooter == player
49-
}
44+
extendedRockets.removeAll { rocket -> event.packet.entityIds.any { it == rocket.id } }
5045
}
5146
}
5247

common/src/main/kotlin/com/lambda/util/extension/Collections.kt

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,19 @@ import kotlin.reflect.KClass
3030
* @param R The target type to filter elements to.
3131
* @param C The type of the destination mutable collection.
3232
* @param destination The mutable collection to which the filtered elements will be added.
33-
* @param iterator The iterator function that processes the filtered elements and their index.
3433
* @param predicate The predicate function that determines whether an element should be included based on its type and other criteria.
3534
*/
3635
inline fun <reified R, C : MutableCollection<in R>> Iterable<*>.filterPointer(
3736
destination: C?,
38-
iterator: (R, Int) -> Unit,
3937
predicate: (R) -> Boolean,
40-
) {
41-
var index = 0
42-
38+
) =
4339
forEach { element ->
4440
val fulfilled = predicate(element as R)
4541

46-
if (fulfilled && destination != null) {
42+
if (fulfilled && destination != null)
4743
destination.add(element)
48-
iterator(element, index)
49-
}
5044

51-
index++
5245
}
53-
}
5446

5547
/**
5648
* Filters elements of the iterable by their runtime type and a predicate, and adds the matching elements to the specified mutable collection.
@@ -63,24 +55,19 @@ inline fun <reified R, C : MutableCollection<in R>> Iterable<*>.filterPointer(
6355
* @param R The target type to filter elements to.
6456
* @param C The type of the destination mutable collection.
6557
* @param destination The mutable collection to which the filtered elements will be added.
66-
* @param iterator The iterator function that processes the filtered elements and their index.
6758
* @param predicate The predicate function that determines whether an element should be included based on its type and other criteria.
6859
*/
6960
inline fun <R : Any, C : MutableCollection<in R>> Iterable<*>.filterPointer(
7061
kClass: KClass<out R>,
7162
destination: C?,
72-
iterator: (R) -> Unit,
7363
predicate: (R) -> Boolean,
74-
) {
64+
) =
7565
@Suppress("UNCHECKED_CAST")
7666
forEach { element ->
7767
// Cannot be replaced with reified type due to type erasure
7868
(element as? R) ?: return@forEach
7969
val fulfilled = kClass.isInstance(element) && predicate(element)
8070

81-
if (fulfilled && destination != null) {
71+
if (fulfilled && destination != null)
8272
destination.add(element)
83-
iterator(element)
84-
}
8573
}
86-
}

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

Lines changed: 0 additions & 109 deletions
This file was deleted.

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

Lines changed: 0 additions & 126 deletions
This file was deleted.

0 commit comments

Comments
 (0)