Esempio n. 1
0
  /** Draws the hover event specified by the given chat component */
  protected void handleComponentHover(
      IChatComponent p_175272_1_, int p_175272_2_, int p_175272_3_) {
    if (p_175272_1_ != null && p_175272_1_.getChatStyle().getChatHoverEvent() != null) {
      HoverEvent hoverevent = p_175272_1_.getChatStyle().getChatHoverEvent();

      if (hoverevent.getAction() == HoverEvent.Action.SHOW_ITEM) {
        ItemStack itemstack = null;

        try {
          NBTBase nbtbase = JsonToNBT.getTagFromJson(hoverevent.getValue().getUnformattedText());

          if (nbtbase instanceof NBTTagCompound) {
            itemstack = ItemStack.loadItemStackFromNBT((NBTTagCompound) nbtbase);
          }
        } catch (NBTException var11) {;
        }

        if (itemstack != null) {
          this.renderToolTip(itemstack, p_175272_2_, p_175272_3_);
        } else {
          this.drawCreativeTabHoveringText(
              EnumChatFormatting.RED + "Invalid Item!", p_175272_2_, p_175272_3_);
        }
      } else if (hoverevent.getAction() == HoverEvent.Action.SHOW_ENTITY) {
        if (this.mc.gameSettings.advancedItemTooltips) {
          try {
            NBTBase nbtbase1 = JsonToNBT.getTagFromJson(hoverevent.getValue().getUnformattedText());

            if (nbtbase1 instanceof NBTTagCompound) {
              List<String> list1 = Lists.<String>newArrayList();
              NBTTagCompound nbttagcompound = (NBTTagCompound) nbtbase1;
              list1.add(nbttagcompound.getString("name"));

              if (nbttagcompound.hasKey("type", 8)) {
                String s = nbttagcompound.getString("type");
                list1.add("Type: " + s + " (" + EntityList.getIDFromString(s) + ")");
              }

              list1.add(nbttagcompound.getString("id"));
              this.drawHoveringText(list1, p_175272_2_, p_175272_3_);
            } else {
              this.drawCreativeTabHoveringText(
                  EnumChatFormatting.RED + "Invalid Entity!", p_175272_2_, p_175272_3_);
            }
          } catch (NBTException var10) {
            this.drawCreativeTabHoveringText(
                EnumChatFormatting.RED + "Invalid Entity!", p_175272_2_, p_175272_3_);
          }
        }
      } else if (hoverevent.getAction() == HoverEvent.Action.SHOW_TEXT) {
        this.drawHoveringText(
            NEWLINE_SPLITTER.splitToList(hoverevent.getValue().getFormattedText()),
            p_175272_2_,
            p_175272_3_);
      } else if (hoverevent.getAction() == HoverEvent.Action.SHOW_ACHIEVEMENT) {
        StatBase statbase = StatList.getOneShotStat(hoverevent.getValue().getUnformattedText());

        if (statbase != null) {
          IChatComponent ichatcomponent = statbase.getStatName();
          IChatComponent ichatcomponent1 =
              new ChatComponentTranslation(
                  "stats.tooltip.type." + (statbase.isAchievement() ? "achievement" : "statistic"),
                  new Object[0]);
          ichatcomponent1.getChatStyle().setItalic(Boolean.valueOf(true));
          String s1 =
              statbase instanceof Achievement ? ((Achievement) statbase).getDescription() : null;
          List<String> list =
              Lists.newArrayList(
                  new String[] {
                    ichatcomponent.getFormattedText(), ichatcomponent1.getFormattedText()
                  });

          if (s1 != null) {
            list.addAll(this.fontRendererObj.listFormattedStringToWidth(s1, 150));
          }

          this.drawHoveringText(list, p_175272_2_, p_175272_3_);
        } else {
          this.drawCreativeTabHoveringText(
              EnumChatFormatting.RED + "Invalid statistic/achievement!", p_175272_2_, p_175272_3_);
        }
      }

      GlStateManager.disableLighting();
    }
  }