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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • OLXTOTO adalah situs bandar togel online resmi terbesar dan terpercaya di Indonesia. Bergabunglah dengan OLXTOTO dan nikmati pengalaman bermain togel yang aman dan terjamin. Koleksi toto 4D dan togel toto terlengkap di OLXTOTO membuat para member memiliki pilihan taruhan yang lebih banyak. Sebagai situs togel terpercaya, OLXTOTO menjaga keamanan dan kenyamanan para membernya dengan sistem keamanan terbaik dan enkripsi data. Transaksi yang cepat, aman, dan terpercaya merupakan jaminan dari OLXTOTO. Nikmati layanan situs toto terbaik dari OLXTOTO dengan tampilan yang user-friendly dan mudah digunakan. Layanan pelanggan tersedia 24/7 untuk membantu para member. Bergabunglah dengan OLXTOTO sekarang untuk merasakan pengalaman bermain togel yang menyenangkan dan menguntungkan.
    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
  • Topics

×
×
  • Create New...

Important Information

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