Jump to content

[1.8] [SOLVED] Dyed Armor crafting recipe


ADaringEnchilada

Recommended Posts

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");

}

Link to comment
Share on other sites

I have, in the MyItemArmor class you'll see some code about set/get/has color using nbbttagcompound, that's ripped straight from the code relevant to leather armor and overriden so it'll accept non leather armor. I would like to find how leather armor that is dyed is crafted, but the only relevant class I can find seems to be RecipesArmorDyes and I'm not experienced enough to take an meaningful information away from it. It would appear that leather armor is not traditionally crafted, however the contents of that class are beyond my understanding.

Link to comment
Share on other sites

Another solution is to implement an IRecipe for your items, then all you have to do to add all of the dye recipes is this:

CraftingManager.getInstance().getRecipeList().add(new YourIRecipeImplementation());
CraftingManager.getInstance().addRecipe(new ItemStack(YourItems.yourItem)," X ", " X ", "XXX", 'X', new ItemStack(Blocks.wool, 1, OreDictionary.WILDCARD_VALUE));
// or whatever the recipe is

Granted, the IRecipe implementation for dyes is a bit more verbose than your solution, but it ends up looking cleaner, imo, and you could easily generalize it to account for any variety of items by creating an IDyable interface or some such.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.