aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/moe/nea/sky/mixin/MixinEntity.java43
-rw-r--r--src/main/java/moe/nea/sky/mixin/MixinSkytilsFunnny.java10
-rw-r--r--src/main/kotlin/moe/nea/sky/NEUHax.kt2
-rw-r--r--src/main/kotlin/moe/nea/sky/config/HaxConfigNeuHax.kt37
-rw-r--r--src/main/kotlin/moe/nea/sky/features/events/YawRotateEvent.kt17
-rw-r--r--src/main/kotlin/moe/nea/sky/features/world/YawSnapping.kt126
-rw-r--r--src/main/resources/mixins.neuhax.json1
7 files changed, 234 insertions, 2 deletions
diff --git a/src/main/java/moe/nea/sky/mixin/MixinEntity.java b/src/main/java/moe/nea/sky/mixin/MixinEntity.java
new file mode 100644
index 0000000..121c07c
--- /dev/null
+++ b/src/main/java/moe/nea/sky/mixin/MixinEntity.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2023 Linnea Gräf
+ *
+ * This file is part of NEUHax.
+ *
+ * NEUHax is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * NEUHax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License along with NEUHax. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package moe.nea.sky.mixin;
+
+import moe.nea.sky.features.events.YawRotateEvent;
+import net.minecraft.client.Minecraft;
+import net.minecraft.entity.Entity;
+import net.minecraftforge.common.MinecraftForge;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+@Mixin(Entity.class)
+public abstract class MixinEntity {
+ @Shadow
+ public float rotationYaw;
+
+ @Shadow public abstract void setAngles(float yaw, float pitch);
+
+ @Inject(method = "setAngles", at = @At("HEAD"), cancellable = true)
+ public void neuhaxOnSetAngles(float yaw, float pitch, CallbackInfo ci) {
+ Entity $this = (Entity) (Object) this;
+ if (yaw != 0F && $this == Minecraft.getMinecraft().thePlayer) {
+ YawRotateEvent yawRotateEvent = new YawRotateEvent(yaw, this.rotationYaw);
+ MinecraftForge.EVENT_BUS.post(yawRotateEvent);
+ if (yawRotateEvent.isCanceled()) {
+ ci.cancel();
+ this.setAngles(0, pitch);
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/moe/nea/sky/mixin/MixinSkytilsFunnny.java b/src/main/java/moe/nea/sky/mixin/MixinSkytilsFunnny.java
index a967f43..aaabbc0 100644
--- a/src/main/java/moe/nea/sky/mixin/MixinSkytilsFunnny.java
+++ b/src/main/java/moe/nea/sky/mixin/MixinSkytilsFunnny.java
@@ -1,3 +1,13 @@
+/*
+ * Copyright (C) 2023 Linnea Gräf
+ *
+ * This file is part of NEUHax.
+ *
+ * NEUHax is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * NEUHax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License along with NEUHax. If not, see <https://www.gnu.org/licenses/>.
+ */
+
package moe.nea.sky.mixin;
import org.spongepowered.asm.mixin.Mixin;
diff --git a/src/main/kotlin/moe/nea/sky/NEUHax.kt b/src/main/kotlin/moe/nea/sky/NEUHax.kt
index 27cd2cd..93e1a6f 100644
--- a/src/main/kotlin/moe/nea/sky/NEUHax.kt
+++ b/src/main/kotlin/moe/nea/sky/NEUHax.kt
@@ -16,6 +16,7 @@ import moe.nea.sky.config.HaxConfigNeuConfig
import moe.nea.sky.features.gui.Enchanting
import moe.nea.sky.features.gui.Melody
import moe.nea.sky.features.world.AutoFishing
+import moe.nea.sky.features.world.YawSnapping
import moe.nea.sky.util.CommandActionRegistry
import net.minecraft.launchwrapper.Launch
import net.minecraftforge.client.ClientCommandHandler
@@ -48,6 +49,7 @@ object NEUHax {
listOf(
Enchanting,
AutoFishing,
+ YawSnapping,
Melody,
).forEach {
MinecraftForge.EVENT_BUS.register(it)
diff --git a/src/main/kotlin/moe/nea/sky/config/HaxConfigNeuHax.kt b/src/main/kotlin/moe/nea/sky/config/HaxConfigNeuHax.kt
index ef342c4..ec82096 100644
--- a/src/main/kotlin/moe/nea/sky/config/HaxConfigNeuHax.kt
+++ b/src/main/kotlin/moe/nea/sky/config/HaxConfigNeuHax.kt
@@ -11,8 +11,7 @@
package moe.nea.sky.config
import com.google.gson.annotations.Expose
-import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigEditorBoolean
-import io.github.moulberry.notenoughupdates.core.config.annotations.ConfigOption
+import io.github.moulberry.notenoughupdates.core.config.annotations.*
class HaxConfigNeuHax {
@@ -25,4 +24,38 @@ class HaxConfigNeuHax {
@JvmField
var autoMelody: Boolean = false
+ @ConfigOption(name = "Yaw Snapping", desc = "")
+ @ConfigEditorAccordion(id = 6)
+ @JvmField
+ var yawSnappingAccordion = false
+
+ @Expose
+ @ConfigOption(name = "Enable Yaw Snapping", desc = "Align your yaw with certain angles")
+ @ConfigEditorBoolean
+ @JvmField
+
+ @ConfigAccordionId(id = 6)
+ var yawSnapping = false
+
+ @Expose
+ @ConfigOption(name = "Release Distance", desc = "How much you have to overshoot an angle to release yaw snapping")
+ @ConfigEditorSlider(minValue = 0F, maxValue = 180F, minStep = 1F)
+ @ConfigAccordionId(id = 6)
+ @JvmField
+
+ var yawTightness = 90f
+
+ @Expose
+ @ConfigOption(name = "Intervals", desc = "In which intervals do you want to enable yaw snapping (45°, 90°, etc.)")
+ @ConfigEditorSlider(minValue = 1F, maxValue = 180F, minStep = 1F)
+ @ConfigAccordionId(id = 6)
+ @JvmField
+ var yawIntervals = 45f
+
+ @JvmField
+ @Expose
+ @ConfigOption(name = "Yaw Overlay", desc = "Display your current yaw over your cursor")
+ @ConfigEditorBoolean
+ @ConfigAccordionId(id = 6)
+ var displayYawOverlay = true
} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/sky/features/events/YawRotateEvent.kt b/src/main/kotlin/moe/nea/sky/features/events/YawRotateEvent.kt
new file mode 100644
index 0000000..407d0fa
--- /dev/null
+++ b/src/main/kotlin/moe/nea/sky/features/events/YawRotateEvent.kt
@@ -0,0 +1,17 @@
+/*
+ * Copyright (C) 2023 Linnea Gräf
+ *
+ * This file is part of NEUHax.
+ *
+ * NEUHax is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * NEUHax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License along with NEUHax. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package moe.nea.sky.features.events
+
+import net.minecraftforge.fml.common.eventhandler.Cancelable
+import net.minecraftforge.fml.common.eventhandler.Event
+
+@Cancelable
+data class YawRotateEvent(val yawDelta: Float, val oldYaw: Float) : Event()
diff --git a/src/main/kotlin/moe/nea/sky/features/world/YawSnapping.kt b/src/main/kotlin/moe/nea/sky/features/world/YawSnapping.kt
new file mode 100644
index 0000000..b6515fb
--- /dev/null
+++ b/src/main/kotlin/moe/nea/sky/features/world/YawSnapping.kt
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2023 Linnea Gräf
+ *
+ * This file is part of NEUHax.
+ *
+ * NEUHax is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * NEUHax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License along with NEUHax. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package moe.nea.sky.features.world
+
+import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils
+import moe.nea.sky.NEUHax
+import moe.nea.sky.features.events.YawRotateEvent
+import net.minecraft.client.Minecraft
+import net.minecraft.client.gui.Gui
+import net.minecraft.client.gui.ScaledResolution
+import net.minecraft.client.renderer.GlStateManager
+import net.minecraftforge.client.event.RenderGameOverlayEvent
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.math.absoluteValue
+import kotlin.math.sign
+
+object YawSnapping {
+
+ fun isEnabled(): Boolean =
+ /*LorenzUtils.inSkyBlock && // */
+ NEUHax.neuHaxConfig.yawSnapping
+
+
+ var overshot = 0F
+ var isLocking = false
+
+ private val snapPoints
+ get() =
+ generateSequence(0F) { it + NEUHax.neuHaxConfig.yawIntervals }
+ .takeWhile { it <= 360 }
+
+ @SubscribeEvent
+ fun onRenderOverlay(event: RenderGameOverlayEvent.Post) {
+ if (!isEnabled()) return
+ if (!NEUHax.neuHaxConfig.displayYawOverlay) return
+ if (event.type != RenderGameOverlayEvent.ElementType.ALL) return
+ val sr = ScaledResolution(Minecraft.getMinecraft())
+ GlStateManager.pushMatrix()
+ GlStateManager.translate(sr.scaledWidth_double / 2, sr.scaledHeight_double / 2, 0.0)
+ Gui.drawRect(-200, -16, 200, -15, 0xFFFFFFFF.toInt())
+ Gui.drawRect(-200, 15, 200, 16, 0xFFFFFFFF.toInt())
+ Gui.drawRect(0, -16, 1, 16, 0xFFFFFFFF.toInt())
+ Gui.drawRect(-200, -16, -199, 16, 0xFFFFFFFF.toInt())
+ Gui.drawRect(199, -16, 200, 16, 0xFFFFFFFF.toInt())
+ val font = Minecraft.getMinecraft().fontRendererObj
+ val player = Minecraft.getMinecraft().thePlayer
+ val playerYaw = (player.rotationYaw % 360 + 360) % 360
+ fun deltaToPosition(delta: Float) = (if (delta < -180) {
+ (360 + delta) % 360
+ } else if (delta > 180) {
+ -(360 - delta) % 360
+ } else delta) * 3
+
+ for (yawBreak in (generateSequence(0F) { it + 15 }.takeWhile { it < 360 } + snapPoints.filter { it < 360 }).toSet()) {
+ val delta = yawBreak - playerYaw
+ val position = deltaToPosition(delta)
+ if (position.absoluteValue < 200) {
+ TextRenderUtils.drawStringCentered(
+ "${yawBreak.toInt()}",
+ font,
+ position,
+ -font.FONT_HEIGHT / 2F,
+ false,
+ 0xFFFFFFFF.toInt()
+ )
+ Gui.drawRect(
+ position.toInt(),
+ font.FONT_HEIGHT / 2,
+ position.toInt() + 1,
+ 16,
+ if (yawBreak in snapPoints) 0xFF00FF00.toInt() else 0xFFFFFFFF.toInt()
+ )
+ }
+ }
+ if (isLocking) {
+ val overshotPos = overshot * 200 / NEUHax.neuHaxConfig.yawTightness
+ Gui.drawRect(
+ overshotPos.toInt(),
+ font.FONT_HEIGHT / 2,
+ overshotPos.toInt() + 1,
+ 16,
+ 0xFFFFFF00.toInt()
+ )
+ }
+ GlStateManager.enableDepth()
+ GlStateManager.color(1F, 1F, 1F, 1F)
+ GlStateManager.popMatrix()
+ }
+
+ @SubscribeEvent
+ fun onYawRotate(event: YawRotateEvent) {
+ if (!isEnabled()) {
+ isLocking = false
+ return
+ }
+ if (isLocking) {
+ overshot += event.yawDelta
+ if (overshot.absoluteValue > NEUHax.neuHaxConfig.yawTightness) {
+ isLocking = false
+ } else {
+ event.isCanceled = true
+ }
+ return
+ }
+ val old = (360 + event.oldYaw % 360) % 360
+ val new = old + event.yawDelta
+ for (snapPoint in snapPoints) {
+ if (sign(old - snapPoint) != sign(new - snapPoint)) {
+ Minecraft.getMinecraft().thePlayer.rotationYaw = snapPoint
+ Minecraft.getMinecraft().thePlayer.prevRotationYaw = snapPoint
+ event.isCanceled = true
+ overshot = 0F
+ isLocking = true
+ }
+ }
+ }
+
+} \ No newline at end of file
diff --git a/src/main/resources/mixins.neuhax.json b/src/main/resources/mixins.neuhax.json
index 867f1f9..12685d3 100644
--- a/src/main/resources/mixins.neuhax.json
+++ b/src/main/resources/mixins.neuhax.json
@@ -8,6 +8,7 @@
"MixinFMLHandshakeMessageModList",
"MixinGenericBlockHighlighter",
"MixinSkytilsFunnny",
+ "MixinEntity",
"MixinUltrasequencerItem",
"config.MixinHaxConfigEnchanting",
"config.MixinHaxConfigFishing",