Example usage for net.minecraftforge.client.event RenderTooltipEvent.PostText getFontRenderer

List of usage examples for net.minecraftforge.client.event RenderTooltipEvent.PostText getFontRenderer

Introduction

In this page you can find the example usage for net.minecraftforge.client.event RenderTooltipEvent.PostText getFontRenderer.

Prototype

@Nonnull
public FontRenderer getFontRenderer() 

Source Link

Usage

From source file:vazkii.botania.client.core.handler.TooltipAdditionDisplayHandler.java

License:Open Source License

@SubscribeEvent
public static void onToolTipRender(RenderTooltipEvent.PostText evt) {
    if (evt.getStack() == null)
        return;//  w  w w.  j  a v a 2s  . c o m

    ItemStack stack = evt.getStack();
    Minecraft mc = Minecraft.getMinecraft();
    int width = evt.getWidth();
    int height = 3;
    int tooltipX = evt.getX();
    int tooltipY = evt.getY() - 4;
    FontRenderer font = evt.getFontRenderer();

    if (stack.getItem() instanceof ItemTerraPick)
        drawTerraPick(stack, tooltipX, tooltipY, width, height, font);
    else if (stack.getItem() instanceof IManaTooltipDisplay)
        drawManaBar(stack, (IManaTooltipDisplay) stack.getItem(), tooltipX, tooltipY, width, height);

    EntryData data = LexiconRecipeMappings.getDataForStack(stack);
    if (data != null) {
        int lexSlot = -1;
        ItemStack lexiconStack = null;

        for (int i = 0; i < InventoryPlayer.getHotbarSize(); i++) {
            ItemStack stackAt = mc.thePlayer.inventory.getStackInSlot(i);
            if (stackAt != null && stackAt.getItem() instanceof ILexicon && ((ILexicon) stackAt.getItem())
                    .isKnowledgeUnlocked(stackAt, data.entry.getKnowledgeType())) {
                lexiconStack = stackAt;
                lexSlot = i;
                break;
            }
        }

        if (lexSlot > -1) {
            int x = tooltipX - 34;
            GlStateManager.disableDepth();

            Gui.drawRect(x - 4, tooltipY - 4, x + 20, tooltipY + 26, 0x44000000);
            Gui.drawRect(x - 6, tooltipY - 6, x + 22, tooltipY + 28, 0x44000000);

            if (ConfigHandler.useShiftForQuickLookup ? GuiScreen.isShiftKeyDown() : GuiScreen.isCtrlKeyDown()) {
                lexiconLookupTime += ClientTickHandler.delta;

                int cx = x + 8;
                int cy = tooltipY + 8;
                float r = 12;
                float time = 20F;
                float angles = lexiconLookupTime / time * 360F;

                GlStateManager.disableLighting();
                GlStateManager.disableTexture2D();
                GlStateManager.shadeModel(GL11.GL_SMOOTH);
                GlStateManager.enableBlend();
                GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

                VertexBuffer buf = Tessellator.getInstance().getBuffer();
                buf.begin(GL11.GL_TRIANGLE_FAN, DefaultVertexFormats.POSITION_COLOR);

                float a = 0.5F + 0.2F * ((float) Math
                        .cos((double) (ClientTickHandler.ticksInGame + ClientTickHandler.partialTicks) / 10)
                        * 0.5F + 0.5F);
                buf.pos(cx, cy, 0).color(0F, 0.5F, 0F, a).endVertex();

                for (float i = angles; i > 0; i--) {
                    double rad = (i - 90) / 180F * Math.PI;
                    buf.pos(cx + Math.cos(rad) * r, cy + Math.sin(rad) * r, 0).color(0F, 1F, 0F, 1F)
                            .endVertex();
                }

                buf.pos(cx, cy, 0).color(0F, 1F, 0F, 0F).endVertex();
                Tessellator.getInstance().draw();

                GlStateManager.disableBlend();
                GlStateManager.enableTexture2D();
                GlStateManager.shadeModel(GL11.GL_FLAT);

                if (lexiconLookupTime >= time) {
                    mc.thePlayer.inventory.currentItem = lexSlot;
                    Botania.proxy.setEntryToOpen(data.entry);
                    Botania.proxy.setLexiconStack(lexiconStack);
                    mc.thePlayer.closeScreen();
                    ItemLexicon.openBook(mc.thePlayer, lexiconStack, mc.theWorld, false);

                }
            } else
                lexiconLookupTime = 0F;

            mc.getRenderItem().renderItemIntoGUI(new ItemStack(ModItems.lexicon), x, tooltipY);
            GlStateManager.disableLighting();

            font.drawStringWithShadow("?", x + 10, tooltipY + 8, 0xFFFFFFFF);
            GlStateManager.scale(0.5F, 0.5F, 1F);
            boolean mac = Minecraft.IS_RUNNING_ON_MAC;

            mc.fontRendererObj.drawStringWithShadow(
                    TextFormatting.BOLD
                            + (ConfigHandler.useShiftForQuickLookup ? "Shift" : mac ? "Cmd" : "Ctrl"),
                    (x + 10) * 2 - 16, (tooltipY + 8) * 2 + 20, 0xFFFFFFFF);
            GlStateManager.scale(2F, 2F, 1F);

            GlStateManager.enableDepth();
        } else
            lexiconLookupTime = 0F;
    } else
        lexiconLookupTime = 0F;
}