From d88a1d54e329f44b0f844ff109e312c2d66a64a8 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Sun, 14 Apr 2024 05:23:01 -0700 Subject: [PATCH 1/6] block specific toasts --- .../config/UTConfigTweaks.java | 21 ++++++++++++++++ .../toastcontrol/mixin/UTGuiToastMixin.java | 24 +++++++++++++++++++ .../mixins.tweaks.misc.toastcontrol.json | 2 +- 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/main/java/mod/acgaming/universaltweaks/tweaks/misc/toastcontrol/mixin/UTGuiToastMixin.java diff --git a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java index fde7af1d..dfe1f4f5 100644 --- a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java +++ b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java @@ -1682,6 +1682,27 @@ public static class ToastControlCategory @Config.Name("[5] Disable Tutorial Toasts") @Config.Comment("Determines if tutorial toasts are blocked. Blocks useless things like use WASD to move.") public boolean utToastControlTutorialToggle = true; + + @Config.Name("[6] Toast Control List") + @Config.Comment + ({ + "List of class names of Toasts to prevent displaying", + "Behavior depends on the list mode", + "Syntax: full class name" + }) + public String[] utToastControlClassList = new String[] {}; + + @Config.Name("[7] List Mode") + @Config.Comment + ({ + "Blacklist Mode: Toast classes which can't be added to the queue, others can", + "Whitelist Mode: Toast classes which can be added to the queue, others can't" + }) + public EnumLists utToastControlClassListMode = EnumLists.BLACKLIST; + + @Config.Name("[8] Debug Logging") + @Config.Comment("Enables debug logging to log class names of displayed toasts to the log") + public boolean utToastNameLogging = false; } } diff --git a/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/toastcontrol/mixin/UTGuiToastMixin.java b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/toastcontrol/mixin/UTGuiToastMixin.java new file mode 100644 index 00000000..9b5bff07 --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/toastcontrol/mixin/UTGuiToastMixin.java @@ -0,0 +1,24 @@ +package mod.acgaming.universaltweaks.tweaks.misc.toastcontrol.mixin; + +import mod.acgaming.universaltweaks.UniversalTweaks; +import mod.acgaming.universaltweaks.config.UTConfigTweaks; +import net.minecraft.client.gui.toasts.GuiToast; +import net.minecraft.client.gui.toasts.IToast; +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; + +import java.util.Arrays; + +@Mixin(value = GuiToast.class) +public abstract class UTGuiToastMixin +{ + @Inject(method = "add", at = @At(value = "HEAD"), cancellable = true) + private void utFilterToasts(IToast toastIn, CallbackInfo ci) + { + if (UTConfigTweaks.MISC.TOAST_CONTROL.utToastNameLogging) UniversalTweaks.LOGGER.info("UTGuiToastMixin ::: Displaying Toast: " + toastIn.getClass().getName()); + boolean isWhitelist = UTConfigTweaks.MISC.TOAST_CONTROL.utToastControlClassListMode == UTConfigTweaks.EnumLists.WHITELIST; + if (Arrays.asList(UTConfigTweaks.MISC.TOAST_CONTROL.utToastControlClassList).contains(toastIn.getClass().getName()) != isWhitelist) ci.cancel(); + } +} diff --git a/src/main/resources/mixins.tweaks.misc.toastcontrol.json b/src/main/resources/mixins.tweaks.misc.toastcontrol.json index 9ba5287c..3d06da7c 100644 --- a/src/main/resources/mixins.tweaks.misc.toastcontrol.json +++ b/src/main/resources/mixins.tweaks.misc.toastcontrol.json @@ -3,5 +3,5 @@ "refmap": "universaltweaks.refmap.json", "minVersion": "0.8", "compatibilityLevel": "JAVA_8", - "client": ["UTAdvancementToastMixin", "UTRecipeToastMixin", "UTSystemToastMixin"] + "client": ["UTAdvancementToastMixin", "UTGuiToastMixin", "UTRecipeToastMixin", "UTSystemToastMixin"] } \ No newline at end of file From 547c3a06426f1631afdd4bd151753fc1b470bfde Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Sun, 14 Apr 2024 05:23:32 -0700 Subject: [PATCH 2/6] create UTKeybindings --- .../universaltweaks/UniversalTweaks.java | 2 + .../universaltweaks/util/UTKeybindings.java | 125 ++++++++++++++++++ .../assets/universaltweaks/lang/en_us.lang | 2 + 3 files changed, 129 insertions(+) create mode 100644 src/main/java/mod/acgaming/universaltweaks/util/UTKeybindings.java diff --git a/src/main/java/mod/acgaming/universaltweaks/UniversalTweaks.java b/src/main/java/mod/acgaming/universaltweaks/UniversalTweaks.java index 12f3d500..6977aa0e 100644 --- a/src/main/java/mod/acgaming/universaltweaks/UniversalTweaks.java +++ b/src/main/java/mod/acgaming/universaltweaks/UniversalTweaks.java @@ -55,6 +55,7 @@ import mod.acgaming.universaltweaks.tweaks.performance.entityradiuscheck.UTEntityRadiusCheck; import mod.acgaming.universaltweaks.tweaks.world.stronghold.UTStronghold; import mod.acgaming.universaltweaks.tweaks.world.stronghold.worldgen.SafeStrongholdWorldGenerator; +import mod.acgaming.universaltweaks.util.UTKeybindings; import mod.acgaming.universaltweaks.util.UTPacketHandler; import mod.acgaming.universaltweaks.util.compat.UTObsoleteModsHandler; import net.tardis.mod.proxy.ClientProxy; @@ -163,6 +164,7 @@ public void initClient(FMLInitializationEvent event) if (UTConfigTweaks.MISC.utLANServerProperties) MinecraftForge.EVENT_BUS.register(UTLanServerProperties.class); if (UTConfigTweaks.MISC.PICKUP_NOTIFICATION.utPickupNotificationToggle) UTPickupNotificationOverlay.init(); if (Loader.isModLoaded("botania")) MinecraftForge.EVENT_BUS.register(UTBotaniaFancySkybox.class); + UTKeybindings.initialize(); } @Mod.EventHandler diff --git a/src/main/java/mod/acgaming/universaltweaks/util/UTKeybindings.java b/src/main/java/mod/acgaming/universaltweaks/util/UTKeybindings.java new file mode 100644 index 00000000..9b9e7de4 --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/util/UTKeybindings.java @@ -0,0 +1,125 @@ +package mod.acgaming.universaltweaks.util; + +import mod.acgaming.universaltweaks.UniversalTweaks; +import mod.acgaming.universaltweaks.tweaks.misc.toastcontrol.UTClearToastKeybind; +import net.minecraft.client.Minecraft; +import net.minecraft.client.settings.KeyBinding; +import net.minecraftforge.client.settings.IKeyConflictContext; +import net.minecraftforge.client.settings.KeyConflictContext; +import net.minecraftforge.client.settings.KeyModifier; +import net.minecraftforge.fml.client.registry.ClientRegistry; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.InputEvent; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import java.util.ArrayList; +import java.util.List; + +@Mod.EventBusSubscriber(modid = UniversalTweaks.MODID, value = Side.CLIENT) +@SideOnly(Side.CLIENT) +public class UTKeybindings extends KeyBinding +{ + private static final List keys = new ArrayList<>(); + + protected UTKeybindings(UTKeybindings.Key key) + { + super(key.getDescription(), key.getKeyConflictContext(), key.getKeyModifier(), key.getKeyCode(), UniversalTweaks.NAME); + ClientRegistry.registerKeyBinding(this); + } + + public static void addKey(UTKeybindings.Key key) + { + keys.add(key); + } + + public static void initialize() + { + for (Key key : keys) + { + key.getKey(); + } + } + + @SubscribeEvent + public static void onKeyInput(InputEvent event) + { + if (!Minecraft.getMinecraft().inGameHasFocus) return; + + for (Key key : keys) + { + if (key.getKey().isPressed()) key.handleKeybind(); + } + } + + public static abstract class Key + { + private final String name; + private final IKeyConflictContext keyConflictContext; + private final KeyModifier keyModifier; + private final int keyCode; + + @SideOnly(Side.CLIENT) + private KeyBinding key; + + public Key(String name, int keyCode) + { + this(name, KeyConflictContext.UNIVERSAL, keyCode); + } + + public Key(String name, IKeyConflictContext keyConflictContext, int keyCode) + { + this(name, keyConflictContext, KeyModifier.NONE, keyCode); + } + + public Key(String name, IKeyConflictContext keyConflictContext, KeyModifier keyModifier, int keyCode) + { + this.name = name; + this.keyConflictContext = keyConflictContext; + this.keyModifier = keyModifier; + this.keyCode = keyCode; + } + + @SideOnly(Side.CLIENT) + public abstract void handleKeybind(); + + public String getName() + { + return name; + } + + public IKeyConflictContext getKeyConflictContext() + { + return keyConflictContext; + } + + public KeyModifier getKeyModifier() + { + return keyModifier; + } + + public int getKeyCode() + { + return keyCode; + } + + @SideOnly(Side.CLIENT) + public KeyBinding getKey() + { + if (key == null) key = new UTKeybindings(this); + return key; + } + + @SideOnly(Side.CLIENT) + public void setKey(KeyBinding key) + { + this.key = key; + } + + public String getDescription() + { + return String.format("keybind.%s.%s", UniversalTweaks.MODID, name); + } + } +} diff --git a/src/main/resources/assets/universaltweaks/lang/en_us.lang b/src/main/resources/assets/universaltweaks/lang/en_us.lang index 348ae753..5841888d 100644 --- a/src/main/resources/assets/universaltweaks/lang/en_us.lang +++ b/src/main/resources/assets/universaltweaks/lang/en_us.lang @@ -3,6 +3,8 @@ msg.universaltweaks.obsoletemods.warning1=Universal Tweaks has replaced and impr msg.universaltweaks.obsoletemods.warning2=Therefore, the following mods are now incompatible with Universal Tweaks: msg.universaltweaks.obsoletemods.warning3=Consider removing them from your game or disabling the respective features. +# KEYBINDS + # TOGGLE CHEATS btn.universaltweaks.cheats.enabled=Cheats: ON btn.universaltweaks.cheats.disabled=Cheats: OFF From dd3b10235b9d6d981ac7f9b84f7527d23e53f915 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Sun, 14 Apr 2024 05:24:30 -0700 Subject: [PATCH 3/6] add Clear Toasts keybind --- .../config/UTConfigTweaks.java | 4 +++ .../toastcontrol/UTClearToastKeybind.java | 30 +++++++++++++++++++ .../universaltweaks/util/UTKeybindings.java | 2 ++ .../assets/universaltweaks/lang/en_us.lang | 1 + 4 files changed, 37 insertions(+) create mode 100644 src/main/java/mod/acgaming/universaltweaks/tweaks/misc/toastcontrol/UTClearToastKeybind.java diff --git a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java index dfe1f4f5..8d7adf2d 100644 --- a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java +++ b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java @@ -1703,6 +1703,10 @@ public static class ToastControlCategory @Config.Name("[8] Debug Logging") @Config.Comment("Enables debug logging to log class names of displayed toasts to the log") public boolean utToastNameLogging = false; + + @Config.Name("[9] Clear Toast Keybind") + @Config.Comment("Enables a keybind (default: CTRL+0) to clear all active toasts") + public boolean utClearToastKeybind = true; } } diff --git a/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/toastcontrol/UTClearToastKeybind.java b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/toastcontrol/UTClearToastKeybind.java new file mode 100644 index 00000000..83a43c2e --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/toastcontrol/UTClearToastKeybind.java @@ -0,0 +1,30 @@ +package mod.acgaming.universaltweaks.tweaks.misc.toastcontrol; + +import mod.acgaming.universaltweaks.config.UTConfigTweaks; +import mod.acgaming.universaltweaks.util.UTKeybindings; +import net.minecraft.client.Minecraft; +import net.minecraftforge.client.settings.KeyConflictContext; +import net.minecraftforge.client.settings.KeyModifier; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import org.lwjgl.input.Keyboard; + +public class UTClearToastKeybind extends UTKeybindings.Key +{ + public UTClearToastKeybind() + { + super("clear_toasts", KeyConflictContext.IN_GAME, KeyModifier.CONTROL, Keyboard.KEY_0); + } + + public static void createKeybind() + { + if (UTConfigTweaks.MISC.TOAST_CONTROL.utClearToastKeybind) UTKeybindings.addKey(new UTClearToastKeybind()); + } + + @SideOnly(Side.CLIENT) + @Override + public void handleKeybind() + { + Minecraft.getMinecraft().getToastGui().clear(); + } +} diff --git a/src/main/java/mod/acgaming/universaltweaks/util/UTKeybindings.java b/src/main/java/mod/acgaming/universaltweaks/util/UTKeybindings.java index 9b9e7de4..367b9e77 100644 --- a/src/main/java/mod/acgaming/universaltweaks/util/UTKeybindings.java +++ b/src/main/java/mod/acgaming/universaltweaks/util/UTKeybindings.java @@ -36,6 +36,8 @@ public static void addKey(UTKeybindings.Key key) public static void initialize() { + UTClearToastKeybind.createKeybind(); + for (Key key : keys) { key.getKey(); diff --git a/src/main/resources/assets/universaltweaks/lang/en_us.lang b/src/main/resources/assets/universaltweaks/lang/en_us.lang index 5841888d..44bedbd0 100644 --- a/src/main/resources/assets/universaltweaks/lang/en_us.lang +++ b/src/main/resources/assets/universaltweaks/lang/en_us.lang @@ -4,6 +4,7 @@ msg.universaltweaks.obsoletemods.warning2=Therefore, the following mods are now msg.universaltweaks.obsoletemods.warning3=Consider removing them from your game or disabling the respective features. # KEYBINDS +keybind.universaltweaks.clear_toasts=Clear Toasts # TOGGLE CHEATS btn.universaltweaks.cheats.enabled=Cheats: ON From 756fc90446ed56d54d8b082736e67b0085941305 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Sun, 14 Apr 2024 05:24:47 -0700 Subject: [PATCH 4/6] log when finishing client init phases --- src/main/java/mod/acgaming/universaltweaks/UniversalTweaks.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/mod/acgaming/universaltweaks/UniversalTweaks.java b/src/main/java/mod/acgaming/universaltweaks/UniversalTweaks.java index 6977aa0e..55c8241c 100644 --- a/src/main/java/mod/acgaming/universaltweaks/UniversalTweaks.java +++ b/src/main/java/mod/acgaming/universaltweaks/UniversalTweaks.java @@ -165,6 +165,7 @@ public void initClient(FMLInitializationEvent event) if (UTConfigTweaks.MISC.PICKUP_NOTIFICATION.utPickupNotificationToggle) UTPickupNotificationOverlay.init(); if (Loader.isModLoaded("botania")) MinecraftForge.EVENT_BUS.register(UTBotaniaFancySkybox.class); UTKeybindings.initialize(); + LOGGER.info(NAME + " client initialized"); } @Mod.EventHandler @@ -190,6 +191,7 @@ public void postInitClient(FMLPostInitializationEvent event) if (UTConfigTweaks.MISC.LOAD_SOUNDS.utLoadSoundMode != UTConfigTweaks.MiscCategory.LoadSoundsCategory.EnumSoundModes.NOTHING) UTLoadSound.initLists(); if (UTConfigTweaks.MISC.TOAST_CONTROL.utToastControlTutorialToggle) UTTutorialToast.utTutorialToast(); if (Loader.isModLoaded("botania")) UTBotaniaFancySkybox.initDimList(); + LOGGER.info(NAME + " client post-initialized"); } @Mod.EventHandler From 09006e3cbea3d2c549a532f7c8e34e6f81a54201 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Sun, 14 Apr 2024 05:31:24 -0700 Subject: [PATCH 5/6] also check toast control toggle for keybind --- .../tweaks/misc/toastcontrol/UTClearToastKeybind.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/toastcontrol/UTClearToastKeybind.java b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/toastcontrol/UTClearToastKeybind.java index 83a43c2e..6d4ef632 100644 --- a/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/toastcontrol/UTClearToastKeybind.java +++ b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/toastcontrol/UTClearToastKeybind.java @@ -18,7 +18,7 @@ public UTClearToastKeybind() public static void createKeybind() { - if (UTConfigTweaks.MISC.TOAST_CONTROL.utClearToastKeybind) UTKeybindings.addKey(new UTClearToastKeybind()); + if (UTConfigTweaks.MISC.TOAST_CONTROL.utToastControlToggle && UTConfigTweaks.MISC.TOAST_CONTROL.utClearToastKeybind) UTKeybindings.addKey(new UTClearToastKeybind()); } @SideOnly(Side.CLIENT) From edb0333d6e8e98d421fe64e33b60ec03a1a6dfbd Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Sun, 14 Apr 2024 05:34:19 -0700 Subject: [PATCH 6/6] note keybind is client only --- .../tweaks/misc/toastcontrol/UTClearToastKeybind.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/toastcontrol/UTClearToastKeybind.java b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/toastcontrol/UTClearToastKeybind.java index 6d4ef632..13620649 100644 --- a/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/toastcontrol/UTClearToastKeybind.java +++ b/src/main/java/mod/acgaming/universaltweaks/tweaks/misc/toastcontrol/UTClearToastKeybind.java @@ -9,6 +9,7 @@ import net.minecraftforge.fml.relauncher.SideOnly; import org.lwjgl.input.Keyboard; +@SideOnly(Side.CLIENT) public class UTClearToastKeybind extends UTKeybindings.Key { public UTClearToastKeybind()