Skip to content

Commit 12edc91

Browse files
authored
Fix: Disable freecam on player respawn packet to prevent excess lag when changing dimension (#288)
1 parent cd4d053 commit 12edc91

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

  • src/main/kotlin/com/lambda/module/modules/render

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ import com.lambda.config.hideAllExcept
2525
import com.lambda.config.withEdits
2626
import com.lambda.context.SafeContext
2727
import com.lambda.event.events.MovementEvent
28+
import com.lambda.event.events.PacketEvent
2829
import com.lambda.event.events.PlayerEvent
2930
import com.lambda.event.events.RenderEvent
3031
import com.lambda.event.events.TickEvent
3132
import com.lambda.event.listener.SafeListener.Companion.listen
33+
import com.lambda.event.listener.UnsafeListener.Companion.listenUnsafe
3234
import com.lambda.interaction.managers.rotating.IRotationRequest.Companion.rotationRequest
3335
import com.lambda.interaction.managers.rotating.Rotation
3436
import com.lambda.interaction.managers.rotating.RotationMode
@@ -58,6 +60,7 @@ import com.lambda.util.world.raycast.RayCastUtils.orMiss
5860
import net.minecraft.client.network.ClientPlayerEntity
5961
import net.minecraft.client.option.Perspective
6062
import net.minecraft.entity.player.PlayerEntity
63+
import net.minecraft.network.packet.s2c.play.PlayerRespawnS2CPacket
6164
import net.minecraft.util.hit.BlockHitResult
6265
import net.minecraft.util.hit.HitResult
6366
import net.minecraft.util.math.BlockPos
@@ -227,6 +230,10 @@ object Freecam : Module(
227230
mc.crosshairTarget = rotation.rayCast(reach, lerpPos).orMiss // Can't be null (otherwise mc will spam "Null returned as 'hitResult', this shouldn't happen!")
228231
mc.crosshairTarget?.let { if (it.type != HitResult.Type.MISS) event.cancel() }
229232
}
233+
234+
listenUnsafe<PacketEvent.Receive.Pre> { event ->
235+
if (event.packet is PlayerRespawnS2CPacket) disable()
236+
}
230237
}
231238

232239
private fun SafeContext.findFollowTarget(): PlayerEntity? {
@@ -247,4 +254,4 @@ object Freecam : Module(
247254
Free("Free", "Move the camera freely with keyboard input"),
248255
FollowPlayer("Follow Player", "Camera follows a player as if attached by an invisible string");
249256
}
250-
}
257+
}

0 commit comments

Comments
 (0)