TechReborn/src/main/java/techreborn/items/ItemIngots.java

94 lines
2.4 KiB
Java
Raw Normal View History

2015-04-11 21:46:55 +02:00
package techreborn.items;
import java.security.InvalidParameterException;
import java.util.List;
2015-04-11 21:46:55 +02:00
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.init.ModItems;
2015-04-15 17:23:12 +02:00
public class ItemIngots extends Item {
public static ItemStack getIngotByName(String name, int count)
{
for (int i = 0; i < types.length; i++) {
if (types[i].equalsIgnoreCase(name)) {
return new ItemStack(ModItems.ingots, count, i);
}
}
throw new InvalidParameterException("The ingot " + name + " could not be found.");
}
public static ItemStack getIngotByName(String name)
{
return getIngotByName(name, 1);
}
2015-04-24 15:20:09 +02:00
public static final String[] types = new String[]
2015-05-04 09:02:01 +02:00
{ "aluminum", "antimony", "batteryAlloy", "redAlloy", "blueAlloy", "brass",
"bronze", "cadmium", "chrome", "copper", "cupronickel", "electrum", "indium",
"invar", "iridium", "kanthal", "lead", "lodestone", "magnalium", "nichrome", "nickel",
"osmium", "platinum", "silver", "steel", "tellurium", "tin", "titanium",
"tungsten", "hotTungstensteel", "tungstensteel", "zinc" };
2015-04-15 17:23:12 +02:00
2015-04-24 15:20:09 +02:00
private IIcon[] textures;
2015-04-15 17:23:12 +02:00
2015-04-24 15:20:09 +02:00
public ItemIngots()
{
setCreativeTab(TechRebornCreativeTabMisc.instance);
setHasSubtypes(true);
setUnlocalizedName("techreborn.ingot");
}
2015-04-15 17:23:12 +02:00
2015-04-24 15:20:09 +02:00
@Override
// Registers Textures For All Dusts
public void registerIcons(IIconRegister iconRegister)
{
textures = new IIcon[types.length];
2015-04-15 17:23:12 +02:00
2015-04-24 15:20:09 +02:00
for (int i = 0; i < types.length; ++i)
{
textures[i] = iconRegister.registerIcon("techreborn:" + "ingot/"
+ types[i] + "Ingot");
}
}
2015-04-11 21:46:55 +02:00
2015-04-24 15:20:09 +02:00
@Override
// Adds Texture what match's meta data
public IIcon getIconFromDamage(int meta)
{
if (meta < 0 || meta >= textures.length)
{
meta = 0;
}
2015-04-11 21:46:55 +02:00
2015-04-24 15:20:09 +02:00
return textures[meta];
}
2015-04-11 21:46:55 +02:00
2015-04-24 15:20:09 +02:00
@Override
// gets Unlocalized Name depending on meta data
public String getUnlocalizedName(ItemStack itemStack)
{
int meta = itemStack.getItemDamage();
if (meta < 0 || meta >= types.length)
{
meta = 0;
}
2015-04-11 21:46:55 +02:00
2015-04-24 15:20:09 +02:00
return super.getUnlocalizedName() + "." + types[meta];
}
2015-04-11 21:46:55 +02:00
2015-04-24 15:20:09 +02:00
// Adds Dusts SubItems To Creative Tab
public void getSubItems(Item item, CreativeTabs creativeTabs, List list)
{
for (int meta = 0; meta < types.length; ++meta)
{
list.add(new ItemStack(item, 1, meta));
}
}
2015-04-11 21:46:55 +02:00
}