Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Shift/Ctrl + keybind sometimes bug out for some people #158

Open
2 tasks done
RobertSkalko opened this issue Dec 16, 2024 · 2 comments
Open
2 tasks done

[Bug]: Shift/Ctrl + keybind sometimes bug out for some people #158

RobertSkalko opened this issue Dec 16, 2024 · 2 comments

Comments

@RobertSkalko
Copy link
Owner

Describe the bug you're experiencing

The explanations are vague, i can't reproduce it in dev.
Some say their spells cast by themselves when it bugs out, others say it casts the wrong spell

Attempted to fix by consuming the keys in https://github.com/RobertSkalko/Mine-And-Slash-Rework/blob/9a9643107e05897113b8dcda836e0d57f4738ba1/src/main/java/com/robertx22/mine_and_slash/event_hooks/player/OnKeyPress.java

Still seems to happen

Reproducability

No clue

Mod up to date

  • Before submitting this issue I updated to the newest version and reproduced it

Tested Without Custom Mine and Slash Datapacks

  • In case I used Mine and Slash datapacks, I ran Mine and Slash in a new instance without custom datapacks and confirmed the bug still exists

Mine and Slash version

5.9.34

Logs

none

@Xcesius
Copy link

Xcesius commented Jan 1, 2025

I've tried looking at it, I just have a question on why there's two loops?

// Current problematic code
for (SpellKeybind key : keys) {
if (key.key.isDown()) {
number = key.getIndex();
}
}
for (SpellKeybind key : keys) {
if (key.key.getKeyModifier() != KeyModifier.NONE && key.key.isDown()) {
number = key.getIndex();
}
}

private static SpellKeybind lastPressedKey = null;
private static long lastPressTime = 0;
private static final long KEY_DEBOUNCE_MS = 50; // 50ms debounce

    // Single pass to check for pressed keys
    for (SpellKeybind key : keys) {
        if (key.key.isDown()) {
            // Only process if the key wasn't the last pressed key or enough time has passed
            if (key != lastPressedKey || (currentTime - lastPressTime) > KEY_DEBOUNCE_MS) {
                boolean isModifierPressed = key.key.getKeyModifier().isActive();
                if (key.key.getKeyModifier() == KeyModifier.NONE || isModifierPressed) {
                    currentPressed = key;
                    spellIndex = key.getIndex();
                    break; // Only process one key at a time
                }
            }
        } else if (key == lastPressedKey) {
            // Reset last pressed key when it's released
            lastPressedKey = null;
        }
    }

Wouldn't it be better with a single loop something like this in a way?

@RobertSkalko
Copy link
Owner Author

I did 2 loops so in case of spell 1: R and spell 2: Shift + R, only the 2nd spell ends up used when you press shift R

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants