Skip to content

Commit

Permalink
AbstractTextInput: Hard-code isAllowedCharacter
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Johni0702 authored May 2, 2024
1 parent df7d7cd commit e697779
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
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

0 comments on commit e697779

Please sign in to comment.