package squeek.wailaharvestability.helpers;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import squeek.wailaharvestability.ModWailaHarvestability;
import squeek.wailaharvestability.proxy.ProxyIguanaTweaks;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;

public class StringHelper
{

	public static Class<?> HarvestLevels = null;
	public static Method getHarvestLevelName = null;
	static
	{
		try
		{
			HarvestLevels = Class.forName("tconstruct.library.util.HarvestLevels");
			getHarvestLevelName = HarvestLevels.getDeclaredMethod("getHarvestLevelName", int.class);
		}
		catch (Exception e)
		{
		}
	}

	// Taken from tconstruct.client.gui.ToolStationGui
	public static String getHarvestLevelName(int num)
	{
		if (getHarvestLevelName != null)
		{
			try
			{
				return (String) getHarvestLevelName.invoke(null, num);
			}
			catch (Exception e)
			{
			}
		}
		else
		{
			if (ModWailaHarvestability.hasIguanaTweaks)
				return ProxyIguanaTweaks.getHarvestLevelName(num);

			String unlocalized = "gui.partcrafter.mining" + (num + 1);
			String localized = StringHelper.getLocalizedString(unlocalized);
			if (!unlocalized.equals(localized))
				return localized;
		}
		return String.valueOf(num);
	}

	// for TCon version < 1.5.3
	public static HashMap<String, String> localizationAlternatives = new HashMap<String, String>();
	static
	{
		localizationAlternatives.put("gui.partcrafter.mining1", "Stone");
		localizationAlternatives.put("gui.partcrafter.mining2", "Iron");
		localizationAlternatives.put("gui.partcrafter.mining3", "Redstone");
		localizationAlternatives.put("gui.partcrafter.mining4", "Obsidian");
		localizationAlternatives.put("gui.partcrafter.mining5", "Cobalt");
		localizationAlternatives.put("gui.partcrafter.mining6", "Atlarus");
		localizationAlternatives.put("gui.partcrafter.mining7", "7");
		localizationAlternatives.put("gui.partcrafter.mining8", "8");
		localizationAlternatives.put("gui.toolstation15", "Mining Level: ");
	}

	public static String getLocalizedString(String unlocalized)
	{
		if (unlocalized.equals("gui.partcrafter.mining6"))
			return localizationAlternatives.get(unlocalized);

		String localized = StatCollector.translateToLocal(unlocalized);
		if (localized.equals(unlocalized))
		{
			localized = localizationAlternatives.get(unlocalized);

			if (localized == null)
				localized = unlocalized;
		}
		return localized;
	}

	public static String concatenateStringList(List<String> strings, String separator)
	{
		StringBuilder sb = new StringBuilder();
		String sep = "";
		for (String s : strings)
		{
			sb.append(sep).append(s);
			sep = separator;
		}
		return sb.toString();
	}

	public static String stripFormatting(String str)
	{
		return EnumChatFormatting.getTextWithoutFormattingCodes(str);
	}
}

@@ -75,34 +75,8 @@
 od;%0A
-import java.util.HashMap;%0A
 impo
@@ -654,60 +654,8 @@
 %09%7D%0A%0A
-%09// Taken from tconstruct.client.gui.ToolStationGui%0A
 %09pub
@@ -860,22 +860,11 @@
 %09%09%7D%0A
-%09%09else%0A%09%09%7B
 %0A%09%09
-%09
 if (
@@ -903,17 +903,16 @@
 Tweaks)%0A
-%09
 %09%09%09retur
@@ -958,17 +958,16 @@
 (num);%0A%0A
-%09
 %09%09String
@@ -986,1382 +986,187 @@
  = %22
-gui.partcrafter.mining%22 + (num + 1);%0A%09%09%09String localized = StringHelper.getLocalizedString(unlocalized);%0A%09%09%09if (!unlocalized.equals(localized))%0A%09%09%09%09return localized;%0A%09%09%7D%0A%09%09return String.valueOf(num);%0A%09%7D%0A%0A%09// for TCon version %3C 1.5.3%0A%09public static HashMap%3CString, String%3E localizationAlternatives = new HashMap%3CString, String%3E();%0A%09static%0A%09%7B%0A%09%09localizationAlternatives.put(%22gui.partcrafter.mining1%22, %22Stone%22);%0A%09%09localizationAlternatives.put(%22gui.partcrafter.mining2%22, %22Iron%22);%0A%09%09localizationAlternatives.put(%22gui.partcrafter.mining3%22, %22Redstone%22);%0A%09%09localizationAlternatives.put(%22gui.partcrafter.mining4%22, %22Obsidian%22);%0A%09%09localizationAlternatives.put(%22gui.partcrafter.mining5%22, %22Cobalt%22);%0A%09%09localizationAlternatives.put(%22gui.partcrafter.mining6%22, %22Atlarus%22);%0A%09%09localizationAlternatives.put(%22gui.partcrafter.mining7%22, %227%22);%0A%09%09localizationAlternatives.put(%22gui.partcrafter.mining8%22, %228%22);%0A%09%09localizationAlternatives.put(%22gui.toolstation15%22, %22Mining Level: %22);%0A%09%7D%0A%0A%09public static String getLocalizedString(String unlocalized)%0A%09%7B%0A%09%09if (unlocalized.equals(%22gui.partcrafter.mining6%22))%0A%09%09%09return localizationAlternatives.get(unlocalized);%0A%0A%09%09String localized = StatCollector.translateToLocal(unlocalized);%0A%09%09if (localized.equals(unlocalized))%0A%09%09%7B%0A%09%09%09localized = localizationAlternatives.get(unlocalized);%0A%0A%09%09%09if (localized == null)%0A%09%09%09%09localized = unlocalized;%0A%09%09%7D%0A%09%09return localized
+wailaharvestability.harvestlevel%22 + (num + 1);%0A%0A%09%09if (StatCollector.canTranslate(unlocalized))%0A%09%09%09return StatCollector.translateToLocal(unlocalized);%0A%0A%09%09return String.valueOf(num)
 ;%0A%09%7D

Remove obsolete TiC backwards compatibility code * Fixes hard-coded Atlarus localization * Changes fallback localization to be Waila Harvestability specific (wailaharvestability.harvestlevel<num>)