-
Notifications
You must be signed in to change notification settings - Fork 20
feat(AutoMount): Add AutoMount module #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1.21.11
Are you sure you want to change the base?
Changes from all commits
e2b6dc3
f23c538
6c97712
dcb3d6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /* | ||
| * Copyright 2026 Lambda | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package com.lambda.module.modules.movement | ||
|
|
||
| import com.lambda.config.AutomationConfig.Companion.setDefaultAutomationConfig | ||
| import com.lambda.context.SafeContext | ||
| import com.lambda.event.events.TickEvent | ||
| import com.lambda.event.listener.SafeListener.Companion.listen | ||
| import com.lambda.interaction.managers.rotating.visibilty.VisibilityChecker.findRotation | ||
| import com.lambda.module.Module | ||
| import com.lambda.module.tag.ModuleTag | ||
| import com.lambda.threading.runSafeAutomated | ||
| import com.lambda.util.Communication.info | ||
| import com.lambda.util.Timer | ||
| import com.lambda.util.world.fastEntitySearch | ||
| import net.minecraft.entity.Entity | ||
| import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket | ||
| import net.minecraft.registry.Registries | ||
| import net.minecraft.util.Hand | ||
| import net.minecraft.util.math.Vec3d | ||
| import kotlin.time.Duration.Companion.milliseconds | ||
|
|
||
| class AutoMount : Module( | ||
| name = "AutoMount", | ||
| description = "Automatically mounts entities", | ||
| tag = ModuleTag.MOVEMENT | ||
| ) { | ||
| var autoRemount by setting("Auto Remount", false, description = "Automatically remounts if you get off") | ||
| var autoMountEntities by setting("Auto Mount Entities", true, description = "Automatically mounts nearby entities in range") | ||
| var autoMountEntityList by setting("Auto Mount Entity List", mutableListOf(), Registries.ENTITY_TYPE.toList()) { autoMountEntities } | ||
|
|
||
| var interval by setting("Interval", 50, 1..200, 1, unit = "ms", description = "Interact interval") | ||
| var range by setting("Range", 4.0, 1.0..20.0, 0.1, description = "Mount range") | ||
| var debug by setting("Debug", false, description = "Print debug messages") | ||
|
|
||
| val intervalTimer = Timer() | ||
| var lastEntity: Entity? = null | ||
|
|
||
| init { | ||
| setDefaultAutomationConfig("AutoMount") | ||
| onEnable { | ||
| intervalTimer.reset() | ||
| lastEntity = null | ||
| } | ||
|
|
||
| listen<TickEvent.Pre> { | ||
| if (!intervalTimer.timePassed(interval.milliseconds)) { | ||
| return@listen | ||
| } | ||
| if (autoMountEntities && player.vehicle == null) { | ||
| runSafeAutomated { | ||
| val entity = fastEntitySearch<Entity>(10.0) { | ||
| autoMountEntityList.contains(it.type) && canRide(it) && it.findRotation(range, player.eyePos) != null | ||
| }.sortedBy { it.squaredDistanceTo(player.pos) } | ||
| entity.firstOrNull()?.let { | ||
| intervalTimer.reset() | ||
| interactEntity(it) | ||
| if (debug) info("Mounting ${it.name}") | ||
| } | ||
| } | ||
| } | ||
| if (!autoRemount) { | ||
| return@listen | ||
| } | ||
| if (player.vehicle != null) { | ||
| lastEntity = player.vehicle | ||
| } | ||
| if (lastEntity == null) { | ||
| return@listen | ||
| } | ||
| lastEntity?.let { | ||
| if (it.isRemoved || it.distanceTo(player) > range) { | ||
| lastEntity = null | ||
| return@let | ||
| } | ||
| if (canRide(it)) { | ||
| intervalTimer.reset() | ||
| interactEntity(it) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun SafeContext.interactEntity(entity: Entity) { | ||
| mc.networkHandler?.sendPacket(PlayerInteractEntityC2SPacket.interactAt(entity, false, Hand.MAIN_HAND, Vec3d(0.5, 0.5, 0.5))) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ideally we should fill the parameters with accurate data like player.isSneaking instead of false
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would cause the module to fail to mount entities while the player is sneaking
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could this potentially cause anticheat conflicts tho? Maybe a setting for override sneak or something
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idk works on 2b |
||
| mc.networkHandler?.sendPacket(PlayerInteractEntityC2SPacket.interact(entity, false, Hand.MAIN_HAND)) | ||
| } | ||
|
|
||
| private fun SafeContext.canRide(entity: Entity) = entity.canAddPassenger(player) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its best to have a rotation setting as currently this checks if its possible for a valid rotation but doesnt perform it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is only to check if the entity is within range as all the other checks I tried didn't work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah but this module wont work on grim tho? Might as well have an option for rotations as you already have the logic for getting the rotation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does work on grim. Grim does not seam to check rotations when mounting entities