feat(AutoMount): Add AutoMount module#240
feat(AutoMount): Add AutoMount module#240IceTank wants to merge 2 commits intolambda-client:1.21.11from
Conversation
|
Not tested yet |
|
Works now |
| } | ||
| } | ||
| } | ||
| if (autoRemount) { |
There was a problem hiding this comment.
in situations like this i would check if (!autoRemount) return@listen
| } | ||
| if (autoRemount) { | ||
| if (player.vehicle != null) { | ||
| lastEntity = player.vehicle |
There was a problem hiding this comment.
here for example, you could add return@listen in the if statement and then you dont have to wrap the rest in the else
| } else { | ||
| lastEntity?.let { | ||
| if (it.isRemoved || it.distanceTo(player) > range) { | ||
| lastEntity = null |
| 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") | ||
|
|
||
| override var automationConfig = AutomationConfig( |
There was a problem hiding this comment.
automation configs are set using setDefaultAutomationConfig at the start of the init block
| ) { | ||
| 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", |
There was a problem hiding this comment.
settings should be written on one line with the exception of some builder style functions like onSelect, onDeselect, onValueChange, etc
| transitive-accessible field net/minecraft/registry/SimpleRegistry frozen Z | ||
|
|
||
| # AutoMount | ||
| accessible method net/minecraft/entity/Entity canAddPassenger (Lnet/minecraft/entity/Entity;)Z |
There was a problem hiding this comment.
this can just be placed under the # Entity group
| if (autoMountEntities && player.vehicle == null) { | ||
| runSafeAutomated { | ||
| val entity = fastEntitySearch<Entity>(10.0) { | ||
| autoMountEntityList.contains(it.type) && canRide(it) && it.findRotation(range, player.eyePos) != null |
There was a problem hiding this comment.
I think its best to have a rotation setting as currently this checks if its possible for a valid rotation but doesnt perform it.
| entity.firstOrNull()?.let { | ||
| intervalTimer.reset() | ||
| interactEntity(it) | ||
| debug("Mounting ${it.name}") |
There was a problem hiding this comment.
just a nitpick but a log setting or something could be good
| } | ||
|
|
||
| private fun SafeContext.interactEntity(entity: Entity) { | ||
| mc.networkHandler?.sendPacket(PlayerInteractEntityC2SPacket.interactAt(entity, false, Hand.MAIN_HAND, Vec3d(0.5, 0.5, 0.5))) |
There was a problem hiding this comment.
ideally we should fill the parameters with accurate data like player.isSneaking instead of false
| mc.networkHandler?.sendPacket(PlayerInteractEntityC2SPacket.interact(entity, false, Hand.MAIN_HAND)) | ||
| } | ||
|
|
||
| private fun SafeContext.canRide(entity: Entity): Boolean { |
There was a problem hiding this comment.
can be inlined into
private fun SafeContext.canRide(entity: Entity) = entity.canAddPassenger(player)|
oh yeah, also use connection inside of SafeContext rather than mc.networkHandler |
Add AutoMount module to automatically mount or remount entities