diff --git a/common/src/main/java/fr/username404/snowygui/mixins/EndTickMixin.java b/common/src/main/java/fr/username404/snowygui/mixins/EndTickMixin.java new file mode 100644 index 0000000..eb83978 --- /dev/null +++ b/common/src/main/java/fr/username404/snowygui/mixins/EndTickMixin.java @@ -0,0 +1,20 @@ +package fr.username404.snowygui.mixins; + +import fr.username404.snowygui.EventSnowy; +import net.minecraft.client.Minecraft; +import org.jetbrains.annotations.NotNull; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Minecraft.class) +public class EndTickMixin implements EventSnowy { + @NotNull + @Override + public String getType() { + return "EndTick"; + } + @Inject(method = "tick", at = @At("RETURN")) + public void endTick(CallbackInfo ci) { fire(); } +} diff --git a/common/src/main/java/fr/username404/snowygui/mixins/KeyMappings.java b/common/src/main/java/fr/username404/snowygui/mixins/KeyMappings.java index f262abb..0829381 100644 --- a/common/src/main/java/fr/username404/snowygui/mixins/KeyMappings.java +++ b/common/src/main/java/fr/username404/snowygui/mixins/KeyMappings.java @@ -1,6 +1,7 @@ package fr.username404.snowygui.mixins; import com.google.common.collect.Lists; +import fr.username404.snowygui.config.AddKeyMaps; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.Options; @@ -8,13 +9,15 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.Shadow; -import fr.username404.snowygui.config.AddKeyMaps; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.io.File; -import java.util.*; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Optional; @Mixin(Options.class) class KeyMappings { @@ -28,7 +31,8 @@ class KeyMappings { List newKeys = Lists.newArrayList(keyMappings); for (KeyMapping key : keysToAdd) { if (!categoryMap.containsKey(key.getCategory())) { - Optional biggest = categoryMap.values().stream().max(Integer::compareTo); int biggestInt = biggest.orElse(0); + Optional biggest = categoryMap.values().stream().max(Integer::compareTo); + int biggestInt = biggest.orElse(0); categoryMap.put(key.getCategory(), biggestInt + 1); } newKeys.remove(key); diff --git a/common/src/main/kotlin/fr/username404/snowygui/EventSnowy.kt b/common/src/main/kotlin/fr/username404/snowygui/EventSnowy.kt new file mode 100644 index 0000000..30f3b46 --- /dev/null +++ b/common/src/main/kotlin/fr/username404/snowygui/EventSnowy.kt @@ -0,0 +1,16 @@ +package fr.username404.snowygui + +interface EventSnowy { + val type: String + fun fire(vararg args: T?) { + useKey(type).forEach { + it(args) + } + } + companion object { + fun useKey(key: String): MutableSet { return eventMap.getOrPut(key, ::mutableSetOf) } + private val eventMap: MutableMap> = mutableMapOf() + } +} + +internal typealias argsLambda = (args: Array<*>) -> Unit \ No newline at end of file diff --git a/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt b/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt index f2c47e9..242fb68 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt @@ -1,14 +1,29 @@ package fr.username404.snowygui +import fr.username404.snowygui.EventSnowy.Companion.useKey +import fr.username404.snowygui.config.AddKeyMaps import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger abstract class Snowy { companion object { + fun onEvent(e: String, lambda: argsLambda) { + useKey(e).add(lambda) + } @JvmStatic val logs: Logger = LogManager.getLogger() } + private fun eventsInit() { + onEvent("EndTick") { + for (Key in AddKeyMaps.list.keys) { + if (Key.isDown) { + AddKeyMaps.list[Key]?.invoke() + } + } + } + } fun atInit() { logs.info("Init point of SnowyGUI hit.") + eventsInit() } } \ No newline at end of file diff --git a/common/src/main/kotlin/fr/username404/snowygui/SnowyScreen.kt b/common/src/main/kotlin/fr/username404/snowygui/SnowyScreen.kt new file mode 100644 index 0000000..79d37fc --- /dev/null +++ b/common/src/main/kotlin/fr/username404/snowygui/SnowyScreen.kt @@ -0,0 +1,8 @@ +package fr.username404.snowygui + +import net.minecraft.client.gui.screens.Screen +import net.minecraft.network.chat.TranslatableComponent + +internal class SnowyScreen: Screen(TranslatableComponent("screen.snowy.gui")) { + +} \ No newline at end of file diff --git a/common/src/main/kotlin/fr/username404/snowygui/config/AddKeyMaps.kt b/common/src/main/kotlin/fr/username404/snowygui/config/AddKeyMaps.kt index 866a494..490f97d 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/config/AddKeyMaps.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/config/AddKeyMaps.kt @@ -1,7 +1,9 @@ package fr.username404.snowygui.config import com.mojang.blaze3d.platform.InputConstants +import fr.username404.snowygui.SnowyScreen import net.minecraft.client.KeyMapping +import net.minecraft.client.Minecraft import org.lwjgl.glfw.GLFW.GLFW_KEY_U import org.lwjgl.glfw.GLFW.GLFW_KEY_Y @@ -15,7 +17,7 @@ object AddKeyMaps { ) to lambda } val list: MutableMap Unit)?> = mutableMapOf( - mkMap("opengui", GLFW_KEY_Y), - mkMap("configkey", GLFW_KEY_U) + mkMap("opengui", GLFW_KEY_Y) { Minecraft.getInstance().setScreen(SnowyScreen()) }, + mkMap("configkey", GLFW_KEY_U) { Minecraft.getInstance().setScreen(SnowyConfigScreen()) } ) } \ No newline at end of file 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 60f5cab..9ff5025 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt @@ -3,6 +3,6 @@ package fr.username404.snowygui.config import net.minecraft.client.gui.screens.Screen import net.minecraft.network.chat.TranslatableComponent -abstract class SnowyConfigScreen: Screen(TranslatableComponent("screen.snowygui.config")) { // TODO Actual config screen +open class SnowyConfigScreen: Screen(TranslatableComponent("screen.snowygui.config")) { // TODO Actual config screen } \ 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 59065af..531debe 100644 --- a/common/src/main/resources/assets/snowygui/lang/en_us.json +++ b/common/src/main/resources/assets/snowygui/lang/en_us.json @@ -1,4 +1,5 @@ { + "screen.snowy.gui": "Snowy Interface", "screen.snowy.config": "Snowy configuration screen", "category.snowy.keycategory": "SnowyGUI", "key.snowy.opengui": "Open the snowy gui", 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 464658f..e52e999 100644 --- a/common/src/main/resources/assets/snowygui/lang/fr_fr.json +++ b/common/src/main/resources/assets/snowygui/lang/fr_fr.json @@ -1,4 +1,5 @@ { + "screen.snowy.gui": "Interface de Snowy", "screen.snowy.config": "Configuration de snowy", "category.snowy.keycategory": "SnowyGUI", "key.snowy.opengui": "Ouvrir l'interface de snowy", diff --git a/common/src/main/resources/snowygui-mixins.json b/common/src/main/resources/snowygui-mixins.json index 2384447..a0f5268 100644 --- a/common/src/main/resources/snowygui-mixins.json +++ b/common/src/main/resources/snowygui-mixins.json @@ -4,7 +4,8 @@ "compatibilityLevel": "JAVA_8", "client": [ "KeysAccessor", - "KeyMappings" + "KeyMappings", + "EndTickMixin" ], "injectors": { "defaultRequire": 1