From e697779286d5a062fb2f24c0e7bd56ba9826ee26 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Thu, 2 May 2024 10:31:09 +0200 Subject: [PATCH] AbstractTextInput: Hard-code isAllowedCharacter It shouldn't ever change and this way the same Elementa build continues to be compatible on 1.20.5+ where the MC method was moved to another class. GitHub: #138 --- .../elementa/components/input/AbstractTextInput.kt | 9 ++++++++- src/main/kotlin/gg/essential/elementa/impl/Platform.kt | 2 -- .../java/gg/essential/elementa/impl/PlatformImpl.java | 6 ------ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/gg/essential/elementa/components/input/AbstractTextInput.kt b/src/main/kotlin/gg/essential/elementa/components/input/AbstractTextInput.kt index 4ae4ddc0..83a8cded 100644 --- a/src/main/kotlin/gg/essential/elementa/components/input/AbstractTextInput.kt +++ b/src/main/kotlin/gg/essential/elementa/components/input/AbstractTextInput.kt @@ -104,7 +104,7 @@ abstract class AbstractTextInput( val operationToRedo = redoStack.pop() operationToRedo.redo() undoStack.push(operationToRedo) - } else if (platform.isAllowedInChat(typedChar)) { // Most of the ASCII characters + } else if (isAllowedCharacter(typedChar)) { // Most of the ASCII characters commitTextAddition(typedChar.toString()) } else if (keyCode == UKeyboard.KEY_LEFT) { val holdingShift = UKeyboard.isShiftKeyDown() @@ -978,4 +978,11 @@ abstract class AbstractTextInput( removeTextOperation.undo() } } + + private companion object { + // Mirroring ChatAllowedCharacters.isAllowedCharacter + private fun isAllowedCharacter(chr: Char): Boolean { + return chr.code != 167 && chr >= ' ' && chr.code != 127 + } + } } diff --git a/src/main/kotlin/gg/essential/elementa/impl/Platform.kt b/src/main/kotlin/gg/essential/elementa/impl/Platform.kt index 9eec5117..1fe62845 100644 --- a/src/main/kotlin/gg/essential/elementa/impl/Platform.kt +++ b/src/main/kotlin/gg/essential/elementa/impl/Platform.kt @@ -9,8 +9,6 @@ interface Platform { var currentScreen: Any? - fun isAllowedInChat(char: Char): Boolean - fun enableStencil() fun isCallingFromMinecraftThread(): Boolean diff --git a/versions/src/main/java/gg/essential/elementa/impl/PlatformImpl.java b/versions/src/main/java/gg/essential/elementa/impl/PlatformImpl.java index 272ef877..faac816b 100644 --- a/versions/src/main/java/gg/essential/elementa/impl/PlatformImpl.java +++ b/versions/src/main/java/gg/essential/elementa/impl/PlatformImpl.java @@ -3,7 +3,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.shader.Framebuffer; -import net.minecraft.util.ChatAllowedCharacters; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -39,11 +38,6 @@ public void setCurrentScreen(@Nullable Object screen) { Minecraft.getMinecraft().displayGuiScreen((GuiScreen) screen); } - @Override - public boolean isAllowedInChat(char c) { - return ChatAllowedCharacters.isAllowedCharacter(c); - } - @Override public void enableStencil() { //#if MC<11500