Jump to content

[MC 1.6.2] How do I make an item take damage after each use


Elite_Forges

Recommended Posts

I really need to know a working (and tested, too) way to code it so when you craft with an item, it takes damage for each use until it finally runs out of durability and gets destroyed. I am working on a mod for my modpack and I have searched through a ridiculous amount of pages explaining how to do it with no success. I managed to get it to take 1 damage when crafted with but after you craft with it once, its done. You can't craft with it anymore and you are left with a slightly damaged item. I understand you use a crafting handler but I can't seem to get it to work any better then what I just explained. Can somebody out there please just take some time and explain to me exactly how to get this to work with minecraft version 1.6.2?  If you could, I'd also like to know how to do the same thing, only instead of taking damage it just has infinite uses. I tried setting the metadata value in the crafting recipes to -1 but that had no effect.

 

An example of this is Equivalent Exchange 3 and Pam's Harvestcraft. In EE3, if you craft with a minium stone, for every time you use it it takes a damage then destroys itself when it's out of durability, just like a tool such as a pickaxe does when it's out of uses. I need to get this same thing to happen with 2 of my mod items.

 

In Pam's Harvestcraft, the cooking utensils such as the juicer or the cutting board have infinite uses in crafting. For example, if you need to use the juicer for some jelly, you put it next to the fruit of choice in the crafting table and when you click on the final product to craft it, the juicer stays while the fruit is consumed. I want this exact thing to happen for a few of my mod items.

 

If you need any more information on my coding/mod please let me know and Il be happy to post it to you.

I am not looking for a reply that leads me to another post unless it has been tested and proven to work with MC 1.6.2, so if you are going to reply with a link to a tutorial or something like that, please make sure that you KNOW it works.

Link to comment
Share on other sites

Hi

 

I don't have any working code, so if that's a problem you should stop reading now :-P

 

I think I might be able to help you get one step further what what you've figured out already-

ShapedRecipes:

.checkMatch()

and in particular

                if (itemstack1 != null || itemstack != null)
                {
                    if (itemstack1 == null && itemstack != null || itemstack1 != null && itemstack == null)
                    {
                        return false;
                    }

                    if (itemstack.itemID != itemstack1.itemID)
                    {
                        return false;
                    }

                    if (itemstack.getItemDamage() != 32767 && itemstack.getItemDamage() != itemstack1.getItemDamage())
                    {
                        return false;
                    }
                }

This is probably the reason that your item stops crafting when it's been damaged.

Luckily it looks like you can create your own MyRecipe implements IRecipe to change the matching to whatever you want (i.e. ignoring damage).

Alternatively, if you put your Item in the Recipe as an ItemStack with damage of 32767, I think it will match regardless of the damage of the tool.

 

-TGG

 

 

Link to comment
Share on other sites

Hi

 

Hmm that's a bummer

 

What I mean is for example

 

ItemStack dirtStack = new ItemStack(Block.dirt);
ItemStack matchAnyDamageValueItemStack = new ItemStack(MyItem, 1, 32767);

GameRegistry.addRecipe(new ItemStack(Block.cobblestone), "xy", "yx", 
                                    'x', dirtStack, 'y', matchAnyDamageValueItemStack);

 

That way the recipe should match your item regardless of its damage value.  (You said you've already figured out how to damage the item by 1 every time it is crafted with?)

 

-TGG

 

Link to comment
Share on other sites

Hi

 

Hmm that's a bummer

 

What I mean is for example

 

ItemStack dirtStack = new ItemStack(Block.dirt);
ItemStack matchAnyDamageValueItemStack = new ItemStack(MyItem, 1, 32767);

GameRegistry.addRecipe(new ItemStack(Block.cobblestone), "xy", "yx", 
                                    'x', dirtStack, 'y', matchAnyDamageValueItemStack);

 

That way the recipe should match your item regardless of its damage value.  (You said you've already figured out how to damage the item by 1 every time it is crafted with?)

 

-TGG

 

Here use this

ItemStack dirtStack = new ItemStack(Block.dirt);
ItemStack matchAnyDamageValueItemStack = new ItemStack(MyItem, 1, WILDCARD_VALUE);

GameRegistry.addRecipe(new ItemStack(Block.cobblestone), "xy", "yx", 
                                    'x', dirtStack, 'y', matchAnyDamageValueItemStack);

 

and put this somewhere too

public static final int WILDCARD_VALUE = Short.MAX_VALUE;

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.