Jump to content

Recommended Posts

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

Posted

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);

    }

}

 

 

Posted

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

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