Jump to content

[1.16.2] Capability doesn't save its change.


Recommended Posts



I got some weird bug with my capability, so please take a look at my repository: https://github.com/Tavi007/ElementalCombat

In DefenseData I have the boolean 'areEnchantmentsApplied', which is usually set to false and changes to true, after checking for any enchantment on an item (see here and here). Once set to true, it should never change back to false. This capability also includes two maps, which changes a lot throughout the whole mod. While these maps saves their data correctly, the boolean does not. This means, that the enchantments are getting applied over and over, whenever I call the capability (which results in incorrect data in the maps).


Why does the boolean not save, that it has been turned to true, while the maps are saving their data just fine?


Best regards,



Link to comment
Share on other sites

I noticed the problem, when I picked up an item in any inventory. But your guess seems to be right, cause I forgot to add the boolean in the readNBT/writeNBT methods. This at least fixed the initial bug, but now I have a new problem, that I didn't noticed before. When I enchant an item using an enchanted book and an anvil, the new itemstack in the right most slot seems to use the nbt data from the base itemstack (the left most slot). Which in my case means, that the new item has 'areEnchantmentsApplied' already set to to true, without actually checking the enchantments.


What I want is, that every itemstack checks for enchantments once and sets the maps accordingly. An other solution would be to check the enchantments everytime the capability is called, but since the enchantments don't change to often, that would be inefficient.


What can I do?

Link to comment
Share on other sites

Sadly not, because I attach the same capability to entities aswell.



Do you know how to check, if an itemstack is newish? That could possibly solve my problem too.



short follow up on my issue. I could solve it, by creating a new DefenseData, that stores the data from the enchantments. This way, it won't change the data stored in the itemstack capability, but this also means, that the DefenseData from the enchantments has to be calculated over and over again. This is a suboptimal solution of course, but for the time being it'll do the trick.

I may rework my code to somehow save the additional data and only change it, whenever the itemstack changes its enchantments.

Edited by Tavi007
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.

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.


  • Create New...

Important Information

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