I've been putting together a mod that emulates dyed leather armor, using the same setColor() function, and now need to create crafting recipes for each piece of armor. Right now I'm trying to associate a metadata with each colored armor, however the result of the recipes always ends up being a brown colored armor piece no matter what color the armor was before and no matter what dye was used. Additionally, every piece of armor has a dyed tool tip, except for the crafting result which has no tool tip. I'll post the armor and crafting recipe code below.
Armor Class
public class MyItemArmor extends ItemArmor {
public MyItemArmor(String unlocalizedName, ArmorMaterial material, int renderIndex, int type) {
super(material, renderIndex, type);
this.setUnlocalizedName(unlocalizedName);
this.setHasSubtypes(false);
this.setMaxDamage(0);
}
@Override
public String getUnlocalizedName(ItemStack stack) {
return super.getUnlocalizedName();
}
int[] dyeints = {1973019, 11743532, 3887386, 5320730, 2437522, 8073150, 2651799, 11250603, 4408131,
14188952, 4312372, 14602026, 6719955, 12801229, 15435844};
String[] dyestrings = {"BLACK", "RED", "GREEN","BROWN","BLUE","PURPLE"};
@Override
public void getSubItems(Item itemIn, CreativeTabs tab, List subItems) {
for (int i = 0; i < 14; i++) {
ItemStack stack = new ItemStack(itemIn, 1, i);
ItemArmor itemArmor = (ItemArmor)stack.getItem();
subItems.add(stack);
if (i != 0) itemArmor.setColor(stack, dyeints[i]);
ItemRenderRegister.reg(itemArmor, i);
}
}
@Override
public int getColor(ItemStack stack)
{
NBTTagCompound nbttagcompound = stack.getTagCompound();
if (nbttagcompound != null)
{
NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");
if (nbttagcompound1 != null && nbttagcompound1.hasKey("color", 3))
{
return nbttagcompound1.getInteger("color");
}
}
return 10511680;
}
@Override
public boolean hasColor(ItemStack stack)
{
return true;
}
@Override
public void setColor(ItemStack stack, int color) {
NBTTagCompound nbttagcompound = stack.getTagCompound();
if (nbttagcompound == null)
{
nbttagcompound = new NBTTagCompound();
stack.setTagCompound(nbttagcompound);
}
NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");
if (!nbttagcompound.hasKey("display", 10))
{
nbttagcompound.setTag("display", nbttagcompound1);
}
nbttagcompound1.setInteger("color", color);
}
}
Crafting Class
public final class ModCrafting {
public static void initCrafting() {
//GameRegistry.addShapelessRecipe(new ItemStack(new ItemStack(itemArmor,1 , i).getItem()), new Object[]
//{itemIn, new ItemStack(Items.dye, 1, i)});
for (int color=0; color<16; color++) {
for (int base=0; base < 16; base++) {
GameRegistry.addShapelessRecipe(new ItemStack(MainMod.clothBoots, 1 , color),
new ItemStack(MainMod.clothBoots, 1, base), new ItemStack(Items.dye, 1, color));
}
}
for (int color=0; color<16; color++) {
for (int base=0; base < 16; base++) {
GameRegistry.addShapelessRecipe(new ItemStack(MainMod.clothHat, 1 , color),
new ItemStack(MainMod.clothHat, 1, base), new ItemStack(Items.dye, 1, color));
}
}
for (int color=0; color<16; color++) {
for (int base=0; base < 16; base++) {
GameRegistry.addShapelessRecipe(new ItemStack(MainMod.clothShirt, 1 , color),
new ItemStack(MainMod.clothShirt, 1, base), new ItemStack(Items.dye, 1, color));
}
}
for (int color=0; color<16; color++) {
for (int base=0; base < 16; base++) {
GameRegistry.addShapelessRecipe(new ItemStack(MainMod.clothPants, 1 , color),
new ItemStack(MainMod.clothPants, 1, base), new ItemStack(Items.dye, 1, color));
}
}
}
}
Snippet of main
public static ArmorMaterial CLOTH = EnumHelper.addArmorMaterial("CLOTH", "mainmod:cloth", 0, new int[] {0, 0, 0, 0}, 0);
public static Item clothHat;
public static Item clothShirt;
public static Item clothPants;
public static Item clothBoots;
public static CreativeTabs tabMainMod = new CreativeTabsMainMod("MainMod");
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
GameRegistry.registerItem(clothHat = new MyItemArmor("cloth_Hat", CLOTH, 1, 0).setCreativeTab(tabMainMod), "cloth_Hat");
GameRegistry.registerItem(clothShirt = new MyItemArmor("cloth_Shirt", CLOTH, 1, 1).setCreativeTab(tabMainMod), "cloth_Shirt");
GameRegistry.registerItem(clothPants = new MyItemArmor("cloth_Pants", CLOTH, 2, 2).setCreativeTab(tabMainMod), "cloth_Pants");
GameRegistry.registerItem(clothBoots = new MyItemArmor("cloth_Boots", CLOTH, 1, 3).setCreativeTab(tabMainMod), "cloth_Boots");
}