Skip to content

Commit 8c4047d

Browse files
committed
ref: better horse control
1 parent cc1e3c1 commit 8c4047d

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,26 @@ import com.lambda.event.listener.SafeListener.Companion.listener
66
import com.lambda.module.Module
77
import com.lambda.module.tag.ModuleTag
88
import com.lambda.util.world.entitySearch
9+
import com.lambda.util.world.fastEntitySearch
910
import net.minecraft.entity.passive.AbstractHorseEntity
11+
import net.minecraft.entity.passive.PigEntity
1012
import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket
1113

12-
// ToDo: Rework this module. All mountables should work, solution should be more elegant.
1314
object EntityControl : Module(
1415
name = "EntityControl",
1516
description = "Control mountable entities",
1617
defaultTags = setOf(ModuleTag.MOVEMENT)
1718
) {
18-
private val forceMount by setting("Force Mount", true, description = "Attempts to force mount chested entities.").apply {
19-
onValueChange { _, _ ->
20-
resetMounts()
21-
}
22-
}
23-
private val modified = mutableSetOf<AbstractHorseEntity>()
19+
private val forceMount by setting("Force Mount", true, description = "Attempts to force mount chested entities.")
20+
21+
private val saddledHorses = mutableSetOf<AbstractHorseEntity>()
2422

2523
init {
2624
listener<TickEvent.Pre> {
27-
if (!forceMount) return@listener
28-
29-
entitySearch<AbstractHorseEntity>(8.0)
25+
fastEntitySearch<AbstractHorseEntity>(8.0)
3026
.forEach {
27+
if (!it.isSaddled) saddledHorses.add(it)
3128
it.setHorseFlag(4, true)
32-
modified.add(it)
3329
}
3430
}
3531

@@ -45,11 +41,8 @@ object EntityControl : Module(
4541
}
4642

4743
onDisable {
48-
resetMounts()
44+
saddledHorses.forEach { it.setHorseFlag(4, false) }
45+
saddledHorses.clear()
4946
}
5047
}
51-
52-
private fun resetMounts() {
53-
modified.forEach { it.updateSaddle() }
54-
}
5548
}

0 commit comments

Comments
 (0)