1
0
forked from Clones/Controlify

vertical/horizontal look sensitivity

This commit is contained in:
isXander
2023-02-01 15:49:12 +00:00
parent 4b085c5cce
commit e3178680f2
4 changed files with 51 additions and 13 deletions

View File

@ -11,7 +11,16 @@ import net.minecraft.resources.ResourceLocation;
import java.util.*; import java.util.*;
public class ControllerBindings { public class ControllerBindings {
public final ControllerBinding JUMP, SNEAK, ATTACK, USE, SPRINT, NEXT_SLOT, PREV_SLOT, PAUSE, INVENTORY, CHANGE_PERSPECTIVE, OPEN_CHAT; public final ControllerBinding
JUMP, SNEAK,
ATTACK, USE,
SPRINT,
NEXT_SLOT, PREV_SLOT,
PAUSE,
INVENTORY,
CHANGE_PERSPECTIVE,
OPEN_CHAT,
GUI_PRESS, GUI_BACK;
private final Map<ResourceLocation, ControllerBinding> registry = new HashMap<>(); private final Map<ResourceLocation, ControllerBinding> registry = new HashMap<>();
@ -29,6 +38,8 @@ public class ControllerBindings {
register(INVENTORY = new ControllerBinding(controller, Bind.Y_BUTTON, new ResourceLocation("controlify", "inventory"), options.keyInventory)); register(INVENTORY = new ControllerBinding(controller, Bind.Y_BUTTON, new ResourceLocation("controlify", "inventory"), options.keyInventory));
register(CHANGE_PERSPECTIVE = new ControllerBinding(controller, Bind.BACK, new ResourceLocation("controlify", "change_perspective"), options.keyTogglePerspective)); register(CHANGE_PERSPECTIVE = new ControllerBinding(controller, Bind.BACK, new ResourceLocation("controlify", "change_perspective"), options.keyTogglePerspective));
register(OPEN_CHAT = new ControllerBinding(controller, Bind.DPAD_UP, new ResourceLocation("controlify", "open_chat"), options.keyChat)); register(OPEN_CHAT = new ControllerBinding(controller, Bind.DPAD_UP, new ResourceLocation("controlify", "open_chat"), options.keyChat));
register(GUI_PRESS = new ControllerBinding(controller, Bind.A_BUTTON, new ResourceLocation("controlify", "gui_press"), null));
register(GUI_BACK = new ControllerBinding(controller, Bind.B_BUTTON, new ResourceLocation("controlify", "gui_back"), null));
ControlifyEvents.CONTROLLER_BIND_REGISTRY.invoker().onRegisterControllerBinds(this, controller); ControlifyEvents.CONTROLLER_BIND_REGISTRY.invoker().onRegisterControllerBinds(this, controller);

View File

@ -30,9 +30,15 @@ public class YACLHelper {
.name(Component.translatable("controlify.gui.group.config")) .name(Component.translatable("controlify.gui.group.config"))
.tooltip(Component.translatable("controlify.gui.group.config.tooltip")) .tooltip(Component.translatable("controlify.gui.group.config.tooltip"))
.option(Option.createBuilder(float.class) .option(Option.createBuilder(float.class)
.name(Component.translatable("controlify.gui.look_sensitivity")) .name(Component.translatable("controlify.gui.horizontal_look_sensitivity"))
.tooltip(Component.translatable("controlify.gui.look_sensitivity.tooltip")) .tooltip(Component.translatable("controlify.gui.horizontal_look_sensitivity.tooltip"))
.binding(def.lookSensitivity, () -> config.lookSensitivity, v -> config.lookSensitivity = v) .binding(def.horizontalLookSensitivity, () -> config.horizontalLookSensitivity, v -> config.horizontalLookSensitivity = v)
.controller(opt -> new FloatSliderController(opt, 0.1f, 2f, 0.05f, v -> Component.literal(String.format("%.0f%%", v*100))))
.build())
.option(Option.createBuilder(float.class)
.name(Component.translatable("controlify.gui.vertical_look_sensitivity"))
.tooltip(Component.translatable("controlify.gui.vertical_look_sensitivity.tooltip"))
.binding(def.verticalLookSensitivity, () -> config.verticalLookSensitivity, v -> config.verticalLookSensitivity = v)
.controller(opt -> new FloatSliderController(opt, 0.1f, 2f, 0.05f, v -> Component.literal(String.format("%.0f%%", v*100)))) .controller(opt -> new FloatSliderController(opt, 0.1f, 2f, 0.05f, v -> Component.literal(String.format("%.0f%%", v*100))))
.build()) .build())
.option(Option.createBuilder(float.class) .option(Option.createBuilder(float.class)

View File

@ -5,7 +5,8 @@ import dev.isxander.controlify.config.ControlifyConfig;
public class ControllerConfig { public class ControllerConfig {
public static final ControllerConfig DEFAULT = new ControllerConfig(); public static final ControllerConfig DEFAULT = new ControllerConfig();
public float lookSensitivity = 1f; public float horizontalLookSensitivity = 1f;
public float verticalLookSensitivity = 0.9f;
public float leftStickDeadzone = 0.2f; public float leftStickDeadzone = 0.2f;
public float rightStickDeadzone = 0.2f; public float rightStickDeadzone = 0.2f;
@ -24,6 +25,8 @@ public class ControllerConfig {
} }
public void overwrite(ControllerConfig from) { public void overwrite(ControllerConfig from) {
this.horizontalLookSensitivity = from.horizontalLookSensitivity;
this.verticalLookSensitivity = from.verticalLookSensitivity;
this.leftStickDeadzone = from.leftStickDeadzone; this.leftStickDeadzone = from.leftStickDeadzone;
this.rightStickDeadzone = from.rightStickDeadzone; this.rightStickDeadzone = from.rightStickDeadzone;
this.leftTriggerDeadzone = from.leftTriggerDeadzone; this.leftTriggerDeadzone = from.leftTriggerDeadzone;

View File

@ -5,13 +5,15 @@ import dev.isxander.controlify.InputMode;
import dev.isxander.controlify.controller.Controller; import dev.isxander.controlify.controller.Controller;
import dev.isxander.controlify.event.ControlifyEvents; import dev.isxander.controlify.event.ControlifyEvents;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.PauseScreen; import net.minecraft.client.player.Input;
import net.minecraft.client.player.KeyboardInput; import net.minecraft.client.player.KeyboardInput;
public class InGameInputHandler { public class InGameInputHandler {
private final Controller controller; private final Controller controller;
private final Minecraft minecraft; private final Minecraft minecraft;
private final Input controllerInput, keyboardInput;
private double accumulatedDX, accumulatedDY; private double accumulatedDX, accumulatedDY;
private double deltaTime; private double deltaTime;
@ -19,11 +21,14 @@ public class InGameInputHandler {
this.controller = controller; this.controller = controller;
this.minecraft = Minecraft.getInstance(); this.minecraft = Minecraft.getInstance();
this.controllerInput = new ControllerPlayerMovement(controller);
this.keyboardInput = new KeyboardInput(minecraft.options);
ControlifyEvents.INPUT_MODE_CHANGED.register(mode -> { ControlifyEvents.INPUT_MODE_CHANGED.register(mode -> {
if (minecraft.player != null) { if (minecraft.player != null) {
minecraft.player.input = mode == InputMode.CONTROLLER minecraft.player.input = mode == InputMode.CONTROLLER
? new ControllerPlayerMovement(controller) ? this.controllerInput
: new KeyboardInput(minecraft.options); : this.keyboardInput;
} }
}); });
} }
@ -55,15 +60,28 @@ public class InGameInputHandler {
var delta = time - deltaTime; var delta = time - deltaTime;
deltaTime = time; deltaTime = time;
var sensitivity = controller.config().lookSensitivity * 8f + 2f; var hsensitivity = controller.config().horizontalLookSensitivity * 8.0 + 2.0;
var sensCubed = sensitivity * sensitivity * sensitivity; var hsensCubed = hsensitivity * hsensitivity * hsensitivity;
var vsensitivity = controller.config().verticalLookSensitivity * 8.0 + 2.0;
var vsensCubed = vsensitivity * vsensitivity * vsensitivity;
var dx = accumulatedDX * delta; var dx = accumulatedDX * delta;
var dy = accumulatedDY * delta; var dy = accumulatedDY * delta;
accumulatedDX -= dx * 20; // 20 is how quickly the camera will slow down
accumulatedDY -= dy * 20; // drag
if (accumulatedDX > 0) {
accumulatedDX -= Math.min(dx * 20, accumulatedDX);
} else if (accumulatedDX < 0) {
accumulatedDX -= Math.max(dx * 20, accumulatedDX);
}
if (accumulatedDY > 0) {
accumulatedDY -= Math.min(dy * 20, accumulatedDY);
} else if (accumulatedDY < 0) {
accumulatedDY -= Math.max(dy * 20, accumulatedDY);
}
if (minecraft.player != null) if (minecraft.player != null)
minecraft.player.turn(dx * sensCubed, dy * sensCubed); minecraft.player.turn(dx * hsensCubed, dy * vsensCubed);
} }
} }