
walkmc.Direction.kt Maven / Gradle / Ivy
package walkmc
import net.minecraft.server.*
import org.bukkit.*
import walkmc.extensions.numbers.*
/**
* Represents a direction enum utility.
*/
enum class Direction(
val axis: Axis,
val direction: AxisDirection,
val modX: Int,
val modY: Int,
val modZ: Int
) {
DOWN(Axis.Y, AxisDirection.NEGATIVE, 0, -1, 0),
UP(Axis.Y, AxisDirection.POSITIVE, 0, 1, 0),
NORTH(Axis.Z, AxisDirection.NEGATIVE, 0, 0, -1),
SOUTH(Axis.Z, AxisDirection.POSITIVE, 0, 0, 1),
WEST(Axis.X, AxisDirection.NEGATIVE, -1, 0, 0),
EAST(Axis.X, AxisDirection.POSITIVE, 1, 0, 0);
fun toEnumDirection(): EnumDirection {
return EnumDirection.valueOf(name)
}
fun opposite(): Direction {
return when (this) {
DOWN -> UP
UP -> DOWN
NORTH -> SOUTH
SOUTH -> NORTH
WEST -> EAST
EAST -> SOUTH
}
}
companion object {
private val VALUES = values()
fun from(index: Int): Direction {
return VALUES[index % VALUES.size]
}
fun fromYaw(yaw: Float): Direction {
return from(floorInt((yaw * 4f / 360f) + 0.5) and 3)
}
fun from(location: Location): Direction {
return fromYaw(location.yaw)
}
}
}
/**
* Represents all axis coordenate dimensions.
*/
enum class Axis {
X, Y, Z
}
/**
* Represents all direction of an axis.
*/
enum class AxisDirection {
POSITIVE,
NEGATIVE
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy