Skip to content

Commit 19b7787

Browse files
committed
elytra grim control efly
1 parent 9490eec commit 19b7787

File tree

10 files changed

+105
-39
lines changed

10 files changed

+105
-39
lines changed

src/main/java/com/lambda/mixin/baritone/BaritonePlayerContextMixin.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ Rotation syncRotationWithBaritone(Rotation original) {
4040
if (baritone != BaritoneManager.getPrimary())
4141
return original;
4242

43-
return new Rotation((float) RotationManager.getActiveRotation().getYaw(), (float) RotationManager.getActiveRotation().getPitch());
43+
float yaw = (float) RotationManager.getActiveRotation().getYaw();
44+
float pitch = (float) RotationManager.getActiveRotation().getPitch();
45+
46+
if (Float.isNaN(yaw) || Float.isNaN(pitch)) {
47+
return original;
48+
}
49+
50+
return new Rotation(net.minecraft.util.math.MathHelper.wrapDegrees(yaw), pitch);
4451
}
4552
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ private EntityPose injectGetPose(EntityPose original) {
175175
var player = getMc().player;
176176
if ((Object) this != getMc().player) return original;
177177

178-
if (ElytraFly.INSTANCE.isDisabled() ||
179-
ElytraFly.getMode() != ElytraFly.FlyMode.Bounce || !player.isGliding()) return original;
178+
if (ElytraFly.INSTANCE.isDisabled() || ElytraFly.getMode() != ElytraFly.FlyMode.Bounce || !player.isGliding()) return original;
180179

181180
return EntityPose.GLIDING;
182181
}

src/main/kotlin/com/lambda/interaction/managers/rotating/RotationManager.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,9 @@ object RotationManager : Manager<RotationRequest>(
329329
}
330330
}
331331

332-
activeRotation = Rotation(newYaw, newPitch)
332+
if (!newYaw.isNaN() && !newPitch.isNaN()) {
333+
activeRotation = Rotation(newYaw, newPitch)
334+
}
333335
}
334336

335337
private fun reset(rotation: Rotation) {

src/main/kotlin/com/lambda/interaction/managers/rotating/RotationRequest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ interface IRotationRequest : Automated {
163163
fun rotation(builder: SafeContext.() -> Rotation) { rotationBuilder = builder }
164164

165165
@RotationRequestDsl
166-
fun rotation(pitch: Double, yaw: Double) { rotationBuilder = { Rotation(pitch, yaw) } }
166+
fun rotation(yaw: Double, pitch: Double) { rotationBuilder = { Rotation(yaw, pitch) } }
167167

168168
@RotationRequestDsl
169-
fun rotation(pitch: Float, yaw: Float) { rotationBuilder = { Rotation(pitch, yaw) } }
169+
fun rotation(yaw: Float, pitch: Float) { rotationBuilder = { Rotation(yaw, pitch) } }
170170

171171
@RotationRequestDsl
172172
fun rotation(rotation: Rotation) { rotationBuilder = { rotation } }

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ object BetterFirework : Module(
170170
* Use a firework from the hotbar or inventory if possible.
171171
* Return true if a firework has been used
172172
*/
173-
@JvmStatic
174-
fun SafeContext.startFirework(silent: Boolean) {
173+
fun SafeContext.startFirework(inventory: Boolean) {
175174
val stack = selectStack(count = 1) { isItem(Items.FIREWORK_ROCKET) }
176175

177176
stack.bestItemMatch(player.hotbarStacks)
@@ -185,7 +184,7 @@ object BetterFirework : Module(
185184
return
186185
}
187186

188-
if (!silent) return
187+
if (!inventory) return
189188

190189
stack.bestItemMatch(player.hotbarAndInventoryStacks)
191190
?.let {

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ import com.lambda.util.Communication.info
3030
import com.lambda.util.NamedEnum
3131
import com.lambda.util.SpeedUnit
3232
import com.lambda.util.Timer
33-
import com.lambda.util.world.fastEntitySearch
33+
import com.lambda.util.player.hasFirework
3434
import net.minecraft.client.network.ClientPlayerEntity
35-
import net.minecraft.entity.projectile.FireworkRocketEntity
3635
import net.minecraft.text.Text.literal
3736
import net.minecraft.util.math.Vec3d
3837
import kotlin.time.Duration.Companion.seconds
@@ -100,7 +99,7 @@ object ElytraAltitudeControl : Module(
10099
run {
101100
when (controlState) {
102101
ControlState.AttitudeControl -> {
103-
if (disableOnFirework && hasFirework) {
102+
if (disableOnFirework && player.hasFirework) {
104103
return@run
105104
}
106105
if (usePitch40OnHeight) {
@@ -120,7 +119,7 @@ object ElytraAltitudeControl : Module(
120119
}.coerceIn(-maxPitchAngle, maxPitchAngle)
121120
rotationRequest { pitch(outputPitch) }.submit()
122121

123-
if (usageDelay.timePassed(2.seconds) && !hasFirework) {
122+
if (usageDelay.timePassed(2.seconds) && !player.hasFirework) {
124123
if (useFireworkOnHeight && minHeight > player.y) {
125124
usageDelay.reset()
126125
runSafe {
@@ -191,9 +190,6 @@ object ElytraAltitudeControl : Module(
191190
}
192191
}
193192

194-
val hasFirework: Boolean
195-
get() = runSafe { return fastEntitySearch<FireworkRocketEntity>(4.0) { it.shooter == player }.any() } ?: false
196-
197193
class PIController(val valueP: () -> Double, val valueD: () -> Double, val valueI: () -> Double, val constant: () -> Double) {
198194
var accumulator = 0.0 // Integral term accumulator
199195
var lastDiff = 0.0

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

Lines changed: 78 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,33 @@ import com.lambda.interaction.managers.rotating.IRotationRequest.Companion.rotat
2929
import com.lambda.module.Module
3030
import com.lambda.module.modules.movement.BetterFirework.canOpenElytra
3131
import com.lambda.module.modules.movement.BetterFirework.canTakeoff
32+
import com.lambda.module.modules.movement.BetterFirework.startFirework
3233
import com.lambda.module.tag.ModuleTag
3334
import com.lambda.threading.runSafe
35+
import com.lambda.util.Timer
3436
import com.lambda.util.extension.isElytraFlying
3537
import com.lambda.util.player.MovementUtils.addSpeed
38+
import com.lambda.util.player.SlotUtils.hotbarAndInventoryStacks
39+
import com.lambda.util.player.SlotUtils.hotbarStacks
40+
import com.lambda.util.player.hasFirework
41+
import com.lambda.interaction.material.StackSelection.Companion.selectStack
42+
import net.minecraft.component.DataComponentTypes
3643
import net.minecraft.entity.Entity
44+
import net.minecraft.item.ItemStack
45+
import net.minecraft.item.Items
3746
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket
3847
import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket
3948
import net.minecraft.sound.SoundEvents
49+
import net.minecraft.util.math.Vec3d
50+
import kotlin.time.Duration.Companion.seconds
4051

4152
object ElytraFly : Module(
4253
name = "ElytraFly",
4354
description = "Allows you to fly with an elytra",
4455
tag = ModuleTag.MOVEMENT,
4556
) {
4657
@JvmStatic val mode by setting("Mode", FlyMode.Bounce)
58+
private val inventory by setting("Inventory", true, "Allow using fireworks from the players inventory")
4759

4860
//ToDo: Implement these commented out settings
4961
private val takeoff by setting("Takeoff", true, "Automatically jumps and initiates gliding") { mode == FlyMode.Bounce }
@@ -54,13 +66,16 @@ object ElytraFly : Module(
5466
// private val passObstacles by setting("Pass Obstacles", true, "Automatically paths around obstacles using baritone") { mode == FlyMode.Bounce }
5567

5668
private val boostSpeed by setting("Boost", 0.00, 0.0..0.5, 0.005, description = "Speed to add when flying")
57-
private val rocketSpeed by setting("Rocket Speed", 0.0, 0.0 ..2.0, description = "Speed multiplier that the rocket gives you") { mode == FlyMode.Enhanced }
69+
private val rocketSpeed by setting("Rocket Speed", 0.0, 0.0..2.0, description = "Speed multiplier that the rocket gives you") { mode == FlyMode.Enhanced }
5870

5971
private val mute by setting("Mute Elytra", false, "Mutes the elytra sound when gliding")
6072

61-
var jumpThisTick = false
62-
var previouslyFlying: Boolean? = null
63-
var glidePause = 0
73+
private var jumpThisTick = false
74+
private var previouslyFlying: Boolean? = null
75+
private var glidePause = 0
76+
private var flipFlop = false
77+
private var lastDuration = 1.0
78+
private val fireworkTimer = Timer()
6479

6580
init {
6681
setDefaultAutomationConfig {
@@ -70,20 +85,8 @@ object ElytraFly : Module(
7085
}
7186

7287
listen<TickEvent.Pre> {
73-
if (mode != FlyMode.Bounce) return@listen
74-
if (autoPitch) rotationRequest { pitch(pitch.toFloat()) }.submit()
75-
76-
if (!player.isGliding) {
77-
if (takeoff && player.canTakeoff) {
78-
if (player.canOpenElytra) {
79-
player.startGliding()
80-
startFlyPacket()
81-
} else jumpThisTick = true
82-
}
83-
return@listen
84-
}
85-
86-
startFlyPacket()
88+
if (mode == FlyMode.GrimControl) onTickGrimControl()
89+
else if (mode == FlyMode.Bounce) onTickBounce()
8790
}
8891

8992
listen<TickEvent.Post> {
@@ -117,6 +120,59 @@ object ElytraFly : Module(
117120
}
118121
}
119122

123+
private fun SafeContext.onTickGrimControl() {
124+
if (!player.isGliding) return
125+
if (fireworkTimer.timePassed(lastDuration.seconds)) {
126+
findFirework()?.let {
127+
lastDuration = (it.get(DataComponentTypes.FIREWORKS)?.flightDuration ?: 1) * 0.5 + 0.5
128+
startFirework(inventory)
129+
fireworkTimer.reset()
130+
}
131+
}
132+
133+
var vec = Vec3d.ZERO
134+
val yaw = player.yaw
135+
if (mc.options.forwardKey.isPressed) vec = vec.add(Vec3d.fromPolar(0f, yaw))
136+
if (mc.options.backKey.isPressed) vec = vec.add(Vec3d.fromPolar(0f, yaw + 180f))
137+
if (mc.options.leftKey.isPressed) vec = vec.add(Vec3d.fromPolar(0f, yaw - 90f))
138+
if (mc.options.rightKey.isPressed) vec = vec.add(Vec3d.fromPolar(0f, yaw + 90f))
139+
if (mc.options.jumpKey.isPressed) vec = vec.add(Vec3d(0.0, 1.0, 0.0))
140+
if (mc.options.sneakKey.isPressed) vec = vec.add(Vec3d(0.0, -1.0, 0.0))
141+
if (vec.lengthSquared() < 1e-4 && player.hasFirework) {
142+
if (flipFlop) {
143+
flipFlop = false
144+
rotationRequest { rotation(0f, 0f) }
145+
} else {
146+
flipFlop = true
147+
rotationRequest { rotation(180f, 0f) }
148+
}
149+
} else {
150+
val rot = vec.yawAndPitch
151+
rotationRequest { rotation(rot.y, rot.x) }
152+
}.submit()
153+
}
154+
155+
private fun SafeContext.findFirework(): ItemStack? {
156+
val stack = selectStack(count = 1) { isItem(Items.FIREWORK_ROCKET) }
157+
return stack.bestItemMatch(player.hotbarStacks) ?: if (inventory) stack.bestItemMatch(player.hotbarAndInventoryStacks) else null
158+
}
159+
160+
private fun SafeContext.onTickBounce() {
161+
if (autoPitch) rotationRequest { pitch(pitch.toFloat()) }.submit()
162+
163+
if (!player.isGliding) {
164+
if (takeoff && player.canTakeoff) {
165+
if (player.canOpenElytra) {
166+
player.startGliding()
167+
startFlyPacket()
168+
} else jumpThisTick = true
169+
}
170+
return
171+
}
172+
173+
startFlyPacket()
174+
}
175+
120176
private fun SafeContext.startFlyPacket() =
121177
connection.sendPacket(ClientCommandC2SPacket(player, ClientCommandC2SPacket.Mode.START_FALL_FLYING))
122178

@@ -136,12 +192,11 @@ object ElytraFly : Module(
136192

137193
@JvmStatic
138194
fun boostRocket() = runSafe {
139-
if (mode == FlyMode.Bounce) return@runSafe
140195
val vec = player.rotationVector
141196
val velocity = player.velocity
142197

143-
val d = 1.5 * rocketSpeed
144-
val e = 0.1 * rocketSpeed
198+
val d = 1.5 * if (mode == FlyMode.Enhanced) rocketSpeed else 1.0
199+
val e = 0.1 * if (mode == FlyMode.Enhanced) rocketSpeed else 1.0
145200

146201
player.velocity = velocity.add(
147202
vec.x * e + (vec.x * d - velocity.x) * 0.5,
@@ -152,6 +207,7 @@ object ElytraFly : Module(
152207

153208
enum class FlyMode {
154209
Bounce,
155-
Enhanced
210+
Enhanced,
211+
GrimControl
156212
}
157213
}

src/main/kotlin/com/lambda/module/modules/player/Scaffold.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ object Scaffold : Module(
4444
) {
4545
private val bridgeRange by setting("Bridge Range", 5, 0..5, 1, "The range at which blocks can be placed to help build support for the player", unit = " blocks")
4646
private val onlyBelow by setting("Only Below", true, "Restricts bridging to only below the player to avoid place spam if it's impossible to reach the supporting position") { bridgeRange > 0 }
47-
private val descend by setting("Descend", KeyCode.Unbound, "Lower the place position by one to allow the player to lower y level")
47+
private val descend by setting("Descend", Bind.EMPTY, "Lower the place position by one to allow the player to lower y level")
4848
private val descendAmount by setting("Descend Amount", 1, 1..5, 1, "The amount to lower the place position by when descending", unit = " blocks") { descend != Bind.EMPTY }
4949

5050
private val pendingActions = ConcurrentLinkedQueue<BuildContext>()

src/main/kotlin/com/lambda/module/modules/render/FreeLook.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ object FreeLook : Module(
3232
name = "FreeLook",
3333
description = "Allows you to look around freely while moving",
3434
tag = ModuleTag.PLAYER,
35+
autoDisable = true
3536
) {
3637
@JvmStatic val enableYaw by setting("Enable Yaw", false, "Don't effect pitch if enabled")
3738
@JvmStatic val enablePitch by setting("Enable Pitch", false, "Don't effect yaw if enabled")

src/main/kotlin/com/lambda/util/player/PlayerUtils.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ package com.lambda.util.player
1919

2020
import com.lambda.config.groups.BuildConfig
2121
import com.lambda.context.SafeContext
22+
import com.lambda.util.world.fastEntitySearch
2223
import com.mojang.authlib.GameProfile
2324
import net.minecraft.client.network.ClientPlayerEntity
2425
import net.minecraft.client.network.OtherClientPlayerEntity
2526
import net.minecraft.client.network.PlayerListEntry
2627
import net.minecraft.entity.player.PlayerEntity
28+
import net.minecraft.entity.projectile.FireworkRocketEntity
2729
import net.minecraft.item.ItemStack
2830
import net.minecraft.network.packet.c2s.play.HandSwingC2SPacket
2931
import net.minecraft.util.Hand
@@ -34,6 +36,10 @@ const val FakePlayerId = -2024-4-20
3436
val SafeContext.gamemode: GameMode
3537
get() = interaction.currentGameMode
3638

39+
context(safeContext: SafeContext)
40+
val ClientPlayerEntity.hasFirework: Boolean
41+
get() = safeContext.fastEntitySearch<FireworkRocketEntity>(4.0) { it.shooter == this }.any()
42+
3743
fun SafeContext.copyPlayer(entity: ClientPlayerEntity) =
3844
ClientPlayerEntity(mc, world, mc.networkHandler, null, null, entity.lastPlayerInput, entity.isSprinting).apply {
3945
setPos(entity.x, entity.y, entity.z)

0 commit comments

Comments
 (0)