yeelp / Scaling-Feast

A simple, balanced way to increase your maximum hunger in Minecraft over the course of a world.
MIT License
0 stars 1 forks source link

[1.12] NPE Crash on onFoodStatsAddition() (ExCompressum compat) #122

Open Krutoy242 opened 2 years ago

Krutoy242 commented 2 years ago

Mod Version: v1.8.2 Minecraft Version: 1.12.2

Describe the bug Right-clicking on Auto Sieve with high-saturated food cause crash:

java.lang.NullPointerException
    at net.minecraft.entity.player.EntityPlayerMP.onChangedPotionEffect(EntityPlayerMP.java:1201)
    at net.minecraft.entity.EntityLivingBase.addPotionEffect(EntityLivingBase.java:756)
    at yeelp.scalingfeast.features.SFBloatedOverflow$1.onFoodStatsAddition(SFBloatedOverflow.java:28)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_4579__onFoodStatsAddition_FoodStatsAddition.invoke(.dynamic)
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
    at com.github.terminatornl.laggoggles.tickcentral.EventBusTransformer.redirectEvent(EventBusTransformer.java:67)
    at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182)
    at squeek.applecore.asm.Hooks.fireFoodStatsAdditionEvent(Hooks.java:264)
    at net.minecraft.util.FoodStats.addStats(SourceFile:27)
    at net.minecraft.util.FoodStats.addStats(SourceFile:32)
    at net.minecraft.item.ItemFood.onItemUseFinish(SourceFile:43)
    at net.blay09.mods.excompressum.block.BlockAutoSieveBase.onBlockActivated(BlockAutoSieveBase.java:120)
    at net.minecraft.server.management.PlayerInteractionManager.processRightClickBlock(PlayerInteractionManager.java:449)

Steps to Reproduce

  1. Right-click Auto Sieve with high-saturation food, being in /gamemode 0

Expected behavior Auto Sieve should increase speed when feeden.

Full crash log

James103 commented 2 years ago

Could it be that the Auto Sieve is attempting to receive potion effects, even though the Auto Sieve is a block and potion effects can only be applied to entities?

yeelp commented 2 years ago

(For starters, it's worth mentioning that this crash could be prevented if Bloated Overflow could be turned off, which I made a mistake in, see #121. So what's happening here is SF is still trying to give the Bloated potion effect).

Could it be that the Auto Sieve is attempting to receive potion effects, even though the Auto Sieve is a block and potion effects can only be applied to entities?

The Auto Sieve is using a FakePlayer to simulate what happens when the item is used. Since it does that, items like golden apples would apply their potion effects too, so I don't think it's that. My deobfuscated vanilla source doesn't line up with the crash report line numbers in EntityPlayerMP so I'm not sure what's going wrong there.

What's interesting is it crashes in onChangedPotionEffect, implying this fake player already had the Bloated potion effect active on them at the time of the crash. So the first time around, everything worked fine.

I can add a simple !world.isRemote check before granting the potion effect, which is what golden apples do (so it wouldn't hurt to have). I can also add a another simple instanceof FakePlayer check as well, since the Auto Sieve fake player doesn't need the potion effect anyway. That would prevent execution from reaching this state, thus preventing the crash, but this doesn't really explain why the problem happens in the first place.