Jump to content

Render an image in front of inventory (1.19.4)?


JooseMann

Recommended Posts

Hi there, I am trying to add an image to the screen when the inventory is opened. So far, I've been able to get the image working (using RenderSystem and blit()), but it always appears behind the inventory (in other words, if you put one over the other, only the inventory will show). I have tried to use RenderSystem.depthFunc(519); (or depthFunc()) to set the image in front, but it still is displayed behind. (Also, just a heads up, the code doesn't bind the image to the mouse like I thought it would, but that is just for testing).

Clearly, I'm missing something here. What function allows an image to be rendered in front of the inventory?

Thanks, and if you see this then have a nice day :)

My code so far:

public static ResourceLocation LOCK = new ResourceLocation(ExampleMod.MOD_ID, "textures/gui/lock-opaque.png");

@SubscribeEvent
public static void onGuiRender(RenderGuiOverlayEvent.Post event) {
    if (Minecraft.getInstance().player != null && Minecraft.getInstance().screen instanceof InventoryScreen) {
        renderOverlay(event.getPoseStack(), (int) Minecraft.getInstance().mouseHandler.xpos(), (int) Minecraft.getInstance().mouseHandler.ypos());
        }
    }

public static void renderOverlay(PoseStack poseStack, int x, int y) {
	RenderSystem.setShader(GameRenderer::getPositionTexShader);
	RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
	RenderSystem.setShaderTexture(0, LOCK);

	RenderSystem.enableDepthTest();
	RenderSystem.depthFunc(519);

	blit(poseStack, x, y, 0, 0, 16, 16, 16, 16);

	RenderSystem.depthFunc(515);
	RenderSystem.disableDepthTest();
}

 

Link to comment
Share on other sites

These are all the different IN GAME overlays. Which doesn't sound like what you want anyway?

https://github.com/MinecraftForge/MinecraftForge/blob/1.20.x/src/main/java/net/minecraftforge/client/gui/overlay/VanillaGuiOverlay.java

Since you are not checking the overlay field in the event,

https://github.com/MinecraftForge/MinecraftForge/blob/ab70bde1d648125acee073a93a25d4b8f08985c9/src/main/java/net/minecraftforge/client/event/RenderGuiOverlayEvent.java#L31

you will actually be drawing multiple times after everyone of them.

 

The event you probably want is one for rendering after a UI/Screen is drawn? i.e. The Post version of this.

https://github.com/MinecraftForge/MinecraftForge/blob/ab70bde1d648125acee073a93a25d4b8f08985c9/src/main/java/net/minecraftforge/client/event/ScreenEvent.java#L153

Where you would check the screen field of the event to make sure it is the Inventory screen.

https://github.com/MinecraftForge/MinecraftForge/blob/ab70bde1d648125acee073a93a25d4b8f08985c9/src/main/java/net/minecraftforge/client/event/ScreenEvent.java#L52

if (event.getScreen() instanceof InventoryScreen) {
  doStuff();
}

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

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.



×
×
  • Create New...

Important Information

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