Skip to content

Commit

Permalink
rewrite part 2 - complete :)
Browse files Browse the repository at this point in the history
  • Loading branch information
nextdayy committed Jan 13, 2025
1 parent 5c27e19 commit 3b6d43e
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 49 deletions.
9 changes: 8 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@file:Suppress("UnstableApiUsage", "PropertyName")

import dev.deftu.gradle.utils.GameSide
import dev.deftu.gradle.utils.MinecraftVersion

plugins {
java
Expand Down Expand Up @@ -56,3 +55,11 @@ dependencies {
}
}
}

sourceSets {
val dummy by creating
main {
compileClasspath += dummy.output
output.setResourcesDir(java.classesDirectory)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ private int checkAndKeepF3(GameSettings instance) {
return BehindYou.INSTANCE.isFinished() ? instance.thirdPersonView : 1;
}

@ModifyVariable(method = "orientCamera", at = @At(value = "STORE"), ordinal = 3)
@ModifyVariable(method = "orientCamera", at = @At(value = "STORE", ordinal = 0), ordinal = 3)
private double set(double z, float partialTicks) {
return BehindYou.INSTANCE.getLevel(z, partialTicks);
}
Expand Down
85 changes: 53 additions & 32 deletions src/main/kotlin/org/polyfrost/behindyou/BehindYou.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,81 @@ package org.polyfrost.behindyou

import net.minecraft.client.Minecraft
import net.minecraftforge.fml.common.Mod
import net.minecraftforge.fml.common.event.FMLInitializationEvent
import org.polyfrost.behindyou.config.BehindYouConfig
import org.polyfrost.oneconfig.api.platform.v1.Platform
import org.polyfrost.polyui.animate.Animation
import org.polyfrost.polyui.animate.Animations
import org.polyfrost.polyui.unit.seconds
import org.polyfrost.universal.UMinecraft

@Mod(
modid = BehindYou.MODID,
name = BehindYou.NAME,
version = BehindYou.VERSION,
modid = "@ID@",
name = "@NAME@",
version = "@VER@",
clientSideOnly = true,
modLanguageAdapter = "org.polyfrost.oneconfig.utils.v1.forge.KotlinLanguageAdapter"
)
object BehindYou {
const val MODID = "@ID@"
const val NAME = "@NAME@"
const val VERSION = "@VER@"
const val NORMAL = 0
const val BACK = 1
const val FRONT = 2

private var zAnimation: Animation = Animations.EaseOutQuart.create(0.5.seconds, 4f, 4f)
private var fovAnimation: Animation = Animations.EaseOutQuart.create(0.5.seconds, 90f, 90f)
val isFinished get() = zAnimation.isFinished
private val isPatcher = Platform.loader().isModLoaded("patcher")

var fov: Float
get() = Minecraft.getMinecraft().gameSettings.fovSetting
set(value) {
val mc = Minecraft.getMinecraft()
//mc.renderGlobal.setDisplayListEntitiesDirty()
mc.gameSettings.fovSetting = value
Minecraft.getMinecraft().gameSettings.fovSetting = value
}
private var initialFov = fov

/**
* 0: normal
* 1: front
* 2: back
* 1: back
* 2: front
*/
var perspective: Int
get() = Minecraft.getMinecraft().gameSettings.thirdPersonView
set(value) {
previousPerspective = perspective
val mc = Minecraft.getMinecraft()
//mc.renderGlobal.setDisplayListEntitiesDirty()
setTargetLevel(if (value == 0) 0.1f else 2f)
val z: Float
val fov: Float
val config = BehindYouConfig
when (value) {
BACK -> {
if (perspective == NORMAL) initialFov = this.fov
z = config.backDistance
fov = config.backFOV
}

FRONT -> {
if (perspective == NORMAL) initialFov = this.fov
z = config.frontDistance
fov = config.frontFOV
}

else -> {
z = if (isPatcher && club.sk1er.patcher.config.PatcherConfig.parallaxFix) -0.05f else 0.1f
fov = initialFov
}
}

setTargetLevel(z, fov)
mc.renderGlobal.setDisplayListEntitiesDirty()
val prev = perspective
if (prev != value) previousPerspective = prev
mc.gameSettings.thirdPersonView = value
}
var previousPerspective = perspective
private set
private var previousPerspective = NORMAL

private var zAnimation: Animation = Animations.EaseOutQuart.create(BehindYouConfig.animSpeed.seconds, 0f, 0f)
private var fovAnimation: Animation = Animations.EaseOutQuart.create(BehindYouConfig.animSpeed.seconds, initialFov, initialFov)
val isFinished get() = zAnimation.isFinished


fun getLevel(zIn: Double, partialTicks: Float): Double {
if (!BehindYouConfig.enabled) return zIn
val deltaTime = partialTicks.toNanoseconds()
fov = fovAnimation.update(deltaTime)
if (BehindYouConfig.changeFOV) fov = fovAnimation.update(deltaTime)
return zAnimation.update(deltaTime).toDouble()
}

Expand All @@ -63,22 +85,21 @@ object BehindYou {
fovAnimation = curve.create(duration, fovAnimation.value, fovAnimation.to)
}

fun setTargetLevel(z: Float) {
private fun setTargetLevel(z: Float, fov: Float) {
val animations = BehindYouConfig.useAnims
zAnimation.to = z
zAnimation.from = zAnimation.value
zAnimation.from = if (animations) zAnimation.value else z
zAnimation.reset()
if (!BehindYouConfig.changeFOV) return
fovAnimation.to = fov
fovAnimation.from = if (animations) fovAnimation.value else fov
fovAnimation.reset()
}

fun toPrevious() {
fun previous() {
perspective = previousPerspective

}

// partial ticks are a fraction (0..1) of a tick, which is 50ms.
fun Float.toNanoseconds() = (this * 50_000_000f).toLong()

@Mod.EventHandler
fun onInit(event: FMLInitializationEvent) {

}
private fun Float.toNanoseconds() = (this * 50_000_000f).toLong()
}
64 changes: 49 additions & 15 deletions src/main/kotlin/org/polyfrost/behindyou/config/BehindYouConfig.kt
Original file line number Diff line number Diff line change
@@ -1,75 +1,109 @@
package org.polyfrost.behindyou.config

import org.polyfrost.behindyou.BehindYou
import org.polyfrost.oneconfig.api.config.v1.Config
import org.polyfrost.oneconfig.api.config.v1.annotations.*
import org.polyfrost.oneconfig.api.ui.v1.keybind.KeybindManager
import org.polyfrost.polyui.animate.Animations
import org.polyfrost.polyui.input.KeybindHelper
import org.polyfrost.universal.UKeyboard
import org.polyfrost.polyui.unit.seconds

object BehindYouConfig : Config("behindyouv3.json", "/behindyou_dark.svg", "BehindYouV3", Category.QOL) {

private var frontActive = false

@Keybind(
title = "Frontview Keybind"
)
var frontKeybind = KeybindHelper.builder().keys(UKeyboard.KEY_Y).does { }.build()
var frontKeybind = KeybindHelper.builder().chars('y').does {
if (frontKeybindMode == 0) frontActive = it
else { // toggle
// only listen to key down
if (it) frontActive = !frontActive
}
if (frontActive) BehindYou.perspective = BehindYou.FRONT
else BehindYou.previous()
}.build()

@RadioButton(
title = "Frontview Keybind Handle Mode",
options = ["Hold", "Toggle"]
)
var frontKeybindMode = 0

private var backActive = false

@Keybind(
title = "Backview Keybind"
)
var backKeybind = KeybindHelper.builder().keys(UKeyboard.KEY_U).does { }.build()
var backKeybind = KeybindHelper.builder().chars('u').does {
if (backKeybindMode == 0) backActive = it
else { // toggle
// only listen to key down
if (it) backActive = !backActive
}
if (backActive) BehindYou.perspective = BehindYou.BACK
else BehindYou.previous()
}.build()

@RadioButton(
title = "Backview Keybind Handle Mode",
options = ["Hold", "Toggle"]
)
var backKeybindMode = 0

@RadioButton(
title = "Back To",
options = ["Previous", "First"]
)
var backToFirst = 1

@Checkbox(
title = "Camera Animations"
)
var animation = false
var useAnims = true

@Slider(
title = "Animation Time (s)",
min = 0.1f, max = 2f
)
var speed = 1f
var animSpeed = 1f

@Switch(
title = "Modify FOV",
)
var changeFOV = false
var changeFOV = true

@Slider(
title = "Backview FOV",
min = 30F,
max = 110F
)
var backFOV = 100
var backFOV = 100f

@Slider(
title = "Backview Distance",
min = 1f,
max = 4f
)
var backDistance = 4f

@Slider(
title = "Frontview FOV",
min = 30F,
max = 110F
)
var frontFOV = 100
var frontFOV = 100f

@Slider(
title = "Frontview Distance",
min = 1f,
max = 4f
)
var frontDistance = 4f

init {
addDependency("speed", "animation")
addDependency("animSpeed", "useAnims")
addDependency("backFOV", "changeFOV")
addDependency("frontFOV", "changeFOV")
addCallback("animSpeed") { value: Float ->
BehindYou.modifyAnimations(value.seconds, Animations.EaseOutQuart)
false
}

KeybindManager.registerKeybind(frontKeybind)
KeybindManager.registerKeybind(backKeybind)
Expand Down

0 comments on commit 3b6d43e

Please sign in to comment.