NPE when retrieving maxDamage of an Item
ben-mkiv opened this issue ยท 2 comments
Minecraft version: 1.12.2
Wizardry version: 4.2.5
Issue details: My mod attaches a capability to items which allows the user to retrieve their durability with OpenComputers, while attaching the capability the mod checks if the item can be damaged to determine if the capability should be attached, however on startup it throws a NPE trying to get the maxDamage for one of your mods Items (ItemFlamingAxe) but looking at the source it looks like this may also apply to other items which can have Spells on them (or are created by spells, whatever)
Other mods involved: OCDevices
Link to crash report (if applicable): https://paste.dimdev.org/ocewixopuc.mccrash
Line of my code that leads to querying the item damage (https://github.com/ben-mkiv/OCDevices/blob/ebdcbd0076d23e562c99a0c268c65bcc10573853/src/main/java/ben_mkiv/ocdevices/common/nanoAnalyzer/NanoAnalyzer.java#L34)
Some of my conjured items depend on spells being initialised (which happens during the registry event for spells) to set their max damages. Normally that's not a problem because the max damage is never queried before the spells are initialised, but clearly the itemstack capability attachment must happen before that, hence the error.
I could add a failsafe that just returns some arbitrary max damage value if the spell isn't initialised, which would solve this particular problem, but I wonder if it's something that will happen with other mods too? In theory, any mod with items that have dynamic max damage values could cause a similar problem.
yea for my use case any value != 0 would be sufficient. but neither do i know of any other mod that would even require such feature within a capability. so its up to you if you want to avoid the NPE.
for now i've worked around the issue by catching the NPE and not adding the capability to the affected items, which are:
ebwizardry:flaming_axe
ebwizardry:frost_axe
ebwizardry:spectral_boots
ebwizardry:spectral_bow
ebwizardry:spectral_chestplate
ebwizardry:spectral_helmet
ebwizardry:spectral_leggings
ebwizardry:spectral_pickaxe
ebwizardry:spectral_sword