Jump to content

Recommended Posts

Posted (edited)

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
Posted

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

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