feldim2425 / MoreOverlays

MC Mod : Brings back some of the NEI Overlays ( Mob Spawns, Chunk Bounds, Item Search)
MIT License
22 stars 18 forks source link

1.14.4/optifine magma block causes NPE #69

Closed wasche closed 4 years ago

wasche commented 4 years ago

Not sure if it is optifine related, but I'm guessing so. Was doing some mining and hit a cave, turning on the light level overlay immediately causes an NPE.

crash report: crash-2019-11-18_08.30.23-client.txt

feldim2425 commented 4 years ago

I can reproduce it without optifine. The problem seems to be something about getting the spawn information from magma blocks. Just turning on the overlay and placing a magmablock in rage of the overlay is enough to crash immediately.

feldim2425 commented 4 years ago

After a quick look into the source code for the magmablock it either seems that it's canEntitySpawn method was programmed without keeping in mind that the EntityType can be null or the method is documented wrong since they marked that parameter as Nullable.

The fix sadly reduces performance a bit since I have to check every singe monster entitytype that might spawn. So I added a config option to make a simple check just for the Zombie entity.

noobanidus commented 4 years ago

That's interesting, I was just coming to report this and was checking through closed issues to see if it had already been discussed. It got brought up on our discord and there was some conversation about it.

I did have a look at the decompiled code from IntelliJ and interestingly enough it doesn't have a @Nullable notation on the EntityType parameter in either the BlockState implementation or the actual Block implementation. I'm not sure if my code has had it stripped out, however.

Of note, though, it seems that BlockMagma is one of the few that actually implement canEntitySpawn. I'm not sure whether that's helpful or not, though, as that can't really be used as a heuristic given modded blocks exist...

I personally would definitely recommend making the Zombie EntityType default, however, and adding an option for the "test every monster entitytype".

feldim2425 commented 4 years ago

Here is a link to the source: https://github.com/MinecraftForge/MinecraftForge/blob/6422310453fe4029a409adf19d3bac6bfb3ea589/src/main/java/net/minecraftforge/common/extensions/IForgeBlock.java#L269

IForgeBlock is implemented by Block because Forge uses a .patch file to add it. And I used that method to determine if mobs can spawn.

wasche commented 4 years ago

Thanks for the super fast fix! Any idea what release this'll be in? Just curious, I've no problems building it for myself, but its nice to be lazy and just click the button in the launcher :)

I'd also second making zombie default and the option to check all.

feldim2425 commented 4 years ago

Already out in 1.16.1 alpha release on curseforge. Along with some other fixes and features. https://www.curseforge.com/minecraft/mc-mods/more-overlays/files/2829171

EDIT: There it is still alpha since there are some more things planed for 1.14.4.

noobanidus commented 4 years ago

That's definitely a bug on Forge's part, then, because neither the function they call in the state nor the function that it calls in the block will accept a null entity type... I might go file a bug.

EDIT: Especially demonstrable by the fact that the Vanilla magma block is accessing the EntityType directly without testing for null first.

EDIT 2: I've filed a Forge issue for this: https://github.com/MinecraftForge/MinecraftForge/issues/6326

feldim2425 commented 4 years ago

Also I should add that only checking for the EntityType "Zombie" has the problem, that blocks like the magma block won't show any overlay, since they only allow monsters that resist fire, thats why I currently set the default to check all mobs, because usually users will complain that the overlay doesn't work when they just had to change to the less performant setting. I will try to add more options like a true ligt only mode and maybe I or someone else finds a better way to optimize the check (maybe caching the blocks spawn mode).

noobanidus commented 4 years ago

Perhaps Zombie Pigman could be an alternative to zombie? I believe they should satisfy most conditions.

Additionally, a block(state?) -> boolean conditional map that could be cached might also help to simplify things, or at least speed up the process.

EDIT: Judging by the adjustment of tags to "1.14" and "cleanup", I'm going to presume that the "@Nullable" annotation remaining was an oversight from 1.12, where I presume it was accepting an Entity(Living?) instead of an EntityType.

feldim2425 commented 4 years ago

In 1.12 there was no extra parameter at least not in the method I used. It simply required the BlockState and the SpawnPlacementType. I don't know if spawns based on State, Placement and Entity were a thing in 1.12 but I assume "no".