(1.21.4) (Client-side) How do I intercept and modify messages sent by the player? #4520
Answered
by
modmuss50
DanPlus6
asked this question in
Mod Dev Support
DescriptionLet's say the player types in chat, "The foo is looking nice today!", how do I intercept this message and modify it to replace "foo" with "bar" so that the message that gets sent out is "The bar is looking nice today!" instead? |
Answered by
modmuss50
Mar 18, 2025
Replies: 2 comments 4 replies
|
Hey, you can use the ServerMessageDecoratorEvent in the conent phase, see the following example from one of the test mods. This example returns replaces the whole message, but you can just as easily replace or add to the message. |
0 replies
|
Just seen you wanted this for the client side, and not the server. On the client you will want |
4 replies
Answer selected by
DanPlus6
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just seen you wanted this for the client side, and not the server. On the client you will want
ClientSendMessageEvents.MODIFY_CHATlike so:https://github.com/FabricMC/fabric/blob/6da4c195991ba0dbdb29f2537bd993b0975830a8/fabric-message-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/message/client/ChatTestClient.java#L54-L61