Fabric API

Fabric API

106M Downloads

Possible nullability error in UseEntityCallback

alex5nader opened this issue ยท 1 comments

commented

UseEntityCallback's handler signature has a @Nullable parameter, hitResult, but this parameter should never be null. The server invoker for this event instantiates the EntityHitResult directly, while the client invoker uses MinecraftClient::crosshairTarget (from MinecraftClient::doItemUse). This field is indeed nullable, but it is only null when not in a world. In a world, this will either be a successful raycast to whatever the client is looking at, or a "miss" result, which is not null.

Alternatively, the client invoker unconditionally uses the variable that gets passed to hitResult, which is supposedly nullable (see here). Either this is an error, or the event handler parameter should not be marked as @Nullable.

commented

That @Nullable doesn't seem necessary indeed. The code for it is two years old, so it's possible that this may have changed in Minecraft, or may have been overlooked in the first implementation.
In all cases, a newer api for interaction events is in the works in #1264.