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.

Announcements



×
×
  • Create New...

Important Information

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