Auto SuppressWarnings on BlockEntiy#getLevel and some else #getLevel or level.dosomething() method
Minecraft Development for IntelliJ plugin version
2025.185
Description of the feature request
When try to use getLevel in BlockEntiy or getLevel in entity ide will warning because it's nullable because this blockentity or entity may not in a level now
but more common scenario is: we know it coult not be null and should't warn unless use getlevel in constructor.
manual requireNonnull or @SuppressWarnings is too annoying!
so, could add a feature to auto auto suppress these warnings?
A nitpick, in mojmap these methods are called level(), not getLevel(). That's actually important because intellij special-cases methods starting with get for this inspection. A workaround is to add the Level class to the list of ignored classes in the inspection settings for the try-with-resources inspection.
I'm not sure it's mcdev's place to solve this problem. Eclipse annotations have Owning and NotOwning to mark responsibility of closing resources, and I'd like to see if I can push for those annotations to go into the jetbrains annotations library, see https://github.com/JetBrains/java-annotations/issues/100. Then, it should only be a short step away from recognizing those annotations in this intellij inspection.
As for applying this annotation to Minecraft code, I will add a feature for adding and removing annotations to Minecraft into Fabric loom, and I would expect yarn to provide mappings for where these annotations should be applied. This ties in to your point about nullability as well. This is caused by Mojang incorrectly applying the @Nullable annotation in some cases. See the docs. In these cases, Mojang should be using @UnknownNullability instead to override non-null by default behaviour. This could be something that yarn could in future provide. I expect that once the Fabric toolchain has this feature, there may be demand for it on NeoForge too, although that would need discussion with them.