Skip to content

Commit

Permalink
fix: fix keybind not being reset sometimes
Browse files Browse the repository at this point in the history
misc: add onecore
  • Loading branch information
Wyvest committed Apr 3, 2022
1 parent 78a1fe1 commit 4fc0690
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 350 deletions.
148 changes: 65 additions & 83 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,119 +1,101 @@
plugins {
// Languages
id "java"
id "org.jetbrains.kotlin.jvm" version "1.6.10"

// Minecraft Tools
id "net.minecraftforge.gradle.forge" version "8708bf3e0"
//file:noinspection UnnecessaryQualifiedReference
//file:noinspection GroovyAssignabilityCheck

// Build Tools
id "com.github.johnrengelman.shadow" version "6.1.0"
plugins {
id "dev.architectury.architectury-pack200" version "0.1.3"
id 'org.jetbrains.kotlin.jvm' version '1.6.10'
id "cc.woverflow.loom" version "0.10.1"
id "net.kyori.blossom" version "1.3.0"
id "java"
}

version = mod_version
group = "dev.isxander"
archivesBaseName = mod_name

blossom {
String className = "src/main/kotlin/dev/isxander/behindyou/BehindYou.kt"
replaceToken("@VER@", mod_version, className)
replaceToken("@VER@", project.version, className)
replaceToken("@NAME@", mod_name, className)
replaceToken("@ID@", mod_id, className)
}

group "dev.isxander"
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
compileJava.options.encoding = 'UTF-8'

targetCompatibility = sourceCompatibility = JavaVersion.VERSION_1_8

minecraft {
version = "1.8.9-11.15.1.2318-1.8.9"
mappings = "stable_22"
runDir = "run"
makeObfSourceJar = false
}

repositories {
mavenCentral()
maven { url "https://repo.spongepowered.org/maven" }
maven { url "https://jitpack.io" }
maven { url "https://repo.sk1er.club/repository/maven-public" }
loom {
launchConfigs {
client {
arg("--tweakClass", "cc.woverflow.onecore.tweaker.OneCoreTweaker")
}
}
runConfigs {
client {
ideConfigGenerated = true
}
}
forge {
pack200Provider = new dev.architectury.pack200.java.Pack200Adapter()
}
}

configurations {
include
implementation.extendsFrom include
}

dependencies {
include "gg.essential:loader-launchwrapper:1.1.3"
compileOnly "gg.essential:essential-1.8.9-forge:1788"
}

jar {
manifest.attributes(
'ModSide': 'CLIENT',
'ForceLoadAsMod': true,
'TweakClass': 'gg.essential.loader.stage0.EssentialSetupTweaker',
'TweakOrder': '0'
)
enabled = false
implementation.extendsFrom(include)
}

tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
repositories {
maven { url 'https://repo.woverflow.cc/' }
}

compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
dependencies {
minecraft("com.mojang:minecraft:1.8.9")
mappings("de.oceanlabs.mcp:mcp_stable:22-1.8.9")
forge("net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9")
compileOnly 'gg.essential:essential-1.8.9-forge:1933'
compileOnly 'cc.woverflow:onecore:1.3.3'
include ('cc.woverflow:onecore-tweaker:1.3.0') {
transitive = false
}
}

processResources {
inputs.property 'mod_version', mod_version
inputs.property 'mod_id', mod_id
inputs.property 'mod_name', mod_name
inputs.property 'mod_description', mod_description
// this will ensure that this task is redone when the versions change.
inputs.property "version", version
inputs.property "name", mod_name
inputs.property "id", mod_id

filesMatching("mcmod.info") {
expand (
"mod_version": mod_version,
"mod_id": mod_id,
"mod_name": mod_name,
"mod_description": mod_description
expand(
"id": mod_id,
"name": mod_name,
"version": version
)
}
filesMatching("bundle.project.json") {
expand (
"mod_version": mod_version,
"mod_id": mod_id
)
}
}

task moveResources {
doLast {
ant.move (
file: "${buildDir}/resources/main",
todir: "${buildDir}/classes/kotlin"
)
}
rename '(.+_at.cfg)', 'META-INF/$1'
}

tasks.moveResources.dependsOn processResources
tasks.classes.dependsOn moveResources

shadowJar {
archiveClassifier.set("")

configurations = [project.configurations.include]
duplicatesStrategy DuplicatesStrategy.EXCLUDE
sourceSets {
main {
output.resourcesDir = java.classesDirectory
}
}

reobf {
shadowJar {
mappingType = "SEARGE"
jar {
dependsOn configurations.include
from(configurations.include.collect { it.isDirectory() ? it : zipTree(it) }) {
def i = 0
filesMatching("META-INF/NOTICE*") { name = "$name.${i++}" }
filesMatching("META-INF/LICENSE*") { name = "$name.${i++}" }
filesMatching("META-INF/mods.toml") { name = "$name.${i++}" }
filesMatching("LICENSE*") { name = "$name.${i++}" }
}
}

reobfJar.dependsOn tasks.shadowJar
manifest.attributes(
'ModSide': 'CLIENT',
'ForceLoadAsMod': true,
'TweakClass': 'cc.woverflow.onecore.tweaker.OneCoreTweaker',
"TweakOrder": "0"
)
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ kotlin.code.style=official
mod_version=3.1.0
mod_id=behindyouv3
mod_name=BehindYouV3
mod_description=Lightweight mod to look behind you.

org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureoncommand=true
org.gradle.parallel.threads=4
org.gradle.jvmargs=-Xmx3G
org.gradle.jvmargs=-Xmx3G
loom.platform = forge
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
21 changes: 2 additions & 19 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()

maven { url 'https://maven.minecraftforge.net' }
maven { url 'https://jitpack.io' }
}

resolutionStrategy {
eachPlugin {
switch (requested.id.id) {
case 'net.minecraftforge.gradle.forge':
useModule "com.github.asbyth:ForgeGradle:${requested.version}"
break
case 'org.spongepowered.mixin':
useModule "com.github.xcfrg:MixinGradle:${requested.version}"
break
}
}
maven { url = "https://repo.woverflow.cc" }
}
}

rootProject.name = 'BehindYouV3'

rootProject.name = mod_name
60 changes: 32 additions & 28 deletions src/main/kotlin/dev/isxander/behindyou/BehindYou.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package dev.isxander.behindyou

import dev.isxander.behindyou.commands.BehindYouCommand
import cc.woverflow.onecore.utils.Updater
import cc.woverflow.onecore.utils.command
import cc.woverflow.onecore.utils.openScreen
import dev.isxander.behindyou.config.Config
import dev.isxander.behindyou.updater.Updater
import gg.essential.api.EssentialAPI
import net.minecraft.client.Minecraft
import gg.essential.universal.UMinecraft
import gg.essential.universal.utils.MCMinecraft
import net.minecraft.client.settings.KeyBinding
import net.minecraftforge.client.event.GuiOpenEvent
import net.minecraftforge.common.MinecraftForge
Expand Down Expand Up @@ -32,8 +33,8 @@ object BehindYou {
const val NAME = "@NAME@"
const val VERSION = "@VER@"

var previousPerspective = mc.gameSettings.thirdPersonView
var previousFOV = mc.gameSettings.fovSetting
var previousPerspective = UMinecraft.getSettings().thirdPersonView
var previousFOV = UMinecraft.getSettings().fovSetting

val backKeybind = KeyBinding("BehindYou (Back)", Keyboard.KEY_NONE, "BehindYouV3")
var previousBackKey = false
Expand All @@ -43,13 +44,12 @@ object BehindYou {
var previousFrontKey = false
var frontToggled = false

lateinit var jarFile: File
val modDir = File(File(mc.mcDataDir, "W-OVERFLOW"), "BehindYouV3")

@Mod.EventHandler
private fun onFMLPreInitialization(event: FMLPreInitializationEvent) {
if (!modDir.exists()) modDir.mkdirs()
jarFile = event.sourceFile
Updater.addToUpdater(event.sourceFile, NAME, MODID, VERSION, "W-OVERFLOW/$MODID")
}

@Mod.EventHandler
Expand All @@ -59,12 +59,10 @@ object BehindYou {

MinecraftForge.EVENT_BUS.register(this)

BehindYouCommand.register()
Updater.update()

EssentialAPI.getShutdownHookUtil().register {
mc.gameSettings.fovSetting = previousFOV
mc.gameSettings.saveOptions()
command("behindyou", aliases = arrayListOf("behindyouv3")) {
main {
Config.openScreen()
}
}
}

Expand All @@ -84,6 +82,9 @@ object BehindYou {
if (backToggled) {
resetBack()
} else {
if (frontToggled) {
resetFront()
}
enterBack()
}
} else if (Config.keybindMode == 0) {
Expand All @@ -98,6 +99,9 @@ object BehindYou {
if (frontToggled) {
resetFront()
} else {
if (backToggled) {
resetBack()
}
enterFront()
}
} else if (Config.keybindMode == 0) {
Expand All @@ -122,34 +126,34 @@ object BehindYou {

fun enterBack() {
backToggled = true
previousPerspective = mc.gameSettings.thirdPersonView
previousFOV = mc.gameSettings.fovSetting
mc.gameSettings.thirdPersonView = 2
previousPerspective = UMinecraft.getSettings().thirdPersonView
previousFOV = UMinecraft.getSettings().fovSetting
UMinecraft.getSettings().thirdPersonView = 2
if (Config.changeFOV) {
mc.gameSettings.fovSetting = Config.backFOV.toFloat()
UMinecraft.getSettings().fovSetting = Config.backFOV.toFloat()
}
}

fun enterFront() {
frontToggled = true
previousPerspective = mc.gameSettings.thirdPersonView
previousFOV = mc.gameSettings.fovSetting
mc.gameSettings.thirdPersonView = 1
previousPerspective = UMinecraft.getSettings().thirdPersonView
previousFOV = UMinecraft.getSettings().fovSetting
UMinecraft.getSettings().thirdPersonView = 1
if (Config.changeFOV) {
mc.gameSettings.fovSetting = Config.frontFOV.toFloat()
UMinecraft.getSettings().fovSetting = Config.frontFOV.toFloat()
}
}

fun resetBack() {
backToggled = false
mc.gameSettings.thirdPersonView = previousPerspective
mc.gameSettings.fovSetting = previousFOV
UMinecraft.getSettings().thirdPersonView = previousPerspective
UMinecraft.getSettings().fovSetting = previousFOV
}

fun resetFront() {
frontToggled = false
mc.gameSettings.thirdPersonView = previousPerspective
mc.gameSettings.fovSetting = previousFOV
UMinecraft.getSettings().thirdPersonView = previousPerspective
UMinecraft.getSettings().fovSetting = previousFOV
}

fun resetAll() {
Expand All @@ -163,5 +167,5 @@ object BehindYou {

}

val mc: Minecraft
get() = Minecraft.getMinecraft()
val mc: MCMinecraft
get() = UMinecraft.getMinecraft()

This file was deleted.

Loading

0 comments on commit 4fc0690

Please sign in to comment.