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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Realizing I was a victim of a scam was a devastating blow. My initial investment of $89,000, driven by dreams of financial success and the buzz surrounding a new cryptocurrency project, turned into a nightmare. The project promised high returns and rapid gains, attracting many eager investors like myself. However, as time passed and inconsistencies began to surface, it became evident that I had made a grave mistake by not thoroughly vetting the brokerage company handling the investment. Feeling anxious and betrayed, I desperately searched for a way to recover my funds. During this frantic search, I stumbled upon the Brigadia Tech Recovery tool through a Facebook post. With little left to lose, I reached out to their team for help. To my relief, they were quick to respond and immediately started recovering my compromised email and regaining access to my cryptocurrency wallets. The team at Brigadia Tech Recovery was incredibly professional and transparent throughout the process. They meticulously traced the digital footprints left by the scammers, employing advanced technological methods to unravel the complex network that had ensnared my funds. Their expertise in cybersecurity and recovery strategies gradually began to turn the tide in my favor. Although the scammers had already siphoned off $30,000 worth of Bitcoin, Brigadia Tech Recovery was relentless in their pursuit. They managed to expose the fraudulent activities of the scam operators, revealing their identities and the mechanisms they used to lure investors. This exposure was crucial not only for my case but also as a warning to the wider community about the perils of unverified investment schemes. As we progressed, it became a race against time to retrieve the remaining $59,000 before the scammers could vanish completely. Each step forward was met with new challenges, as these criminals constantly shifted tactics and moved their digital assets to evade capture. Nonetheless, the determination and skill of the recovery team kept us hopeful. Throughout this ordeal, I learned the hard value of caution and due diligence in investment, especially within the volatile world of cryptocurrency. The experience has been incredibly taxing, both emotionally and financially, but the support and results provided by Brigadia Tech Recovery have been indispensable. Currently, the recovery process is ongoing and I have already received 50% of my money, and while the outcome remains uncertain, the progress made so far gives me hope. The battle to recover the full amount of my investment continues, and with the expertise of Brigadia Tech Recovery, I remain optimistic about the eventual recovery of my funds. Their commitment to their clients and proficiency in handling such complex cases truly sets them apart in the field of cyber recovery.I share this testimony because i am sure someone out there is going through the same issue and devastated mentally by all these fake brokers all around the world,This is the main contact information incase you are interested to recover your lost investments  Email:(Brigadiatechremikeable (@) Proton.Me) Telegram +1 (323) 910-1605)  
    • So I finally downloaded forge for my girl and I, I got hers working no problem but when I did it, I load up and get a black screen with the narration with these codes, I've tried to figure it out but I give up after 3 days, ZERO mods or anything, help would be greatly appreciated. [18:14:48] [main/WARN] [os.ut.FileUtil/]: Configuration conflict: there is more than one oshi.properties file on the classpath: [jar:file:///C:/Users/Night/Desktop/Minecraft%20Modded%20Server/libraries/com/github/oshi/oshi-core/6.4.10/oshi-core-6.4.10.jar!/oshi.properties, jar:file:/C:/Users/Night/Desktop/Minecraft%20Modded%20Server/libraries/com/github/oshi/oshi-core/6.4.10/oshi-core-6.4.10.jar!/oshi.properties, jar:file:///C:/Users/Night/Desktop/Minecraft%20Modded%20Server/libraries/com/github/oshi/oshi-core/6.4.10/oshi-core-6.4.10.jar!/oshi.properties, jar:file:/C:/Users/Night/Desktop/Minecraft%20Modded%20Server/libraries/com/github/oshi/oshi-core/6.4.10/oshi-core-6.4.10.jar!/oshi.properties] [18:14:49] [main/WARN] [os.ut.FileUtil/]: Configuration conflict: there is more than one oshi.architecture.properties file on the classpath: [jar:file:///C:/Users/Night/Desktop/Minecraft%20Modded%20Server/libraries/com/github/oshi/oshi-core/6.4.10/oshi-core-6.4.10.jar!/oshi.architecture.properties, jar:file:/C:/Users/Night/Desktop/Minecraft%20Modded%20Server/libraries/com/github/oshi/oshi-core/6.4.10/oshi-core-6.4.10.jar!/oshi.architecture.properties, jar:file:///C:/Users/Night/Desktop/Minecraft%20Modded%20Server/libraries/com/github/oshi/oshi-core/6.4.10/oshi-core-6.4.10.jar!/oshi.architecture.properties, jar:file:/C:/Users/Night/Desktop/Minecraft%20Modded%20Server/libraries/com/github/oshi/oshi-core/6.4.10/oshi-core-6.4.10.jar!/oshi.architecture.properties] [18:14:49] [main/WARN] [os.dr.wi.pe.PerfmonDisabled/]: Invalid registry value type detected for PerfOS counters. Should be REG_DWORD. Ignoring: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PerfOS\Performance\Disable Performance Counters.
    • Somewhat recently, I wanted to try to get into mod development. I've been following the videos by Kaupenjoe, and the mod has been coming along well... until I tried to add the Create mod as an API for my mod. I followed the guide on Create's Github, but no matter what I tried, it corrupted everything, and either the build failed or Minecraft crashed on startup. I have found absolutely nothing relevant online about the issue, and I don't know what to try next. How do I add Create as dependency? Here is the Github page for my mod.
    • Hello 44STEFAN444
    • I am currently watching a YouTube series. After a few episodes they started adding some custom effects. One of them Is called "Paranoia", and It moves your camera around every few seconds, and another called "Anxiety" where, when you move your camera, It adds a blurred effect to the camera. Another One, called "Fear", moves you randomly. Does anybody have any clue what this mod Is called? (also, as a descriptions for the icons, Paranoia is a pair of eyes looking away, Anxiety Is a Blue Eye, and Fear Is a Ghost).
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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