Skip to content

Commit 9d047cb

Browse files
committed
bounce efly fixes / improvements
1 parent fca8b54 commit 9d047cb

File tree

3 files changed

+53
-20
lines changed

3 files changed

+53
-20
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
3030
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
3131
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
32+
import net.minecraft.client.network.ClientPlayerEntity;
3233
import net.minecraft.entity.Entity;
34+
import net.minecraft.entity.EntityPose;
3335
import net.minecraft.entity.MovementType;
3436
import net.minecraft.entity.data.TrackedData;
3537
import net.minecraft.util.math.Vec3d;
@@ -161,6 +163,13 @@ private boolean wrapSetPitch(Entity instance, float yaw) {
161163
private void injectIsSprinting(CallbackInfoReturnable<Boolean> cir) {
162164
var player = Lambda.getMc().player;
163165
if ((Object) this != Lambda.getMc().player) return;
164-
if (ElytraFly.INSTANCE.isEnabled() && ElytraFly.getSprint() && player.isGliding()) cir.setReturnValue(true);
166+
if (ElytraFly.INSTANCE.isEnabled() && ElytraFly.getMode() == ElytraFly.FlyMode.Bounce && player.isGliding()) cir.setReturnValue(true);
167+
}
168+
169+
@Inject(method = "getPose", at = @At("HEAD"), cancellable = true)
170+
private void injectGetPose(CallbackInfoReturnable<EntityPose> cir) {
171+
var entity = (Entity) (Object) this;
172+
if (!(entity instanceof ClientPlayerEntity player)) return;
173+
if (ElytraFly.INSTANCE.isEnabled() && ElytraFly.getMode() == ElytraFly.FlyMode.Bounce && player.isGliding()) cir.setReturnValue(EntityPose.GLIDING);
165174
}
166175
}

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import net.minecraft.entity.LivingEntity;
3232
import net.minecraft.util.math.MathHelper;
3333
import net.minecraft.util.math.Vec3d;
34-
import org.jetbrains.annotations.Nullable;
3534
import org.spongepowered.asm.mixin.Mixin;
3635
import org.spongepowered.asm.mixin.Shadow;
3736
import org.spongepowered.asm.mixin.Unique;
@@ -186,20 +185,9 @@ private void wrapPushAwayFrom(Entity entity, Operation<Void> original) {
186185
original.call(entity);
187186
}
188187

189-
@Nullable
190-
@Unique
191-
Boolean previouslyFlying = null;
192-
193188
@Inject(method = "isGliding", at = @At("HEAD"), cancellable = true)
194189
private void injectIsGliding(CallbackInfoReturnable<Boolean> cir) {
195190
if (lambda$instance != Lambda.getMc().player) return;
196-
var original = lambda$instance.getFlag(Entity.GLIDING_FLAG_INDEX);
197-
if (previouslyFlying == null) {
198-
previouslyFlying = original;
199-
return;
200-
}
201-
if (ElytraFly.INSTANCE.isEnabled() && ElytraFly.getMode() == ElytraFly.FlyMode.Bounce && previouslyFlying) {
202-
cir.setReturnValue(true);
203-
} else previouslyFlying = original;
191+
cir.setReturnValue(ElytraFly.isGliding());
204192
}
205193
}

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

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ package com.lambda.module.modules.movement
1919

2020
import com.lambda.config.AutomationConfig.Companion.setDefaultAutomationConfig
2121
import com.lambda.config.applyEdits
22+
import com.lambda.context.SafeContext
2223
import com.lambda.event.events.ClientEvent
2324
import com.lambda.event.events.MovementEvent
25+
import com.lambda.event.events.PacketEvent
2426
import com.lambda.event.events.TickEvent
2527
import com.lambda.event.listener.SafeListener.Companion.listen
2628
import com.lambda.interaction.managers.rotating.IRotationRequest.Companion.rotationRequest
@@ -31,7 +33,9 @@ import com.lambda.module.tag.ModuleTag
3133
import com.lambda.threading.runSafe
3234
import com.lambda.util.extension.isElytraFlying
3335
import com.lambda.util.player.MovementUtils.addSpeed
36+
import net.minecraft.entity.Entity
3437
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket
38+
import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket
3539
import net.minecraft.sound.SoundEvents
3640

3741
object ElytraFly : Module(
@@ -44,17 +48,19 @@ object ElytraFly : Module(
4448
//ToDo: Implement these commented out settings
4549
private val takeoff by setting("Takeoff", true, "Automatically jumps and initiates gliding") { mode == FlyMode.Bounce }
4650
private val autoPitch by setting("Auto Pitch", true, "Automatically pitches the players rotation down to bounce at faster speeds") { mode == FlyMode.Bounce }
47-
private val pitch by setting("Pitch", 70, 0..90, 1) { autoPitch && mode == FlyMode.Bounce }
51+
private val pitch by setting("Pitch", 80, 0..90, 1) { autoPitch && mode == FlyMode.Bounce }
4852
private val jump by setting("Jump", true, "Automatically jumps") { mode == FlyMode.Bounce }
49-
@JvmStatic val sprint by setting("Sprint", true) { mode == FlyMode.Bounce }
53+
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 }
5054
// private val passObstacles by setting("Pass Obstacles", true, "Automatically paths around obstacles using baritone") { mode == FlyMode.Bounce }
5155

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

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

5761
var jumpThisTick = false
62+
var previouslyFlying: Boolean? = null
63+
var glidePause = 0
5864

5965
init {
6066
setDefaultAutomationConfig {
@@ -73,14 +79,27 @@ object ElytraFly : Module(
7379

7480
if (!player.isGliding) {
7581
if (takeoff && player.canTakeoff) {
76-
if (player.canOpenElytra) player.startGliding();
82+
if (player.canOpenElytra) {
83+
player.startGliding()
84+
startFlyPacket()
85+
};
7786
else jumpThisTick = true
7887
}
7988
return@listen
8089
}
8190

82-
if (mode == FlyMode.Bounce)
83-
connection.sendPacket(ClientCommandC2SPacket(player, ClientCommandC2SPacket.Mode.START_FALL_FLYING))
91+
if (mode == FlyMode.Bounce) startFlyPacket()
92+
}
93+
94+
listen<TickEvent.Post> {
95+
if (glidePause > 0) glidePause--
96+
}
97+
98+
listen<PacketEvent.Receive.Post> { event ->
99+
if (event.packet !is PlayerPositionLookS2CPacket) return@listen
100+
if (mode == FlyMode.Bounce && player.isGliding) {
101+
glidePause = flagPause
102+
}
84103
}
85104

86105
listen<MovementEvent.InputUpdate> { event ->
@@ -103,6 +122,23 @@ object ElytraFly : Module(
103122
}
104123
}
105124

125+
private fun SafeContext.startFlyPacket() =
126+
connection.sendPacket(ClientCommandC2SPacket(player, ClientCommandC2SPacket.Mode.START_FALL_FLYING))
127+
128+
@JvmStatic
129+
fun isGliding(): Boolean? = runSafe {
130+
val original: Boolean = player.getFlag(Entity.GLIDING_FLAG_INDEX)
131+
if (previouslyFlying == null) {
132+
previouslyFlying = original
133+
return@runSafe original
134+
}
135+
return if (isEnabled && mode == FlyMode.Bounce && previouslyFlying == true && glidePause <= 0) true
136+
else {
137+
previouslyFlying = original
138+
original
139+
}
140+
}
141+
106142
@JvmStatic
107143
fun boostRocket() = runSafe {
108144
if (mode == FlyMode.Bounce) return@runSafe

0 commit comments

Comments
 (0)