-
Notifications
You must be signed in to change notification settings - Fork 9
Description
If you create a command like this for example:
Where you have your weapon in slot 1, a shield in slot 9 and something like torches in your offhand and a Pick in you main hand, And you what to select your shield (slot 9) swap it with your torches (Off hand) then select your weapon (Slot 1)
it ends up swapping your weapon to the off hand.
This is because of the timing of the operations requires a game Tick. so if you change your runQueue code from
public class KeybindHandler {
public static ArrayList<KeyBinding> queuedKeys = new ArrayList<>();
private static final ArrayList<KeyBinding> queuedRelease = new ArrayList<>();
private static boolean didPress = false;
public static void runQueue() {
if (didPress) {
for (KeyBinding keyBinding : queuedRelease) {
keyBinding.setPressed(false);
}
didPress = false;
queuedRelease.clear();
}
for (KeyBinding keyBinding : queuedKeys) {
KeyBindingMixin keyBindingMixin = (KeyBindingMixin) keyBinding;
keyBindingMixin.setTimesPressed(1);
keyBinding.setPressed(true);
didPress = true;
queuedRelease.add(keyBinding);
}
queuedKeys.clear();
}
// The REST IS UNMODIFIED
}TO:
public class KeybindHandler {
// public static ArrayList<KeyBinding> queuedKeys = new ArrayList<>();
public static Queue<KeyBinding> queuedKeys = new LinkedList<>();
private static final ArrayList<KeyBinding> queuedRelease = new ArrayList<>();
private static boolean didPress = false;
public static void runQueue() {
if (didPress) {
for (KeyBinding keyBinding : queuedRelease) {
keyBinding.setPressed(false);
}
didPress = false;
queuedRelease.clear();
}
//for (KeyBinding keyBinding : queuedKeys) {
if (!queuedKeys.isEmpty()) {
KeyBinding keyBinding = queuedKeys.poll();
KeyBindingMixin keyBindingMixin = (KeyBindingMixin) keyBinding;
keyBindingMixin.setTimesPressed(1);
keyBinding.setPressed(true);
didPress = true;
queuedRelease.add(keyBinding);
}
//}
//queuedKeys.clear();
}
// The REST IS UNMODIFIED
}Note:
Because this will change the timing a little bit. It get more out of order if you add an inline Command between swaps. The commands will happen out of order. My suggestion is treat all the commands and KeyBinding alike and put them into the Queue in order and have each execute on the Game Tick. But his will require some refactoring. but will allow for Minecraft to react to the Bindings as the game updates on ticks.
Not that I would use those commands, but the /help and the Combat Mode happen before the end of the execution (of course) which actually happens with your prior code as well.

