UtilitiX

UtilitiX

2M Downloads

Unorthodox use of "makesPiglinsNeutral" causes NPE with mod expecting standard behavior

ZeMilkmann opened this issue ยท 1 comments

commented

Minecraft version

1.19.2

LibX version

1.19.2-4.2.7

UtilitiX version

UtilitiX-1.19.1-0.6.2

Forge version

43.1.43

The latest.log file

https://gist.github.com/ZeMilkmann/1aa3c43b89764b557df96bbfb026b58e

Issue description

In GildingArmorRecipe.java you pass a null value for the wearer parameter in the makesPiglinsNeutral method.

Since this method is supposed to pass a valid LivingEntity when it is called by the Piglin-AI, the creator of the mod "Upgraded Netherite" has not made contingencies for a null value being passed which causes a crash whenever attempting to insert an ArmorItem from these mods into an anvil when UtilitiX is installed as well.

I did ponder for a while which mod was ultimately responsible to fix it and landed on you, since there is no indication that the wearer parameter is nullable in the Forge docs and during intented use it will never be null.

The fix should be relatively simple and universal if you pass a FakePlayer instead of null

Steps to reproduce

No response

Other information

No response

commented

Thank you for the report. You're right, null isn't the best solution, but it's allowed: The parameter isn't annotated with NotNull nor Nullable. Thus, it's technically okay to set it null in my opinion.
Using a FakePlayer would be a good idea, but it's not very simple as this requires a ServerLevel which I can't provide in this recipe class. I decided to use try/catch. When a NullPointerException is thrown, it simply returns false. This could cause issues with other mods overriding this method and don't check for null, but I don't think that many use this. And if they do, they mainly are items which can be converted in other ways, if they aren't "gilded" items. This doesn't look nice in code but it's the best solution in that case I guess :)