Skip to content

Commit 4d934cf

Browse files
committed
feat(AutoMount): Add AutoMount module to automatically mount or remount entities
1 parent 340d967 commit 4d934cf

1 file changed

Lines changed: 87 additions & 0 deletions

File tree

  • src/main/kotlin/com/lambda/module/modules/movement
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright 2026 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.module.modules.movement
19+
20+
import com.lambda.context.SafeContext
21+
import com.lambda.event.events.TickEvent
22+
import com.lambda.event.listener.SafeListener.Companion.listen
23+
import com.lambda.module.Module
24+
import com.lambda.module.tag.ModuleTag
25+
import com.lambda.util.Timer
26+
import com.lambda.util.world.fastEntitySearch
27+
import net.minecraft.entity.Entity
28+
import net.minecraft.entity.EntityType
29+
import net.minecraft.registry.Registries
30+
import kotlin.time.Duration.Companion.milliseconds
31+
32+
class AutoMount : Module(
33+
name = "AutoMount",
34+
description = "Automatically mounts entities",
35+
tag = ModuleTag.MOVEMENT
36+
) {
37+
var autoRemount by setting("Auto Remount", false, description = "Automatically remounts if you get off")
38+
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 }
40+
41+
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")
43+
44+
val intervalTimer = Timer()
45+
var lastEntity: Entity? = null
46+
47+
init {
48+
listen<TickEvent.Pre> {
49+
if (!intervalTimer.timePassed(interval.milliseconds)) {
50+
return@listen
51+
}
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)
59+
}
60+
}
61+
if (autoRemount) {
62+
if (player.isRiding) {
63+
lastEntity = player.vehicle
64+
} else {
65+
lastEntity?.let {
66+
if (it.isRemoved || it.distanceTo(player) > range) {
67+
lastEntity = null
68+
} else {
69+
if (canRide(it)) {
70+
intervalTimer.reset()
71+
player.startRiding(it)
72+
}
73+
}
74+
}
75+
}
76+
}
77+
}
78+
}
79+
80+
private fun SafeContext.canRide(entity: Entity): Boolean {
81+
return entity.canAddPassenger(player)
82+
}
83+
84+
private fun Entity.canAddPassenger(other: Entity): Boolean {
85+
return this.canAddPassenger(other)
86+
}
87+
}

0 commit comments

Comments
 (0)