@SuppressWarnings("unchecked")
  @SideOnly(Side.CLIENT)
  protected void renderTooltipAndTransfer(
      GuiBooklet gui,
      ItemStack stack,
      int x,
      int y,
      boolean checkAndTransfer,
      boolean mousePressed) {
    boolean flagBefore = gui.mc.fontRenderer.getUnicodeFlag();
    gui.mc.fontRenderer.setUnicodeFlag(false);

    List list = stack.getTooltip(gui.mc.thePlayer, gui.mc.gameSettings.advancedItemTooltips);

    for (int k = 0; k < list.size(); ++k) {
      if (k == 0) {
        list.set(k, stack.getRarity().rarityColor + (String) list.get(k));
      } else {
        list.set(k, EnumChatFormatting.GRAY + (String) list.get(k));
      }
    }

    if (checkAndTransfer) {
      BookletPage page = BookletUtils.getFirstPageForStack(stack);
      if (page != null && page != this) {
        list.add(
            EnumChatFormatting.GOLD
                + StringUtil.localize("booklet." + ModUtil.MOD_ID_LOWER + ".clickToSeeRecipe"));

        if (mousePressed) {
          BookletUtils.openIndexEntry(
              gui,
              page.getChapter().entry,
              InitBooklet.entries.indexOf(page.getChapter().entry)
                      / GuiBooklet.CHAPTER_BUTTONS_AMOUNT
                  + 1,
              true);
          BookletUtils.openChapter(gui, page.getChapter(), page);
          Minecraft.getMinecraft()
              .getSoundHandler()
              .playSound(
                  PositionedSoundRecord.func_147674_a(
                      new ResourceLocation("gui.button.press"), 1.0F));
        }
      }
    }

    gui.drawHoveringText(list, x, y);

    gui.mc.fontRenderer.setUnicodeFlag(flagBefore);
  }
 /** Called when one of the buttons to open an index or a chapter is pressed */
 public static void handleChapterButtonClick(GuiBooklet booklet, GuiButton button) {
   int place = Util.arrayContains(booklet.chapterButtons, button);
   if (place >= 0) {
     if (booklet.currentIndexEntry != null) {
       if (booklet.currentChapter == null) {
         if (place < booklet.currentIndexEntry.chapters.size()) {
           BookletChapter chap =
               booklet.currentIndexEntry.chapters.get(
                   place
                       + (booklet.chapterButtons.length * booklet.pageOpenInIndex
                           - booklet.chapterButtons.length));
           openChapter(booklet, chap, chap.pages[0]);
         }
       }
     } else {
       if (place < InitBooklet.entries.size()) {
         openIndexEntry(booklet, InitBooklet.entries.get(place), 1, true);
       }
     }
   }
 }