Skip to content

Commit

Permalink
fix(Rotation): raycast fails when spot inside box (#5635)
Browse files Browse the repository at this point in the history
When we are inside a box, we cannot raycast to a point on the box. We should just use our preferred spot, since we are already inside the box and therefore aiming correctly anyway.
  • Loading branch information
1zun4 authored Feb 15, 2025
1 parent 96ad620 commit d3a417a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ object SubmoduleCrystalDestroyer : ToggleableConfigurable(ModuleCrystalAura, "De
range = range.toDouble(),
wallsRange = wallsRange.toDouble(),
futureTarget = base,
prioritizeVisible = prioritizeVisibleFaces,
allowInside = true
prioritizeVisible = prioritizeVisibleFaces
) ?: return

queueDestroy(rotation, target, base, eyePos, vec3d)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,16 +295,16 @@ fun raytraceBox(
visibilityPredicate: VisibilityPredicate = BoxVisibilityPredicate(),
rotationPreference: RotationPreference = LeastDifferencePreference.LEAST_DISTANCE_TO_CURRENT_ROTATION,
futureTarget: Box? = null,
prioritizeVisible: Boolean = true,
allowInside: Boolean = false
prioritizeVisible: Boolean = true
): VecRotation? {
val rangeSquared = range * range
val wallsRangeSquared = wallsRange * wallsRange

val preferredSpot = rotationPreference.getPreferredSpot(eyes, range)
var preferredSpotOnBox = box.raycast(eyes, preferredSpot).getOrNull()
if (preferredSpotOnBox == null && box.contains(eyes) && allowInside) {
preferredSpotOnBox = eyes
var preferredSpotOnBox = if (box.contains(eyes) && box.contains(preferredSpot)) {
preferredSpot
} else {
box.raycast(eyes, preferredSpot).getOrNull()
}

if (preferredSpotOnBox != null) {
Expand Down Expand Up @@ -369,7 +369,12 @@ private fun considerSpot(
) {
// Elongate the line so we have no issues with fp-precision
val raycastTarget = (preferredSpot - eyes) * 2.0 + eyes
val spotOnBox = box.raycast(eyes, raycastTarget).getOrNull() ?: return

val spotOnBox = if (box.contains(eyes) && box.contains(raycastTarget)) {
raycastTarget
} else {
box.raycast(eyes, raycastTarget).getOrNull() ?: return
}
val distance = eyes.squaredDistanceTo(spotOnBox)

val visible = visibilityPredicate.isVisible(eyes, raycastTarget)
Expand All @@ -389,7 +394,7 @@ private fun considerSpot(
*
* Will return `true` if the player is inside the [box].
*/
fun canSeeBox(eyes: Vec3d, box: Box, range: Double, wallsRange: Double, expectedTarget: BlockPos? = null, ): Boolean {
fun canSeeBox(eyes: Vec3d, box: Box, range: Double, wallsRange: Double, expectedTarget: BlockPos? = null): Boolean {
if (box.contains(eyes)) {
return true
}
Expand Down

0 comments on commit d3a417a

Please sign in to comment.