diff --git a/build.gradle b/build.gradle index e5baf03..16a7855 100644 --- a/build.gradle +++ b/build.gradle @@ -106,7 +106,7 @@ dependencies { // Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed // that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied. // The userdev artifact is a special name and will get all sorts of transformations applied to it. - minecraft 'net.minecraftforge:forge:1.19-41.0.45' + minecraft 'net.minecraftforge:forge:1.19-41.0.64' // You may put jars on which you depend on in ./libs or you may define them like so.. // compile "some.group:artifact:version:classifier" diff --git a/src/main/java/exopandora/worldhandler/WorldHandler.java b/src/main/java/exopandora/worldhandler/WorldHandler.java index cd78c2d..ebb0214 100644 --- a/src/main/java/exopandora/worldhandler/WorldHandler.java +++ b/src/main/java/exopandora/worldhandler/WorldHandler.java @@ -14,9 +14,9 @@ import exopandora.worldhandler.usercontent.UsercontentLoader; import exopandora.worldhandler.util.AdvancementHelper; import exopandora.worldhandler.util.CommandHelper; import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.client.ClientRegistry; import net.minecraftforge.client.event.RegisterClientCommandsEvent; import net.minecraftforge.client.event.RegisterClientReloadListenersEvent; +import net.minecraftforge.client.event.RegisterKeyMappingsEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -50,9 +50,9 @@ public class WorldHandler Config.setupDirectories(WorldHandler.USERCONTENT_PATH); modLoadingContext.registerConfig(Type.CLIENT, Config.CLIENT_SPEC, Main.MODID + "/" + Main.MODID + ".toml"); UsercontentLoader.load(WorldHandler.USERCONTENT_PATH); - modEventBus.register(Config.class); modEventBus.addListener(WorldHandler.this::clientSetup); modEventBus.addListener(WorldHandler.this::registerClientReloadListeners); + modEventBus.addListener(WorldHandler.this::registerKeyMappingsEvent); modEventBus.addListener(Content::createRegistry); modEventBus.addListener(Category::createRegistry); modEventBus.addListener(Content::register); @@ -68,9 +68,14 @@ public class WorldHandler MinecraftForge.EVENT_BUS.addListener(KeyHandler::keyInputEvent); MinecraftForge.EVENT_BUS.addListener(ClientEventHandler::renderLevelLastEvent); MinecraftForge.EVENT_BUS.addListener(ClientEventHandler::clientTickEvent); - - ClientRegistry.registerKeyBinding(KeyHandler.KEY_WORLD_HANDLER); - KeyHandler.updatePosKeys(); + } + + @SubscribeEvent + public void registerKeyMappingsEvent(RegisterKeyMappingsEvent event) + { + event.register(KeyHandler.KEY_WORLD_HANDLER); + event.register(KeyHandler.KEY_WORLD_HANDLER_POS1); + event.register(KeyHandler.KEY_WORLD_HANDLER_POS2); } @SubscribeEvent diff --git a/src/main/java/exopandora/worldhandler/config/Config.java b/src/main/java/exopandora/worldhandler/config/Config.java index b8b22f0..2b6097d 100644 --- a/src/main/java/exopandora/worldhandler/config/Config.java +++ b/src/main/java/exopandora/worldhandler/config/Config.java @@ -7,11 +7,7 @@ import java.util.List; import org.apache.commons.lang3.tuple.Pair; -import exopandora.worldhandler.event.KeyHandler; import net.minecraftforge.common.ForgeConfigSpec; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.config.ModConfig.Type; -import net.minecraftforge.fml.event.config.ModConfigEvent.Reloading; public class Config { @@ -89,15 +85,6 @@ public class Config } } - @SubscribeEvent - public static void configReload(Reloading event) - { - if(event.getConfig().getType().equals(Type.CLIENT)) - { - KeyHandler.updatePosKeys(); - } - } - public static void setupDirectories(Path path) { try diff --git a/src/main/java/exopandora/worldhandler/config/ConfigCategorySettings.java b/src/main/java/exopandora/worldhandler/config/ConfigCategorySettings.java index c941e52..7d5898c 100644 --- a/src/main/java/exopandora/worldhandler/config/ConfigCategorySettings.java +++ b/src/main/java/exopandora/worldhandler/config/ConfigCategorySettings.java @@ -1,6 +1,5 @@ package exopandora.worldhandler.config; -import exopandora.worldhandler.event.KeyHandler; import exopandora.worldhandler.util.BlockPlacingMode; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.ForgeConfigSpec.BooleanValue; @@ -11,7 +10,6 @@ public class ConfigCategorySettings { private final BooleanValue commandSyntax; private final BooleanValue shortcuts; - private final BooleanValue shortcutKeys; private final BooleanValue tooltips; private final BooleanValue watch; private final BooleanValue smoothWatch; @@ -37,10 +35,6 @@ public class ConfigCategorySettings .translation("gui.worldhandler.config.settings.shortcuts") .comment("Whether or not to display a row of quick access buttons at the top") .define("shortcuts", false); - this.shortcutKeys = builder - .translation("gui.worldhandler.config.settings.key_shortcuts") - .comment("Whether or not to enable button keys for pos1 and pos2") - .define("key_shortcuts", false); this.tooltips = builder .translation("gui.worldhandler.config.settings.tooltips") .comment("Whether or not to display tooltips for buttons") @@ -115,23 +109,6 @@ public class ConfigCategorySettings Config.set(this.shortcuts, enabled); } - public boolean shortcutKeys() - { - return this.shortcutKeys.get(); - } - - public void setShortcutKeys(boolean enabled) - { - boolean previous = this.shortcutKeys(); - - Config.set(this.shortcutKeys, enabled); - - if(previous != enabled) - { - KeyHandler.updatePosKeys(); - } - } - public boolean tooltips() { return this.tooltips.get(); diff --git a/src/main/java/exopandora/worldhandler/event/KeyHandler.java b/src/main/java/exopandora/worldhandler/event/KeyHandler.java index fadc99b..a5dbb51 100644 --- a/src/main/java/exopandora/worldhandler/event/KeyHandler.java +++ b/src/main/java/exopandora/worldhandler/event/KeyHandler.java @@ -1,65 +1,37 @@ package exopandora.worldhandler.event; -import org.apache.commons.lang3.ArrayUtils; import org.lwjgl.glfw.GLFW; -import exopandora.worldhandler.config.Config; import exopandora.worldhandler.util.ActionHelper; import exopandora.worldhandler.util.BlockHelper; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; -import net.minecraftforge.client.ClientRegistry; -import net.minecraftforge.client.event.InputEvent.KeyInputEvent; +import net.minecraftforge.client.event.InputEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; public class KeyHandler { public static final KeyMapping KEY_WORLD_HANDLER = new KeyMapping("key.worldhandler", GLFW.GLFW_KEY_V, "key.categories.worldhandler"); - public static final KeyMapping KEY_WORLD_HANDLER_POS1 = new KeyMapping("key.worldhandler.pos1", GLFW.GLFW_KEY_O, "key.categories.worldhandler"); - public static final KeyMapping KEY_WORLD_HANDLER_POS2 = new KeyMapping("key.worldhandler.pos2", GLFW.GLFW_KEY_P, "key.categories.worldhandler"); + public static final KeyMapping KEY_WORLD_HANDLER_POS1 = new KeyMapping("key.worldhandler.pos1", GLFW.GLFW_KEY_UNKNOWN, "key.categories.worldhandler"); + public static final KeyMapping KEY_WORLD_HANDLER_POS2 = new KeyMapping("key.worldhandler.pos2", GLFW.GLFW_KEY_UNKNOWN, "key.categories.worldhandler"); @SubscribeEvent - public static void keyInputEvent(KeyInputEvent event) + public static void keyInputEvent(InputEvent.Key event) { if(Minecraft.getInstance() != null && Minecraft.getInstance().screen == null) { - if(KEY_WORLD_HANDLER.isDown()) + if(KEY_WORLD_HANDLER.consumeClick()) { ActionHelper.displayGui(); } - else if(Config.getSettings().shortcutKeys() && KEY_WORLD_HANDLER_POS1.isDown()) + else if(KEY_WORLD_HANDLER_POS1.consumeClick()) { BlockHelper.pos1().set(BlockHelper.getFocusedBlockPos()); } - else if(Config.getSettings().shortcutKeys() && KEY_WORLD_HANDLER_POS2.isDown()) + else if(KEY_WORLD_HANDLER_POS2.consumeClick()) { BlockHelper.pos2().set(BlockHelper.getFocusedBlockPos()); } } } - - public static void updatePosKeys() - { - boolean isRegistered = KeyHandler.arePosKeysRegistered(); - - if(Config.getSettings().shortcutKeys() && !isRegistered) - { - ClientRegistry.registerKeyBinding(KEY_WORLD_HANDLER_POS1); - ClientRegistry.registerKeyBinding(KEY_WORLD_HANDLER_POS2); - } - else if(!Config.getSettings().shortcutKeys() && isRegistered) - { - KeyHandler.removePosKeys(); - } - } - - public static boolean arePosKeysRegistered() - { - return ArrayUtils.contains(Minecraft.getInstance().options.keyMappings, KEY_WORLD_HANDLER_POS1) || ArrayUtils.contains(Minecraft.getInstance().options.keyMappings, KEY_WORLD_HANDLER_POS2); - } - - public static void removePosKeys() - { - Minecraft.getInstance().options.keyMappings = ArrayUtils.removeElements(Minecraft.getInstance().options.keyMappings, KEY_WORLD_HANDLER_POS1, KEY_WORLD_HANDLER_POS2); - } } diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSettings.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSettings.java index d6db7c7..3445aca 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSettings.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSettings.java @@ -29,7 +29,6 @@ public class ContentSettings extends ContentChild { SETTINGS.add(new BooleanSetting("command_syntax", Config.CLIENT.getSettings()::commandSyntax, Config.CLIENT.getSettings()::setCommandSyntax)); SETTINGS.add(new BooleanSetting("shortcuts", Config.CLIENT.getSettings()::shortcuts, Config.CLIENT.getSettings()::setShortcuts)); - SETTINGS.add(new BooleanSetting("key_shortcuts", Config.CLIENT.getSettings()::shortcutKeys, Config.CLIENT.getSettings()::setShortcutKeys)); SETTINGS.add(new BooleanSetting("tooltips", Config.CLIENT.getSettings()::tooltips, Config.CLIENT.getSettings()::setTooltips)); SETTINGS.add(new BooleanSetting("watch", Config.CLIENT.getSettings()::watch, Config.CLIENT.getSettings()::setWatch)); SETTINGS.add(new BooleanSetting("smooth_watch", Config.CLIENT.getSettings()::smoothWatch, Config.CLIENT.getSettings()::setSmoothWatch)); @@ -84,7 +83,7 @@ public class ContentSettings extends ContentChild }); container.add(settings); - + this.valueField = new GuiTextFieldTooltip(x + 118, y + 24, 114, 20, Component.translatable("gui.worldhandler.generic.value")); this.valueField.setFilter(string -> { diff --git a/src/main/resources/assets/worldhandler/lang/de_de.json b/src/main/resources/assets/worldhandler/lang/de_de.json index 702b0b9..3072a21 100644 --- a/src/main/resources/assets/worldhandler/lang/de_de.json +++ b/src/main/resources/assets/worldhandler/lang/de_de.json @@ -3,7 +3,6 @@ "gui.worldhandler.config.settings.command_syntax": "Befehlssyntax", "gui.worldhandler.config.settings.shortcuts": "Schnellsteuerleiste", - "gui.worldhandler.config.settings.key_shortcuts": "Tasten Abkürzungen", "gui.worldhandler.config.settings.tooltips": "Tooltips", "gui.worldhandler.config.settings.watch": "Uhr", "gui.worldhandler.config.settings.smooth_watch": "Geschmeidige Uhr", @@ -45,7 +44,6 @@ "gui.worldhandler.config.comment.settings.custom_time_dawn": "Aktiviert Biome Indikator", "gui.worldhandler.config.comment.settings.command_syntax": "Aktiviert Befehlssyntax", "gui.worldhandler.config.comment.settings.shortcuts": "Aktiviert Schnellsteuerleiste", - "gui.worldhandler.config.comment.settings.key_shortcuts": "Aktiviert Tasten Abkürzungen", "gui.worldhandler.config.comment.settings.tooltips": "Aktiviert Tooltips", "gui.worldhandler.config.comment.settings.watch": "Aktiviert Uhr", "gui.worldhandler.config.comment.settings.smooth_watch": "Aktiviert Geschmeidige Uhr", diff --git a/src/main/resources/assets/worldhandler/lang/en_us.json b/src/main/resources/assets/worldhandler/lang/en_us.json index 9fdec77..3d65411 100644 --- a/src/main/resources/assets/worldhandler/lang/en_us.json +++ b/src/main/resources/assets/worldhandler/lang/en_us.json @@ -3,7 +3,6 @@ "gui.worldhandler.config.settings.command_syntax": "Command Syntax", "gui.worldhandler.config.settings.shortcuts": "Shortcuts", - "gui.worldhandler.config.settings.key_shortcuts": "Key Shortcuts", "gui.worldhandler.config.settings.tooltips": "Tooltips", "gui.worldhandler.config.settings.watch": "Watch", "gui.worldhandler.config.settings.smooth_watch": "Smooth Watch", @@ -44,7 +43,6 @@ "gui.worldhandler.config.comment.settings.command_syntax": "Displays the current command at the bottom", "gui.worldhandler.config.comment.settings.shortcuts": "Adds a row of buttons at the top for quick access", - "gui.worldhandler.config.comment.settings.key_shortcuts": "Enables button keys for pos1 and pos2", "gui.worldhandler.config.comment.settings.tooltips": "Whether or not to display tooltips", "gui.worldhandler.config.comment.settings.watch": "Whether or not to display a watch", "gui.worldhandler.config.comment.settings.smooth_watch": "Whether or not the watch pointers move smooth", diff --git a/src/main/resources/assets/worldhandler/lang/fr_fr.json b/src/main/resources/assets/worldhandler/lang/fr_fr.json index 022e686..c20f245 100644 --- a/src/main/resources/assets/worldhandler/lang/fr_fr.json +++ b/src/main/resources/assets/worldhandler/lang/fr_fr.json @@ -3,7 +3,6 @@ "gui.worldhandler.config.settings.command_syntax": "Syntaxe commandes", "gui.worldhandler.config.settings.shortcuts": "Raccourcis", - "gui.worldhandler.config.settings.key_shortcuts": "Raccourcis clavier", "gui.worldhandler.config.settings.tooltips": "Info-bulles", "gui.worldhandler.config.settings.watch": "Montre", "gui.worldhandler.config.settings.smooth_watch": "Montre fluide", @@ -44,7 +43,6 @@ "gui.worldhandler.config.comment.settings.command_syntax": "Afficher en bas la commande actuelle", "gui.worldhandler.config.comment.settings.shortcuts": "Adds a row of buttons at the top for quick access", - "gui.worldhandler.config.comment.settings.key_shortcuts": "Enables button keys for pos1 and pos2", "gui.worldhandler.config.comment.settings.tooltips": "Afficher ou non les info-bulles", "gui.worldhandler.config.comment.settings.watch": "Afficher ou non une montre", "gui.worldhandler.config.comment.settings.smooth_watch": "Rendre ou non lisse les aiguilles de la montre", diff --git a/src/main/resources/assets/worldhandler/lang/ru_ru.json b/src/main/resources/assets/worldhandler/lang/ru_ru.json index 52f23ca..71ab0fe 100644 --- a/src/main/resources/assets/worldhandler/lang/ru_ru.json +++ b/src/main/resources/assets/worldhandler/lang/ru_ru.json @@ -3,7 +3,6 @@ "gui.worldhandler.config.settings.command_syntax": "Синтаксис команд", "gui.worldhandler.config.settings.shortcuts": "Ярлыки", - "gui.worldhandler.config.settings.key_shortcuts": "Сочетания клавиш", "gui.worldhandler.config.settings.tooltips": "Всплывающие подсказки", "gui.worldhandler.config.settings.watch": "Часы", "gui.worldhandler.config.settings.smooth_watch": "Плавные часы", @@ -44,7 +43,6 @@ "gui.worldhandler.config.comment.settings.command_syntax": "Отображает текущую команду в нижней части экрана", "gui.worldhandler.config.comment.settings.shortcuts": "Добавляет ряд кнопок в верхней части для быстрого доступа", - "gui.worldhandler.config.comment.settings.key_shortcuts": "Включает кнопки для pos1 и pos2", "gui.worldhandler.config.comment.settings.tooltips": "Отображать подсказки или нет", "gui.worldhandler.config.comment.settings.watch": "Отображать часы или нет", "gui.worldhandler.config.comment.settings.smooth_watch": "Стрелки часов движутся плавно или нет", diff --git a/src/main/resources/assets/worldhandler/lang/zh_cn.json b/src/main/resources/assets/worldhandler/lang/zh_cn.json index 9339f19..6056b63 100644 --- a/src/main/resources/assets/worldhandler/lang/zh_cn.json +++ b/src/main/resources/assets/worldhandler/lang/zh_cn.json @@ -3,7 +3,6 @@ "gui.worldhandler.config.settings.command_syntax": "命令句法", "gui.worldhandler.config.settings.shortcuts": "快捷键", - "gui.worldhandler.config.settings.key_shortcuts": "键盘快捷键", "gui.worldhandler.config.settings.tooltips": "浮动提示", "gui.worldhandler.config.settings.watch": "时钟", "gui.worldhandler.config.settings.smooth_watch": "时钟平滑效果", @@ -45,7 +44,6 @@ "gui.worldhandler.config.comment.settings.custom_time_dawn": "生物群系指示器开启", "gui.worldhandler.config.comment.settings.command_syntax": "命令句法开启", "gui.worldhandler.config.comment.settings.shortcuts": "快捷键开启", - "gui.worldhandler.config.comment.settings.key_shortcuts": "键盘快捷键开启", "gui.worldhandler.config.comment.settings.tooltips": "浮动提示开启", "gui.worldhandler.config.comment.settings.watch": "时钟开启", "gui.worldhandler.config.comment.settings.smooth_watch": "时钟平滑效果开启",