Electroblob's Wizardry

Electroblob's Wizardry

18M Downloads

ISyncedPotion default on-remove event triggering NullPointerException

noobanidus opened this issue · 9 comments

commented

Minecraft version: 1.12.2
Wizardry version: 4.2
Environment: Singleplayer

Issue details: While attempting to debug world generation with another mod I was flying under bedrock at high speed when I encountered a crash with single player. The code on your GitHub doesn't seem to reflect the latest release, however:

    @SubscribeEvent
    default void onPotionRemoveEvent(final PotionEvent.PotionRemoveEvent event) {
        if (event.getPotionEffect().getPotion() instanceof ISyncedPotion && ((ISyncedPotion)event.getPotionEffect().getPotion()).shouldSync(event.getEntityLiving()) && !event.getEntityLiving().world.isRemote) {
            event.getEntityLiving().world.playerEntities.stream().filter(p -> p.getDistanceSq((Entity)event.getEntityLiving()) < 4096.0).forEach(p -> p.connection.sendPacket((Packet)new SPacketRemoveEntityEffect(event.getEntity().getEntityId(), event.getPotionEffect().getPotion())));
        }
    }
}

This appears to be the problematic code. Judging by the fact that the effect PotionEffect variable in the base PotionEvent class as well as the getPotionEffect functions are both marked as @Nullable, you might need to add a null check before attempting to access the actual potion.

Example (from Forge):

    @Nullable
    public PotionEffect getPotionEffect()
    {
        return effect;
    }

It's most likely the fact that circumstances have never resulted in this actually being set to null and that it is the interaction with Potion Core that is causing the problem, but considering it is a @Nullable field it's worth being cautious.

Other mods involved: Potentially potion core, you can see the complete list of mods in the crash report.

Link to crash report (if applicable): https://gist.github.com/duely/0c2aec0a3a5415b5094cb85e05b47519

commented

Yeah, sometimes expected behaviours aren't what we expect and Forge tuna-face-slaps you with a @Nullable somewhere you really didn't want it.

commented

Similar issue here:

https://pastebin.com/NZW1WTcw

commented

Potion core is obviously doing something strange, you'd be forgiven for thinking that if you're removing a potion then it must exist... then again, it is marked @Nullable so that's my fault. I'll add a check to fix this for the next patch. Thanks for reporting.

commented

i can add a report to this https://pastebin.com/ry0wLV5x if it helps happened when testing all summons silverfish caused it also tells about the ISyncedPotion

commented

Another report when attacking the Ferrous Wroughtnaut from Mowzie's Mobs: https://pastebin.com/mTT6XZaX

commented

My share of issues:

  1. On critical hit -> https://paste.dimdev.org/ureqaminug.mccrash
  2. On normal hit -> https://paste.dimdev.org/ebemizabac.mccrash

Both are at a SpecialMobs zombie, same one.

(One without PotionCore installed: https://paste.dimdev.org/vuyojagasa.mccrash)

commented

I got this same crash from punching a vanilla chicken. https://hatebin.com/ioqflbmtvp

commented

I also got a similar crash w/ Dynamic Stealth on world load, which I have also reported here: Laike-Endaril/Dynamic-Stealth#70

commented

Okay these are great, it's obviously happening a lot but I already know what the fix is so I don't need any more crash reports! Thanks anyway everyone.