Jump to content

Recommended Posts

Posted (edited)

When drawing a rectangle during the RenderGameOverlayEvent the hot bar gets tinted very strangely. The effect seems to vary between day and night too.

Here's the code for the overlay.

 

@Mod.EventBusSubscriber(modid = WeaponsCore.ID, value = {Side.CLIENT})
public class OverlayReload extends Gui
{
	@SubscribeEvent
	public static void render(RenderGameOverlayEvent.Post event)
	{
		if(event.getType() != RenderGameOverlayEvent.ElementType.HOTBAR)
		{
			//if (Minecraft.getMinecraft().playerController.shouldDrawHUD())
			//{
				renderReload(event.getResolution());
			//}
		}
	}

	public static void renderReload(ScaledResolution resolution) // TODO
	{
		Minecraft mc = Minecraft.getMinecraft();
		if (mc.getRenderViewEntity() instanceof EntityPlayer)
		{
			EntityPlayer player = (EntityPlayer) mc.getRenderViewEntity();
			ItemStack stack = player.getHeldItemMainhand(); //  TODO
			if(player.isHandActive())
			{
				if(stack.getItem() != null && stack.getItem() instanceof WeaponRanged)
				{
					float reload = Math.min((float) player.getItemInUseMaxCount() / (float) ((WeaponRanged) stack.getItem()).getRangedComponent().getProperties().getReload(), 1F);
					int color = 0;
					if(ReloadHelper.isEmpty(stack))
					{
						if(reload < 1F)
						{
							color = 0x60EAA800;
						}
						else
						{
							color = 0x60348E00;
						}
					}
					else if(ReloadHelper.isReloaded(stack))
					{
						color = 0x60C60000;
						reload = 1F;
					}
					int slot = player.inventory.getSlotFor(stack);
					GlStateManager.color(1F, 1F, 1F, 1F);
					GlStateManager.pushAttrib();
					int x0 = resolution.getScaledWidth() / 2 - 88 + slot * 20;
					int y0 = resolution.getScaledHeight() - 3;
					drawRect(x0, y0, x0 + 16, y0 - (int) (reload * 16), color);
					GlStateManager.popAttrib();
				}
			}
		}
	}
}

 

Untitled.png

Edited by Melonslise

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.