Add chat peeking keybinding
This commit is contained in:
@@ -6,7 +6,9 @@
|
|||||||
|
|
||||||
package moe.nea.firmament.mixins;
|
package moe.nea.firmament.mixins;
|
||||||
|
|
||||||
|
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
|
||||||
import moe.nea.firmament.events.ClientChatLineReceivedEvent;
|
import moe.nea.firmament.events.ClientChatLineReceivedEvent;
|
||||||
|
import moe.nea.firmament.features.fixes.Fixes;
|
||||||
import net.minecraft.client.gui.hud.ChatHud;
|
import net.minecraft.client.gui.hud.ChatHud;
|
||||||
import net.minecraft.client.gui.hud.MessageIndicator;
|
import net.minecraft.client.gui.hud.MessageIndicator;
|
||||||
import net.minecraft.network.message.MessageSignatureData;
|
import net.minecraft.network.message.MessageSignatureData;
|
||||||
@@ -19,6 +21,16 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||||||
|
|
||||||
@Mixin(ChatHud.class)
|
@Mixin(ChatHud.class)
|
||||||
public class MixinChatHud {
|
public class MixinChatHud {
|
||||||
|
|
||||||
|
@ModifyExpressionValue(method = "render",at = @At(value = "INVOKE",target = "Lnet/minecraft/client/gui/hud/ChatHud;isChatFocused()Z"))
|
||||||
|
public boolean onGetChatHud(boolean old) {
|
||||||
|
return old || Fixes.INSTANCE.shouldPeekChat();
|
||||||
|
}
|
||||||
|
@ModifyExpressionValue(method = "getHeight",at = @At(value = "INVOKE",target = "Lnet/minecraft/client/gui/hud/ChatHud;isChatFocused()Z"))
|
||||||
|
public boolean onGetChatHudHeight(boolean old) {
|
||||||
|
return old || Fixes.INSTANCE.shouldPeekChat();
|
||||||
|
}
|
||||||
|
|
||||||
@ModifyArg(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/ChatHud;addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;ILnet/minecraft/client/gui/hud/MessageIndicator;Z)V"), method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V")
|
@ModifyArg(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/ChatHud;addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;ILnet/minecraft/client/gui/hud/MessageIndicator;Z)V"), method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V")
|
||||||
public Text onAddMessage(Text message) {
|
public Text onAddMessage(Text message) {
|
||||||
var event = new ClientChatLineReceivedEvent(message);
|
var event = new ClientChatLineReceivedEvent(message);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ object Fixes : FirmamentFeature {
|
|||||||
object TConfig : ManagedConfig(identifier) {
|
object TConfig : ManagedConfig(identifier) {
|
||||||
val fixUnsignedPlayerSkins by toggle("player-skins") { true }
|
val fixUnsignedPlayerSkins by toggle("player-skins") { true }
|
||||||
val autoSprint by toggle("auto-sprint") { false }
|
val autoSprint by toggle("auto-sprint") { false }
|
||||||
|
val peekChat by keyBindingWithDefaultUnbound("peek-chat")
|
||||||
}
|
}
|
||||||
|
|
||||||
override val config: ManagedConfig
|
override val config: ManagedConfig
|
||||||
@@ -35,4 +36,8 @@ object Fixes : FirmamentFeature {
|
|||||||
|
|
||||||
override fun onLoad() {
|
override fun onLoad() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun shouldPeekChat(): Boolean {
|
||||||
|
return TConfig.peekChat.isPressed(atLeast = true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,11 @@
|
|||||||
|
|
||||||
package moe.nea.firmament.keybindings
|
package moe.nea.firmament.keybindings
|
||||||
|
|
||||||
import org.lwjgl.glfw.GLFW
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
import moe.nea.firmament.util.MC
|
||||||
import net.minecraft.client.MinecraftClient
|
import net.minecraft.client.MinecraftClient
|
||||||
import net.minecraft.client.util.InputUtil
|
import net.minecraft.client.util.InputUtil
|
||||||
import moe.nea.firmament.util.MC
|
import org.lwjgl.glfw.GLFW
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class SavedKeyBinding(
|
data class SavedKeyBinding(
|
||||||
@@ -38,24 +38,28 @@ data class SavedKeyBinding(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isPressed(): Boolean {
|
fun isPressed(atLeast: Boolean = false): Boolean {
|
||||||
if (this.keyCode == GLFW.GLFW_KEY_UNKNOWN) return false
|
if (this.keyCode == GLFW.GLFW_KEY_UNKNOWN) return false
|
||||||
val h = MC.window.handle
|
val h = MC.window.handle
|
||||||
if (!InputUtil.isKeyPressed(h, keyCode)) return false
|
if (!InputUtil.isKeyPressed(h, keyCode)) return false
|
||||||
|
|
||||||
val ctrl = if (MinecraftClient.IS_SYSTEM_MAC) {
|
val ctrl = if (MinecraftClient.IS_SYSTEM_MAC) {
|
||||||
InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_SUPER)
|
InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_SUPER)
|
||||||
|| InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_SUPER)
|
|| InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_SUPER)
|
||||||
} else InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_CONTROL)
|
} else InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_CONTROL)
|
||||||
|| InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_CONTROL)
|
|| InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_CONTROL)
|
||||||
val shift = InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_SHIFT)
|
val shift = InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_SHIFT)
|
||||||
|| InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_SHIFT)
|
|| InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_SHIFT)
|
||||||
val alt = InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_ALT)
|
val alt = InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_ALT)
|
||||||
|| InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_ALT)
|
|| InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_ALT)
|
||||||
|
if (atLeast)
|
||||||
|
return (ctrl >= this.ctrl) &&
|
||||||
|
(alt >= this.alt) &&
|
||||||
|
(shift >= this.shift)
|
||||||
|
|
||||||
return (ctrl == this.ctrl) &&
|
return (ctrl == this.ctrl) &&
|
||||||
(alt == this.alt) &&
|
(alt == this.alt) &&
|
||||||
(shift == this.shift)
|
(shift == this.shift)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun matches(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
|
override fun matches(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user