mouse stuff
This commit is contained in:
parent
85ea21e83b
commit
5ca214534d
@ -36,9 +36,6 @@ public interface AbstractGameEventListener extends IGameEventListener {
|
||||
@Override
|
||||
default void onPlayerUpdate(PlayerUpdateEvent event) {}
|
||||
|
||||
@Override
|
||||
default void onProcessKeyBinds() {}
|
||||
|
||||
@Override
|
||||
default void onSendChatMessage(ChatEvent event) {}
|
||||
|
||||
|
@ -49,11 +49,6 @@ public interface IGameEventListener {
|
||||
*/
|
||||
void onPlayerUpdate(PlayerUpdateEvent event);
|
||||
|
||||
/**
|
||||
* Run once per game tick from before keybinds are processed.
|
||||
*/
|
||||
void onProcessKeyBinds();
|
||||
|
||||
/**
|
||||
* Runs whenever the client player sends a message to the server.
|
||||
*
|
||||
|
@ -27,9 +27,7 @@ import net.minecraft.client.settings.KeyBinding;
|
||||
*/
|
||||
public interface IInputOverrideHandler extends IBehavior {
|
||||
|
||||
default boolean isInputForcedDown(KeyBinding key) {
|
||||
return isInputForcedDown(Input.getInputForBind(key));
|
||||
}
|
||||
Boolean isInputForcedDown(KeyBinding key);
|
||||
|
||||
boolean isInputForcedDown(Input input);
|
||||
|
||||
|
@ -18,8 +18,10 @@
|
||||
package baritone.launch.mixins;
|
||||
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.utils.Helper;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
@ -31,6 +33,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
@Mixin(KeyBinding.class)
|
||||
public class MixinKeyBinding {
|
||||
|
||||
@Shadow
|
||||
public int pressTime;
|
||||
|
||||
@Inject(
|
||||
method = "isKeyDown",
|
||||
at = @At("HEAD"),
|
||||
@ -38,8 +43,26 @@ public class MixinKeyBinding {
|
||||
)
|
||||
private void isKeyDown(CallbackInfoReturnable<Boolean> cir) {
|
||||
// only the primary baritone forces keys
|
||||
if (BaritoneAPI.getProvider().getPrimaryBaritone().getInputOverrideHandler().isInputForcedDown((KeyBinding) (Object) this)) {
|
||||
cir.setReturnValue(true);
|
||||
Boolean force = BaritoneAPI.getProvider().getPrimaryBaritone().getInputOverrideHandler().isInputForcedDown((KeyBinding) (Object) this);
|
||||
if (force != null) {
|
||||
cir.setReturnValue(force); // :sunglasses:
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(
|
||||
method = "isPressed",
|
||||
at = @At("HEAD"),
|
||||
cancellable = true
|
||||
)
|
||||
private void isPressed(CallbackInfoReturnable<Boolean> cir) {
|
||||
// only the primary baritone forces keys
|
||||
Boolean force = BaritoneAPI.getProvider().getPrimaryBaritone().getInputOverrideHandler().isInputForcedDown((KeyBinding) (Object) this);
|
||||
if (force != null && force == false) { // <-- cursed
|
||||
if (pressTime > 0) {
|
||||
Helper.HELPER.logDirect("You're trying to press this mouse button but I won't let you");
|
||||
pressTime--;
|
||||
}
|
||||
cir.setReturnValue(force); // :sunglasses:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,15 +96,6 @@ public class MixinMinecraft {
|
||||
|
||||
}
|
||||
|
||||
@Inject(
|
||||
method = "processKeyBinds",
|
||||
at = @At("HEAD")
|
||||
)
|
||||
private void runTickKeyboard(CallbackInfo ci) {
|
||||
// keyboard input is only the primary baritone
|
||||
BaritoneAPI.getProvider().getPrimaryBaritone().getGameEventHandler().onProcessKeyBinds();
|
||||
}
|
||||
|
||||
@Inject(
|
||||
method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V",
|
||||
at = @At("HEAD")
|
||||
|
@ -54,11 +54,6 @@ public final class GameEventHandler implements IEventBus, Helper {
|
||||
listeners.forEach(l -> l.onPlayerUpdate(event));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onProcessKeyBinds() {
|
||||
listeners.forEach(IGameEventListener::onProcessKeyBinds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onSendChatMessage(ChatEvent event) {
|
||||
listeners.forEach(l -> l.onSendChatMessage(event));
|
||||
|
@ -17,8 +17,6 @@
|
||||
|
||||
package baritone.utils;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
@ -52,26 +50,8 @@ public final class BlockBreakHelper implements Helper {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean fakeBreak() {
|
||||
if (playerContext != BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext()) {
|
||||
// for a non primary player, we need to fake break always, CLICK_LEFT has no effect
|
||||
return true;
|
||||
}
|
||||
if (!Baritone.settings().leftClickWorkaround.get()) {
|
||||
// if this setting is false, we CLICK_LEFT regardless of gui status
|
||||
return false;
|
||||
}
|
||||
return mc.currentScreen != null;
|
||||
}
|
||||
|
||||
public boolean tick(boolean isLeftClick) {
|
||||
if (!fakeBreak()) {
|
||||
if (didBreakLastTick) {
|
||||
stopBreakingBlock();
|
||||
}
|
||||
return isLeftClick;
|
||||
}
|
||||
|
||||
public void tick(boolean isLeftClick) {
|
||||
RayTraceResult trace = playerContext.objectMouseOver();
|
||||
boolean isBlockTrace = trace != null && trace.typeOfHit == RayTraceResult.Type.BLOCK;
|
||||
|
||||
@ -82,6 +62,5 @@ public final class BlockBreakHelper implements Helper {
|
||||
stopBreakingBlock();
|
||||
didBreakLastTick = false;
|
||||
}
|
||||
return false; // fakeBreak is true so no matter what we aren't forcing CLICK_LEFT
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ import baritone.api.utils.input.Input;
|
||||
import baritone.behavior.Behavior;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.util.MovementInput;
|
||||
import net.minecraft.util.MovementInputFromOptions;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -60,14 +60,18 @@ public final class InputOverrideHandler extends Behavior implements IInputOverri
|
||||
* @return Whether or not it is being forced down
|
||||
*/
|
||||
@Override
|
||||
public final boolean isInputForcedDown(KeyBinding key) {
|
||||
public final Boolean isInputForcedDown(KeyBinding key) {
|
||||
Input input = Input.getInputForBind(key);
|
||||
if (input == null || (input != Input.CLICK_LEFT && input != Input.CLICK_RIGHT)) {
|
||||
// TODO handle left and right better
|
||||
// ideally we wouldn't force any keybinds and would do everything directly for real
|
||||
if (input == null || !inControl()) {
|
||||
return null;
|
||||
}
|
||||
if (input == Input.CLICK_LEFT) {
|
||||
return false;
|
||||
}
|
||||
return isInputForcedDown(input);
|
||||
if (input == Input.CLICK_RIGHT) {
|
||||
return isInputForcedDown(Input.CLICK_RIGHT);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,36 +104,27 @@ public final class InputOverrideHandler extends Behavior implements IInputOverri
|
||||
this.inputForceStateMap.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onProcessKeyBinds() {
|
||||
// Simulate the key being held down this tick
|
||||
for (Input input : Input.values()) {
|
||||
KeyBinding keyBinding = input.getKeyBinding();
|
||||
|
||||
if (isInputForcedDown(keyBinding) && !keyBinding.isKeyDown()) {
|
||||
int keyCode = keyBinding.getKeyCode();
|
||||
|
||||
if (keyCode < Keyboard.KEYBOARD_SIZE) {
|
||||
KeyBinding.onTick(keyCode < 0 ? keyCode + 100 : keyCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onTick(TickEvent event) {
|
||||
if (event.getType() == TickEvent.Type.OUT) {
|
||||
return;
|
||||
}
|
||||
boolean stillClick = blockBreakHelper.tick(isInputForcedDown(Input.CLICK_LEFT));
|
||||
setInputForceState(Input.CLICK_LEFT, stillClick);
|
||||
if (baritone.getPathingBehavior().isPathing() || baritone != BaritoneAPI.getProvider().getPrimaryBaritone()) {
|
||||
ctx.player().movementInput = new PlayerMovementInput(this);
|
||||
} else {
|
||||
ctx.player().movementInput = new MovementInputFromOptions(Minecraft.getMinecraft().gameSettings);
|
||||
blockBreakHelper.tick(isInputForcedDown(Input.CLICK_LEFT));
|
||||
|
||||
MovementInput desired = inControl()
|
||||
? new PlayerMovementInput(this)
|
||||
: new MovementInputFromOptions(Minecraft.getMinecraft().gameSettings);
|
||||
|
||||
if (ctx.player().movementInput.getClass() != desired.getClass()) {
|
||||
ctx.player().movementInput = desired; // only set it if it was previously incorrect
|
||||
// gotta do it this way, or else it constantly thinks you're beginning a double tap W sprint lol
|
||||
}
|
||||
}
|
||||
|
||||
private boolean inControl() {
|
||||
return baritone.getPathingBehavior().isPathing() || baritone != BaritoneAPI.getProvider().getPrimaryBaritone();
|
||||
}
|
||||
|
||||
public BlockBreakHelper getBlockBreakHelper() {
|
||||
return blockBreakHelper;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user