(1.21.4) (Client-side) How do I intercept and modify messages sent by the player? #4520
-
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? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 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. |
Beta Was this translation helpful? Give feedback.
-
Just seen you wanted this for the client side, and not the server. On the client you will want |
Beta Was this translation helpful? Give feedback.
Just seen you wanted this for the client side, and not the server. On the client you will want
ClientSendMessageEvents.MODIFY_CHAT
like so:fabric/fabric-message-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/message/client/ChatTestClient.java
Lines 54 to 61 in 6da4c19