lehjr / MachineMusePowersuits

Minecraft mod, take 3
Other
16 stars 15 forks source link

Fix crash caused by unsafe cast #13

Closed Crimix closed 2 years ago

Crimix commented 3 years ago

This mod caused a crash with one of my mods by making an unsafe cast see Crimix/jetboots#23. java.lang.ClassCastException: com.black_dog20.jetboots.common.util.EnchantableItemHandler cannot be cast to com.github.lehjr.numina.util.capabilities.inventory.modularitem.IModularItem

I think it was caused by line 110-111 because of how the logic statement was evaluated as ( (iModularItem instanceof IModularItem) && ((IModularItem) iModularItem).isModuleOnline(MPSRegistryNames.JETPACK_MODULE_REGNAME) ) || ((IModularItem) iModularItem).isModuleOnline(MPSRegistryNames.GLIDER_MODULE_REGNAME) instead of (iModularItem instanceof IModularItem) && ( ((IModularItem) iModularItem).isModuleOnline(MPSRegistryNames.JETPACK_MODULE_REGNAME) || ((IModularItem) iModularItem).isModuleOnline(MPSRegistryNames.GLIDER_MODULE_REGNAME) )

This PR fixes the issue by using the filter and map methods of the LazyOptional to cast the Item handler to IModularItem thus making the code more robust

Fixes Crimix/jetboots#23

Crimix commented 3 years ago

@lehjr Have you missed this PR?

lehjr commented 3 years ago

@lehjr Have you missed this PR?

Not so much. Haven't had much of a chance to even look at it. Currently I'm working on the new GUI's.

lehjr commented 3 years ago

I ended up manually applying this since it was quicker than resolving conflicts. I'm probably going to have to apply the same fix in multiple locations before the next release.

Crimix commented 3 years ago

That's fine. I have not looked for other places, but I guess more places could use the same bump in robustness