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

Minecraft 1.9

Forge 12.16.0.1867

 

I noticed that GUI I'm drawing is displayed twice, when in Normal or Large GUI Scale, and works correctly in Small GUI Scale only, where is is displayed only once.

Screenshots:

 

CTntulf.png

7THl0lt.png

 

 

Code:

 

 

import net.minecraft.client.Minecraft;

import net.minecraft.client.gui.Gui;

import net.minecraft.client.gui.ScaledResolution;

import net.minecraft.entity.player.EntityPlayer;

 

public class Overlay extends Gui

{

    public Overlay(Minecraft mc, EntityPlayer player)

    {

        ScaledResolution res = new ScaledResolution(mc);

        int width = res.getScaledWidth();

        int height = res.getScaledHeight();

        String playerPitch = "Pitch: "+String.format("%.2f", -player.rotationPitch);

        int strw = mc.fontRendererObj.getStringWidth("Pitch: -90.00");

        int strh = mc.fontRendererObj.FONT_HEIGHT;

 

        Gui.drawRect(width-30, height - 30 - strh, width-10, height-10, 0xC0000000);

 

        mc.fontRendererObj.drawStringWithShadow(playerPitch, width-20-strw, height - 20 - strh, 0x00FFFFFF);

    }

}

 

 

 

Also, the rectangle is not being drawn where it should be, unless I really messed up the coordinates

Could you show you Event class?

1.7.10 is no longer supported by forge, you are on your own.

  • Author

Here it is:

 

 

import net.minecraft.client.Minecraft;

import net.minecraft.client.gui.Gui;

import net.minecraft.client.gui.ScaledResolution;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraftforge.client.event.RenderGameOverlayEvent;

import net.minecraftforge.event.entity.player.PlayerEvent;

import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

 

public class Events

{

    public boolean isFlying = false;

    public EntityPlayer player;

 

    @SubscribeEvent

    public void playerEvent(PlayerEvent.LivingUpdateEvent event)

    {

        if(event.getEntity() instanceof EntityPlayer)

        {

            //if(((EntityPlayer)event.getEntity()).isElytraFlying())

            {

                isFlying = true;

                player = (EntityPlayer)event.getEntity();

            }

            /*else

                isFlying = false;*/

        }

    }

 

    @SubscribeEvent

    public void drawHUD(RenderGameOverlayEvent event)

    {

        if(isFlying)

            new Overlay(Minecraft.getMinecraft(), player);

    }

}

 

 

Oh dang, dude.

 

Okay, so:

 

1.1. It's non-optimal (pointless) to make 'new' objects when you don't need that.

* Make static field and make 'Overlay(Minecraft.getMinecraft(), player);' once.

 

1.2. I am not saying anything (but I am), but the constructor (and whole design) is pointless.

*Just make static method or in-event code that will get player and mc from Minecraft#thePlayer and Minecraft.getMinecraft().

 

2. Actual problem:

2.1. RenderGameOverlayEvent has TWO sub-events. Pre and Post (look into class).

* You need to use one event, preferably Post.

2.2. In RenderGameOverlayEvent there is event.type.

* Pick one EventType, otherwise code is called multiple times (about 15). I suggest using 'ALL'.

 

Why do you get multiple renders:

You should alredy come up with that reading 1 and 2. You are making new Overaly that renders stuff multiple times per frame.

1.7.10 is no longer supported by forge, you are on your own.

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.