Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AbstractTextInput: Hard-code isAllowedCharacter #138

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
}
}
2 changes: 0 additions & 2 deletions src/main/kotlin/gg/essential/elementa/impl/Platform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ interface Platform {

var currentScreen: Any?

fun isAllowedInChat(char: Char): Boolean

fun enableStencil()

fun isCallingFromMinecraftThread(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
Loading