diff --git a/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt b/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt index a02f5e4..3274cf0 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt @@ -2,9 +2,11 @@ package fr.username404.snowygui import fr.username404.snowygui.config.Configuration import fr.username404.snowygui.gui.feature.ButtonImpl +import fr.username404.snowygui.gui.feature.ButtonImpl.Companion.initButtons import fr.username404.snowygui.gui.feature.ButtonInfo import fr.username404.snowygui.misc.AddKeyMaps -import net.minecraft.network.chat.TranslatableComponent +import net.minecraft.network.chat.Component +import net.minecraft.network.chat.Component.translatable import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger import java.lang.reflect.Modifier @@ -16,7 +18,7 @@ abstract class Snowy { abstract val annotatedButtons: Set> companion object { @Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") - object MissingComponent: TranslatableComponent(null) { override fun getString(): String = "MISSING_COMPONENT" } + val MissingComponent: Component = translatable("MISSING_COMPONENT") @Suppress("JVM_STATIC_ON_CONST_OR_JVM_FIELD") // See KT-39868 @JvmStatic protected const val FeaturePackage: String = "fr.username404.snowygui.gui.feature" diff --git a/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt b/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt index aa655de..e33fbac 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt @@ -13,16 +13,16 @@ import fr.username404.snowygui.gui.feature.Keystrokes import fr.username404.snowygui.gui.feature.Zoom import net.minecraft.client.gui.screens.Screen import net.minecraft.network.chat.Component -import net.minecraft.network.chat.TranslatableComponent +import net.minecraft.network.chat.Component.translatable import java.util.Optional private const val confPrefix: String = "screen.snowy.config" -private val translationComponent = TranslatableComponent(confPrefix) +private val translationComponent = translatable(confPrefix) var configScreenParent: Screen? = null private fun supplyComponent(string: String?): Optional = string?.run { - Optional.of(TranslatableComponent(string)) + Optional.of(translatable(string)) } ?: Optional.empty() val SnowyConfigScreen: Screen = object: Screen(translationComponent) { @@ -47,20 +47,20 @@ val SnowyConfigScreen: Screen = object: Screen(translationComponent) { .setShouldListSmoothScroll(true) .setTitle(translationComponent).apply { with(entryBuilder()) { - getOrCreateCategory(TranslatableComponent("$confPrefix.general")).addEntry(startSubCategory(TranslatableComponent("$confPrefix.behavior")).apply { + getOrCreateCategory(translatable("$confPrefix.general")).addEntry(startSubCategory(translatable("$confPrefix.behavior")).apply { addAll( setOf( - startBooleanToggle(TranslatableComponent("$confPrefix.behavior.sortalphabetically"), sortAlphabetically) + startBooleanToggle(translatable("$confPrefix.behavior.sortalphabetically"), sortAlphabetically) .setDefaultValue(true).requireRestart() .setSaveConsumer { sortAlphabetically = it }.build(), - startDoubleField(TranslatableComponent("$confPrefix.behavior.zoom.factor"), Zoom.zoomFactor).setSaveConsumer { + startDoubleField(translatable("$confPrefix.behavior.zoom.factor"), Zoom.zoomFactor).setSaveConsumer { Zoom.zoomFactor = it }.setMin(1.1).build(), - startBooleanToggle(TranslatableComponent("$confPrefix.behavior.zoom.smoothcamera"), Zoom.smoothCameraOnZoom).setSaveConsumer { + startBooleanToggle(translatable("$confPrefix.behavior.zoom.smoothcamera"), Zoom.smoothCameraOnZoom).setSaveConsumer { Zoom.smoothCameraOnZoom = it Zoom.execAction() }.build(), - startEnumSelector(TranslatableComponent("$confPrefix.behavior.keystrokes.position"), Keystrokes.Position::class.java, Keystrokes.Position.values().find { + startEnumSelector(translatable("$confPrefix.behavior.keystrokes.position"), Keystrokes.Position::class.java, Keystrokes.Position.values().find { it.value == Keystrokes.currentPosition }).setSaveConsumer { Keystrokes.currentPosition = it.value @@ -68,7 +68,7 @@ val SnowyConfigScreen: Screen = object: Screen(translationComponent) { ) ) }.build()) - .addEntry(startSubCategory(TranslatableComponent("$confPrefix.colors")).also { builder -> + .addEntry(startSubCategory(translatable("$confPrefix.colors")).also { builder -> builder.addAll( ClickGui.clickBoxes.map { box -> startColorField(box.name, box.color).setSaveConsumer { @@ -77,7 +77,7 @@ val SnowyConfigScreen: Screen = object: Screen(translationComponent) { } ) }.build()).addEntry(startStrList( - TranslatableComponent(Category.MACROS.translationKey), + Category.MACROS.box.name, macrosButtons.getTitleCommand() ).setInsertInFront(false).setDefaultValue(Configuration.foundMacros.getTitleCommand()).setErrorSupplier { list -> supplyComponent(if (list.size > buttonsMax) "$confPrefix.general.macros.toomuchbuttons" else null) @@ -93,7 +93,7 @@ val SnowyConfigScreen: Screen = object: Screen(translationComponent) { } ) } - }.setTooltip(TranslatableComponent("$confPrefix.general.macros.tooltip")).setSaveConsumer { it.forEach { string -> + }.setTooltip(translatable("$confPrefix.general.macros.tooltip")).setSaveConsumer { it.forEach { string -> with(string.split(":")) { if (size == 2) Macro(title = component1().trimStart(), command = component2().trim()).let { newMacro -> macrosButtons.removeIf { existingMacro -> diff --git a/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt b/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt index 9ae3043..9db4022 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt @@ -29,6 +29,8 @@ import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.decodeFromString import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json +import net.minecraft.network.chat.MutableComponent +import net.minecraft.network.chat.contents.TranslatableContents import org.jetbrains.annotations.ApiStatus import kotlin.reflect.KClass import kotlin.reflect.full.isSuperclassOf @@ -46,9 +48,9 @@ object Configuration { } }, "box_colors" to mapOf(*ClickGui.clickBoxes.filter { box -> - (box.name.key != MissingComponent.key) && Category.fromBox(box)?.categoryColor != box.color + ((box.name.contents as TranslatableContents).key != (MissingComponent.contents as TranslatableContents).key) && Category.fromBox(box)?.categoryColor != box.color }.map { - it.name.key to it.color + (it.name as TranslatableContents).key to it.color }.toTypedArray()), ) } diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/SnowyScreen.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/SnowyScreen.kt index 2a62695..ceccd48 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/SnowyScreen.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/SnowyScreen.kt @@ -2,9 +2,9 @@ package fr.username404.snowygui.gui import com.mojang.blaze3d.vertex.PoseStack import net.minecraft.client.gui.screens.Screen -import net.minecraft.network.chat.TranslatableComponent +import net.minecraft.network.chat.Component.translatable -abstract class SnowyScreen(translatableString: String = "screen.snowy.gui", private val willPauseScreen: Boolean = false): Screen(TranslatableComponent(translatableString)) { +abstract class SnowyScreen(translatableString: String = "screen.snowy.gui", private val willPauseScreen: Boolean = false): Screen(translatable(translatableString)) { abstract val components: MutableCollection override fun render(poseStack: PoseStack?, i: Int, j: Int, f: Float) { if (poseStack != null) { diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt index a0cdb8e..aaa8704 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt @@ -19,7 +19,7 @@ import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import net.minecraft.client.Minecraft -import net.minecraft.network.chat.TranslatableComponent +import net.minecraft.network.chat.Component import org.jetbrains.annotations.ApiStatus import java.util.TreeSet import kotlin.collections.LinkedHashSet @@ -28,9 +28,9 @@ import kotlin.collections.LinkedHashSet class ClickBox( x: Double, y: Double, override var color: Int = Colors.BLUE.hexValue, - val name: TranslatableComponent = MissingComponent + val name: Component = MissingComponent ): ColoredElement(x, y, 80, 10, color, 0.5F) { - fun isCategory(c: Category): Boolean = (name.key == c.translationKey) + fun isCategory(c: Category): Boolean = (name.string == c.box.name.string) val buttons: MutableSet = if (sortAlphabetically) TreeSet(compareBy(String.CASE_INSENSITIVE_ORDER) { it.title }) @@ -126,7 +126,7 @@ class ClickBox( } } init { - savedColors?.get(name.key)?.let { + savedColors?.get(name.string)?.let { this.color = it } } diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonInfo.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonInfo.kt index 2e89b7f..f32027b 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonInfo.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonInfo.kt @@ -2,7 +2,8 @@ package fr.username404.snowygui.gui.feature import fr.username404.snowygui.ClickGui import fr.username404.snowygui.gui.elements.ClickBox -import net.minecraft.network.chat.TranslatableComponent +import net.minecraft.network.chat.Component.translatable +import net.minecraft.network.chat.contents.TranslatableContents /** * Should be used on classes/objects extending [ButtonImpl] @@ -22,7 +23,7 @@ annotation class ButtonInfo( TOGGLE, CLICK } - enum class Category(val translationKey: String, val categoryColor: Int, val shouldHide: Boolean = false) { + enum class Category(translationKey: String, val categoryColor: Int, val shouldHide: Boolean = false) { MISC("snowy.clickbox.misc", Colors.BLUE), HUD("snowy.clickbox.hud", Colors.DARK_PURPLE), MACROS("snowy.clickbox.macros", Colors.GREEN); @@ -35,14 +36,14 @@ annotation class ButtonInfo( x = 4.0 + (ordinal - ClickGui.clickBoxes.count { category -> category.hidden }) * 86, y = 4.0, - name = TranslatableComponent(translationKey), + name = translatable(translationKey), color = categoryColor ); private set private fun addBox() = ClickGui.components.add(box.apply { if (shouldHide) hidden = true }) constructor( translationKey: String, categoryColor: Colors, condition: Boolean = false ): this(translationKey, categoryColor.hexValue, condition) - constructor(categoryBox: ClickBox): this(translationKey = categoryBox.name.key, categoryColor = categoryBox.color) { + constructor(categoryBox: ClickBox): this(translationKey = (categoryBox.name.contents as TranslatableContents).key, categoryColor = categoryBox.color) { with(ClickGui.components) { remove(this@Category.box) this@Category.box = categoryBox diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/GammaBoost.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/GammaBoost.kt index 03a34d3..1bdf51b 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/GammaBoost.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/GammaBoost.kt @@ -8,10 +8,13 @@ object GammaBoost: ButtonImpl() { private var oldGamma = 0.0 override fun execAction() { with(Minecraft.getInstance().options) { - gamma = if (toggled) { - if (gamma < boost) oldGamma = gamma - boost - } else oldGamma + val gamma = gamma().get(); + gamma().set( + if (toggled) { + if (gamma < boost) oldGamma = gamma + boost + } else oldGamma + ) } } } \ No newline at end of file