#drawtooltip rendering backdrop, but not the main 'text' part of the tooltip

53 messages · Page 1 of 1 (latest)

slow schooner
#

I don't quite know why the text is not appearing, could it be that I need to call the method in drawForeground instead of drawBackground?

code:

    @Override
    protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) {
        RenderSystem.setShader(GameRenderer::getPositionTexProgram);
        RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
        RenderSystem.setShaderTexture(0, TEXTURE);
        int x = this.x;
        int y = this.y;
        context.drawTexture(TEXTURE, x, y, 0, 0, this.backgroundWidth, this.backgroundHeight);
        //Ruby dust amount tooltip, pretty cool!
        if ((mouseX > x + 25 && mouseX < x + 44) && (mouseY > y +37 && mouseY < y + 44)){
            context.drawItem(ModItems.RUBY_DUST.getDefaultStack(), mouseX, mouseY - 16);
            context.drawTooltip(this.textRenderer, Text.literal(String.format("     %d/%d", handler.getDustAmount(), 64)), mouseX - 8, mouseY);
        }
    }

I have tested if the values get through, and they do. It also seems to be very 'situational'.
Sometimes it renders without issue, sometimes it doesn't render at all. If anyone with more experience in Screens could help me out that would be greatly appreciated!

mortal tendon
#

doesn't DrawContext have methods to draw tooltips directly?

#

it does

#

it has a bunch of drawTooltip methods

slow schooner
#

I am calling the drawtooltip method, that's the weird part

mortal tendon
#

wait you're calling in drawBackground

slow schooner
#

yes

#

I tried the foreground method, but my x and y coordinates are not exactly where they should be

mortal tendon
#

any reason why? i feel like this method would have a translated matrix stack, hence the text going back

#

is there no regular render method?

slow schooner
#

Oh crap I didn't even think of that

#

my god

mortal tendon
#

try that

slow schooner
#

I will

#

It does render the text, but any idea on what could be causing the itemstack to not be drawn?

#

I could just be drawing it before the tooltip, I'm not necessarily the best at the whole Screen thing yet

mortal tendon
#

it's there

#

you can barely see it

slow schooner
#

what in the world, you're right

mortal tendon
#

can you try translating the item stack across z

slow schooner
#

I presume minecraft renders it with higher Z's being closer to the screen?

mortal tendon
#

yep iirc

slow schooner
#

doesn't really appear to do much, I'm using the drawtooltip with the additional parameters of seed and z, could be that I'm doing it wrong though lol

#
context.drawItem(ModItems.RUBY_DUST.getDefaultStack(), mouseX + 5, mouseY - 16, 1, 10);```
mortal tendon
#

lemme check something

#

ok this might take a bit, my test project is broken

slow schooner
#

take your time, I'm not in a rush to get this to work as it's mostly visual

slow schooner
#

281 right now

mortal tendon
#

put like 1000

slow schooner
#

weird, It's set too 1000 but still just does not render above it

#

Let's see if it's dependant on what you try to render since you're rendering the stack of a block

#

uhhh... so I guess 2D itemstack textures ignore the Z axis entirely?

mortal tendon
#
context.getMatrices().push();
context.getMatrices().translate(0,0, 280);
//context.drawItemWithoutEntity(Items.DIAMOND_SWORD.getDefaultStack(), mouseX+10, mouseY-10);
context.drawItem(Items.DIAMOND_SWORD.getDefaultStack(), mouseX+10, mouseY-10);
context.getMatrices().pop();
#

try this

slow schooner
#

You're a genious

mortal tendon
#

i'll tell you another way to do this

slow schooner
#

Go ahead, I'm all ears

mortal tendon
#

a bit of a hassle but i think it would be better if you ever need to add more things into that tooltip

#

there's a thing called TooltipComponent which allows you to fully control what's rendered within it. you can pass arbitary data into it and use it to render custom things. from what i've seen, there's no need to mess with z values since everything should be at the tooltip's z level.

the bundle tooltip uses one of those.

the annoying part is you will have to use this private method from DrawContext https://maven.fabricmc.net/docs/yarn-1.21.1+build.3/net/minecraft/client/gui/DrawContext.html#drawTooltip(net.minecraft.client.font.TextRenderer,java.util.List,int,int,net.minecraft.client.gui.tooltip.TooltipPositioner) which you'll need an accessor for

then of course you'll need to implement your own TooltipComponent. for reference you can check the bundle https://maven.fabricmc.net/docs/yarn-1.21.1+build.3/net/minecraft/client/gui/tooltip/BundleTooltipComponent.html

#

i do this tooltip with a component

slow schooner
#

Oof, I'm working in fabric 1.20.1, is that a thing in there as well?

#

guessing by the recipe book it is

#

the accessor thing won't be an issue, since intelliJ with the mod plugin practically autogenerates those now

mortal tendon
#

seem so

slow schooner
#

Your help is incredibly appreciated