Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Currently I'm writing a mod that will simply display the keystrokes of the player on the screen. I'm using the renderGameOverlay event, and filtering out the event if it's not the crosshair being rendered. This works fine, but the crosshair stops being rendered entirely. Is there any way for me to keep the current context of a certain event on top of the content I want to add? Code:

@SubscribeEvent
	public void renderString(RenderGameOverlayEvent event)
	{
		GuiIngame guiTool = Minecraft.getMinecraft().ingameGUI;
		if (event.getType() != ElementType.CROSSHAIRS)
		{
			return;
		}
		if(Minecraft.getMinecraft().gameSettings.keyBindForward.isKeyDown())
		{
			guiTool.drawRect(300, 100, 320, 120, 0x60FFFFFF);
			guiTool.drawString(guiTool.getFontRenderer(), "W", 307, 107, 0xFF000000);
		}
		else
		{
			guiTool.drawRect(300, 100, 320, 120, 0x60000000);
			guiTool.drawString(guiTool.getFontRenderer(), "W", 307, 107, 0xFFFFFFFF);
		}
	}

 

Edited by bboc

The first thing is that the RenderGameOverlayEvent is actually a parent event that has Pre and Post sub-events. You should really just subscribe to one of those otherwise you're actually handling it twice.

 

The normal crosshairs should still render if you don't cancel the Pre event. You can see this in the GuiIngameForge#renderCrosshairs which has the code:

    protected void renderCrosshairs(float partialTicks)
    {
        if (pre(CROSSHAIRS)) return;
        bind(Gui.ICONS);
        GlStateManager.enableBlend();
        super.renderAttackIndicator(partialTicks, res);
        post(CROSSHAIRS);
    }

Where you can follow the call to pre(CROSSHAIRS) and see that is only true if the event is canceled.

 

Since you didn't cancel the event, something else must be going on. At the time the event is called, there is already an GL11 matrix being processed so usually I directly use GL code to draw what I want. You're using the Gui class methods. Maybe it should work, just I know that weird stuff can happen with GL code once you start nesting methods -- for example the drawString() calls the enableAlpha() method so maybe that is making the crosshairs transparent or something.  One way to test for this is to comment out all your code inside the event (but leave the event to fire) and I should expect that the crosshair should draw. Then add the code back bit by bit to see which line is leaving some residual effect on the rendering.

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.