Merge branch 'mc-1.21.3'
This commit is contained in:
@@ -13,6 +13,7 @@ import moe.nea.firmament.util.ErrorUtil
|
||||
import moe.nea.firmament.util.json.KJsonOps
|
||||
|
||||
class ChoiceHandler<E>(
|
||||
val enumClass: Class<E>,
|
||||
val universe: List<E>,
|
||||
) : ManagedConfig.OptionHandler<E> where E : Enum<E>, E : StringIdentifiable {
|
||||
val codec = StringIdentifiable.createCodec {
|
||||
|
||||
@@ -117,13 +117,24 @@ abstract class ManagedConfig(
|
||||
|
||||
protected fun <E> choice(
|
||||
propertyName: String,
|
||||
universe: List<E>,
|
||||
enumClass: Class<E>,
|
||||
default: () -> E
|
||||
): ManagedOption<E> where E : Enum<E>, E : StringIdentifiable {
|
||||
return option(propertyName, default, ChoiceHandler(universe))
|
||||
return option(propertyName, default, ChoiceHandler(enumClass, enumClass.enumConstants.toList()))
|
||||
}
|
||||
|
||||
// TODO: wait on https://youtrack.jetbrains.com/issue/KT-73434
|
||||
protected inline fun <reified E> choice(
|
||||
propertyName: String,
|
||||
noinline default: () -> E
|
||||
): ManagedOption<E> where E : Enum<E>, E : StringIdentifiable {
|
||||
return choice(propertyName, E::class.java, default)
|
||||
}
|
||||
|
||||
private fun <E> createStringIdentifiable(x: () -> Array<out E>): Codec<E> where E : Enum<E>, E : StringIdentifiable {
|
||||
return StringIdentifiable.createCodec { x() }
|
||||
}
|
||||
|
||||
// TODO: wait on https://youtrack.jetbrains.com/issue/KT-73434
|
||||
// protected inline fun <reified E> choice(
|
||||
// propertyName: String,
|
||||
// noinline default: () -> E
|
||||
@@ -136,6 +147,8 @@ abstract class ManagedConfig(
|
||||
// default
|
||||
// )
|
||||
// }
|
||||
open fun onChange(option: ManagedOption<*>) {
|
||||
}
|
||||
|
||||
protected fun duration(
|
||||
propertyName: String,
|
||||
|
||||
@@ -6,7 +6,6 @@ import kotlinx.serialization.json.JsonObject
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
import kotlin.reflect.KProperty
|
||||
import net.minecraft.text.Text
|
||||
import moe.nea.firmament.Firmament
|
||||
import moe.nea.firmament.util.ErrorUtil
|
||||
|
||||
class ManagedOption<T : Any>(
|
||||
@@ -28,7 +27,13 @@ class ManagedOption<T : Any>(
|
||||
val descriptionTranslationKey = "firmament.config.${element.name}.${propertyName}.description"
|
||||
val labelDescription: Text = Text.translatable(descriptionTranslationKey)
|
||||
|
||||
lateinit var value: T
|
||||
private var actualValue: T? = null
|
||||
var value: T
|
||||
get() = actualValue ?: error("Lateinit variable not initialized")
|
||||
set(value) {
|
||||
actualValue = value
|
||||
element.onChange(this)
|
||||
}
|
||||
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
|
||||
this.value = value
|
||||
|
||||
@@ -111,8 +111,9 @@ object EntityRenderer {
|
||||
renderContext: DrawContext,
|
||||
posX: Int,
|
||||
posY: Int,
|
||||
mouseX: Float,
|
||||
mouseY: Float
|
||||
// TODO: Add width, height properties here
|
||||
mouseX: Double,
|
||||
mouseY: Double
|
||||
) {
|
||||
var bottomOffset = 0.0F
|
||||
var currentEntity = entity
|
||||
@@ -148,15 +149,15 @@ object EntityRenderer {
|
||||
y2: Int,
|
||||
size: Float,
|
||||
bottomOffset: Float,
|
||||
mouseX: Float,
|
||||
mouseY: Float,
|
||||
mouseX: Double,
|
||||
mouseY: Double,
|
||||
entity: LivingEntity
|
||||
) {
|
||||
context.enableScissorWithTranslation(x1.toFloat(), y1.toFloat(), x2.toFloat(), y2.toFloat())
|
||||
val centerX = (x1 + x2) / 2f
|
||||
val centerY = (y1 + y2) / 2f
|
||||
val targetYaw = atan(((centerX - mouseX) / 40.0f).toDouble()).toFloat()
|
||||
val targetPitch = atan(((centerY - mouseY) / 40.0f).toDouble()).toFloat()
|
||||
val targetYaw = atan(((centerX - mouseX) / 40.0f)).toFloat()
|
||||
val targetPitch = atan(((centerY - mouseY) / 40.0f)).toFloat()
|
||||
val rotateToFaceTheFront = Quaternionf().rotateZ(Math.PI.toFloat())
|
||||
val rotateToFaceTheCamera = Quaternionf().rotateX(targetPitch * 20.0f * (Math.PI.toFloat() / 180))
|
||||
rotateToFaceTheFront.mul(rotateToFaceTheCamera)
|
||||
|
||||
Reference in New Issue
Block a user