Skip to content

Commit 18e58ea

Browse files
committed
bounce elytra fly y motion setting with speed limit and y motion start speed settings
1 parent aa45991 commit 18e58ea

4 files changed

Lines changed: 51 additions & 12 deletions

File tree

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package com.lambda.mixin.entity;
1919

20-
import com.lambda.Lambda;
2120
import com.lambda.event.EventFlow;
2221
import com.lambda.event.events.EntityEvent;
2322
import com.lambda.event.events.PlayerEvent;
@@ -40,6 +39,7 @@
4039
import org.spongepowered.asm.mixin.injection.At;
4140
import org.spongepowered.asm.mixin.injection.Inject;
4241
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
42+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
4343

4444
import static com.lambda.Lambda.getMc;
4545

@@ -51,6 +51,9 @@ public void move(MovementType movementType, Vec3d movement) {}
5151
@Shadow
5252
public abstract float getYaw();
5353

54+
@Shadow
55+
private Vec3d velocity;
56+
5457
/**
5558
* Modifies the player yaw when there is an active rotation to apply the player velocity correctly
5659
*/
@@ -186,4 +189,10 @@ private EntityPose injectGetPose(EntityPose original) {
186189
private float modifyGetYaw(float original) {
187190
return (Object) this == getMc().player ? RotationManager.getServerRotation().getYawF() : original;
188191
}
192+
193+
@Inject(method = "getVelocity", at = @At("HEAD"), cancellable = true)
194+
private void injectGetVelocity(CallbackInfoReturnable<Vec3d> cir) {
195+
if (ElytraFly.INSTANCE.isDisabled() || ElytraFly.getMode() != ElytraFly.FlyMode.Bounce) return;
196+
cir.setReturnValue(ElytraFly.getModifiedBounceVelocity(velocity));
197+
}
189198
}

src/main/kotlin/com/lambda/module/hud/Speedometer.kt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.lambda.module.hud
1919

20+
import com.lambda.context.SafeContext
2021
import com.lambda.event.events.TickEvent
2122
import com.lambda.event.listener.SafeListener.Companion.listen
2223
import com.lambda.gui.dsl.ImGuiBuilder
@@ -39,15 +40,10 @@ object Speedometer : HudModule(
3940
var speed: Double = 0.0
4041

4142
init {
42-
listen<TickEvent.Post> {
43+
listen<TickEvent.Post>(alwaysListen = true) {
4344
previousPos = currentPos
4445
currentPos = player.pos
45-
46-
var vecDelta = player.pos.subtract(previousPos)
47-
if (onlyHorizontal) {
48-
vecDelta = Vec3d(vecDelta.x, 0.0, vecDelta.z)
49-
}
50-
speed = speedUnit.convertFromMinecraft(vecDelta.length())
46+
speed = calculateSpeed()
5147
}
5248

5349
onEnable {
@@ -59,6 +55,18 @@ object Speedometer : HudModule(
5955
onDisable { speed = 0.0 }
6056
}
6157

58+
context(safeContext: SafeContext)
59+
fun calculateSpeed(
60+
onlyHorizontal: Boolean = this.onlyHorizontal,
61+
speedUnit: SpeedUnit = this.speedUnit
62+
) = with(safeContext) {
63+
var vecDelta = player.pos.subtract(previousPos)
64+
if (onlyHorizontal) {
65+
vecDelta = Vec3d(vecDelta.x, 0.0, vecDelta.z)
66+
}
67+
speedUnit.convertFromMinecraft(vecDelta.length())
68+
}
69+
6270
override fun ImGuiBuilder.buildLayout() {
6371
runSafe {
6472
text("Speed: %.2f %s".format(speed, speedUnit.unitName))

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import com.lambda.util.player.SlotUtils.hotbarAndInventoryStacks
3939
import com.lambda.util.player.SlotUtils.hotbarStacks
4040
import com.lambda.util.player.hasFirework
4141
import com.lambda.interaction.material.StackSelection.Companion.selectStack
42+
import com.lambda.module.hud.Speedometer
43+
import com.lambda.util.SpeedUnit
4244
import net.minecraft.component.DataComponentTypes
4345
import net.minecraft.entity.Entity
4446
import net.minecraft.item.ItemStack
@@ -55,12 +57,15 @@ object ElytraFly : Module(
5557
tag = ModuleTag.MOVEMENT,
5658
) {
5759
@JvmStatic val mode by setting("Mode", FlyMode.Bounce)
58-
private val inventory by setting("Inventory", true, "Allow using fireworks from the players inventory")
60+
private val inventory by setting("Inventory", true, "Allow using fireworks from the players inventory") { mode == FlyMode.GrimControl }
5961

6062
//ToDo: Implement these commented out settings
6163
private val takeoff by setting("Takeoff", true, "Automatically jumps and initiates gliding") { mode == FlyMode.Bounce }
6264
private val autoPitch by setting("Auto Pitch", true, "Automatically pitches the players rotation down to bounce at faster speeds") { mode == FlyMode.Bounce }
6365
private val pitch by setting("Pitch", 80, 0..90, 1) { autoPitch && mode == FlyMode.Bounce }
66+
private val yMotion by setting("Y Motion", false, "Cancels the players y velocity to aid speed") { mode == FlyMode.Bounce }
67+
private val yMotionStartSpeed by setting("Y Motion Start Speed", 20, 5..30, 1, "bps") { mode == FlyMode.Bounce && yMotion }
68+
private val speedLimit by setting("Speed Limit", 110, 10..720, 1, "bps") { mode == FlyMode.Bounce && yMotion }
6469
private val jump by setting("Jump", true, "Automatically jumps") { mode == FlyMode.Bounce }
6570
private val flagPause by setting("Flag Pause", 20, 0..100, 1, "How long to pause if the server flags you for a movement check") { mode == FlyMode.Bounce }
6671
// private val passObstacles by setting("Pass Obstacles", true, "Automatically paths around obstacles using baritone") { mode == FlyMode.Bounce }
@@ -85,8 +90,11 @@ object ElytraFly : Module(
8590
}
8691

8792
listen<TickEvent.Pre> {
88-
if (mode == FlyMode.GrimControl) onTickGrimControl()
89-
else if (mode == FlyMode.Bounce) onTickBounce()
93+
when (mode) {
94+
FlyMode.Bounce -> onTickBounce()
95+
FlyMode.GrimControl -> onTickGrimControl()
96+
else -> {}
97+
}
9098
}
9199

92100
listen<TickEvent.Post> {
@@ -170,9 +178,22 @@ object ElytraFly : Module(
170178
return
171179
}
172180

173-
startFlyPacket()
181+
if (!player.getFlag(Entity.GLIDING_FLAG_INDEX) || yMotion) {
182+
player.setFlag(Entity.GLIDING_FLAG_INDEX, true)
183+
startFlyPacket()
184+
}
174185
}
175186

187+
@JvmStatic
188+
fun getModifiedBounceVelocity(original: Vec3d) =
189+
runSafe {
190+
if (!yMotion || !player.isGliding || !player.isOnGround) return@runSafe original
191+
val speed = Speedometer.calculateSpeed(true, SpeedUnit.BlocksPerSecond)
192+
if (speed >= speedLimit) return@runSafe original
193+
if (speed <= yMotionStartSpeed) return@runSafe original
194+
Vec3d(original.x, 0.0, original.z)
195+
} ?: original
196+
176197
private fun SafeContext.startFlyPacket() =
177198
connection.sendPacket(ClientCommandC2SPacket(player, ClientCommandC2SPacket.Mode.START_FALL_FLYING))
178199

src/main/kotlin/com/lambda/module/modules/world/AirPlace.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ object AirPlace : Module(
6868

6969
private var distance by setting("Distance", 4.0, 1.0..7.0, 0.01).group(Group.General)
7070
private val distanceScrollBind by setting("Distance Scroll Bind", Bind(KeyCode.Unbound.code, GLFW.GLFW_MOD_CONTROL), "Allows you to hold the given key and scroll to adjust distance").group(Group.General)
71+
// Credit to THCFree for the rotation scroll idea
7172
private val rotationScrollBind by setting("Rotation Scroll Bind", Bind(KeyCode.Unbound.code, GLFW.GLFW_MOD_ALT), "Allows you to hold the given key and scroll to adjust the rotation of the block you're placing").group(Group.General)
7273

7374
private val renderState by setting("Render State", true).group(Group.Render)

0 commit comments

Comments
 (0)