Jump to content

[1.16.5] Rendering text in GUI causes all future rendering to fail


DARKHAWX

Recommended Posts

So I've got myself a GUI similar to that of the Advancements screen or the Creative screen where I've got a main screen that renders the window, and tabs that render their own info.

Everything works fine and dandy, until I have one of the tabs render text. When that happens, all other text rendered by the screen, along with the tab icon are no longer rendered. There seemingly are no errors, and when I try debugging I can see that each code path is still called so I'm not sure what's going on.

So within my screen the main render function looks as follows

    public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
        int i = (this.width - GUI_WIDTH) / 2;
        int j = (this.height - GUI_HEIGHT) / 2;
        this.renderBackground(matrixStack);
        if (maxPages != 0) {
            ITextComponent page = new StringTextComponent(String.format("%d / %d", tabPage + 1, maxPages + 1));
            int width = this.font.width(page);
            RenderSystem.disableLighting();
            this.font.draw(matrixStack, page.getString(), i + (GUI_WIDTH / 2) - (width / 2), j - 44, -1);
        }
        this.drawWindowBackground(matrixStack, mouseX, mouseY, i, j);
        this.renderWindow(matrixStack, i, j);
        this.drawWindowTooltips(matrixStack, mouseX, mouseY, i, j);
    }

The errant line is within this.drawWindowBackground(matrixStack, mouseX, mouseY, i, j);. Here we render the tab window itself.

    private void drawWindowBackground(MatrixStack matrixStack, int mouseX, int mouseY, int offsetX, int offsetY) {
        if (this.selectedTab == null) {
            fill(matrixStack, offsetX + 9, offsetY + 18, offsetX + 9 + 234, offsetY + 18 + 113, -16777216);
            int i = offsetX + 9 + 117;
            drawCenteredString(matrixStack, this.font, EMPTY, i, offsetY + 18 + 56 - 9 / 2, -1);
            drawCenteredString(matrixStack, this.font, SAD_LABEL, i, offsetY + 18 + 113 - 9, -1);
        } else {
            RenderSystem.pushMatrix();
            RenderSystem.translatef((float)(offsetX + 9), (float)(offsetY + 18), 0.0F);
            this.selectedTab.drawTabBackground(matrixStack);
            RenderSystem.popMatrix();
            RenderSystem.depthFunc(515);
            RenderSystem.disableDepthTest();
        }
    }

From there the tab draws itself as follows:

    public void drawTabBackground(MatrixStack matrixStack) {
        if (!this.centered) {
            this.scrollX = 117 - (this.maxX + this.minX) / 2.0D;
            this.scrollY = 56 - (this.maxY + this.minY) / 2.0D;
            this.centered = true;
        }

        RenderSystem.pushMatrix();
        RenderSystem.enableDepthTest();
        RenderSystem.translatef(0.0F, 0.0F, 950.0F);
        RenderSystem.colorMask(false, false, false, false);
        fill(matrixStack, 4680, 2260, -4680, -2260, -16777216);
        RenderSystem.colorMask(true, true, true, true);
        RenderSystem.translatef(0.0F, 0.0F, -950.0F);
        RenderSystem.depthFunc(518);
        fill(matrixStack, MAX_WIDTH, MAX_HEIGHT, 0, 0, -16777216);
        RenderSystem.depthFunc(515);
        this.minecraft.getTextureManager().bind(background);
        int i = MathHelper.floor(this.scrollX);
        int j = MathHelper.floor(this.scrollY);
        int k = i % 16;
        int l = j % 16;

        for(int i1 = -1; i1 <= 15; ++i1) {
            for(int j1 = -1; j1 <= 8; ++j1) {
                blit(matrixStack, k + 16 * i1, l + 16 * j1, 0.0F, 0.0F, 16, 16, 16, 16);
            }
        }

        this.renderWindow(matrixStack);
        RenderSystem.depthFunc(518);
        RenderSystem.translatef(0.0F, 0.0F, -950.0F);
        RenderSystem.colorMask(false, false, false, false);
        fill(matrixStack, 4680, 2260, -4680, -2260, -16777216);
        RenderSystem.colorMask(true, true, true, true);
        RenderSystem.translatef(0.0F, 0.0F, 950.0F);
        RenderSystem.depthFunc(515);
        RenderSystem.popMatrix();
    }

And finally we get to the errant line: this.renderWindow(matrixStack);. This method is overridden by each tab and renders the content of the tab. For my tab it is simple, we render a piece of text at the center of the tab. This text renders fine, however it breaks the tab icon and window name.

    @Override
    protected void renderWindow(MatrixStack matrixStack) {
        ITextComponent divineFavourText = new TranslationTextComponent("screen.mesoamericamythology.divine_relationships.favour.divine_favour", this.getRelationship().getDivineFavour());
        // x, y, colour
        // This line breaks the rendering :(
        drawCenteredString(matrixStack, this.minecraft.font, divineFavourText, MAX_WIDTH / 2, MAX_HEIGHT / 2, Integer.parseInt("FFFFFF", 16));
    }

Below I have two screenshots. The one on the left is what the UI looks like when I don't draw the string in renderWindow. The right is what happens when I do.

yTbmbY9.png

I'm a little befuddled at the moment. Hoping someone has more pointers that would help me understand what is going on.

No signature for you!

Link to comment
Share on other sites

Here's the code which renders the GUI_LABEL and tab.drawIcon is called. It's called after drawWindowBackground (in code above) is called

    public void renderWindow(MatrixStack matrixStack, int offsetX, int offsetY) {
        RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
        RenderSystem.enableBlend();
        this.minecraft.getTextureManager().bind(WINDOW);
        this.blit(matrixStack, offsetX, offsetY, 0, 0, GUI_WIDTH, GUI_HEIGHT);
        if (this.tabs.size() >= 1) {
            this.minecraft.getTextureManager().bind(TABS);

            for (DivineRelationshipsTabGui tab : this.tabs) {
                if (tab.getPage() == tabPage) {
                    tab.renderTabSelectorBackground(matrixStack, offsetX, offsetY, tab == this.selectedTab);
                }
            }

            RenderSystem.enableRescaleNormal();
            RenderSystem.defaultBlendFunc();

            for (DivineRelationshipsTabGui tab : this.tabs) {
                if (tab.getPage() == tabPage)
                    tab.drawIcon(offsetX, offsetY, this.itemRenderer);
            }

            RenderSystem.disableBlend();
        }

        this.font.draw(matrixStack, GUI_LABEL, (float)(offsetX + 8), (float)(offsetY + 6), 4210752);
    }

drawIcon simply looks like the following. Where index is the tab number and stack is the item to render.

    public void drawIcon(int offsetX, int offsetY, int index, ItemRenderer renderItemIn, ItemStack stack) {
        int i = offsetX + this.getX(index);
        int j = offsetY + this.getY(index);
        switch(this) {
            case ABOVE:
                i += 6;
                j += 9;
                break;
            case BELOW:
                i += 6;
                j += 6;
                break;
        }

        renderItemIn.renderGuiItem(stack, i, j);
    }

I believe these are effectively clones of the Advancements screen code just with some code removed.

No signature for you!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.