Nbt Crafting (Fabric)

Nbt Crafting (Fabric)

630k Downloads

[bug] NullPointerException when calling ItemStack#areTagsEqual

deirn opened this issue ยท 1 comments

commented

Version
Minecraft: 1.16.5
NBT Crafting: 2.0.4

Describe the bug
It appears that your injects to ItemStack has wrong ordinal value

@Inject(method = "areTagsEqual", at = @At(value = "RETURN", ordinal = 1), cancellable = true)
private static void areTagsEqualReturn1(ItemStack stack1, ItemStack stack2, CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
if (stack2.getTag().isEmpty())
callbackInfoReturnable.setReturnValue(true);
}
@Inject(method = "areTagsEqual", at = @At(value = "RETURN", ordinal = 2), cancellable = true)
private static void areTagsEqualReturn2(ItemStack stack1, ItemStack stack2, CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
if (stack1.getTag() == null && stack2.getTag().isEmpty())
callbackInfoReturnable.setReturnValue(true);
}

It looks like it's correct in code, but the bytecode says otherwise :P.
You can see it get injected on wrong place when you export the mixin

public static boolean areTagsEqual(ItemStack left, ItemStack right) {
    if (left.isEmpty() && right.isEmpty()) {
        return true;
    } else if (!left.isEmpty() && !right.isEmpty()) {
        if (left.tag == null && right.tag != null) {
            CallbackInfoReturnable callbackInfo3 = false;
            CallbackInfoReturnable callbackInfo3 = new CallbackInfoReturnable("areTagsEqual", true, callbackInfo3);
            handler$zbc000$areTagsEqualReturn2(left, right, callbackInfo3);
            return callbackInfo3.isCancelled() ? callbackInfo3.getReturnValueZ() : false;
        } else {
            return left.tag == null || left.tag.equals(right.tag);
        }
    } else {
        CallbackInfoReturnable callbackInfo2 = false;
        CallbackInfoReturnable callbackInfo2 = new CallbackInfoReturnable("areTagsEqual", true, callbackInfo2);
        handler$zbc000$areTagsEqualReturn1(left, right, callbackInfo2);
        return callbackInfo2.isCancelled() ? callbackInfo2.getReturnValueZ() : false;
    }
}

This can cause a NullPointerException when it hits areTagsEqualReturn1.

Additional context
Related: badasintended/slotlink#71

commented

Thanks, would have never found this bug without you.

The decompiler messed up the ordering of the if-conditions and return statements.

Should be fixed in the latest release.