package net.minecraft.src;

import java.util.ArrayList;


public class PCco_Utils {

	
	/** Tests if a given stack is a fuel */
	public static boolean isFuel(ItemStack itemstack) {
		if (itemstack == null) { 
			return false;
		}
	
		int i = itemstack.getItem().shiftedIndex;
	
		return (i < 256 && Block.blocksList[i] != null && Block.blocksList[i].blockMaterial == Material.wood)
				|| (i == Item.stick.shiftedIndex)
				|| (i == Item.coal.shiftedIndex)
				|| (i == Item.bucketLava.shiftedIndex)
				|| (i == Block.sapling.blockID)
				|| ModLoader.addAllFuel(i, itemstack.getItemDamage()) > 0;
	}
	

	/** Tests if a given stack can be smelted */
	public static boolean isSmeltable(ItemStack itemstack) {
		if (itemstack == null || FurnaceRecipes.smelting().getSmeltingResult(itemstack.getItem().shiftedIndex) == null) {
			return false;
		}
		return true;
	}
	

	/**
	 * Is "reverse placing key" pressed?
	 * @return true if placing is reversed.
	 */
	public static boolean isPlacingReversed(){
		return mod_PCcore.conf.isKeyDown(mod_PCcore.pk_ReverseKey);
	}
	

	/** Sends chat message onto the screen. Parameters MESSAGE, CLEAR SCREEN */
	public static void chatMsg(String msg, boolean clear) {
		if (clear) ModLoader.getMinecraftInstance().ingameGUI.clearChatMessages();
		ModLoader.getMinecraftInstance().thePlayer.addChatMessage(msg);
	}
	

	/**
	 * Hide item from TMI if TMI is present.
	 * @param id item or block id
	 */
	public static void TMI_hideId(int id) {
		try {
			TMIItemInfo.hideItem(id);
		} catch (Throwable t) {
		}
	}
	

	/**
	 * Set max damage listed in TMI if TMI is present. 
	 * @param id item ID
	 * @param damage max damage / metadata
	 */
	public static void TMI_maxDamage(int id, int damage) {
		try {
			TMIItemInfo.setMaxDamageException(id, damage);
		} catch (Throwable t) {
		}
	}
	

	/**
	 * Set item metadata range in TMI if TMI is present
	 * @param id item ID
	 * @param from lower meta boundary
	 * @param to upper meta boundary
	 */
	public static void TMI_rangeDamage(int id, int from, int to) {
		try {
			TMIItemInfo.showItemWithDamageRange(id, from, to);
		} catch (Throwable t) {
		}
	}
	

	/**
	 * Set alternative name in TMI, if item has no name by default
	 * @param id item ID
	 * @param meta metadata
	 * @param s the alt name
	 */
	public static void TMI_setAltName(int id, int meta, String s) {
		try {
			TMIItemInfo.addFallbackName(id, meta, s);
		} catch (Throwable t) {
		}
	}
	
	
	public Integer[] parseIntList(String list, String delimiter){
		if(list == null) return null;
		String[] parts = list.split(delimiter);
		
		ArrayList<Integer> intList = new ArrayList<Integer>();
		
		for(String part : parts){
			try{
				intList.add(Integer.parseInt(part));				
			}catch(NumberFormatException e){				
			}
		}
		
		return intList.toArray(new Integer[intList.size()]);
		
	}

}
