Skip to content

Commit

Permalink
2.1.0
Browse files Browse the repository at this point in the history
Completely rewrite keybind handling
Remove Requisite due to current problems with it
  • Loading branch information
Wyvest committed Aug 27, 2021
1 parent 33947b2 commit 303e32f
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 42 deletions.
11 changes: 4 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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 {
Expand All @@ -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'
}

Expand All @@ -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'
)

Expand Down
31 changes: 24 additions & 7 deletions src/main/kotlin/net/wyvest/behindyou/BehindYou.kt
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -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)
}
}
38 changes: 33 additions & 5 deletions src/main/kotlin/net/wyvest/behindyou/Listener.kt
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/kotlin/net/wyvest/behindyou/config/BehindYouConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 1 addition & 22 deletions src/main/kotlin/net/wyvest/behindyou/utils/StringUtils.kt
Original file line number Diff line number Diff line change
@@ -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)
fun String?.startsWithAny(vararg sequences: CharSequence?) = ApacheStringUtils.startsWithAny(this, *sequences)
6 changes: 5 additions & 1 deletion src/main/kotlin/net/wyvest/behindyou/utils/Updater.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down

0 comments on commit 303e32f

Please sign in to comment.