diff options
author | nea <nea@nea.moe> | 2023-04-15 01:39:27 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-04-15 01:44:55 +0200 |
commit | 044b6ace9c75c3f50fccd66d21ed9de319e4130d (patch) | |
tree | a47dbccbde09255607aa51a3930bf1620a09c64a /src/main/kotlin | |
parent | db32a80d4a95ca57c834ae467899fb454381e131 (diff) | |
download | neuhax-044b6ace9c75c3f50fccd66d21ed9de319e4130d.tar.gz neuhax-044b6ace9c75c3f50fccd66d21ed9de319e4130d.tar.bz2 neuhax-044b6ace9c75c3f50fccd66d21ed9de319e4130d.zip |
Add yaw snapping
Diffstat (limited to 'src/main/kotlin')
4 files changed, 180 insertions, 2 deletions
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 |