-
Notifications
You must be signed in to change notification settings - Fork 22
feat(Freecam): Add Exclude Rotation mode to freecam #269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1.21.11
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ import com.lambda.event.events.PlayerEvent | |
| import com.lambda.event.events.RenderEvent | ||
| import com.lambda.event.events.TickEvent | ||
| import com.lambda.event.listener.SafeListener.Companion.listen | ||
| import com.lambda.interaction.managers.rotating.IRotationRequest | ||
| import com.lambda.interaction.managers.rotating.IRotationRequest.Companion.rotationRequest | ||
| import com.lambda.interaction.managers.rotating.Rotation | ||
| import com.lambda.interaction.managers.rotating.RotationMode | ||
|
|
@@ -77,6 +78,7 @@ object Freecam : Module( | |
| private val sprint by setting("Sprint Multiplier", 3.0, 0.1..10.0, 0.1, description = "Set below 1.0 to fly slower on sprint.") { mode == Mode.Free } | ||
| private val reach by setting("Reach", 10.0, 1.0..100.0, 1.0, "Freecam reach distance") | ||
| private val rotateMode by setting("Rotate Mode", FreecamRotationMode.None, "Rotation mode").onValueChange { _, it -> if (it == FreecamRotationMode.LookAtTarget) mc.crosshairTarget = BlockHitResult.createMissed(Vec3d.ZERO, Direction.UP, BlockPos.ORIGIN) } | ||
| private val excludeRotation by setting("Exclude Rotation", FreecamRotationExclusion.None, description = "Exclude certain rotation changes from rotate mode") { rotateMode != FreecamRotationMode.None } | ||
| private val relative by setting("Relative", false, "Moves freecam relative to player position") { mode == Mode.Free }.onValueChange { _, it -> if (it) lastPlayerPosition = player.pos } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. onValueChanged on the next line again |
||
| private val keepYLevel by setting("Keep Y Level", false, "Don't change the camera y-level on player movement") { mode == Mode.Free && relative } | ||
|
|
||
|
|
@@ -143,14 +145,6 @@ object Freecam : Module( | |
| mc.options.perspective = lastPerspective | ||
| } | ||
|
|
||
| listen<TickEvent.Pre> { | ||
| when (rotateMode) { | ||
| FreecamRotationMode.None -> return@listen | ||
| FreecamRotationMode.KeepRotation -> rotationRequest { rotation(rotation) }.submit() | ||
| FreecamRotationMode.LookAtTarget -> mc.crosshairTarget?.let { rotationRequest { rotation(lookAt(it.pos)) }.submit() } | ||
| } | ||
| } | ||
|
|
||
| listen<PlayerEvent.ChangeLookDirection> { | ||
| rotation = rotation.withDelta(it.deltaYaw * SENSITIVITY_FACTOR, it.deltaPitch * SENSITIVITY_FACTOR) | ||
| it.cancel() | ||
|
|
@@ -227,6 +221,33 @@ object Freecam : Module( | |
| mc.crosshairTarget = rotation.rayCast(reach, lerpPos).orMiss // Can't be null (otherwise mc will spam "Null returned as 'hitResult', this shouldn't happen!") | ||
| mc.crosshairTarget?.let { if (it.type != HitResult.Type.MISS) event.cancel() } | ||
| } | ||
|
|
||
| listen<TickEvent.Pre> { | ||
| when (rotateMode) { | ||
| FreecamRotationMode.None -> return@listen | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can change the None case to null and remove the submit calls for the other outcomes. Then you can move the .submit to the end of the when block with ?.submit(). Or the submit calls could be moved into the buildRotationTo function |
||
| FreecamRotationMode.KeepRotation -> rotationRequest { | ||
| buildRotationTo(rotation) | ||
| }.submit() | ||
| FreecamRotationMode.LookAtTarget -> mc.crosshairTarget?.let { rotationRequest { | ||
| buildRotationTo(lookAt(it.pos)) | ||
| }.submit() } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| context(rotationContext: IRotationRequest.RotationRequestBuilder) | ||
| private fun buildRotationTo(rotation: Rotation) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rather than passing a rotation request context, you could just have this function create the request and return it. rotationRequest { when block with builder calls } |
||
| when (excludeRotation) { | ||
| FreecamRotationExclusion.Pitch -> { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can inline these to avoid the brackets |
||
| rotationContext.yaw(rotation.yaw) | ||
| } | ||
| FreecamRotationExclusion.Yaw -> { | ||
| rotationContext.pitch(rotation.pitch) | ||
| } | ||
| else -> { | ||
| rotationContext.rotation(rotation) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private enum class FreecamRotationMode(override val displayName: String, override val description: String) : NamedEnum, Describable { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can remove the Freecam prefix for these enums. Theyre private so theres no need to preface what theyre for. Also while you're cleaning things up, might as well move these enums below the function at the bottom and remove the extra white space under the followTrackPlayer setting |
||
|
|
@@ -235,6 +256,12 @@ object Freecam : Module( | |
| KeepRotation("Keep Rotation", "Look in the same direction as the camera"); | ||
| } | ||
|
|
||
| private enum class FreecamRotationExclusion(override val displayName: String, override val description: String) : NamedEnum, Describable { | ||
| Yaw("Yaw", "Don't change yaw"), | ||
| Pitch("Pitch", "Don't change pitch"), | ||
| None("None", "Don't exclude any rotation changes"); | ||
| } | ||
|
|
||
| private enum class Mode(override val displayName: String, override val description: String) : NamedEnum, Describable { | ||
| Free("Free", "Move the camera freely with keyboard input"), | ||
| FollowPlayer("Follow Player", "Camera follows a player as if attached by an invisible string"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onValueChange can be placed on the next line. Also you sure we need this onValueChange?