Skip to content

Instantly share code, notes, and snippets.

@Ensamisten
Created July 18, 2023 19:12
Show Gist options
  • Select an option

  • Save Ensamisten/b48046bb1d56ea272700481c86deb71e to your computer and use it in GitHub Desktop.

Select an option

Save Ensamisten/b48046bb1d56ea272700481c86deb71e to your computer and use it in GitHub Desktop.
A Mixin in Java for Fabric (Minecraft 1.20.1) which prints "Player is typing..." each time a letter is written manually in the chat box.
@Mixin(TextFieldWidget.class)
public abstract class PlayerIsTyping {
@Unique
public abstract String charTyped(char chr, int modifiers);
@Inject(at = @At("RETURN"), method = "charTyped")
public void type(char chr, int modifiers, CallbackInfoReturnable<Boolean> cir) {
if (cir.getReturnValue()) {
assert MinecraftClient.getInstance().player != null;
boolean returnValue = Boolean.parseBoolean(String.valueOf(cir.getReturnValue()));
if (returnValue) {
// The description of the action
String message = MinecraftClient.getInstance().player.getName().getString() + " is typing...";
// Send the chat message to the player
MinecraftClient.getInstance().player.sendMessage(Text.of(message));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment