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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I'm trying to start up a 1.16.5 server with a kitchensink modpack that I made, but it won't work and the server keeps crashing. https://paste.ee/p/yBk8L  
    • BITCOIN RECOVERY; The Expertise of Captain WebGenesis in Retrieving scammed Cryptocurrency. I was involved in a bitcoin trading scam, I came across a company website that promised a big return on investment. I was completely sold. The website was excellent, and after much coaxing, I opted to invest 278,000 USD, which unfortunately ended up in the wrong hands. I was frustrated until I sought the counsel of a Crypto Expert  CAPTAIN WEBGENESIS. I had no notion there were techniques for reclaiming stolen funds. I emailed the highly rated expert. I explained my case to Expert and provided all the required information and to my amazement, CAPTAIN WEBGENESIS refunded 90% of my BITCOIN to my wallet within a few working days, which I didn't think was possible. I was startled as well as relieved. With folks like CAPTAIN WEBGENESIS on your side, Crypto recovery is possible
    • I can’t see what the problem is since there seem to be no errors. Are you sure that was everything? The last log seems to be about the graphics library. Maybe that is the issue.  [20:26:39] [main/INFO]: Incorrect key [earlyWindowSkipGLVersions] was corrected from null to [] …… [20:26:41] [main/INFO]: Trying GL version 4.6 looks sus, but it might not be the issue
    • setDeltaMovement only works on the client. this makes the animations smoother. The reason sendSystemMessage works is because you don’t have to constantly send messages from the server to the client, and a little bit of lag is ok. This is a core minecraft mechanism, but you can send custom packets over to the client to set its deltaMovement. The client has to have a way to receive the packets too.
    • The full log is this What do I do? [20:26:39] [main/INFO]: ModLauncher running: args [--username, xYumixks, --version, forge-47.2.32, --gameDir, C:\Users\danil\curseforge\minecraft\Instances\mine guerra 2, --assetsDir, C:\Users\danil\curseforge\minecraft\Install\assets, --assetIndex, 5, --uuid, 979909db94104f33a94abdc77f4cc574, --accessToken, ????????, --clientId, NzI5M2NmYmUtZWI3Ni00MWVlLWFhZTgtODUzMTFjZTVkYTM0, --xuid, 2535414120491579, --userType, msa, --versionType, release, --width, 1024, --height, 768, --quickPlayPath, C:\Users\danil\curseforge\minecraft\Install\quickPlay\java\1715815597218.json, --launchTarget, forgeclient, --fml.forgeVersion, 47.2.32, --fml.mcVersion, 1.20.1, --fml.forgeGroup, net.minecraftforge, --fml.mcpVersion, 20230612.114412] [20:26:39] [main/INFO]: ModLauncher 10.0.9+10.0.9+main.dcd20f30 starting: java version 17.0.8 by Microsoft; OS Windows 11 arch amd64 version 10.0 [20:26:39] [main/WARN]: Configuration file C:\Users\danil\curseforge\minecraft\Instances\mine guerra 2\config\fml.toml is not correct. Correcting [20:26:39] [main/INFO]: Incorrect key [earlyWindowSkipGLVersions] was corrected from null to [] [20:26:39] [main/INFO]: Incorrect key [earlyWindowSquir] was corrected from null to false [20:26:39] [main/INFO]: Incorrect key [earlyWindowShowCPU] was corrected from null to false [20:26:41] [main/INFO]: Loading ImmediateWindowProvider fmlearlywindow [20:26:41] [main/INFO]: Trying GL version 4.6
  • Topics

×
×
  • Create New...

Important Information

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