Created
September 22, 2024 10:11
-
-
Save Densamisten/3ae6ca542adc67c105d053cbb3576beb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This injects into the addMessage method of ChatHud, which handles adding messages to the chat. | |
@Inject(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V", at = @At("HEAD")) | |
private void onAddMessage(Text message, MessageSignatureData signatureData, MessageIndicator indicator, CallbackInfo ci) { | |
if (message instanceof MutableText mutableText) { | |
// Create a new style with a click event to copy text and a hover event with instructions. | |
Style style = mutableText.getStyle().withClickEvent( | |
new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, mutableText.getString()) | |
).withHoverEvent( | |
new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal("Click to copy this message")) | |
); | |
// Apply the new style to the text. | |
mutableText.setStyle(style); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment