Skip to content

Instantly share code, notes, and snippets.

@mDiyo
Created March 16, 2013 22:39
Show Gist options
  • Save mDiyo/5178634 to your computer and use it in GitHub Desktop.
Save mDiyo/5178634 to your computer and use it in GitHub Desktop.
Basic Item for Icons and Names
public class CraftingItem extends Item
{
public String[] textureNames;
public String[] unlocalizedNames;
public String folder;
public Icon[] icons;
public CraftingItem(int id, String[] names, String[] tex, String f)
{
super(id);
this.setCreativeTab(TConstruct.materialTab);
this.setMaxDamage(0);
this.setHasSubtypes(true);
textureNames = tex;
unlocalizedNames = names;
folder = f;
}
@SideOnly(Side.CLIENT)
public Icon getIconFromDamage(int meta)
{
return icons[meta];
}
@SideOnly(Side.CLIENT)
public void func_94581_a(IconRegister iconRegister)
{
this.icons = new Icon[textureNames.length];
for (int i = 0; i < this.icons.length; ++i)
{
this.icons[i] = iconRegister.func_94245_a("tinker:"+folder+textureNames[i]);
}
}
public String getUnlocalizedName(ItemStack stack)
{
int arr = MathHelper.clamp_int(stack.getItemDamage(), 0, unlocalizedNames.length);
return getUnlocalizedName() + "." +unlocalizedNames[arr];
}
public void getSubItems (int id, CreativeTabs tab, List list)
{
for (int i = 0; i < unlocalizedNames.length; i++)
list.add(new ItemStack(id, 1, i));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment