package aeronicamc.mods.mxtune.events;

import aeronicamc.mods.mxtune.Reference;
import aeronicamc.mods.mxtune.init.ModBlocks;
import aeronicamc.mods.mxtune.init.ModItems;
import aeronicamc.mods.mxtune.util.IInstrument;
import aeronicamc.mods.mxtune.util.SheetMusicHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = Reference.MOD_ID, value = Dist.CLIENT)
public class RenderEvents
{
    private static final Minecraft mc = Minecraft.getInstance();
    @SubscribeEvent
    public static void event(ItemTooltipEvent event)
    {
        if (event.getItemStack().getItem().equals(ModBlocks.MUSIC_BLOCK.get().asItem()))
            event.getToolTip().add(new TranslationTextComponent("tooltip.mxtune.block_music.help").withStyle(TextFormatting.YELLOW));
        else if (event.getItemStack().getItem().equals(ModItems.MUSIC_PAPER.get()))
            event.getToolTip().add(new TranslationTextComponent("tooltip.mxtune.music_paper.help").withStyle(TextFormatting.YELLOW));
    }

    @SubscribeEvent
    public static void event(RenderGameOverlayEvent.Post event)
    {
        PlayerEntity player = mc.player;
        ItemStack itemStack = player.inventory.getSelected();

        if (event.getType() == RenderGameOverlayEvent.ElementType.ALL && (mc.screen == null) && itemStack.getItem() instanceof IInstrument)
        {
            FontRenderer fontRenderer = Minecraft.getInstance().font;
            ItemStack sheetMusic = SheetMusicHelper.getIMusicFromIInstrument(itemStack);
            fontRenderer.drawShadow(event.getMatrixStack(), SheetMusicHelper.getFormattedMusicTitle(sheetMusic), 10, 10, -1);
        }
    }
}

@@ -262,24 +262,118 @@
 usicHelper;%0A
+import com.mojang.blaze3d.matrix.MatrixStack;%0Aimport com.mojang.blaze3d.systems.RenderSystem;%0A
 import net.m
@@ -431,28 +431,27 @@
 ent.gui.
-FontRenderer
+AbstractGui
 ;%0Aimport
@@ -526,24 +526,68 @@
 .ItemStack;%0A
+import net.minecraft.util.ResourceLocation;%0A
 import net.m
@@ -1057,16 +1057,8 @@
     
-private 
 stat
@@ -1633,16 +1633,191 @@
 %0A    %7D%0A%0A
+    static ResourceLocation TEXTURE = new ResourceLocation(%22textures/gui/toasts.png%22);%0A    static int width = 160;%0A    static int height = 32;%0A    static int blitOffset = 0;%0A%0A
     @Sub
@@ -1890,32 +1890,85 @@
 st event)%0A    %7B%0A
+        if (mc.player == null )%0A            return;%0A%0A
         PlayerEn
@@ -2055,16 +2055,72 @@
 ted();%0A%0A
+        // borrow toast render for testing some ideast.%0A
         
@@ -2265,78 +2265,8 @@
   %7B%0A
-            FontRenderer fontRenderer = Minecraft.getInstance().font;%0A
     
@@ -2366,131 +2366,975 @@
     
-fontRenderer.drawShadow(event.getMatrixStack(), SheetMusicHelper.getFormattedMusicTitle(sheetMusic), 10, 10, -1);%0A        %7D
+int offset = Math.max(mc.font.width(SheetMusicHelper.getFormattedMusicTitle(sheetMusic)) + 40, width);%0A            MatrixStack pPoseStack = event.getMatrixStack();%0A%0A            mc.getTextureManager().bind(TEXTURE);%0A            RenderSystem.color3f(1.0F, 1.0F, 1.0F);%0A            blit(pPoseStack, 0, 0, 0, 0, width, height);%0A            blit(pPoseStack, offset - width + 10, 0, 10, 0, width, height);%0A%0A            mc.font.draw(pPoseStack, SheetMusicHelper.getFormattedMusicTitle(sheetMusic), 30.0F, 7.0F, -11534256);%0A            mc.font.draw(pPoseStack, SheetMusicHelper.getFormattedMusicDuration(sheetMusic), 30.0F, 17.0F, -11534256);%0A            mc.getItemRenderer().renderAndDecorateItem(itemStack, 8, 8);%0A        %7D%0A    %7D%0A%0A    static void blit(MatrixStack pMatrixStack, int pX, int pY, int pUOffset, int pVOffset, int pUWidth, int pVHeight) %7B%0A        AbstractGui.blit(pMatrixStack, pX, pY, blitOffset, (float)pUOffset, (float)pVOffset, pUWidth, pVHeight, 256, 256);
 %0A   

Test overlay ideas using some borrowed toast rendering code.