Closed Alexdoru closed 8 months ago
I added that feature to my mod too, and I figured out that when you add a message to the chat history and the chat stays opened, you also need to increment the pointer GuiChat.sentHistoryAccessor
.
Otherwise when you add a message to the chat history, the message you just added will be found by pressing the "down arrow key" instead of the "up arrow key", this only happens if you are not already "scrolling" in the history of sent messages.
To fix I did the following :
public static void sendChatMessage(String msg, boolean addToHistory) {
if (mc.thePlayer == null) return;
mc.thePlayer.sendChatMessage(msg);
if (!addToHistory) return;
boolean flag = false;
if (mc.currentScreen instanceof GuiChatAccessor) {
flag = ((GuiChatAccessor) mc.currentScreen).getSentHistoryCursor() == mc.ingameGUI.getChatGUI().getSentMessages().size();
}
mc.ingameGUI.getChatGUI().addToSentMessages(msg);
if (flag) {
((GuiChatAccessor) mc.currentScreen).setSentHistoryCursor(mc.ingameGUI.getChatGUI().getSentMessages().size());
}
}
In
GuiScreen#handleComponentClick(IChatComponent component)
there is this piece of code that sends the command to the server but doesn't add it to the history of sent commands. You could add a feature that replaces thatfalse
with aPatcherConfig.wahteversetting
to add the commands to the history of chat messages.