<commit_before>package net.silentchaos512.gems.core.util;

import java.util.List;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.silentchaos512.gems.SilentGems;
import net.silentchaos512.gems.item.Gem;
import net.silentchaos512.gems.item.tool.GemAxe;
import net.silentchaos512.gems.item.tool.GemHoe;
import net.silentchaos512.gems.item.tool.GemPickaxe;
import net.silentchaos512.gems.item.tool.GemShovel;
import net.silentchaos512.gems.item.tool.GemSickle;
import net.silentchaos512.gems.item.tool.GemSword;
import net.silentchaos512.gems.material.ModMaterials;

public class ToolHelper {

  public static final String NBT_ROOT = SilentGems.MOD_ID + "Tool";
  public static final String NBT_HEAD_L = "HeadL";
  public static final String NBT_HEAD_M = "HeadM";
  public static final String NBT_HEAD_R = "HeadR";
  public static final String NBT_ROD = "Rod";
  public static final String NBT_ROD_DECO = "RodDeco";
  public static final String NBT_ROD_WOOL = "RodWool";
  public static final String NBT_TIP = "Tip";

  /**
   * Gets the "gem ID", or base material ID for a tool. Note that the regular and supercharged gems have the same ID
   * (ie, regular ruby == supercharged ruby == 0). For gems, this number is in [0, 11]. Other IDs can be found in
   * ModMaterials.
   * 
   * @param tool
   * @return The material ID, or -1 if it can't be determined.
   */
  public static int getToolGemId(ItemStack tool) {

    if (tool == null) {
      return -1;
    }

    Item item = tool.getItem();
    if (item instanceof GemSword) {
      return ((GemSword) item).gemId;
    } else if (item instanceof GemPickaxe) {
      return ((GemPickaxe) item).gemId;
    } else if (item instanceof GemShovel) {
      return ((GemShovel) item).gemId;
    } else if (item instanceof GemAxe) {
      return ((GemAxe) item).gemId;
    } else if (item instanceof GemHoe) {
      return ((GemHoe) item).gemId;
    } else if (item instanceof GemSickle) {
      return ((GemSickle) item).gemId;
    } else {
      LogHelper.debug("Called ToolHelper.getToolGemId on a non-Gems tool!");
      return -1;
    }
  }

  /**
   * Determines whether the tool is "supercharged" or not.
   * 
   * @param tool
   * @return True for supercharged tools (ornate rod) or false for regular tools (wooden rod).
   */
  public static boolean getToolIsSupercharged(ItemStack tool) {

    if (tool == null) {
      return false;
    }

    Item item = tool.getItem();
    if (item instanceof GemSword) {
      return ((GemSword) item).supercharged;
    } else if (item instanceof GemPickaxe) {
      return ((GemPickaxe) item).supercharged;
    } else if (item instanceof GemShovel) {
      return ((GemShovel) item).supercharged;
    } else if (item instanceof GemAxe) {
      return ((GemAxe) item).supercharged;
    } else if (item instanceof GemHoe) {
      return ((GemHoe) item).supercharged;
    } else if (item instanceof GemSickle) {
      return ((GemSickle) item).supercharged;
    } else {
      LogHelper.debug("Called ToolHelper.getToolIsSupercharged on a non-Gems tool!");
      return false;
    }
  }

  /**
   * Gets the material ID for the given material, or -1 if it's not a recognized tool material.
   * 
   * @param material
   * @return
   */
  public static int getIdFromMaterial(ItemStack material) {

    Item item = material.getItem();
    if (item instanceof Gem) {
      return material.getItemDamage() & 0xF;
    } else if (item == Items.flint) {
      return ModMaterials.FLINT_GEM_ID;
    } else if (item == Items.fish) {
      return ModMaterials.FISH_GEM_ID;
    } else {
      return -1;
    }
  }

  // ==========================================================================
  // Tooltip helpers
  // ==========================================================================
  
  public static void addInformation(ItemStack tool, EntityPlayer player, List list, boolean advanced) {

    String line;
    
    // Old NBT warning.
    if (hasOldNBT(tool)) {
      line = LocalizationHelper.getMiscText("Tool.OldNBT1");
      list.add(EnumChatFormatting.DARK_BLUE + line);
      line = LocalizationHelper.getMiscText("Tool.OldNBT2");
      list.add(EnumChatFormatting.DARK_BLUE + line);
    }
    
    // TODO More tooltip stuff!
  }

  // ==========================================================================
  // NBT helper methods
  // ==========================================================================

  private static int getTag(String name, ItemStack tool) {

    // Create tag compound, if needed.
    if (tool.stackTagCompound == null) {
      tool.setTagCompound(new NBTTagCompound());
    }

    // Create root tag, if needed.
    if (!tool.stackTagCompound.hasKey(NBT_ROOT)) {
      tool.stackTagCompound.setTag(NBT_ROOT, new NBTTagCompound());
    }

    // Get the requested value.
    NBTTagCompound tags = (NBTTagCompound) tool.stackTagCompound.getTag(NBT_ROOT);
    if (!tags.hasKey(name)) {
      return -1;
    }<commit_msg>Added tipped upgrade to tooltips<commit_after>package net.silentchaos512.gems.core.util;

import java.util.List;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.silentchaos512.gems.SilentGems;
import net.silentchaos512.gems.item.Gem;
import net.silentchaos512.gems.item.tool.GemAxe;
import net.silentchaos512.gems.item.tool.GemHoe;
import net.silentchaos512.gems.item.tool.GemPickaxe;
import net.silentchaos512.gems.item.tool.GemShovel;
import net.silentchaos512.gems.item.tool.GemSickle;
import net.silentchaos512.gems.item.tool.GemSword;
import net.silentchaos512.gems.material.ModMaterials;

public class ToolHelper {

  public static final String NBT_ROOT = SilentGems.MOD_ID + "Tool";
  public static final String NBT_HEAD_L = "HeadL";
  public static final String NBT_HEAD_M = "HeadM";
  public static final String NBT_HEAD_R = "HeadR";
  public static final String NBT_ROD = "Rod";
  public static final String NBT_ROD_DECO = "RodDeco";
  public static final String NBT_ROD_WOOL = "RodWool";
  public static final String NBT_TIP = "Tip";

  /**
   * Gets the "gem ID", or base material ID for a tool. Note that the regular and supercharged gems have the same ID
   * (ie, regular ruby == supercharged ruby == 0). For gems, this number is in [0, 11]. Other IDs can be found in
   * ModMaterials.
   * 
   * @param tool
   * @return The material ID, or -1 if it can't be determined.
   */
  public static int getToolGemId(ItemStack tool) {

    if (tool == null) {
      return -1;
    }

    Item item = tool.getItem();
    if (item instanceof GemSword) {
      return ((GemSword) item).gemId;
    } else if (item instanceof GemPickaxe) {
      return ((GemPickaxe) item).gemId;
    } else if (item instanceof GemShovel) {
      return ((GemShovel) item).gemId;
    } else if (item instanceof GemAxe) {
      return ((GemAxe) item).gemId;
    } else if (item instanceof GemHoe) {
      return ((GemHoe) item).gemId;
    } else if (item instanceof GemSickle) {
      return ((GemSickle) item).gemId;
    } else {
      LogHelper.debug("Called ToolHelper.getToolGemId on a non-Gems tool!");
      return -1;
    }
  }

  /**
   * Determines whether the tool is "supercharged" or not.
   * 
   * @param tool
   * @return True for supercharged tools (ornate rod) or false for regular tools (wooden rod).
   */
  public static boolean getToolIsSupercharged(ItemStack tool) {

    if (tool == null) {
      return false;
    }

    Item item = tool.getItem();
    if (item instanceof GemSword) {
      return ((GemSword) item).supercharged;
    } else if (item instanceof GemPickaxe) {
      return ((GemPickaxe) item).supercharged;
    } else if (item instanceof GemShovel) {
      return ((GemShovel) item).supercharged;
    } else if (item instanceof GemAxe) {
      return ((GemAxe) item).supercharged;
    } else if (item instanceof GemHoe) {
      return ((GemHoe) item).supercharged;
    } else if (item instanceof GemSickle) {
      return ((GemSickle) item).supercharged;
    } else {
      LogHelper.debug("Called ToolHelper.getToolIsSupercharged on a non-Gems tool!");
      return false;
    }
  }

  /**
   * Gets the material ID for the given material, or -1 if it's not a recognized tool material.
   * 
   * @param material
   * @return
   */
  public static int getIdFromMaterial(ItemStack material) {

    Item item = material.getItem();
    if (item instanceof Gem) {
      return material.getItemDamage() & 0xF;
    } else if (item == Items.flint) {
      return ModMaterials.FLINT_GEM_ID;
    } else if (item == Items.fish) {
      return ModMaterials.FISH_GEM_ID;
    } else {
      return -1;
    }
  }

  // ==========================================================================
  // Tooltip helpers
  // ==========================================================================
  
  public static void addInformation(ItemStack tool, EntityPlayer player, List list, boolean advanced) {

    String line;
    
    // Old NBT warning.
    if (hasOldNBT(tool)) {
      line = LocalizationHelper.getMiscText("Tool.OldNBT1");
      list.add(EnumChatFormatting.DARK_BLUE + line);
      line = LocalizationHelper.getMiscText("Tool.OldNBT2");
      list.add(EnumChatFormatting.DARK_BLUE + line);
    }
    
    // Tipped upgrade
    int tip = getToolHeadTip(tool);
    if (tip == 1) {
      line = LocalizationHelper.getMiscText("Tool.IronTipped");
      list.add(EnumChatFormatting.WHITE + line);
    } else if (tip == 2) {
      line = LocalizationHelper.getMiscText("Tool.DiamondTipped");
      list.add(EnumChatFormatting.AQUA + line);
    }
  }

  // ==========================================================================
  // NBT helper methods
  // ==========================================================================

  private static int getTag(String name, ItemStack tool) {

    // Create tag compound, if needed.
    if (tool.stackTagCompound == null) {
      tool.setTagCompound(new NBTTagCompound());
    }

    // Create root tag, if needed.
    if (!tool.stackTagCompound.hasKey(NBT_ROOT)) {
      tool.stackTagCompound.setTag(NBT_ROOT, new NBTTagCompound());
    }

    // Get the requested value.
    NBTTagCompound tags = (NBTTagCompound) tool.stackTagCompound.getTag(NBT_ROOT);
    if (!tags.hasKey(name)) {
      return -1;
    }
{'fraction_non_alphanumeric': 0.15949248120300752, 'fraction_numerical': 0.008270676691729323, 'mean_word_length': 3.343265306122449, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5828114', 'n_tokens_mistral': 3552, 'n_tokens_neox': 3345, 'n_words': 876}