Skip to content

Commit 09a6bc3

Browse files
committed
Fix user interaction on differing internal rotations
1 parent d8ea6aa commit 09a6bc3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import com.lambda.context.SafeContext
2222
import com.lambda.event.EventFlow.post
2323
import com.lambda.event.events.ConnectionEvent
2424
import com.lambda.event.events.PacketEvent
25+
import com.lambda.event.events.PlayerEvent
26+
import com.lambda.event.events.RenderEvent
2527
import com.lambda.event.events.TickEvent
2628
import com.lambda.event.events.UpdateManagerEvent
2729
import com.lambda.event.listener.SafeListener.Companion.listen
@@ -37,9 +39,11 @@ import com.lambda.util.extension.rotation
3739
import com.lambda.util.math.MathUtils.toRadian
3840
import com.lambda.util.math.Vec2d
3941
import com.lambda.util.math.lerp
42+
import com.lambda.util.world.raycast.RayCastUtils.orMiss
4043
import net.minecraft.client.input.Input
4144
import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket
4245
import net.minecraft.util.PlayerInput
46+
import net.minecraft.util.hit.EntityHitResult
4347
import net.minecraft.util.math.Vec2f
4448
import kotlin.math.PI
4549
import kotlin.math.atan2
@@ -79,6 +83,29 @@ object RotationManager : RequestHandler<RotationRequest>(
7983
changedThisTick = false
8084
}
8185

86+
listen<RenderEvent.UpdateTarget> {
87+
if (activeRequest == null) return@listen
88+
it.cancel()
89+
90+
val eye = player.eyePos
91+
val entityHit = player.rotation.rayCast(player.entityInteractionRange, eye).orMiss
92+
mc.targetedEntity = (entityHit as? EntityHitResult)?.entity
93+
val blockHit = player.rotation.rayCast(player.blockInteractionRange, eye).orMiss
94+
mc.crosshairTarget = blockHit
95+
}
96+
97+
listen<PlayerEvent.Interact.Block> {
98+
activeRotation = player.rotation
99+
}
100+
101+
listen<PlayerEvent.Interact.Entity> {
102+
activeRotation = player.rotation
103+
}
104+
105+
listen<PlayerEvent.Interact.Item> {
106+
activeRotation = player.rotation
107+
}
108+
82109
listen<PacketEvent.Receive.Post>(priority = Int.MIN_VALUE) { event ->
83110
val packet = event.packet
84111
if (packet !is PlayerPositionLookS2CPacket) return@listen

0 commit comments

Comments
 (0)