Sk1erLLC / Patcher

A Forge mod full of Vanilla bug fixes, Quality of Life improvements, and performance enhancements.
Other
228 stars 59 forks source link

Suggestion : add config option to add commands sent via chat click events to history of chat messages #172

Closed Alexdoru closed 6 months ago

Alexdoru commented 6 months ago

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 that false with a PatcherConfig.wahteversetting to add the commands to the history of chat messages. image

Alexdoru commented 4 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());
        }
    }