Fix issue with InputOverrideHandler that could cause while loop holdups
This commit is contained in:
parent
bc7cd2efcc
commit
6a686d11f3
@ -1,7 +1,8 @@
|
|||||||
package baritone.bot;
|
package baritone.bot;
|
||||||
|
|
||||||
import baritone.bot.event.IGameEventListener;
|
import baritone.bot.event.IGameEventListener;
|
||||||
import baritone.Baritone;
|
import net.minecraft.client.settings.KeyBinding;
|
||||||
|
import org.lwjgl.input.Keyboard;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Brady
|
* @author Brady
|
||||||
@ -13,6 +14,23 @@ public final class GameEventHandler implements IGameEventListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onTick() {
|
public final void onTick() {
|
||||||
Baritone.onTick();
|
baritone.Baritone.onTick();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProcessKeyBinds() {
|
||||||
|
InputOverrideHandler inputHandler = Baritone.INSTANCE.getInputOverrideHandler();
|
||||||
|
|
||||||
|
// Simulate the key being held down this tick
|
||||||
|
for (InputOverrideHandler.Input input : InputOverrideHandler.Input.values()) {
|
||||||
|
KeyBinding keyBinding = input.getKeyBinding();
|
||||||
|
|
||||||
|
if (inputHandler.isInputForcedDown(keyBinding) && !keyBinding.isKeyDown()) {
|
||||||
|
int keyCode = keyBinding.getKeyCode();
|
||||||
|
|
||||||
|
if (keyCode < Keyboard.KEYBOARD_SIZE)
|
||||||
|
KeyBinding.onTick(keyCode < 0 ? keyCode + 100 : keyCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ public final class InputOverrideHandler implements Helper {
|
|||||||
private final Map<KeyBinding, Boolean> inputForceStateMap = new HashMap<>();
|
private final Map<KeyBinding, Boolean> inputForceStateMap = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps keycodes to whether or not we are forcing their state down
|
* Maps keycodes to whether or not we are forcing their state down.
|
||||||
*/
|
*/
|
||||||
private final Map<Integer, Boolean> keyCodeForceStateMap = new HashMap<>();
|
private final Map<Integer, Boolean> keyCodeForceStateMap = new HashMap<>();
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ public final class InputOverrideHandler implements Helper {
|
|||||||
/**
|
/**
|
||||||
* A redirection in multiple places of {@link Keyboard#isKeyDown}.
|
* A redirection in multiple places of {@link Keyboard#isKeyDown}.
|
||||||
*
|
*
|
||||||
* @return Whether or not the specified key is down or overriden.
|
* @return Whether or not the specified key is down or overridden.
|
||||||
*/
|
*/
|
||||||
public boolean isKeyDown(int keyCode) {
|
public boolean isKeyDown(int keyCode) {
|
||||||
return Keyboard.isKeyDown(keyCode) || keyCodeForceStateMap.computeIfAbsent(keyCode, k -> false);
|
return Keyboard.isKeyDown(keyCode) || keyCodeForceStateMap.computeIfAbsent(keyCode, k -> false);
|
||||||
|
@ -9,7 +9,12 @@ import net.minecraft.client.Minecraft;
|
|||||||
public interface IGameEventListener {
|
public interface IGameEventListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run once per game tick from {@link Minecraft#runTick}.
|
* Run once per game tick from {@link Minecraft#runTick()}
|
||||||
*/
|
*/
|
||||||
void onTick();
|
void onTick();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run once per game tick from {@link Minecraft#processKeyBinds()}
|
||||||
|
*/
|
||||||
|
void onProcessKeyBinds();
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,9 @@ package baritone.launch.mixins;
|
|||||||
|
|
||||||
import baritone.bot.Baritone;
|
import baritone.bot.Baritone;
|
||||||
import net.minecraft.client.settings.KeyBinding;
|
import net.minecraft.client.settings.KeyBinding;
|
||||||
import net.minecraft.util.IntHashMap;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -16,33 +14,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|||||||
@Mixin(KeyBinding.class)
|
@Mixin(KeyBinding.class)
|
||||||
public abstract class MixinKeyBinding {
|
public abstract class MixinKeyBinding {
|
||||||
|
|
||||||
@Redirect(
|
|
||||||
method = "onTick",
|
|
||||||
at = @At(
|
|
||||||
value = "INVOKE",
|
|
||||||
target = "net/minecraft/util/IntHashMap.lookup(I)Ljava/lang/Object;"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
private static Object lookup(IntHashMap<KeyBinding> HASH, int keyCode) {
|
|
||||||
KeyBinding keyBinding = HASH.lookup(keyCode);
|
|
||||||
|
|
||||||
// If we're overriding the key state, we don't want to be incrementing the pressTime
|
|
||||||
if (keyBinding != null && Baritone.INSTANCE.getInputOverrideHandler().isInputForcedDown(keyBinding))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return keyBinding;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(
|
|
||||||
method = "isPressed",
|
|
||||||
at = @At("HEAD"),
|
|
||||||
cancellable = true
|
|
||||||
)
|
|
||||||
private void isPressed(CallbackInfoReturnable<Boolean> cir) {
|
|
||||||
if (Baritone.INSTANCE.getInputOverrideHandler().isInputForcedDown((KeyBinding) (Object) this))
|
|
||||||
cir.setReturnValue(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject(
|
@Inject(
|
||||||
method = "isKeyDown",
|
method = "isKeyDown",
|
||||||
at = @At("HEAD"),
|
at = @At("HEAD"),
|
||||||
|
@ -57,6 +57,14 @@ public class MixinMinecraft {
|
|||||||
return Baritone.INSTANCE.getInputOverrideHandler().isKeyDown(keyCode);
|
return Baritone.INSTANCE.getInputOverrideHandler().isKeyDown(keyCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method = "processKeyBinds",
|
||||||
|
at = @At("HEAD")
|
||||||
|
)
|
||||||
|
private void runTickKeyboard(CallbackInfo ci) {
|
||||||
|
Baritone.INSTANCE.getGameEventHandler().onProcessKeyBinds();
|
||||||
|
}
|
||||||
|
|
||||||
@Redirect(
|
@Redirect(
|
||||||
method = {
|
method = {
|
||||||
"setIngameFocus",
|
"setIngameFocus",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user