Lithium (Fabric)

Lithium (Fabric)

22M Downloads

Lithium 0.9.0 hopper optimization may cause NPE with other mods

Fallen-Breath opened this issue ยท 1 comments

commented

Instructions

The following @ModifyVariable sets the booleanSupplier variable to null, causing mods accessing this variable throwing NPE after this @ModifyVariable

@SuppressWarnings("InvalidInjectorMethodSignature" )
@ModifyVariable(
method = "insertAndExtract",
at = @At(value = "JUMP", opcode = Opcodes.IFEQ, ordinal = 2),
argsOnly = true
)
private static BooleanSupplier rememberBranch(BooleanSupplier booleanSupplier) {
return null;
}

And the variable being null is only used in the following injection

@Inject(
method = "insertAndExtract",
at = @At(value = "RETURN", ordinal = 2)
)
private static void sleepIfBranchNotRemembered(World world, BlockPos pos, BlockState state, HopperBlockEntity blockEntity, BooleanSupplier booleanSupplier, CallbackInfoReturnable<Boolean> cir) {
if (booleanSupplier != null && !((HopperBlockEntityMixin) (Object) blockEntity).needsCooldown()) {
//When this code is reached, rememberBranch(BooleanSupplier) wasn't reached. Therefore the hopper is locked and not on cooldown.
((HopperBlockEntityMixin) (Object) blockEntity).startSleeping();
}
}

Example

Example compatibility issue with Carpet-TIS-Addition mod

TISUnion/Carpet-TIS-Addition#81

Reproduced by

  • Minecraft version: 1.19.2
  • Fabric Carpet version: 1.4.83
  • Carpet TIS Addition version: 1.40.1
  • Lithium version: 0.9.1

Mixined classes:

// net.minecraft.block.entity.HopperBlockEntity#insertAndExtract

    // ....

    booleanSupplier = localvar$bod000$rememberBranch(booleanSupplier);  // <-- lithium sets booleanSupplier to null
    if (bl) {
        blockEntity.setTransferCooldown(8);
        handler$bdd000$doHopperCountersUnlimitedSpeed(world, pos, state, blockEntity, booleanSupplier, (CallbackInfoReturnable)null);   // <-- NPE
        markDirty(world, pos, state);
        return true;
    }
}

handler$bod000$sleepIfBranchNotRemembered(world, pos, state, blockEntity, booleanSupplier, (CallbackInfoReturnable)null);
return false;
commented

64078c5 should fix this