kyrptonaught / DiggusMaximus

MIT License
25 stars 20 forks source link

The Config "Invert Activation" Doesn't Work #46

Closed Slarper closed 2 years ago

Slarper commented 2 years ago

whatever the config "Invert Activation" turn ON or OFF, you should press the activation key (default is ACCENT GRAVE key ` ) to enable the mod.

Slarper commented 2 years ago

The fix explanation is below:

Slarper commented 2 years ago

The mixin class net.kyrptonaught.diggusmaximus.mixin.MixinClientPlayerInteractionManager

injects into the method breakBlock as:

    @Inject(method = "breakBlock", at = @At(value = "HEAD"))
    private void DIGGUS$BREAKBLOCK(BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
        if (DiggusMaximusMod.getOptions().enabled && DiggusMaximusClientMod.getActivationKey().isKeybindPressed())
            DIGGUS$activate(pos, null, -1);
        else if (DiggusMaximusMod.getExcavatingShapes().enableShapes && DiggusMaximusClientMod.getShapeKey().isKeybindPressed()) {
            Direction facing = null;
            HitResult result = client.player.raycast(10, 0, false);
            if (result.getType() == HitResult.Type.BLOCK)
                facing = ((BlockHitResult) result).getSide();
            int selection = DiggusMaximusMod.getExcavatingShapes().selectedShape.ordinal();
            DIGGUS$activate(pos, facing, selection);
        }
    }

But the 3rd line

        if (DiggusMaximusMod.getOptions().enabled && DiggusMaximusClientMod.getActivationKey().isKeybindPressed())

evaluates a boolean

DiggusMaximusClientMod.getActivationKey().isKeybindPressed()

while the DiggusMaximusClientMod.getActivationKey() returns DiggusMaximusMod.getOptions().keybinding which is declared in class net.kyrptonaught.diggusmaximus.config.ConfigOptions as:

    public CustomKeyBinding keybinding = new DiggusKeyBinding(true, true, "key.keyboard.grave.accent");

because its class type is declared asCustomKeyBinding so the isKeybindPressed() in DiggusMaximusClientMod.getActivationKey().isKeybindPressed()

will be resolved to the wrong CustomKeyBinding::isKeybindPressed instead of the correct DiggusMaximusMod::isKeybindPressed.

So the solution is replace the problematic declaration for

    public DiggusMaximusMod keybinding = new DiggusKeyBinding(true, true, "key.keyboard.grave.accent");