Posted April 29, 20169 yr 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: 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
April 29, 20169 yr Could you show you Event class? 1.7.10 is no longer supported by forge, you are on your own.
April 29, 20169 yr 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); } }
April 29, 20169 yr 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.