diff --git a/src/main/java/org/polyfrost/chatting/mixin/ChatPeekMixin_SkyHanni.java b/src/main/java/org/polyfrost/chatting/mixin/ChatPeekMixin_SkyHanni.java new file mode 100644 index 0000000..c8604aa --- /dev/null +++ b/src/main/java/org/polyfrost/chatting/mixin/ChatPeekMixin_SkyHanni.java @@ -0,0 +1,31 @@ +package org.polyfrost.chatting.mixin; + +import cc.polyfrost.oneconfig.utils.Notifications; +import org.polyfrost.chatting.config.ChattingConfig; +import org.spongepowered.asm.mixin.Dynamic; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Pseudo +@Mixin(targets = {"at.hannibal2.skyhanni.features.chat.ChatPeek"}) +public class ChatPeekMixin_SkyHanni { + + @Unique + private static long chatting$lastNotify = System.currentTimeMillis(); + + @Dynamic("SkyHanni") + @Inject(method = "peek", at = @At("HEAD"), cancellable = true, remap = false) + private static void cancel(CallbackInfoReturnable cir) { + if (!ChattingConfig.INSTANCE.getChatPeek() && cir.getReturnValue()) { + if (System.currentTimeMillis() - chatting$lastNotify >= 1000) { + Notifications.INSTANCE.send("Chatting", "SkyHanni's chat peek has been replaced by Chatting. You can configure this via OneConfig, by clicking the right shift key on your keyboard, or by typing /chatting in your chat."); + chatting$lastNotify = System.currentTimeMillis(); + } + } + cir.setReturnValue(false); + } +} \ No newline at end of file diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiContainerCreativeMixin.java b/src/main/java/org/polyfrost/chatting/mixin/GuiContainerCreativeMixin.java new file mode 100644 index 0000000..d308b4f --- /dev/null +++ b/src/main/java/org/polyfrost/chatting/mixin/GuiContainerCreativeMixin.java @@ -0,0 +1,20 @@ +package org.polyfrost.chatting.mixin; + +import net.minecraft.client.gui.inventory.GuiContainerCreative; +import org.polyfrost.chatting.Chatting; +import org.polyfrost.chatting.config.ChattingConfig; +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(GuiContainerCreative.class) +public class GuiContainerCreativeMixin { + + @Inject(method = "handleMouseInput", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Mouse;getEventDWheel()I"), cancellable = true) + private void cancelScrolling(CallbackInfo ci) { + if (Chatting.INSTANCE.getPeeking() && ChattingConfig.INSTANCE.getPeekScrolling()) { + ci.cancel(); + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/Chatting.kt b/src/main/kotlin/org/polyfrost/chatting/Chatting.kt index 42a7a69..3e17063 100644 --- a/src/main/kotlin/org/polyfrost/chatting/Chatting.kt +++ b/src/main/kotlin/org/polyfrost/chatting/Chatting.kt @@ -167,10 +167,23 @@ object Chatting { @SubscribeEvent fun onTickEvent(event: TickEvent.ClientTickEvent) { - if (event.phase == TickEvent.Phase.START && mc.theWorld != null && mc.thePlayer != null && (mc.currentScreen == null || mc.currentScreen is GuiChat)) { - if (doTheThing) { - screenshotChat() - doTheThing = false + if (event.phase == TickEvent.Phase.START && mc.theWorld != null && mc.thePlayer != null) { + if ((mc.currentScreen == null || mc.currentScreen is GuiChat)) { + if (doTheThing) { + screenshotChat() + doTheThing = false + } + } + + val key = ChattingConfig.chatPeekBind + if (key.isActive != lastPressed && ChattingConfig.chatPeek) { + lastPressed = key.isActive + if (key.isActive) { + peeking = !peeking + } else if (!ChattingConfig.peekMode) { + peeking = false + } + if (!peeking) mc.ingameGUI.chatGUI.resetScroll() } if (mc.currentScreen is GuiChat) peeking = false @@ -191,20 +204,6 @@ object Chatting { } } - @SubscribeEvent - fun peek(e: KeyInputEvent) { - val key = ChattingConfig.chatPeekBind - if (key.isActive != lastPressed && ChattingConfig.chatPeek) { - lastPressed = key.isActive - if (key.isActive) { - peeking = !peeking - } else if (!ChattingConfig.peekMode) { - peeking = false - } - if (!peeking) mc.ingameGUI.chatGUI.resetScroll() - } - } - fun getChatHeight(opened: Boolean): Int { return if (opened) ChattingConfig.chatWindow.focusedHeight else ChattingConfig.chatWindow.unfocusedHeight } diff --git a/src/main/resources/mixins.chatting.json b/src/main/resources/mixins.chatting.json index b1e39e2..c9c7e55 100644 --- a/src/main/resources/mixins.chatting.json +++ b/src/main/resources/mixins.chatting.json @@ -11,6 +11,7 @@ "EntityRendererMixin", "GameSettingsMixin", "GuiChatMixin", + "GuiContainerCreativeMixin", "GuiIngameForgeAccessor", "GuiIngameForgeMixin", "GuiNewChatAccessor", @@ -28,6 +29,7 @@ "InventoryPlayerMixin" ], "mixins": [ + "ChatPeekMixin_SkyHanni", "ChatStyleMixin", "EssentialKeybindingRegistryMixin" ]