Jump to content

[1.7.10] [SOLVED] How do i add durable items to my crafting recipes???


WiseNoobCrusher

Recommended Posts

How would i go in doing that?

 

The item i want to lose durability:

package com.hardwareplus.items;

import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

import com.hardwareplus.creativetabs.MCreativeTabs;
import com.hardwareplus.lib.RefStrings;

import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class IronFile{

public static void mainRegistry(){
	initializeItem();
	registerItem();
}

public static Item iFile;

public static void initializeItem(){
	iFile = new Item().setUnlocalizedName("iFile").setMaxDamage(64).setMaxStackSize(1).setCreativeTab(MCreativeTabs.tabItems).setTextureName(RefStrings.MODID + ":IFile");

	}

public static void registerItem(){
	GameRegistry.registerItem(iFile, iFile.getUnlocalizedName());

}

}

 

My Crafting Handler:

package com.hardwareplus.Main;

import com.hardwareplus.items.IronFile;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.ItemCraftedEvent;

public class CraftingHandler {

@SubscribeEvent
public void onCrafting(ItemCraftedEvent event) {

	final IInventory craftMatrix = null;
	for(int i = 0; 1 < event.craftMatrix.getSizeInventory(); i++){
		if (event.craftMatrix.getStackInSlot(i) != null){
			ItemStack item0 = event.craftMatrix.getStackInSlot(i);
				if (item0 != null && item0.getItem() == IronFile.iFile){
					ItemStack k = new ItemStack(IronFile.iFile, 2, (item0.getItemDamage() + 1));

					if (k.getItemDamage() >= k.getMaxDamage()){
						k.stackSize--;

					}
			event.craftMatrix.setInventorySlotContents(i, k);	
					}
		     }
      }	
     }
}

 

Where My recipes are:

package com.hardwareplus.Main;

import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import com.hardwareplus.items.IronFile;
import com.hardwareplus.items.IronPlate;
import com.hardwareplus.items.IronRod;
import com.hardwareplus.Main.CraftingHandler;

import cpw.mods.fml.common.registry.GameRegistry;

public class CraftingManager {
public static void mainRegistry(){
	addCraftingRec();
	addSmeltingRec();
}
public static void addCraftingRec(){
	//Iron File
	GameRegistry.addRecipe(new ItemStack(IronRod.iRod, 4), new Object[]{"FR", 'F', new ItemStack(IronFile.iFile, 1, OreDictionary.WILDCARD_VALUE), 'R', IronPlate.iPlate});
}
public static void addSmeltingRec(){

}
}

 

MainRegistry:

package com.hardwareplus.Main;

import com.hardwareplus.creativetabs.MCreativeTabs;
import com.hardwareplus.items.IronFile;
import com.hardwareplus.items.IronPlate;
import com.hardwareplus.items.IronRod;
import com.hardwareplus.items.TinPlate;
import com.hardwareplus.lib.RefStrings;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
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;

@Mod(modid = RefStrings.MODID , name = RefStrings.NAME , version = RefStrings.VERSION)
public class MainRegistry {

@SidedProxy(clientSide = RefStrings.CLIENTSIDE , serverSide = RefStrings.SERVERSIDE)
public static ServerProxy proxy;

@EventHandler
public static void PreLoad(FMLPreInitializationEvent PreEvent){
	proxy.registerRenderInfo();
	MCreativeTabs.initializeTabs();
	IronPlate.mainRegistry();
	TinPlate.mainRegistry();
	IronFile.mainRegistry();
	IronRod.mainRegistry();
	CraftingManager.mainRegistry();


    }
@EventHandler
public static void load(FMLInitializationEvent event){

	FMLCommonHandler.instance().bus().register(new CraftingHandler());


    }
@EventHandler
public static void PostLoad(FMLPostInitializationEvent PostEvent){

    }
}

 

My Strings:

package com.hardwareplus.lib;

public class RefStrings {

	public static final String MODID = "hardwareplus";
	public static final String NAME = "Hardware Plus";
	public static final String VERSION = "0.1";
	public static final String CLIENTSIDE = "com.hardwareplus.Main.ClientProxy";
	public static final String SERVERSIDE = "com.hardwareplus.Main.ServerProxy";

}

 

All this and i can't figure it out...it just crashes when crafting the 4 iron rods....

Yes i am new at modding, i am using this mod for my modpack cause i can't find the right mod to use so i decided to make my own mod to fulfill my needs...

Link to comment
Share on other sites

I see that all over the place but idk where to put it, in the item class...

 

You create a custom item that is your "durable item" and you override those two functions.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

You put this in your item class to override it from Item.java:

 

public ItemStack getContainerItem(ItemStack stack) {
	ItemStack newStack = stack.copy();

	newStack.setItemDamage(newStack.getItemDamage() + 1);
	stack.stackSize = 1;

	return newStack;
}

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

Put this code near the bottom of your item class:

	@Override
 public ItemStack getContainerItem(ItemStack stack) {
if (stack.attemptDamageItem(1, itemRand)) {
 return null;
}
return stack;
 }

 

And if you want it to stay in your crafting grid add this under the last one:

 

	@Override

public boolean doesContainerItemLeaveCraftingGrid(ItemStack par1ItemStack)
{
return false;
}

 

and in your crafting manager, use it like this for simplicity:

 

GameRegistry.addShapelessRecipe(new ItemStack(IronRod.iRod, 4), new ItemStack(IronFile.iFile, 1, OreDictionary.WILDCARD_VALUE), (IronPlate.iPlate));

 

Hope this helps.

Link to comment
Share on other sites

Still didnt work...

 

Gosh, probably because:

 

Moreover the code you posted is incorrect.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Then override getContainerItem and hasContainerItem in your Item class. In getContainerItem you return the result of when Item is being used in crafting (e.g. a water bucket returns an empty bucket). In your case you'd return a more damaged Item.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Sorry about the wrong code; I didn't have my IDE open and I remembered using it from 1.6.4. I'll re-make it myself to see how to do what he wants to accomplish. But diesieben, the way you addressed me did come off quite rude. O.o You could of just said it was incorrect in a less condescending format.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

>:( Ok....i tried everything everyone told me to do...looked up on the web and still no answer.....really i will post what i have right now..

 

IronFile class

package com.hardwareplus.items;

import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import com.hardwareplus.creativetabs.MCreativeTabs;
import com.hardwareplus.lib.RefStrings;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class IronFile extends Item{

@Override
    public boolean doesContainerItemLeaveCraftingGrid(ItemStack itemStack)
    {
        return false;
    }

    @Override
    public boolean getShareTag()
    {
        return true;
    }

    public boolean hasContainerItem(ItemStack itemStack)
    {
       return true;
    }
    
    @Override
    public ItemStack getContainerItem(ItemStack itemStack)
    {
        ItemStack stack = itemStack.copy();

        stack.setItemDamage(stack.getItemDamage() + 1);
        stack.stackSize = 1;

        return stack;
    }


public static void mainRegistry(){
	initializeItem();
	registerItem();
}

public static Item iFile;


public static void initializeItem(){
	iFile = new Item().setUnlocalizedName("iFile").setNoRepair().setMaxStackSize(1).setMaxDamage(80).setCreativeTab(MCreativeTabs.tabItems).setTextureName(RefStrings.MODID + ":IFile");

  }

public static void registerItem(){
	GameRegistry.registerItem(iFile, iFile.getUnlocalizedName());

}

}

 

CraftingManager class

package com.hardwareplus.Main;

import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;

import com.hardwareplus.items.IronFile;
import com.hardwareplus.items.IronPlate;
import com.hardwareplus.items.IronRod;

import cpw.mods.fml.common.registry.GameRegistry;

public class CraftingManager {
public static void mainRegistry(){
	addCraftingRec();
	addSmeltingRec();
}
public static void addCraftingRec(){
	//Iron File
	GameRegistry.addRecipe(new ItemStack(IronFile.iFile, 1), new Object[]{"  P"," P ","R  ", 'P', IronPlate.iPlate, 'R', IronRod.iRod});
	//Iron Rod
	GameRegistry.addShapelessRecipe(new ItemStack(IronRod.iRod, 4), new ItemStack(IronPlate.iPlate), new ItemStack(IronFile.iFile, 1, OreDictionary.WILDCARD_VALUE));

}
public static void addSmeltingRec(){

}
}

 

 

Hopefully someone can find  solution for me....and thx HappyKiller

Link to comment
Share on other sites

You do know, you are trying to return your IronFile as a result of the crafting, correct? getContainerItem only refers to the item if it is being used to craft the item. I believe ScratchForFun made a battery video that easily made the crafting result be damaged if that is what you want to do.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

So, I just tested this and it worked. Put this in your item:

//Makes it so the item stays in the crafting grid
    public boolean doesContainerItemLeaveCraftingGrid(ItemStack stack) {
        return false;
    }
    
    //Tells the game your item has a container item
    public boolean hasContainerItem() {
    	return true;
    }
    
    //Sets teh container item
    public ItemStack getContainerItem(ItemStack itemStack) {
    	itemStack.attemptDamageItem(1, itemRand);
    	
    	return itemStack;
    }

 

I registered my crafting recipe like so:

GameRegistry.addRecipe(new ItemStack(Items.stick, 1), "C  ", "S  ", "S  ", 'C', CrewMod.crewHammer, 'S', Items.stick);

 

It should work with shapeless recipes also.

 

EDIT:

 

There is no need for you to use the WILDCARDVALUE param in the IronFile recipe you registered. Make sure to remove that.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

U telling me that

 

GameRegistry.addShapelessRecipe(new ItemStack(IronRod.iRod, 4), new ItemStack(IronPlate.iPlate), new ItemStack(IronFile.iFile, 1, OreDictionary.WILDCARD_VALUE));

 

is wrong??? Because i was told to use OreDictionary.WILDCARD_VALUE???

If this is wrong then how am i suppose to do it?

Link to comment
Share on other sites

No no no no. Remove the ".setContainerItem(iFile)" from your initiation of the Item. Then, the the IronFile item class, put what I showed above to set the container item. After that, registered your shapeless crafting recipe like this:

GameRegistry.addShapelessRecipe(new ItemStack(IronRod.iRod, 4), new ItemStack(IronPlate.iPlate, 1), new ItemStack(IronFile.iFile, 1));

 

This is not meant to be a Java school. I do not like taking people step by step on how to fix their problem so, I encourage you to look harder at your problems and try to fix them yourself. :P

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Link to comment
Share on other sites

I tested it completely and it worked just fine. Please post your crafting class, where you initialize your item and, the IronFile class. I will look through it and see what you did wrong. Never give up when a problem arises; if you do, why are you programming? Life is full of problems that need to be solved in order to move on.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

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

    • How I Recovered Over €72,000 from a Scam Trading Broker in London with the Help of Adrian Lamo Hacker I’d like to share my recovery experience here from London, UK, with a scam trading broker to help others avoid falling into the same trap I did. Like many, I thought I was making a smart investment by trading online. I had heard stories of people earning substantial returns, so I was excited when I found a trading platform that seemed legitimate. However, little did I know, I was dealing with a scam. The broker I encountered was highly convincing. They promised me high returns and offered a professional-looking platform. I was persuaded by their smooth talk, testimonials, and fake success stories. Over time, I started transferring funds into the trading account they set up for me. My initial investments were small, but soon I transferred a significant amount—almost €72,620—hoping to see my account grow. Unfortunately, things took a sharp turn for the worse. Despite the early promises of returns, I was unable to withdraw any of my funds. Each time I requested to withdraw, I was met with endless excuses and delays. It became clear that I was dealing with a fraudulent broker, and my money was stuck in their fake account with no way of getting it back. I felt devastated and helpless. It was hard to believe that I had been scammed. However, after doing some research, I came across Adrian Lamo Hacker a company that specializes in recovering funds lost to scams. I was skeptical at first, but after reading positive reviews and testimonials, I decided to reach out for help. From the moment I contacted them through , the team was professional, understanding, and reassuring. They guided me through the recovery process step by step, and after some time, I was overjoyed to learn that my money had been successfully recovered. I’m incredibly grateful to Adrian Lamo Hacker for their expertise and hard work. They helped me get back what I thought was lost forever. If you’re reading this and have fallen victim to a similar scam, I urge you to reach out to a reputable recovery service like ADRIAN LAMO HACKER via Email: Adrianlamo @ consultant . com/ / Telegram ID: @ADRIANLAMOHACKERTECH Don’t give up on getting your money back. There are experts out there who can help, and I am proof that recovery is possible.
    • No se me descarga la carpeta de forge. Despues de darle a install y q me salte a la pagina de publicidad, espero los 5 segundos, le doy a skip pero en vez de descargarse del archivo del forge, se me descarga un .jar que es un bloc de notas, no me aparece la carpeta con la descarga por ningun lado 
    • Alright, well before removing IC2 I changed the max chunks from 15 to 6, and that seems to have fixed most of it, BUT, the console log keeps spamming out this "[16:01:09] [File IO Thread/WARN] [FML]: Large Chunk Detected: (11, 19) Size: 578 ./servermodworld2024oct/region/r.5.2.mca", and it is still lagging a little. What exactly does this mean and by some chance is this a chunk I can find and fix? If so how can I find it? After testing the server without IC2, the same error message still shows up, and the server continues to suffer in terms of lag.
    • I often can play and enjoy modded MC for a few hours each day after I start my computer, but then after a while it just stops Tried updating drivers on my Nividia card but not worked. I think it might be bad sectors I got on my RAM though, not sure this computer is over 7 years old and getting bit tired.
  • Topics

×
×
  • Create New...

Important Information

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