Skip to content

Commit df268a9

Browse files
committed
fix flag checks and general cleanup
1 parent 94f28ac commit df268a9

5 files changed

Lines changed: 48 additions & 40 deletions

File tree

src/main/java/com/lambda/mixin/entity/LivingEntityMixin.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import com.lambda.module.modules.movement.ElytraFly;
2525
import com.lambda.module.modules.movement.Velocity;
2626
import com.lambda.module.modules.render.ViewModel;
27+
import com.llamalad7.mixinextras.expression.Definition;
28+
import com.llamalad7.mixinextras.expression.Expression;
2729
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
2830
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
2931
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
@@ -46,7 +48,9 @@ public abstract class LivingEntityMixin extends EntityMixin {
4648

4749
@Unique private final LivingEntity lambda$instance = (LivingEntity) (Object) this;
4850

49-
@Inject(method = "jump", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/entity/LivingEntity;getJumpVelocity()F"), cancellable = true)
51+
@Definition(id = "getJumpVelocity", method = "Lnet/minecraft/entity/LivingEntity;getJumpVelocity()F")
52+
@Expression("? = ?.getJumpVelocity()")
53+
@Inject(method = "jump", at = @At(value = "MIXINEXTRAS:EXPRESSION", shift = At.Shift.AFTER), cancellable = true)
5054
void onJump(CallbackInfo ci, @Local LocalFloatRef heightRef) {
5155
if (lambda$instance != Lambda.getMc().player) return;
5256

@@ -173,6 +177,6 @@ private void wrapPushAwayFrom(Entity entity, Operation<Void> original) {
173177
private boolean injectIsGliding(boolean original) {
174178
if (lambda$instance != Lambda.getMc().player) return original;
175179

176-
return ElytraFly.isGliding();
180+
return ElytraFly.INSTANCE.isEnabled() ? ElytraFly.isGliding() : original;
177181
}
178182
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import com.lambda.util.player.SlotUtils.hotbarAndInventoryStacks
4141
import com.lambda.util.player.SlotUtils.hotbarStacks
4242
import net.minecraft.client.network.ClientPlayerEntity
4343
import net.minecraft.entity.EquipmentSlot
44-
import net.minecraft.entity.effect.StatusEffects
4544
import net.minecraft.item.Items
4645
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket
4746
import net.minecraft.network.packet.c2s.play.HandSwingC2SPacket
@@ -94,11 +93,11 @@ object BetterFirework : Module(
9493
.filterStacks(inventory.mainStacks)
9594
.isNotEmpty() || offHandStack.item == Items.FIREWORK_ROCKET
9695

97-
val ClientPlayerEntity.canTakeoff: Boolean
96+
private val ClientPlayerEntity.canTakeoff: Boolean
9897
get() = (isOnGround || canOpenElytra) && isElytraEquipped && hasFireworks
9998

10099
val ClientPlayerEntity.canOpenElytra: Boolean
101-
get() = !abilities.flying && !isClimbing && !isGliding && !isTouchingWater && !isOnGround && !hasVehicle() && !hasStatusEffect(StatusEffects.LEVITATION)
100+
get() = !isGliding && !isClimbing && !isTouchingWater && canGlide()
102101

103102
init {
104103
setDefaultAutomationConfig()

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

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ import com.lambda.module.modules.movement.BetterFirework.canOpenElytra
3838
import com.lambda.module.modules.movement.BetterFirework.isElytraEquipped
3939
import com.lambda.module.modules.movement.BetterFirework.startFirework
4040
import com.lambda.module.tag.ModuleTag
41+
import com.lambda.threading.runGameScheduled
4142
import com.lambda.threading.runSafe
4243
import com.lambda.util.BlockUtils.blockState
4344
import com.lambda.util.SpeedUnit
45+
import com.lambda.util.TickTimer
4446
import com.lambda.util.Timer
4547
import com.lambda.util.extension.isElytraFlying
4648
import com.lambda.util.math.dist
@@ -84,23 +86,31 @@ object ElytraFly : Module(
8486

8587
private val takeoff by setting("Takeoff", true, "Automatically jumps and initiates gliding") { mode == FlyMode.Bounce }
8688
private val autoPitch by setting("Auto Pitch", true, "Automatically pitches the players rotation down to bounce at faster speeds") { mode == FlyMode.Bounce }
87-
private val pitch by setting("Pitch", 80.0, 0.0..90.0, 0.000001) { mode == FlyMode.Bounce && autoPitch }
89+
private val pitch by setting("Pitch", 80.0, -90.0..90.0, 0.000001) { mode == FlyMode.Bounce && autoPitch }
8890
private val jump by setting("Jump", true, "Automatically jumps") { mode == FlyMode.Bounce }
89-
private val flagPause by setting("Flag Pause", 5, 0..100, 1, "How long to pause if the server flags you for a movement check", "ticks") { mode == FlyMode.Bounce }
91+
private val interruptPause by setting("Interrupt Pause", 5, 0..100, 1, "How long to pause if the server flags you for a movement check", "ticks") { mode == FlyMode.Bounce }
9092

9193
private const val Y_MOTION_GROUP = "Y Motion"
9294
@Group(Y_MOTION_GROUP) private val yMotionSetting by setting("Y Motion", false, "Cancels the players y velocity to aid speed") { mode == FlyMode.Bounce }
93-
private val yMotion
94-
get() = yMotionSetting && (!onlyOnDiagonal || abs(RotationManager.activeRotation.yaw % 90) > minDiagonalAngle)
9595
@Group(Y_MOTION_GROUP) private val onlyOnDiagonal: Boolean by setting("Only On Diagonal", true, "Only use y motion when the player is flying on a non-axial angle") { mode == FlyMode.Bounce && yMotionSetting }
9696
@Group(Y_MOTION_GROUP) private val minDiagonalAngle by setting("Min Diagonal Angle", 15.0, 0.0..180.0, 0.1, "The minimum angle the player must be flying to use y motion") { mode == FlyMode.Bounce && yMotionSetting && onlyOnDiagonal }
97-
@Group(Y_MOTION_GROUP) private val yMotionStartSpeed by setting("Y Motion Start Speed", 30, 5..40, 1, "bps") { mode == FlyMode.Bounce && yMotion }
98-
@Group(Y_MOTION_GROUP) private val speedLimit by setting("Speed Limit", 110, 10..400, 1, "bps") { mode == FlyMode.Bounce && yMotion }
97+
@Group(Y_MOTION_GROUP) private val yMotionStartSpeed by setting("Y Motion Start Speed", 30, 5..40, 1, "bps") { mode == FlyMode.Bounce && yMotionSetting }
98+
@Group(Y_MOTION_GROUP) private val speedLimit by setting("Speed Limit", 110, 10..400, 1, "bps") { mode == FlyMode.Bounce && yMotionSetting }
99+
context(safeContext: SafeContext)
100+
private val yMotion
101+
get() = yMotionSetting &&
102+
(!onlyOnDiagonal || abs(RotationManager.activeRotation.yaw % 90) > minDiagonalAngle) &&
103+
safeContext.player.isOnGround &&
104+
safeContext.player.isGliding &&
105+
Speedometer.calculateSpeed(true, SpeedUnit.BlocksPerSecond).let { speed ->
106+
speed > yMotionStartSpeed && speed < speedLimit
107+
}
99108

100109
private const val OBSTACLE_PASSER_GROUP = "Obstacle Passer"
101110
@Group(OBSTACLE_PASSER_GROUP) private val passObstacles by setting("Pass Obstacles", true, "Automatically paths around obstacles using baritone") { mode == FlyMode.Bounce }
102-
@Group(OBSTACLE_PASSER_GROUP) private val minObstacleHeight by setting("Min Obstacle Height", 0.063, 0.0..1.0, 0.0001, "The minimum height an obstacle must be above the ground to trigger obstacle passer")
103-
@Group(OBSTACLE_PASSER_GROUP) private val applyPauseAfterBaritone by setting("Apply Pause After Baritone", false, "Ticks the flag pause after baritone has finished pathing") { mode == FlyMode.Bounce && passObstacles }
111+
@Group(OBSTACLE_PASSER_GROUP) private val walkWhenFlagged by setting("Walk When Flagged", true, "Triggers obstacle passer when the server forces your position (typically getting flagged by the anticheat)") { mode == FlyMode.Bounce && passObstacles }
112+
@Group(OBSTACLE_PASSER_GROUP) private val minObstacleHeight by setting("Min Obstacle Height", 0.063, 0.0..1.0, 0.0001, "The minimum height an obstacle must be above the ground to trigger obstacle passer") { mode == FlyMode.Bounce && passObstacles }
113+
@Group(OBSTACLE_PASSER_GROUP) private val pauseAfterPathing by setting("Pause After Pathing", false, "Ticks the flag pause after baritone has finished pathing") { mode == FlyMode.Bounce && passObstacles }
104114
@Group(OBSTACLE_PASSER_GROUP) private val acceptableOffsetRange by setting("Acceptable Offset Range", 2.0, 0.1..5.0, 0.01, "Acceptable offset from the original flight line to allow when starting to fly again after passing obstacles") { mode == FlyMode.Bounce && passObstacles }
105115
@Group(OBSTACLE_PASSER_GROUP) private val obstacleLookAhead by setting("Obstacle Look-Ahead", 15, 0..50, 1, "Looks ahead of the player to see if obstacles are in the way") { mode == FlyMode.Bounce && passObstacles }
106116
@Group(OBSTACLE_PASSER_GROUP) private val directionStep by setting("Direction Step", 45.0, 0.0..180.0, 0.1, "The step size to use when locking the flight direction") { mode == FlyMode.Bounce && passObstacles }
@@ -112,9 +122,9 @@ object ElytraFly : Module(
112122

113123
private var startPos = Vec3d.ZERO
114124
private var jumpThisTick = false
115-
private var previouslyFlying: Boolean? = null
125+
private var prevGliding: Boolean? = null
116126
private var passingToPos: Vec3d? = null
117-
private var glidePause = 0
127+
private val pauseTimer = TickTimer()
118128

119129
private var flipFlop = false
120130
private var lastDuration = 1.0
@@ -137,10 +147,6 @@ object ElytraFly : Module(
137147
}
138148
}
139149

140-
listen<TickEvent.Post> {
141-
if (glidePause > 0 && !applyPauseAfterBaritone) glidePause--
142-
}
143-
144150
onEnable {
145151
startPos = player.pos
146152
}
@@ -155,7 +161,11 @@ object ElytraFly : Module(
155161
if (mode == FlyMode.Bounce && player.isGliding) {
156162
val snappedDir = getSnappedDir()
157163
val closestLinePoint = player.pos.findClosestPointOnLine(snappedDir)
158-
pathToValidPoint(closestLinePoint, snappedDir, true)
164+
pauseTimer.reset()
165+
if (walkWhenFlagged) runGameScheduled {
166+
val pathToPoint = closestLinePoint.add(snappedDir.multiply(obstacleLookAhead.toDouble()))
167+
pathToValidPoint(pathToPoint, snappedDir)
168+
}
159169
}
160170
}
161171

@@ -221,13 +231,14 @@ object ElytraFly : Module(
221231

222232
if (autoPitch) rotationRequest { pitch(pitch) }.submit()
223233

234+
if (!pauseAfterPathing) pauseTimer.tick()
235+
224236
if (passObstacles && player.isOnGround && handleObstaclePassing()) return
225237
if (BaritoneHandler.isActive) return
226238

227-
if (glidePause > 0 && applyPauseAfterBaritone) {
228-
glidePause--
229-
return
230-
}
239+
if (pauseAfterPathing) pauseTimer.tick()
240+
241+
if (!pauseTimer.hasSurpassed(interruptPause)) return
231242

232243
if (!player.isGliding) {
233244
if (takeoff && player.canTakeoff) {
@@ -303,7 +314,7 @@ object ElytraFly : Module(
303314
}
304315
passTo(searchPos)
305316
safeContext.player.stopGliding()
306-
glidePause = flagPause
317+
pauseTimer.reset()
307318
}
308319

309320
private fun passTo(pos: Vec3d) {
@@ -319,7 +330,7 @@ object ElytraFly : Module(
319330
!safeContext.blockState(downPos).isSolidBlock(safeContext.world, downPos)
320331
} ||
321332
add(0.0, minObstacleHeight, 0.0).rayCastObstructed(direction) ||
322-
add(0.0, 1.0, 0.0).rayCastObstructed(direction) ||
333+
add(0.0, 1.01, 0.0).rayCastObstructed(direction) ||
323334
add(0.0, 1.99, 0.0).rayCastObstructed(direction)
324335
}
325336

@@ -362,11 +373,8 @@ object ElytraFly : Module(
362373
@JvmStatic
363374
fun getModifiedBounceVelocity(original: Vec3d) =
364375
runSafe {
365-
if (!yMotion || !player.isGliding || !player.isOnGround) return@runSafe original
366-
val speed = Speedometer.calculateSpeed(true, SpeedUnit.BlocksPerSecond)
367-
if (speed >= speedLimit) return@runSafe original
368-
if (speed <= yMotionStartSpeed) return@runSafe original
369-
Vec3d(original.x, 0.0, original.z)
376+
if (!yMotion) return@runSafe original
377+
else Vec3d(original.x, 0.0, original.z)
370378
} ?: original
371379

372380
private fun SafeContext.startFlyPacket() =
@@ -375,18 +383,13 @@ object ElytraFly : Module(
375383
@JvmStatic
376384
fun isGliding(): Boolean? = runSafe {
377385
val original: Boolean = player.getFlag(Entity.GLIDING_FLAG_INDEX)
378-
if (previouslyFlying == null) {
379-
previouslyFlying = original
380-
return@runSafe original
381-
}
382386
return if (
383-
isEnabled &&
384387
mode == FlyMode.Bounce &&
385-
previouslyFlying == true &&
386-
glidePause <= 0 &&
388+
prevGliding == true &&
389+
pauseTimer.hasSurpassed(interruptPause) &&
387390
!BaritoneHandler.isActive) true
388391
else {
389-
previouslyFlying = original
392+
prevGliding = original
390393
original
391394
}
392395
}

src/main/kotlin/com/lambda/util/TickTimer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package com.lambda.util
1919

2020
class TickTimer {
21-
private var ticks = 0
21+
private var ticks = 0L
2222

2323
fun tick() {
2424
ticks++

src/main/resources/lambda.accesswidener

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ transitive-accessible class net/minecraft/screen/slot/ArmorSlot
6161
transitive-accessible field net/minecraft/screen/slot/ArmorSlot equipmentSlot Lnet/minecraft/entity/EquipmentSlot;
6262
transitive-accessible field net/minecraft/entity/Entity FLAGS Lnet/minecraft/entity/data/TrackedData;
6363
transitive-accessible field net/minecraft/block/entity/BeaconBlockEntity level I
64+
transitive-accessible method net/minecraft/entity/LivingEntity canGlide ()Z
65+
transitive-accessible method net/minecraft/entity/player/PlayerEntity canGlide ()Z
6466

6567
# Camera
6668
transitive-accessible method net/minecraft/client/render/Camera setPos (DDD)V

0 commit comments

Comments
 (0)