Jump to content

[Solved-ish]Crafting Recipe: Returning an Item


Joeman7

Recommended Posts

I am currently attempting to add bacon to minecraft by adding a recipe using shears and a raw pork chop. I have successfully added the recipe and allowed it to return the shears to my inventory after crafting by using .setContainerItem, but I would like to be able to use shears of any durability and for the recipe to slightly lower the durability of the shears each time you craft. Thank you for your consideration.

 

Here are the source files.

 

package breakfast.craft;

// This Import list will grow longer with each additional tutorial.
// It's not pruned between full class postings, unlike other tutorial code.
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemSeeds;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.Mod;
//import cpw.mods.fml.common.Mod.Init;       //Used in 1.5.2 and before
import cpw.mods.fml.common.Mod.Instance;
//import cpw.mods.fml.common.Mod.PostInit;   //Used in 1.5.2 and before
//import cpw.mods.fml.common.Mod.PreInit;    //Used in 1.5.2 and before
import cpw.mods.fml.common.Mod.EventHandler; //Added for 1.6.X
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import net.minecraft.item.crafting.FurnaceRecipes ;
import net.minecraft.item.ItemFood;
import net.minecraft.creativetab.*;
import net.minecraftforge.common.MinecraftForge;
import breakfast.craft.Items;

@Mod(modid="breakfastCraft", name="Breakfast Craft", version="0.0.0")
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
public class Breakfast {
        
        
        @Instance("Breakfast")
        public static Breakfast instance;
        
        public static Item syrup = (new Food(5000, 1)).setUnlocalizedName("syrup").setCreativeTab(CreativeTabs.tabFood).func_111206_d("breakfastcraft:Syrup");
        public static Item eggyBread = (new Food(5001, 2)).setUnlocalizedName("eggyBread").setCreativeTab(CreativeTabs.tabFood).func_111206_d("breakfastcraft:EggyBread");
        public static Item pancakeBatter = (new Food(5002, 2)).setUnlocalizedName("pancakeBatter").setCreativeTab(CreativeTabs.tabFood).func_111206_d("breakfastcraft:PancakeBatter");
        public static Item waffleBatter = (new Food(5003, 2)).setUnlocalizedName("waffleBatter").setCreativeTab(CreativeTabs.tabFood).func_111206_d("breakfastcraft:WaffleBatter");
        public static Item frenchToast = (new Food(5004, 6)).setUnlocalizedName("frenchToast").setCreativeTab(CreativeTabs.tabFood).func_111206_d("breakfastcraft:FrenchToast");
        public static Item frenchToastSyrup = (new Food(5005, ).setUnlocalizedName("frenchToast").setCreativeTab(CreativeTabs.tabFood).func_111206_d("breakfastcraft:FrenchToastSyrup");
        public static Item pancake = (new Food(5006, 10)).setUnlocalizedName("pancake").setCreativeTab(CreativeTabs.tabFood).func_111206_d("breakfastcraft:Pancake");
        public static Item pancakeSyrup = (new Food(5007, 12)).setUnlocalizedName("pancakeSyrup").setCreativeTab(CreativeTabs.tabFood).func_111206_d("breakfastcraft:PancakeSyrup");
        public static Item waffle = (new Food(5008, ).setUnlocalizedName("waffle").setCreativeTab(CreativeTabs.tabFood).func_111206_d("breakfastcraft:Waffle");
        public static Item waffleSyrup = (new Food(5009, 10)).setUnlocalizedName("waffleSyrup").setCreativeTab(CreativeTabs.tabFood).func_111206_d("breakfastcraft:WaffleSyrup");
        public static Item baconRaw = (new Food(5010, 10)).setUnlocalizedName("baconRaw").setCreativeTab(CreativeTabs.tabFood).func_111206_d("breakfastcraft:BaconRaw");
        
        
        
        @SidedProxy(clientSide="breakfast.craft.client.ClientProxy",
                        serverSide="breakfast.craft.CommonProxy")
        public static CommonProxy proxy;
        
        @EventHandler
        public void preInit(FMLPreInitializationEvent event) {
                // Stub Method
        }
        
        @EventHandler
        public void load(FMLInitializationEvent event) {
        	ItemStack eggStack = new ItemStack(Item.egg);
        	ItemStack breadStack = new ItemStack(Item.bread);
        	ItemStack bucketMilkStack = new ItemStack(Item.bucketMilk);
        	ItemStack wheatStack = new ItemStack(Item.wheat);
        	ItemStack sugarStack = new ItemStack(Item.sugar);
        	ItemStack syrupStack = new ItemStack(syrup);
        	ItemStack reedStack = new ItemStack(Item.reed);
        	ItemStack porkRawStack = new ItemStack(Item.porkRaw);
        	ItemStack shearStack = new ItemStack(Item.shears);
        	GameRegistry.addShapelessRecipe(new ItemStack(eggyBread),
        	                eggStack, breadStack, eggStack);
        	GameRegistry.addRecipe(new ItemStack(pancakeBatter), "xxx", "yzy", "vzv", 'x', wheatStack, 'y', sugarStack, 'v', eggStack, 'z', bucketMilkStack);
        	GameRegistry.addRecipe(new ItemStack(waffleBatter), "xxx", "yyy", "vzv", 'x', wheatStack, 'y', sugarStack, 'v', eggStack, 'z', bucketMilkStack);
        	GameRegistry.addSmelting(eggyBread.itemID, new ItemStack(frenchToast), 0.1f);
        	GameRegistry.addSmelting(pancakeBatter.itemID, new ItemStack(pancake), 0.1f);
        	GameRegistry.addSmelting(waffleBatter.itemID, new ItemStack(waffle), 0.1f);
        	GameRegistry.addShapelessRecipe(new ItemStack(frenchToastSyrup),
                syrup, frenchToast);
        	GameRegistry.addShapelessRecipe(new ItemStack(pancakeSyrup),
                syrup, pancake);
        	GameRegistry.addShapelessRecipe(new ItemStack(waffleSyrup),
                syrup, waffle);
        	GameRegistry.addShapelessRecipe(new ItemStack(syrup),
        			reedStack, reedStack, reedStack, reedStack, reedStack, reedStack);
        	GameRegistry.addShapelessRecipe(new ItemStack(baconRaw),
        			porkRawStack, Item.shears.setContainerItem(Item.shears));
        	LanguageRegistry.addName(eggyBread, "Eggy Bread");
        	LanguageRegistry.addName(pancakeBatter, "Pancake Batter");
        	LanguageRegistry.addName(waffleBatter, "Waffle Batter");
            LanguageRegistry.addName(pancake, "Pancake");
            LanguageRegistry.addName(frenchToast, "French Toast");
            LanguageRegistry.addName(waffle, "Waffle");
            LanguageRegistry.addName(syrup, "Syrup");
            LanguageRegistry.addName(frenchToastSyrup, "French Toast");
            LanguageRegistry.addName(pancakeSyrup, "Pancake");
            LanguageRegistry.addName(waffleSyrup, "Waffle");
            LanguageRegistry.addName(baconRaw, "Raw Bacon");
                
        }
        
        @EventHandler
        public void postInit(FMLPostInitializationEvent event) {
                // Stub Method
        }
}

Link to comment
Share on other sites

You can add OreDictionary.WILDCARD_VALUE to the shears ItemStack itemdamage. This way any shears will do.

AFAIK, any item in a recipe will get damaged/removed when taking out the recipe output. It may depend on how you implemented the ContainerItem thing though.

Link to comment
Share on other sites

Adding the wildcard value and reorganizing the ItemStack stuff (Originally I used the item itself in the crafting recipe, but now I am using the itemStack) did allow any shears to work in the crafting recipe, thanks! However, I am still unsure how to make the recipe damage the shears. Currently, if I use fully repaired shears and craft it with raw pork, I get raw bacon. However, it returns me shears undamaged. When I use already damaged shears and craft them in the recipe for bacon, it gives me raw bacon, but it returns me fully repaired shears. Currently with the .setContainerItem, I just have it set it to regular shears. It doesn't seem to allow me to add extra parameters to the .setContainerItem(Item.shears) and it does not except item stacks. Is there any way to fix it? Or is there an alternative method to returning shears? Thanks for your help.

 

Here's new relevant source:

        	ItemStack porkRawStack = new ItemStack(Item.porkRaw);
        	ItemStack shearStack = new ItemStack(Item.shears.setContainerItem(Item.shears), 1, OreDictionary.WILDCARD_VALUE);
               GameRegistry.addShapelessRecipe(new ItemStack(baconRaw),
        			porkRawStack, shearStack);

Link to comment
Share on other sites

I don't know if a simple way to accept a container item of any durability and return a lower durability version, however, you can make the recipe behave any way you want before and after crafting by making your own class and extending net.minecraft.item.crafting.IRecipe and using your own logic, then registering the completed recipe.

Link to comment
Share on other sites

How else can I allow it to return the shears though? I would not like to have to spend 2 iron every time I need bacon...

Do baconRaw.setContainerItem(Item.shears) then.

 

IRecipe is mostly to recognize a complex recipe that wouldn't be handled by Minecraft (like say, with ItemStack NBTTagCompound).

It doesn't tell what damage to apply to which item.

You need a ICraftingHandler to do that.

Link to comment
Share on other sites

Goto Link, I think you are missing the point. I am trying to make shears and pork craft bacon. The whole point of .setContainerItem for me was so I didn't loose the shears when I craft bacon. If I use .setContainerItem(Item.Shears) for bacon, it would return shears when I craft with bacon, opposite of my goal. I either need to modify/extend minecrafts files to allow .setContainerItem to except parameters, or I need to find an alternative method to return shears to the crafting table or my inventory.

Link to comment
Share on other sites

Since I am rather new to modding minecraft with forge, and to using java in general, I have decided to just create a knife that does not have a durability so I can easily just use .setContainerItem to make it return to me each time I craft. Thank you both for all of your help.

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.