mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-11-05 17:46:21 +00:00
Fix NPE when rendering turtle's label
Minecraft.hitResult may /technically/ be null when rendering a turtle. In vanilla, this doesn't appear to happen, but other mods (e.g. Immersive Portals) may still take advantage of this. This hitResult is then propagated to BlockEntityRenderDispatcher, where the field was /not/ marked as nullable. This meant we didn't even notice the potential of an NPE! Closes #1775
This commit is contained in:
parent
8b2516abb5
commit
825d45eb26
@ -55,7 +55,7 @@ public class TurtleBlockEntityRenderer implements BlockEntityRenderer<TurtleBloc
|
||||
// Render the label
|
||||
var label = turtle.getLabel();
|
||||
var hit = renderer.cameraHitResult;
|
||||
if (label != null && hit.getType() == HitResult.Type.BLOCK && turtle.getBlockPos().equals(((BlockHitResult) hit).getBlockPos())) {
|
||||
if (label != null && hit != null && hit.getType() == HitResult.Type.BLOCK && turtle.getBlockPos().equals(((BlockHitResult) hit).getBlockPos())) {
|
||||
var mc = Minecraft.getInstance();
|
||||
var font = this.font;
|
||||
|
||||
|
@ -7,6 +7,7 @@ package cc.tweaked.linter
|
||||
import com.google.common.collect.ImmutableSet
|
||||
import com.google.common.collect.ImmutableSetMultimap
|
||||
import com.uber.nullaway.LibraryModels
|
||||
import com.uber.nullaway.LibraryModels.FieldRef.fieldRef
|
||||
import com.uber.nullaway.LibraryModels.MethodRef.methodRef
|
||||
|
||||
/**
|
||||
@ -34,4 +35,9 @@ class MinecraftLibraryModel : LibraryModels {
|
||||
// Reasoning about nullability of BlockEntity.getLevel() is awkward. For now, assume it's non-null.
|
||||
methodRef("net.minecraft.world.level.block.entity.BlockEntity", "getLevel()"),
|
||||
)
|
||||
|
||||
override fun nullableFields(): ImmutableSet<LibraryModels.FieldRef> = ImmutableSet.of(
|
||||
// This inherits from Minecraft.hitResult, and so can also be null.
|
||||
fieldRef("net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher", "cameraHitResult"),
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user