diff --git a/build.gradle b/build.gradle index d45b253..6346b69 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { id "org.jetbrains.kotlin.jvm" version "1.5.21" } -version = "2.0.0" +version = "2.1.0" group = "net.wyvest" archivesBaseName = "BehindYouv2" @@ -18,7 +18,7 @@ minecraft { mappings = "stable_22" makeObfSourceJar = false clientJvmArgs += '-Dfml.coreMods.load=net.wyvest.behindyou.tweaker.BehindYouLoadingPlugin' - clientRunArgs += '--tweakClass net.wyvest.requisiteessentialloader.RequisiteEssentialTweaker' + clientRunArgs += '--tweakClass gg.essential.loader.stage0.EssentialSetupTweaker' } configurations { @@ -36,10 +36,7 @@ repositories { dependencies { // Libraries - provided 'xyz.matthewtgm:Requisite:1.1.1' - include 'com.github.W-OVERFLOW:RequisiteEssentialLoader:7a4eb4eeb7' - implementation ('xyz.matthewtgm:RequisiteLaunchwrapper:1.1') - implementation ('gg.essential:loader-launchwrapper:1.1.0') + include ('gg.essential:loader-launchwrapper:1.1.0') provided 'gg.essential:essential-1.8.9-forge:1300' } @@ -49,7 +46,7 @@ jar { 'FMLCorePlugin': 'net.wyvest.behindyou.tweaker.BehindYouLoadingPlugin', 'FMLCorePluginContainsFMLMod': true, 'ForceLoadAsMod': true, - 'TweakClass': 'net.wyvest.requisiteessentialloader.RequisiteEssentialTweaker', + 'TweakClass': 'gg.essential.loader.stage0.EssentialSetupTweaker', 'TweakOrder': '0' ) diff --git a/src/main/kotlin/net/wyvest/behindyou/BehindYou.kt b/src/main/kotlin/net/wyvest/behindyou/BehindYou.kt index b94f9b5..1897b63 100644 --- a/src/main/kotlin/net/wyvest/behindyou/BehindYou.kt +++ b/src/main/kotlin/net/wyvest/behindyou/BehindYou.kt @@ -1,32 +1,48 @@ package net.wyvest.behindyou +import gg.essential.universal.ChatColor import net.minecraft.client.Minecraft +import net.minecraft.client.settings.KeyBinding +import net.minecraft.util.ChatComponentText import net.minecraft.util.EnumChatFormatting +import net.minecraftforge.common.MinecraftForge.EVENT_BUS +import net.minecraftforge.fml.client.registry.ClientRegistry import net.minecraftforge.fml.common.Mod import net.minecraftforge.fml.common.event.FMLInitializationEvent import net.minecraftforge.fml.common.event.FMLPreInitializationEvent import net.wyvest.behindyou.commands.BehindYouCommand import net.wyvest.behindyou.config.BehindYouConfig import net.wyvest.behindyou.utils.Updater -import xyz.matthewtgm.requisite.util.ChatHelper -import xyz.matthewtgm.requisite.util.ForgeHelper +import org.lwjgl.input.Keyboard import java.io.File -@Mod(name = BehindYou.NAME, modid = BehindYou.ID, version = BehindYou.VERSION, modLanguageAdapter = "gg.essential.api.utils.KotlinAdapter") + +@Mod( + name = BehindYou.NAME, + modid = BehindYou.ID, + version = BehindYou.VERSION, + modLanguageAdapter = "gg.essential.api.utils.KotlinAdapter" +) object BehindYou { const val NAME = "BehindYouv2" - const val VERSION = "2.0.0" + const val VERSION = "2.1.0" const val ID = "behindyouv2" val mc: Minecraft get() = Minecraft.getMinecraft() + fun sendMessage(message: String) { - ChatHelper.sendMessage(EnumChatFormatting.DARK_PURPLE.toString() + "[$NAME] ", message) + if (mc.thePlayer == null) + return + val text = ChatComponentText(EnumChatFormatting.DARK_PURPLE.toString() + "[$NAME] " + ChatColor.RESET.toString() + " " + message) + Minecraft.getMinecraft().thePlayer.addChatMessage(text) } + lateinit var jarFile: File val modDir = File(File(File(mc.mcDataDir, "config"), "Wyvest"), NAME) + val keybind = KeyBinding("Behind Keybind", Keyboard.KEY_R, "Behind You") @Mod.EventHandler - private fun onFMLPreInitialization(event: FMLPreInitializationEvent) { + fun onFMLPreInitialization(event: FMLPreInitializationEvent) { if (!modDir.exists()) modDir.mkdirs() jarFile = event.sourceFile } @@ -35,7 +51,8 @@ object BehindYou { fun onFMLInitialization(event: FMLInitializationEvent) { BehindYouConfig.initialize() BehindYouCommand.register() + ClientRegistry.registerKeyBinding(keybind) + EVENT_BUS.register(Listener) Updater.update() - ForgeHelper.registerEventListener(Listener) } } \ No newline at end of file diff --git a/src/main/kotlin/net/wyvest/behindyou/Listener.kt b/src/main/kotlin/net/wyvest/behindyou/Listener.kt index cdee9ad..205085d 100644 --- a/src/main/kotlin/net/wyvest/behindyou/Listener.kt +++ b/src/main/kotlin/net/wyvest/behindyou/Listener.kt @@ -1,17 +1,45 @@ package net.wyvest.behindyou +import net.minecraft.client.settings.GameSettings import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent +import net.wyvest.behindyou.BehindYou.keybind +import net.wyvest.behindyou.BehindYou.mc import net.wyvest.behindyou.config.BehindYouConfig object Listener { + private var prevState = false + + /** + * Keybind hold / toggle logic stolen from PerspectiveModv4 under MIT License + * https://github.com/DJtheRedstoner/PerspectiveModv4/blob/28fb656d8b285f3da2227dd859735392902a31ef/LICENSE + */ @SubscribeEvent - fun listen(e : TickEvent.ClientTickEvent) { - if (e.phase == TickEvent.Phase.END) { - if (BehindYouConfig.toggled) { - if (BehindYou.mc.gameSettings.thirdPersonView == 1) { - ++BehindYou.mc.gameSettings.thirdPersonView + fun onKeyInput(event: TickEvent.RenderTickEvent) { + if (BehindYouConfig.toggled) { + val isDown = GameSettings.isKeyDown(keybind) + if (isDown != prevState && mc.currentScreen == null && mc.theWorld != null && mc.thePlayer != null) { + prevState = isDown + if (isDown) { + when (mc.gameSettings.thirdPersonView) { + 0 -> { + mc.gameSettings.thirdPersonView = 2 + mc.entityRenderer.loadEntityShader(null) + } + 1 -> { + mc.gameSettings.thirdPersonView = 2 + } + 2 -> { + mc.gameSettings.thirdPersonView = 0 + mc.entityRenderer.loadEntityShader(mc.renderViewEntity) + } + } + mc.renderGlobal.setDisplayListEntitiesDirty() + } else if (BehindYouConfig.hold) { + mc.gameSettings.thirdPersonView = 0 + mc.entityRenderer.loadEntityShader(mc.renderViewEntity) + mc.renderGlobal.setDisplayListEntitiesDirty() } } } diff --git a/src/main/kotlin/net/wyvest/behindyou/config/BehindYouConfig.kt b/src/main/kotlin/net/wyvest/behindyou/config/BehindYouConfig.kt index 4d5e5b4..35c13ce 100644 --- a/src/main/kotlin/net/wyvest/behindyou/config/BehindYouConfig.kt +++ b/src/main/kotlin/net/wyvest/behindyou/config/BehindYouConfig.kt @@ -21,6 +21,23 @@ object BehindYouConfig : Vigilant(File(BehindYou.modDir, "${BehindYou.ID}.toml") ) var toggled = true + @Property( + type = PropertyType.SWITCH, + name = "Hold Keybind", + description = "Allow the option to turn back to the first person after releasing the keybind.", + category = "General" + ) + var hold = true + + @Property( + type = PropertyType.PARAGRAPH, + name = "Keybind", + description = "The ability to edit the keybind is in the Minecraft Controls Menu, in options -> controls.", + category = "General", + protectedText = true + ) + var placeholder = "" + @Property( type = PropertyType.SWITCH, name = "Show Update Notification", diff --git a/src/main/kotlin/net/wyvest/behindyou/utils/StringUtils.kt b/src/main/kotlin/net/wyvest/behindyou/utils/StringUtils.kt index 0c89681..043f16f 100644 --- a/src/main/kotlin/net/wyvest/behindyou/utils/StringUtils.kt +++ b/src/main/kotlin/net/wyvest/behindyou/utils/StringUtils.kt @@ -1,30 +1,9 @@ package net.wyvest.behindyou.utils -import net.minecraft.util.EnumChatFormatting import org.apache.commons.lang3.StringUtils as ApacheStringUtils /** * Adapted from Skytils under AGPLv3 * https://github.com/Skytils/SkytilsMod/blob/1.x/LICENSE.md */ -fun String?.startsWithAny(vararg sequences: CharSequence?) = ApacheStringUtils.startsWithAny(this, *sequences) - -/** - * Adapted from Skytils under AGPLv3 - * https://github.com/Skytils/SkytilsMod/blob/1.x/LICENSE.md - */ -fun String?.equalsAny(vararg sequences: CharSequence?): Boolean { - if (this == null) return false - return sequences.any { it != null && this.equals(it as String, true) } -} - -/** - * Adapted from Skytils under AGPLv3 - * https://github.com/Skytils/SkytilsMod/blob/1.x/LICENSE.md - */ -fun String?.containsAny(vararg sequences: CharSequence?): Boolean { - if (this == null) return false - return sequences.any { it != null && this.contains(it, true) } -} - -fun String.withoutFormattingCodes(): String = EnumChatFormatting.getTextWithoutFormattingCodes(this) \ No newline at end of file +fun String?.startsWithAny(vararg sequences: CharSequence?) = ApacheStringUtils.startsWithAny(this, *sequences) \ No newline at end of file diff --git a/src/main/kotlin/net/wyvest/behindyou/utils/Updater.kt b/src/main/kotlin/net/wyvest/behindyou/utils/Updater.kt index 2e8b3d5..8f14b63 100644 --- a/src/main/kotlin/net/wyvest/behindyou/utils/Updater.kt +++ b/src/main/kotlin/net/wyvest/behindyou/utils/Updater.kt @@ -48,7 +48,11 @@ object Updater { if (updateUrl.isNotEmpty()) { if (BehindYouConfig.showUpdateNotification) { EssentialAPI.getNotifications() - .push("Mod Update", "${BehindYou.NAME} $latestTag is available!\nClick here to download it!", 5f) { + .push( + "Mod Update", + "${BehindYou.NAME} $latestTag is available!\nClick here to download it!", + 5f + ) { EssentialAPI.getGuiUtil().openScreen(DownloadConfirmGui(mc.currentScreen)) } }