diff --git a/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt b/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt index 49a5463..00c3525 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt @@ -18,7 +18,7 @@ abstract class Snowy { @JvmStatic protected val FeaturePackage: String = "fr.username404.snowygui.gui.feature" lateinit var annotatedButtons: Set> - fun onEvent(e: String, lambda: argsLambda) = useKey(e).add(lambda) + fun onEvent(e: Any, lambda: argsLambda) = useKey(e.toString()).add(lambda) @JvmField val logs: Logger = LogManager.getLogger() } 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 06bf72a..6906a0c 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt @@ -10,6 +10,7 @@ import fr.username404.snowygui.gui.feature.Category import fr.username404.snowygui.gui.feature.Colors import fr.username404.snowygui.gui.feature.Macro import fr.username404.snowygui.gui.feature.riskyCheats +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.TextComponent @@ -48,9 +49,18 @@ val SnowyConfigScreen: Screen = object: Screen(translationComponent) { .setTitle(translationComponent).apply { with(entryBuilder()) { getOrCreateCategory(TranslatableComponent("$confPrefix.general")).addEntry(startSubCategory(TranslatableComponent("$confPrefix.behavior")).apply { - add(startBooleanToggle(TranslatableComponent("$confPrefix.behavior.sortalphabetically"), sortAlphabetically) - .setDefaultValue(true).requireRestart() - .setSaveConsumer { sortAlphabetically = it }.build() + addAll( + setOf( + startBooleanToggle(TranslatableComponent("$confPrefix.behavior.sortalphabetically"), sortAlphabetically) + .setDefaultValue(true).requireRestart() + .setSaveConsumer { sortAlphabetically = it }.build(), + startDoubleField(TranslatableComponent("$confPrefix.behavior.zoom.factor"), Zoom.zoomFactor).setSaveConsumer { + Zoom.zoomFactor = it + }.setMin(1.1).build(), + startBooleanToggle(TranslatableComponent("$confPrefix.behavior.zoom.smoothcamera"), Zoom.smoothCameraOnZoom).setSaveConsumer { + Zoom.smoothCameraOnZoom = it + }.build() + ) ) }.build()) .addEntry( 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 789eabf..c6ff098 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt @@ -27,6 +27,7 @@ import kotlinx.coroutines.runBlocking import kotlinx.serialization.decodeFromString import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json +import kotlin.reflect.full.isSuperclassOf object Configuration { @Deprecated("Use the getValue or setValue methods instead", level = DeprecationLevel.ERROR) @@ -65,9 +66,7 @@ object Configuration { parseString( """ |Snowy { - | displayInitMessage = false | macros = [] - | riskyCheats = false | sortAlphabetically = true |} """.trimMargin() @@ -136,7 +135,20 @@ object Configuration { @Suppress("DEPRECATION_ERROR") if (ModifiableValues.containsKey(property.name)) ModifiableValues[property.name] as T - else invoke().getValue(ref, property) + else try { + invoke().getValue(ref, property) + } catch (e: ConfigException) { + when { + Number::class.isSuperclassOf(T::class) -> when (T::class) { + Double::class -> 2.0 + Int::class, UInt::class, Short::class, UShort::class -> 2 + Float::class -> 2F + else -> throw e + } as T + T::class == Boolean::class -> false as T + else -> throw e + } + } operator fun setValue(ref: Any?, property: KProperty<*>, value: T) = @Suppress("DEPRECATION_ERROR") ModifiableValues.setValue(ref, property, value) diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Zoom.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Zoom.kt new file mode 100644 index 0000000..73a0592 --- /dev/null +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/Zoom.kt @@ -0,0 +1,15 @@ +package fr.username404.snowygui.gui.feature + +import fr.username404.snowygui.config.Configuration +import net.minecraft.client.Minecraft + +@ButtonInfo(Category.MISC) +object Zoom: ButtonImpl() { + internal var smoothCameraOnZoom: Boolean by Configuration + internal var zoomFactor: Double by Configuration + @JvmStatic + fun getNewZoom(fov: Double): Double = fov / zoomFactor + override fun execAction() { + Minecraft.getInstance().options.smoothCamera = toggled && smoothCameraOnZoom + } +} \ No newline at end of file diff --git a/common/src/main/resources/assets/snowygui/lang/en_us.json b/common/src/main/resources/assets/snowygui/lang/en_us.json index 8e37ed7..7f17058 100644 --- a/common/src/main/resources/assets/snowygui/lang/en_us.json +++ b/common/src/main/resources/assets/snowygui/lang/en_us.json @@ -12,6 +12,8 @@ "screen.snowy.config.colors": "Box colors", "screen.snowy.config.behavior": "Behavior", "screen.snowy.config.behavior.sortalphabetically": "Sort buttons alphabetically", + "screen.snowy.config.behavior.zoom.factor": "Zoom factor", + "screen.snowy.config.behavior.zoom.smoothcamera": "Smooth camera on zoom", "category.snowy.keycategory": "SnowyGUI", "key.snowy.opengui": "Open the snowy gui", "key.snowy.configkey": "Open the snowy configuration screen", diff --git a/common/src/main/resources/assets/snowygui/lang/fr_fr.json b/common/src/main/resources/assets/snowygui/lang/fr_fr.json index f0f4f47..40ddb4b 100644 --- a/common/src/main/resources/assets/snowygui/lang/fr_fr.json +++ b/common/src/main/resources/assets/snowygui/lang/fr_fr.json @@ -11,6 +11,8 @@ "screen.snowy.config.colors": "Couleurs des boîtes", "screen.snowy.config.behavior": "Comportement", "screen.snowy.config.behavior.sortalphabetically": "Trier les boutons alphabétiquement", + "screen.snowy.config.behavior.zoom.factor": "Facteur de zoom", + "screen.snowy.config.behavior.zoom.smoothcamera": "Caméra fluide pendant le zoom", "category.snowy.keycategory": "SnowyGUI", "key.snowy.opengui": "Ouvrir l'interface de snowy", "key.snowy.configkey": "Ouvrir l'écran de configuration de snowy", diff --git a/fabric/src/main/java/fr/username404/snowygui/mixins/ZoomMixin.java b/fabric/src/main/java/fr/username404/snowygui/mixins/ZoomMixin.java new file mode 100644 index 0000000..1d54b01 --- /dev/null +++ b/fabric/src/main/java/fr/username404/snowygui/mixins/ZoomMixin.java @@ -0,0 +1,20 @@ +package fr.username404.snowygui.mixins; + +import fr.username404.snowygui.gui.feature.Zoom; +import net.minecraft.client.Options; +import net.minecraft.client.renderer.GameRenderer; +import org.objectweb.asm.Opcodes; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(GameRenderer.class) +abstract class ZoomMixin { + @Redirect( + at = @At(value = "FIELD", target = "Lnet/minecraft/client/Options;fov:D", opcode = Opcodes.GETFIELD, ordinal = 0), + method = "getFov(Lnet/minecraft/client/Camera;FZ)D" + ) + private double getFov(Options options) { + return Zoom.INSTANCE.getToggled() ? Zoom.getNewZoom(options.fov) : options.fov; + } +} diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index b047895..f332e62 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -29,7 +29,8 @@ ] }, "mixins": [ - "snowygui-mixins.json" + "snowygui-mixins.json", + "snowygui-mixins-fabric.json" ], "depends": { "fabricloader": ">=0.11.0", diff --git a/fabric/src/main/resources/snowygui-mixins-fabric.json b/fabric/src/main/resources/snowygui-mixins-fabric.json new file mode 100644 index 0000000..dabb1c8 --- /dev/null +++ b/fabric/src/main/resources/snowygui-mixins-fabric.json @@ -0,0 +1,12 @@ +{ + "required": true, + "package": "fr.username404.snowygui.mixins", + "compatibilityLevel": "JAVA_8", + "client": [ + "ZoomMixin" + ], + "injectors": { + "defaultRequire": 1 + }, + "minVersion": "0.8" +} \ No newline at end of file diff --git a/forge/src/main/kotlin/fr/username404/snowygui/forge/ForgeInit.kt b/forge/src/main/kotlin/fr/username404/snowygui/forge/ForgeInit.kt index ac3e2ec..c24ea44 100644 --- a/forge/src/main/kotlin/fr/username404/snowygui/forge/ForgeInit.kt +++ b/forge/src/main/kotlin/fr/username404/snowygui/forge/ForgeInit.kt @@ -49,6 +49,9 @@ class ForgeInit: Snowy() { addListener(this@ForgeInit::initSetup) addListener(this@ForgeInit::configSetup) } - FORGE_BUS.register(HudHandler) + with(FORGE_BUS) { + register(HudHandler) + register(ZoomHandler) + } } } \ No newline at end of file diff --git a/forge/src/main/kotlin/fr/username404/snowygui/forge/HudHandler.kt b/forge/src/main/kotlin/fr/username404/snowygui/forge/HudHandler.kt index 4d06496..2411044 100644 --- a/forge/src/main/kotlin/fr/username404/snowygui/forge/HudHandler.kt +++ b/forge/src/main/kotlin/fr/username404/snowygui/forge/HudHandler.kt @@ -1,4 +1,3 @@ -@file:Suppress("UNUSED") package fr.username404.snowygui.forge import fr.username404.snowygui.EventSnowy diff --git a/forge/src/main/kotlin/fr/username404/snowygui/forge/ZoomHandler.kt b/forge/src/main/kotlin/fr/username404/snowygui/forge/ZoomHandler.kt new file mode 100644 index 0000000..4037576 --- /dev/null +++ b/forge/src/main/kotlin/fr/username404/snowygui/forge/ZoomHandler.kt @@ -0,0 +1,12 @@ +package fr.username404.snowygui.forge + +import fr.username404.snowygui.gui.feature.Zoom +import net.minecraftforge.client.event.EntityViewRenderEvent +import net.minecraftforge.eventbus.api.SubscribeEvent + +object ZoomHandler { + @SubscribeEvent + fun onFOVEvent(event: EntityViewRenderEvent.FOVModifier) { + if (Zoom.toggled) event.fov = Zoom.getNewZoom(event.fov) + } +} \ No newline at end of file