diff options
author | nea <nea@nea.moe> | 2023-04-19 12:59:35 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-04-19 12:59:58 +0200 |
commit | f752e32b24f066547d065a6df9d73d4af753884f (patch) | |
tree | f111fcd62c8647556aec906935b6a39273d70925 /src | |
parent | 72d3ebd3f16b0ae164d005abcfacc47be6c3674b (diff) | |
download | neuhax-f752e32b24f066547d065a6df9d73d4af753884f.tar.gz neuhax-f752e32b24f066547d065a6df9d73d4af753884f.tar.bz2 neuhax-f752e32b24f066547d065a6df9d73d4af753884f.zip |
Add Yaw Snapping Keybinding
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/moe/nea/sky/mixin/MixinEntity.java | 2 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/sky/config/HaxConfigNeuHax.kt | 10 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/sky/constants.kt | 4 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/sky/events/YawRotateEvent.kt (renamed from src/main/kotlin/moe/nea/sky/features/events/YawRotateEvent.kt) | 2 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/sky/features/world/YawSnapping.kt | 21 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/sky/util/chatutils.kt | 5 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/sky/util/keyboard.kt | 18 |
7 files changed, 54 insertions, 8 deletions
diff --git a/src/main/java/moe/nea/sky/mixin/MixinEntity.java b/src/main/java/moe/nea/sky/mixin/MixinEntity.java index 121c07c..485f741 100644 --- a/src/main/java/moe/nea/sky/mixin/MixinEntity.java +++ b/src/main/java/moe/nea/sky/mixin/MixinEntity.java @@ -10,7 +10,7 @@ package moe.nea.sky.mixin; -import moe.nea.sky.features.events.YawRotateEvent; +import moe.nea.sky.events.YawRotateEvent; import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraftforge.common.MinecraftForge; diff --git a/src/main/kotlin/moe/nea/sky/config/HaxConfigNeuHax.kt b/src/main/kotlin/moe/nea/sky/config/HaxConfigNeuHax.kt index ec82096..013bc9d 100644 --- a/src/main/kotlin/moe/nea/sky/config/HaxConfigNeuHax.kt +++ b/src/main/kotlin/moe/nea/sky/config/HaxConfigNeuHax.kt @@ -12,6 +12,7 @@ package moe.nea.sky.config import com.google.gson.annotations.Expose import io.github.moulberry.notenoughupdates.core.config.annotations.* +import org.lwjgl.input.Keyboard class HaxConfigNeuHax { @@ -33,7 +34,6 @@ class HaxConfigNeuHax { @ConfigOption(name = "Enable Yaw Snapping", desc = "Align your yaw with certain angles") @ConfigEditorBoolean @JvmField - @ConfigAccordionId(id = 6) var yawSnapping = false @@ -42,7 +42,6 @@ class HaxConfigNeuHax { @ConfigEditorSlider(minValue = 0F, maxValue = 180F, minStep = 1F) @ConfigAccordionId(id = 6) @JvmField - var yawTightness = 90f @Expose @@ -58,4 +57,11 @@ class HaxConfigNeuHax { @ConfigEditorBoolean @ConfigAccordionId(id = 6) var displayYawOverlay = true + + @JvmField + @Expose + @ConfigOption(name = "Yaw Snapping Keybinding", desc = "Press to toggle yaw snapping") + @ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE) + @ConfigAccordionId(id = 6) + var yawSnappingKeybinding = Keyboard.KEY_NONE }
\ No newline at end of file diff --git a/src/main/kotlin/moe/nea/sky/constants.kt b/src/main/kotlin/moe/nea/sky/constants.kt index b8e43d6..3020bd1 100644 --- a/src/main/kotlin/moe/nea/sky/constants.kt +++ b/src/main/kotlin/moe/nea/sky/constants.kt @@ -10,8 +10,8 @@ package moe.nea.sky -import org.slf4j.LoggerFactory +import org.apache.logging.log4j.LogManager -val LOGGER = LoggerFactory.getLogger("NEUHax") +val LOGGER = LogManager.getLogger("NEUHax") const val MODID = "neuhax" diff --git a/src/main/kotlin/moe/nea/sky/features/events/YawRotateEvent.kt b/src/main/kotlin/moe/nea/sky/events/YawRotateEvent.kt index 407d0fa..b724ce1 100644 --- a/src/main/kotlin/moe/nea/sky/features/events/YawRotateEvent.kt +++ b/src/main/kotlin/moe/nea/sky/events/YawRotateEvent.kt @@ -8,7 +8,7 @@ * 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 +package moe.nea.sky.events import net.minecraftforge.fml.common.eventhandler.Cancelable import net.minecraftforge.fml.common.eventhandler.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 index b6515fb..0f41467 100644 --- a/src/main/kotlin/moe/nea/sky/features/world/YawSnapping.kt +++ b/src/main/kotlin/moe/nea/sky/features/world/YawSnapping.kt @@ -12,13 +12,18 @@ 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 moe.nea.sky.events.YawRotateEvent +import moe.nea.sky.util.getEffectiveKeyCode +import moe.nea.sky.util.showPlayerMessage 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.minecraft.util.EnumChatFormatting.* import net.minecraftforge.client.event.RenderGameOverlayEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent +import org.lwjgl.input.Keyboard import kotlin.math.absoluteValue import kotlin.math.sign @@ -28,7 +33,6 @@ object YawSnapping { /*LorenzUtils.inSkyBlock && // */ NEUHax.neuHaxConfig.yawSnapping - var overshot = 0F var isLocking = false @@ -37,6 +41,19 @@ object YawSnapping { generateSequence(0F) { it + NEUHax.neuHaxConfig.yawIntervals } .takeWhile { it <= 360 } + + @SubscribeEvent + fun onKeybind(event: KeyInputEvent) { + if (!Keyboard.getEventKeyState()) return + + if (event.getEffectiveKeyCode() == NEUHax.neuHaxConfig.yawSnappingKeybinding) { + NEUHax.neuHaxConfig.yawSnapping = !NEUHax.neuHaxConfig.yawSnapping + showPlayerMessage { + text("Yaw Snapping ${if (isEnabled()) "${GREEN}Enabled" else "${RED}Disabled"}") + } + } + } + @SubscribeEvent fun onRenderOverlay(event: RenderGameOverlayEvent.Post) { if (!isEnabled()) return diff --git a/src/main/kotlin/moe/nea/sky/util/chatutils.kt b/src/main/kotlin/moe/nea/sky/util/chatutils.kt index 509b069..df54cc8 100644 --- a/src/main/kotlin/moe/nea/sky/util/chatutils.kt +++ b/src/main/kotlin/moe/nea/sky/util/chatutils.kt @@ -10,6 +10,7 @@ package moe.nea.sky.util +import net.minecraft.client.Minecraft import net.minecraft.command.CommandBase import net.minecraft.command.ICommandSender import net.minecraft.event.ClickEvent @@ -97,6 +98,10 @@ class MessageTarget { } +fun showPlayerMessage(mode: MessageMode = MessageMode.INFO, block: MessageTarget.() -> Unit) { + Minecraft.getMinecraft().thePlayer?.showMessage(mode, block) +} + fun ICommandSender.showMessage(mode: MessageMode = MessageMode.INFO, block: MessageTarget.() -> Unit) { MessageTarget().also(block).aggregate.map { mode.format(it) }.forEach { addChatMessage(it) } } diff --git a/src/main/kotlin/moe/nea/sky/util/keyboard.kt b/src/main/kotlin/moe/nea/sky/util/keyboard.kt new file mode 100644 index 0000000..e75a3a0 --- /dev/null +++ b/src/main/kotlin/moe/nea/sky/util/keyboard.kt @@ -0,0 +1,18 @@ +/* + * 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.util + +import net.minecraftforge.fml.common.gameevent.InputEvent +import org.lwjgl.input.Keyboard + +fun InputEvent.KeyInputEvent.getEffectiveKeyCode(): Int = + if (Keyboard.getEventKey() == 0) Keyboard.getEventCharacter().code + 256 else Keyboard.getEventKey() + |