aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/main/java/at/hannibal2/skyhanni/features/garden/GardenYawAndPitch.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt36
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt20
3 files changed, 44 insertions, 18 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenYawAndPitch.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenYawAndPitch.kt
index ebc266692..cdbb07963 100755
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenYawAndPitch.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenYawAndPitch.kt
@@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.config.enums.OutsideSbFeature
import at.hannibal2.skyhanni.events.GardenToolChangeEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
+import at.hannibal2.skyhanni.utils.LocationUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.round
import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
@@ -29,10 +30,7 @@ object GardenYawAndPitch {
if (GardenAPI.toolInHand == null && !config.showWithoutTool) return
val player = Minecraft.getMinecraft().thePlayer
-
- var yaw = player.rotationYaw % 360
- if (yaw < 0) yaw += 360
- if (yaw > 180) yaw -= 360
+ var yaw = LocationUtils.calculatePlayerYaw()
val pitch = player.rotationPitch
if (yaw != lastYaw || pitch != lastPitch) {
diff --git a/src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt b/src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt
index 00fa25459..ababb9b65 100644
--- a/src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt
+++ b/src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt
@@ -367,17 +367,19 @@ object GraphEditor {
}
private fun editModeClicks() {
- KeyboardManager.WasdInputMatrix.w.handleEditClicks(x = 1)
- KeyboardManager.WasdInputMatrix.s.handleEditClicks(x = -1)
- KeyboardManager.WasdInputMatrix.a.handleEditClicks(z = 1)
- KeyboardManager.WasdInputMatrix.d.handleEditClicks(z = -1)
- KeyboardManager.WasdInputMatrix.up.handleEditClicks(y = 1)
- KeyboardManager.WasdInputMatrix.down.handleEditClicks(y = -1)
+ var vector = LocationUtils.calculatePlayerFacingDirection()
+ KeyboardManager.WasdInputMatrix.w.handleEditClicks(vector)
+ KeyboardManager.WasdInputMatrix.a.handleEditClicks(vector.rotateXZ(Math.toRadians(90.0)))
+ KeyboardManager.WasdInputMatrix.s.handleEditClicks(vector.rotateXZ(Math.toRadians(180.0)))
+ KeyboardManager.WasdInputMatrix.d.handleEditClicks(vector.rotateXZ(Math.toRadians(270.0)))
+
+ KeyboardManager.WasdInputMatrix.up.handleEditClicks(LorenzVec(0, 1, 0))
+ KeyboardManager.WasdInputMatrix.down.handleEditClicks(LorenzVec(0, -1, 0))
}
- private fun KeyBinding.handleEditClicks(x: Int = 0, y: Int = 0, z: Int = 0) {
+ private fun KeyBinding.handleEditClicks(vector: LorenzVec) {
if (this.keyCode.isKeyClicked()) {
- activeNode?.position = activeNode?.position?.add(x, y, z) ?: return
+ activeNode?.position = activeNode?.position?.plus(vector) ?: return
}
}
@@ -391,14 +393,20 @@ object GraphEditor {
private fun addNode() {
val closedNode = closedNode
if (closedNode != null && closedNode.position.distanceSqToPlayer() < 9.0) {
- feedBackInTutorial("Removed node, since you where closer than 3 blocks from a node.")
- nodes.remove(closedNode)
- edges.removeIf { it.isInEdge(closedNode) }
- if (closedNode == activeNode) activeNode = null
- this.closedNode = null
- return
+ if (closedNode == activeNode) {
+ feedBackInTutorial("Removed node, since you where closer than 3 blocks from a the active node.")
+ nodes.remove(closedNode)
+ edges.removeIf { it.isInEdge(closedNode) }
+ if (closedNode == activeNode) activeNode = null
+ this.closedNode = null
+ return
+ }
}
val position = LocationUtils.playerEyeLocation().roundLocationToBlock()
+ if (nodes.any { it.position == position }) {
+ feedBackInTutorial("Can't create node, here is already another one.")
+ return
+ }
val node = GraphingNode(id++, position)
nodes.add(node)
feedBackInTutorial("Added graph node.")
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt
index b9a790d31..ba82321f2 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt
@@ -106,4 +106,24 @@ object LocationUtils {
val maxZ = min(this.maxZ, other.maxZ)
return AxisAlignedBB(minX, minY, minZ, maxX, maxY, maxZ)
}
+
+ fun calculatePlayerYaw(): Float {
+ val player = Minecraft.getMinecraft().thePlayer
+ var yaw = player.rotationYaw % 360
+ if (yaw < 0) yaw += 360
+ if (yaw > 180) yaw -= 360
+
+ return yaw
+ }
+
+ fun calculatePlayerFacingDirection(): LorenzVec {
+ var yaw = LocationUtils.calculatePlayerYaw() + 180
+ return when {
+ yaw < 45 -> LorenzVec(0, 0, -1)
+ yaw < 135 -> LorenzVec(1, 0, 0)
+ yaw < 225 -> LorenzVec(0, 0, 1)
+ yaw < 315 -> LorenzVec(-1, 0, 0)
+ else -> LorenzVec(0, 0, -1)
+ }
+ }
}