Jump to content

Change an ItemStack's maximum damage


Zetal

Recommended Posts

    public int getMaxDamage()
    {
        return this.item.getMaxDamage(this);
    }

 

This method is located in the ItemStack class. It references the Item class, which then gets a universal maximum damage for all ItemStacks of an Item instance. In other words, if I want to set the maximum damage of just a specific ItemStack, I am unable to.

 

I've hijacked the crafting events, so when something is crafted I can set it's current damage, but I would like to be able to set the ItemStacks MAXIMUM damage based on the Blacksmith level of the player who crafted it.

 

In previous unreleased versions, I accomplished this by performing base-changes to the ItemStack class, but for 1.8 I'm turning over a new leaf and avoiding the use of base-class changes entirely. I've managed to solve the vast majority of my old features using varying methods, including Java reflection when needed or just flat-out replacing what I'm trying to change with a new class.

 

In this case, even if I wanted to do that, it isn't an option since the ItemStack class is final.

So! Given all of this, I wanted to check in with the forum, and hopefully you guys could help me with some suggestions on how I could accomplish what I need to accomplish? Workarounds are A-OK as well. Thanks!

Have a modding question? PM me and hopefully I'll be able to help. Good at 2d Pixel Art? We need your help!  http://www.minecraftforum.net/topic/1806355-looking-for-2d-pixel-artist/

Link to comment
Share on other sites

If it's your own

Item

class, use the

ItemStack

argument of

getMaxDamage

to determine the max damage (e.g. store the Blacksmith level in the NBT when crafted, read it back in

getMaxDamage

).

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

public int getMaxDamage()
    {
        return this.item.getMaxDamage(this);
    }

If you look closely, ItemStack is passing "this" (ItemStack) to Item.class. For your own items you can change it to be based on NBT.

That was said before, now:

 

Question what should be asked - do you need this for vanilla items?

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

I'm afraid that I very much would need this for vanilla items, but if there is no other way to do it without making my own items, then I could probably just duplicate every instance of a Minecraft item with durability and replace it with my own using Forge events. Obviously that wouldn't be ideal, so if there's another way I would appreciate a different method, but well... I'll do whatever I've got to do.

Have a modding question? PM me and hopefully I'll be able to help. Good at 2d Pixel Art? We need your help!  http://www.minecraftforum.net/topic/1806355-looking-for-2d-pixel-artist/

Link to comment
Share on other sites

After the Minecraft Items are initialized, you can use e.g.

Items.diamond_pickaxe.setMaxDamage(maxDamage)

to set the max damage of an Item.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

I appreciate the effort lars, but that isn't what I'm looking for, as I explained in the original post. The method you describe sets the max damage for an Item, but I need to set the max damage of an ItemStack.

Have a modding question? PM me and hopefully I'll be able to help. Good at 2d Pixel Art? We need your help!  http://www.minecraftforum.net/topic/1806355-looking-for-2d-pixel-artist/

Link to comment
Share on other sites

Only option I see without hardcode modding (ASM) would be to extend given vanilla class and do your stuff like with any other item.

Then using (various) events you could replace item with your item and alter its durability/NBT as needed.

 

You probably alredy thought of it, but jut saying.

 

As to "various" events - best shot would be PlayerTickEvent and check held item. You might also want to alter e.g Crafting events or even drop events if you need more control.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

This would be designed solely for fresh servers, so if I replace the vanilla crafting recipes with my own and add a handler for EntityItem joins world event, that should cover everything, right?

Have a modding question? PM me and hopefully I'll be able to help. Good at 2d Pixel Art? We need your help!  http://www.minecraftforum.net/topic/1806355-looking-for-2d-pixel-artist/

Link to comment
Share on other sites

Yeah, pretty much your best option to stay compatybile.

 

Just note that vanilla items might be used outside vanilla - remember to replicate its behaviur (e.g enchantments saved in NBT).

1.7.10 is no longer supported by forge, you are on your own.

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.