1818package com.lambda.interaction.request.rotation.visibilty
1919
2020import com.lambda.interaction.request.rotation.Rotation
21- import com.lambda.util.Communication.info
2221import net.minecraft.entity.Entity
2322import net.minecraft.util.math.Direction
2423import net.minecraft.util.math.MathHelper
24+ import net.minecraft.util.math.MathHelper.wrapDegrees
2525import net.minecraft.util.math.Vec3i
2626
2727enum class PlaceDirection (
@@ -33,37 +33,35 @@ enum class PlaceDirection(
3333 Down ( 0.0 , 90.0 , 0 , - 1 , 0 , listOf (Double .MIN_VALUE .. Double .MAX_VALUE )),
3434
3535 UpNorth ( - 180.0 , - 90.0 , 0 , 1 , - 1 , northYawRanges),
36- UpSouth ( 0.0 , - 90.0 , 0 , 1 , 1 , listOf (southYawRange)),
37- UpWest ( 90.0 , - 90.0 , 1 , 1 , 0 , listOf (westYawRange)),
38- UpEast ( - 90.0 , - 90.0 , - 1 , 1 , 0 , listOf (eastYawRange)),
36+ UpSouth ( 0.0 , - 90.0 , 0 , 1 , 1 , listOf (southYawRange)),
37+ UpWest ( 90.0 , - 90.0 , 1 , 1 , 0 , listOf (westYawRange)),
38+ UpEast ( - 90.0 , - 90.0 , - 1 , 1 , 0 , listOf (eastYawRange)),
3939
4040 DownNorth ( - 180.0 , 90.0 , 0 , - 1 , - 1 , northYawRanges),
41- DownSouth ( 0.0 , 90.0 , 0 , - 1 , 1 , listOf (southYawRange)),
42- DownWest ( 90.0 , 90.0 , 1 , - 1 , 0 , listOf (westYawRange)),
43- DownEast ( - 90.0 , 90.0 , - 1 , - 1 , 0 , listOf (eastYawRange)),
41+ DownSouth ( 0.0 , 90.0 , 0 , - 1 , 1 , listOf (southYawRange)),
42+ DownWest ( 90.0 , 90.0 , 1 , - 1 , 0 , listOf (westYawRange)),
43+ DownEast ( - 90.0 , 90.0 , - 1 , - 1 , 0 , listOf (eastYawRange)),
4444
4545 North ( - 180.0 , 0.0 , 0 , 0 , - 1 , northYawRanges),
46- South ( 0.0 , 0.0 , 0 , 0 , 1 , listOf (southYawRange)),
47- West ( 90.0 , 0.0 , 1 , 0 , 0 , listOf (westYawRange)),
48- East ( - 90.0 , 0.0 , - 1 , 0 , 0 , listOf (eastYawRange));
46+ South ( 0.0 , 0.0 , 0 , 0 , 1 , listOf (southYawRange)),
47+ West ( 90.0 , 0.0 , 1 , 0 , 0 , listOf (westYawRange)),
48+ East ( - 90.0 , 0.0 , - 1 , 0 , 0 , listOf (eastYawRange));
4949
5050 constructor (yaw: Double , pitch: Double , x: Int , y: Int , z: Int , yawRanges: List <ClosedRange <Double >>)
5151 : this (Rotation (yaw, pitch), Vec3i (x, y, z), yawRanges)
5252
53+ // ToDo: Add dynamic pitch border calculations to avoid excess rotation distance
5354 fun snapToArea (rot : Rotation ): Rotation {
54- // if (isInArea(rot)) return rot
55+ if (isInArea(rot)) return rot
5556
56- // ToDo: fix snapping to a given directions area to speed up rotations in the case they are not instant
57- // val normalizedYaw = wrapDegrees(rot.yaw)
58- // val clampedYaw = when {
59- // this.rotation.yaw != 180.0 -> normalizedYaw.coerceIn(yawRanges[0])
60- // normalizedYaw < 0 -> normalizedYaw.coerceIn(yawRanges[0])
61- // else -> normalizedYaw.coerceIn(yawRanges[1])
62- // }
63-
64- info(" $rotation " )
57+ val normalizedYaw = wrapDegrees(rot.yaw)
58+ val clampedYaw = when {
59+ this .rotation.yaw != - 180.0 -> normalizedYaw.coerceIn(yawRanges[0 ])
60+ normalizedYaw < 0 -> normalizedYaw.coerceIn(yawRanges[0 ])
61+ else -> normalizedYaw.coerceIn(yawRanges[1 ])
62+ }
6563
66- return Rotation (rotation.yaw, rotation.pitch)
64+ return Rotation (clampedYaw, this . rotation.pitch)
6765 }
6866
6967 fun isInArea (rot : Rotation ) = fromRotation(rot) == this
@@ -117,8 +115,9 @@ enum class PlaceDirection(
117115 }
118116}
119117
120- // North and south take priority at borders. Same rule applies with up and down over horizontal directions
121- val northYawRanges = listOf (- 180.0 .. - 135.0 , 135.0 .. 180.0 )
122- val southYawRange = - 45.0 .. 45.0
123- val eastYawRange = - 134.99 .. - 45.01
124- val westYawRange = 45.01 .. 134.99
118+ const val FUDGE_FACTOR = 0.01
119+
120+ val northYawRanges = listOf (- 180.0 .. (- 135.0 - FUDGE_FACTOR ), (135.0 + FUDGE_FACTOR ).. 180.0 )
121+ val southYawRange = ( - 45.0 + FUDGE_FACTOR ).. ( 45.0 - FUDGE_FACTOR )
122+ val eastYawRange = (- 135.0 + FUDGE_FACTOR ).. (- 45.0 - FUDGE_FACTOR )
123+ val westYawRange = ( 45.0 + FUDGE_FACTOR ).. (135.0 - FUDGE_FACTOR )
0 commit comments