Posted September 10, 20205 yr Hello! 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, Tavi007
September 10, 20205 yr Do you mean that you also want to save the state of the boolean when you exit the world? If so, then you also have to write/read it in your IStorage<IDefenseData> class.
September 10, 20205 yr Author 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?
September 11, 20205 yr Would a solution be to save nothing at all, i.e. let writeNBT and readNBT be empty methods? Then the maps would be set after an anvil enchant, and also every time the world is restarted (which would not be a big problem I think).
September 11, 20205 yr Author Sadly not, because I attach the same capability to entities aswell. Edit: Do you know how to check, if an itemstack is newish? That could possibly solve my problem too. Edit2: 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 September 14, 20205 yr by Tavi007
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.