Не полностью отображается чат

Версия Minecraft
1.12.2
124
1
8
Создал "типа" свой чат. Содержимое класса чата скопировал полностью из ванильного класса GuiChat(для теста тип). Пишу различные сообщения в чат и ничего не отображается, кроме последних сообщений, которые через неск сек исчезают, хз че делать, хелп.
 
1,159
38
544
Телепаты в отпуске. Прикладывай код своего чата.
 
124
1
8
Содержимое класса чата скопировал полностью из ванильного класса GuiChat
Ну лан, вот

Java:
public class CustomChat extends GuiScreen implements ITabCompleter{
    
    private static final Logger LOGGER = LogManager.getLogger();
    private String historyBuffer = "";
    private int sentHistoryCursor = -1;
    private TabCompleter tabCompleter;
    protected GuiTextField inputField;
    private String defaultInputFieldText = "";
    private final List<ChatLine> drawnChatLines = Lists.<ChatLine>newArrayList();
    private int scrollPos;
    public CustomChat()
    {
    }

    public CustomChat(String defaultText)
    {
        this.defaultInputFieldText = defaultText;
    }

    public void initGui()
    {
        Keyboard.enableRepeatEvents(true);
        this.sentHistoryCursor = this.mc.ingameGUI.getChatGUI().getSentMessages().size();
        this.inputField = new GuiTextField(0, this.fontRenderer, 57, this.height - 26, this.width - 4, 12);
        this.inputField.setMaxStringLength(30);
        this.inputField.setEnableBackgroundDrawing(false);
        this.inputField.setFocused(true);
        this.inputField.setText(this.defaultInputFieldText);
        this.inputField.setCanLoseFocus(false);
        this.tabCompleter = new CustomChat.ChatTabCompleter(this.inputField);
    }


    public void onGuiClosed()
    {
        Keyboard.enableRepeatEvents(false);
        this.mc.ingameGUI.getChatGUI().resetScroll();
    }

    public void updateScreen()
    {
        this.inputField.updateCursorCounter();
    }

    protected void keyTyped(char typedChar, int keyCode) throws IOException
    {
        this.tabCompleter.resetRequested();

        if (keyCode == 15)
        {
            this.tabCompleter.complete();
        }
        else
        {
            this.tabCompleter.resetDidComplete();
        }

        if (keyCode == 1)
        {
            this.mc.displayGuiScreen((GuiScreen)null);
        }
        else if (keyCode != 28 && keyCode != 156)
        {
            if (keyCode == 200)
            {
                this.getSentHistory(-1);
            }
            else if (keyCode == 208)
            {
                this.getSentHistory(1);
            }
            else if (keyCode == 201)
            {
                this.mc.ingameGUI.getChatGUI().scroll(this.mc.ingameGUI.getChatGUI().getLineCount() - 1);
            }
            else if (keyCode == 209)
            {
                this.mc.ingameGUI.getChatGUI().scroll(-this.mc.ingameGUI.getChatGUI().getLineCount() + 1);
            }
            else
            {
                this.inputField.textboxKeyTyped(typedChar, keyCode);
            }
        }
        else
        {
            String s = this.inputField.getText().trim();

            if (!s.isEmpty())
            {
                this.sendChatMessage(s);
            }

            this.mc.displayGuiScreen((GuiScreen)null);
        }
    }

    public void handleMouseInput() throws IOException
    {
        super.handleMouseInput();
        int i = Mouse.getEventDWheel();

        if (i != 0)
        {
            if (i > 1)
            {
                i = 1;
            }

            if (i < -1)
            {
                i = -1;
            }

            if (!isShiftKeyDown())
            {
                i *= 7;
            }

            this.mc.ingameGUI.getChatGUI().scroll(i);
        }
    }

    protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
    {
        if (mouseButton == 0)
        {
            ITextComponent itextcomponent = this.mc.ingameGUI.getChatGUI().getChatComponent(Mouse.getX(), Mouse.getY());

            if (itextcomponent != null && this.handleComponentClick(itextcomponent))
            {
                return;
            }
        }

        this.inputField.mouseClicked(mouseX, mouseY, mouseButton);
        super.mouseClicked(mouseX, mouseY, mouseButton);
    }

    protected void setText(String newChatText, boolean shouldOverwrite)
    {
        if (shouldOverwrite)
        {
            this.inputField.setText(newChatText);
        }
        else
        {
            this.inputField.writeText(newChatText);
        }
    }

    public void getSentHistory(int msgPos)
    {
        int i = this.sentHistoryCursor + msgPos;
        int j = this.mc.ingameGUI.getChatGUI().getSentMessages().size();
        i = MathHelper.clamp(i, 0, j);

        if (i != this.sentHistoryCursor)
        {
            if (i == j)
            {
                this.sentHistoryCursor = j;
                this.inputField.setText(this.historyBuffer);
            }
            else
            {
                if (this.sentHistoryCursor == j)
                {
                    this.historyBuffer = this.inputField.getText();
                }

                this.inputField.setText((String)this.mc.ingameGUI.getChatGUI().getSentMessages().get(i));
                this.sentHistoryCursor = i;
            }
        }
    }



    @Override
    public void drawScreen(int mouseX, int mouseY, float partialTicks) {     

         drawRect(2, this.height - 14, this.width - 2, this.height - 2, Integer.MIN_VALUE);
        this.inputField.drawTextBox();
      
        ITextComponent itextcomponent = this.mc.ingameGUI.getChatGUI().getChatComponent(Mouse.getX(), Mouse.getY());

        if (itextcomponent != null && itextcomponent.getStyle().getHoverEvent() != null)
        {
            this.handleComponentHover(itextcomponent, mouseX, mouseY);
        }
        
        super.drawScreen(mouseX, mouseY, partialTicks);

        
    }
    

    public boolean doesGuiPauseGame()
    {
        return false;
    }


    public void setCompletions(String... newCompletions)
    {
        this.tabCompleter.setCompletions(newCompletions);
    }

    @SideOnly(Side.CLIENT)
    public static class ChatTabCompleter extends TabCompleter
        {
            private final Minecraft client = Minecraft.getMinecraft();

            public ChatTabCompleter(GuiTextField p_i46749_1_)
            {
                super(p_i46749_1_, false);
            }

            public void complete()
            {
                super.complete();

                if (this.completions.size() > 1)
                {
                    StringBuilder stringbuilder = new StringBuilder();

                    for (String s : this.completions)
                    {
                        if (stringbuilder.length() > 0)
                        {
                            stringbuilder.append(", ");
                        }

                        stringbuilder.append(s);
                    }

                    this.client.ingameGUI.getChatGUI().printChatMessageWithOptionalDeletion(new TextComponentString(stringbuilder.toString()), 1);
                }
            }

            @Nullable
            public BlockPos getTargetBlockPos()
            {
                BlockPos blockpos = null;

                if (this.client.objectMouseOver != null && this.client.objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK)
                {
                    blockpos = this.client.objectMouseOver.getBlockPos();
                }

                return blockpos;
            }
        }
}
 
  • Супер-код!
Реакции: jopi
1,159
38
544
Залей свой проект куда нибудь. На гитхаб или архивом. Отправь мне - я покопаюсь и попробую помочь
 

jopi

Попрошайка
1,421
30
260
[Решение проблемы в 1.6.4, методы должны быть очень схожи]
Еще с 1.6.4 нам известен евент CLientChatReceivedEvent который вызывается при получении на клиент сообщения.
Вопрос. Чем он нам поможет? Изменяем его название, получаем ошибку в классе NetClientHandler
1592229163225.png
судя из этого кода, становится ясно что NetClientHandler берет чат из класса GuiIngameForge, и потом просто печатает сообщение напрямую.
Как-же решить твою проблему? Попробуй в своем гуи унаследовать GuiChat, после чего просто замени рефлексией объект чата,
Рефлексией потому-что он private(так на версии 1.6.4), после того как пропатчил, заменил GuiIngameForge#объектЧата, сообщения должны появлятся в твоем чате.
 
124
1
8
Тут вообщем-то не все так просто.
Мне кажется не надо ничего менять рефлексией,
GuiChat отвечает за вывод сообщений, а GuiNewChat отвечает за их показ(скорее всего так).
Мне надо поискать где и как используется GuiNewChat, чтобы понять как его открыть
 
Сверху