Skip to content

Commit 4774b62

Browse files
committed
fix(AutoMount): Fix AutoMount module
1 parent 4d934cf commit 4774b62

2 files changed

Lines changed: 45 additions & 15 deletions

File tree

src/main/kotlin/com/lambda/module/modules/movement/AutoMount.kt

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,27 @@
1717

1818
package com.lambda.module.modules.movement
1919

20+
import com.lambda.config.AutomationConfig
2021
import com.lambda.context.SafeContext
2122
import com.lambda.event.events.TickEvent
2223
import com.lambda.event.listener.SafeListener.Companion.listen
24+
import com.lambda.interaction.managers.rotating.visibilty.VisibilityChecker
25+
import com.lambda.interaction.managers.rotating.visibilty.VisibilityChecker.findRotation
2326
import com.lambda.module.Module
2427
import com.lambda.module.tag.ModuleTag
28+
import com.lambda.threading.runSafeAutomated
29+
import com.lambda.util.Communication.debug
30+
import com.lambda.util.Communication.info
31+
import com.lambda.util.EntityUtils
2532
import com.lambda.util.Timer
33+
import com.lambda.util.math.dist
2634
import com.lambda.util.world.fastEntitySearch
2735
import net.minecraft.entity.Entity
2836
import net.minecraft.entity.EntityType
37+
import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket
2938
import net.minecraft.registry.Registries
39+
import net.minecraft.util.Hand
40+
import net.minecraft.util.math.Vec3d
3041
import kotlin.time.Duration.Companion.milliseconds
3142

3243
class AutoMount : Module(
@@ -36,30 +47,45 @@ class AutoMount : Module(
3647
) {
3748
var autoRemount by setting("Auto Remount", false, description = "Automatically remounts if you get off")
3849
var autoMountEntities by setting("Auto Mount Entities", true, description = "Automatically mounts nearby entities in range")
39-
var autoMountEntityList by setting("Auto Mount Entity List", mutableListOf<EntityType<*>>(), mutableListOf(Registries.ENTITY_TYPE.toList())) { autoMountEntities }
50+
var autoMountEntityList by setting("Auto Mount Entity List",
51+
mutableListOf(),
52+
Registries.ENTITY_TYPE.toList()
53+
) { autoMountEntities }
4054

4155
var interval by setting("Interval", 50, 1..200, 1, unit = "ms", description = "Interact interval")
42-
var range by setting("Range", 5.0, 1.0..10.0, 0.1, description = "Mount range")
56+
var range by setting("Range", 4.0, 1.0..20.0, 0.1, description = "Mount range")
57+
58+
override var automationConfig = AutomationConfig(
59+
name = "AutoMount"
60+
)
4361

4462
val intervalTimer = Timer()
4563
var lastEntity: Entity? = null
4664

4765
init {
66+
onEnable {
67+
intervalTimer.reset()
68+
lastEntity = null
69+
}
70+
4871
listen<TickEvent.Pre> {
4972
if (!intervalTimer.timePassed(interval.milliseconds)) {
5073
return@listen
5174
}
52-
if (autoMountEntities && !player.isRiding) {
53-
val entity = fastEntitySearch<Entity>(range) {
54-
autoMountEntityList.contains(it.type) && canRide(it) && it.distanceTo(player) <= range
55-
}
56-
entity.firstOrNull()?.let {
57-
intervalTimer.reset()
58-
player.startRiding(it)
75+
if (autoMountEntities && player.vehicle == null) {
76+
runSafeAutomated {
77+
val entity = fastEntitySearch<Entity>(10.0) {
78+
autoMountEntityList.contains(it.type) && canRide(it) && it.findRotation(range, player.eyePos) != null
79+
}.sortedBy { it.squaredDistanceTo(player.pos) }
80+
entity.firstOrNull()?.let {
81+
intervalTimer.reset()
82+
interactEntity(it)
83+
debug("Mounting ${it.name}")
84+
}
5985
}
6086
}
6187
if (autoRemount) {
62-
if (player.isRiding) {
88+
if (player.vehicle != null) {
6389
lastEntity = player.vehicle
6490
} else {
6591
lastEntity?.let {
@@ -68,7 +94,7 @@ class AutoMount : Module(
6894
} else {
6995
if (canRide(it)) {
7096
intervalTimer.reset()
71-
player.startRiding(it)
97+
interactEntity(it)
7298
}
7399
}
74100
}
@@ -77,11 +103,12 @@ class AutoMount : Module(
77103
}
78104
}
79105

80-
private fun SafeContext.canRide(entity: Entity): Boolean {
81-
return entity.canAddPassenger(player)
106+
private fun SafeContext.interactEntity(entity: Entity) {
107+
mc.networkHandler?.sendPacket(PlayerInteractEntityC2SPacket.interactAt(entity, false, Hand.MAIN_HAND, Vec3d(0.5, 0.5, 0.5)))
108+
mc.networkHandler?.sendPacket(PlayerInteractEntityC2SPacket.interact(entity, false, Hand.MAIN_HAND))
82109
}
83110

84-
private fun Entity.canAddPassenger(other: Entity): Boolean {
85-
return this.canAddPassenger(other)
111+
private fun SafeContext.canRide(entity: Entity): Boolean {
112+
return entity.canAddPassenger(player)
86113
}
87114
}

src/main/resources/lambda.accesswidener

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,6 @@ transitive-accessible method net/minecraft/block/AbstractBlock getPickStack (Lne
155155
transitive-accessible field net/minecraft/client/gui/screen/ingame/HandledScreen focusedSlot Lnet/minecraft/screen/slot/Slot;
156156
transitive-accessible field net/minecraft/registry/SimpleRegistry frozen Z
157157
transitive-accessible field net/minecraft/client/gui/screen/ingame/AbstractSignEditScreen messages [Ljava/lang/String;
158+
159+
# AutoMount
160+
accessible method net/minecraft/entity/Entity canAddPassenger (Lnet/minecraft/entity/Entity;)Z

0 commit comments

Comments
 (0)