1
0
forked from Clones/Controlify

🐛 Fix move/jump/sneak not working after hotplugging a controller ingame

This commit is contained in:
isXander
2023-07-11 22:05:55 +01:00
parent 2010eb1d58
commit 7ccfd426a1
3 changed files with 23 additions and 12 deletions

View File

@ -11,6 +11,7 @@ import dev.isxander.controlify.controller.sdl2.SDL2NativesManager;
import dev.isxander.controlify.debug.DebugProperties;
import dev.isxander.controlify.gui.screen.ControllerCalibrationScreen;
import dev.isxander.controlify.gui.screen.SDLOnboardingScreen;
import dev.isxander.controlify.ingame.ControllerPlayerMovement;
import dev.isxander.controlify.reacharound.ReachAroundHandler;
import dev.isxander.controlify.reacharound.ReachAroundMode;
import dev.isxander.controlify.screenop.ScreenProcessorProvider;
@ -480,9 +481,11 @@ public class Controlify implements ControlifyApi {
this.inGameInputHandler = new InGameInputHandler(controller);
if (minecraft.player != null) {
this.inGameButtonGuide = new InGameButtonGuide(controller, Minecraft.getInstance().player);
this.inGameButtonGuide = new InGameButtonGuide(controller, minecraft.player);
}
ControllerPlayerMovement.updatePlayerInput(minecraft.player);
if (!controller.config().deadzonesCalibrated)
calibrationQueue.add(controller);
}

View File

@ -4,7 +4,9 @@ import dev.isxander.controlify.Controlify;
import dev.isxander.controlify.controller.Controller;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.Input;
import net.minecraft.client.player.KeyboardInput;
import net.minecraft.client.player.LocalPlayer;
import org.jetbrains.annotations.Nullable;
public class ControllerPlayerMovement extends Input {
private final Controller<?, ?> controller;
@ -66,4 +68,19 @@ public class ControllerPlayerMovement extends Input {
}
}
}
public static void updatePlayerInput(@Nullable LocalPlayer player) {
if (player == null)
return;
if (Controlify.instance().getCurrentController().isPresent()) {
player.input = new DualInput(
new KeyboardInput(Minecraft.getInstance().options),
new ControllerPlayerMovement(Controlify.instance().getCurrentController().get(), player)
);
} else if (!(player.input instanceof KeyboardInput)) {
player.input = new KeyboardInput(Minecraft.getInstance().options);
}
}
}

View File

@ -27,20 +27,11 @@ public class ClientPacketListenerMixin {
@Inject(method = "handleLogin", at = @At(value = "FIELD", target = "Lnet/minecraft/client/player/LocalPlayer;input:Lnet/minecraft/client/player/Input;", opcode = Opcodes.ASTORE, shift = At.Shift.AFTER))
private void overrideNewPlayerInput(ClientboundLoginPacket packet, CallbackInfo ci) {
overrideInput(minecraft.player);
ControllerPlayerMovement.updatePlayerInput(minecraft.player);
}
@Inject(method = "handleRespawn", at = @At(value = "FIELD", target = "Lnet/minecraft/client/player/LocalPlayer;input:Lnet/minecraft/client/player/Input;", opcode = Opcodes.ASTORE, shift = At.Shift.AFTER))
private void overrideRespawnInput(ClientboundRespawnPacket packet, CallbackInfo ci, @Local(ordinal = 1) LocalPlayer newPlayer) {
overrideInput(newPlayer);
}
private void overrideInput(LocalPlayer player) {
if (player == null)
return;
ControlifyApi.get().getCurrentController().ifPresent(controller -> {
player.input = new DualInput(new KeyboardInput(minecraft.options), new ControllerPlayerMovement(controller, player));
});
ControllerPlayerMovement.updatePlayerInput(newPlayer);
}
}