
[Bug]: Shift/Ctrl + keybind sometimes bug out for some people
RobertSkalko opened this issue ยท 3 comments
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
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?
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