/**
  * Change attribute format when displayed on item tooltip
  *
  * @param event
  */
 @SubscribeEvent
 public void onItemTooltip(ItemTooltipEvent event) {
   for (String txt : event.toolTip) {
     if (txt.startsWith(EnumChatFormatting.BLUE.toString())) {
       if (txt.contains(attributeNames[0]) || txt.contains(attributeNames[2]))
         event.toolTip.set(
             event.toolTip.indexOf(txt),
             EnumChatFormatting.DARK_GREEN
                 + EnumChatFormatting.getTextWithoutFormattingCodes(txt));
       else if (txt.contains(attributeNames[3]))
         event.toolTip.set(
             event.toolTip.indexOf(txt), EnumChatFormatting.DARK_GREEN + reformat(txt, 3));
       else if (txt.contains(attributeNames[1]))
         event.toolTip.set(event.toolTip.indexOf(txt), EnumChatFormatting.GOLD + reformat(txt, 1));
     }
   }
   if (event.itemStack.getItem() instanceof IBackStabbable) {
     event.toolTip.add(
         EnumChatFormatting.GOLD
             + StatCollector.translateToLocal("attribute.name.weapon.backstab"));
   }
 }
  /**
   * Format into "ratio" attribute localization
   *
   * @param txt current attribute local
   * @param type the attribute index
   * @return the new localization
   */
  private String reformat(String txt, int type) {
    String result = EnumChatFormatting.getTextWithoutFormattingCodes(txt);
    Matcher matcher = FLOAT.matcher(result);
    if (matcher.find()) {
      int start = matcher.start();
      int end = matcher.end();
      String temp = result.substring(start, end).replace(",", ".");
      try {
        float value = Float.valueOf(temp) * 100;
        temp = ".plus.1";
        if (start > 0 && result.charAt(start - 1) == '-') {
          temp = ".take.1";
        }
        return StatCollector.translateToLocalFormatted(
            "attribute.modifier" + temp,
            ItemStack.DECIMALFORMAT.format(value),
            attributeNames[type]);
      } catch (NumberFormatException notNumber) {
        notNumber.printStackTrace();
      }
    }

    return result;
  }
Ejemplo n.º 3
0
 public static int getStringWidth(String s) {
   if (s == null || s.equals("")) return 0;
   return fontRenderer.getStringWidth(EnumChatFormatting.getTextWithoutFormattingCodes(s));
 }
Ejemplo n.º 4
0
 public static String func_178909_a(String p_178909_0_, boolean p_178909_1_) {
   return !p_178909_1_ && !Minecraft.getMinecraft().gameSettings.chatColours
       ? EnumChatFormatting.getTextWithoutFormattingCodes(p_178909_0_)
       : p_178909_0_;
 }