mirror of
https://github.com/TeamMidnightDust/MidnightControls.git
synced 2025-12-13 15:25:08 +01:00
✨ Add look keybindings.
This commit is contained in:
@@ -53,8 +53,9 @@ public class ButtonBinding implements Nameable
|
||||
public static final ButtonBinding RIGHT = new ButtonBinding("right", axis_as_button(GLFW.GLFW_GAMEPAD_AXIS_LEFT_X, true));
|
||||
public static final ButtonBinding SCREENSHOT = new ButtonBinding("screenshot", GLFW.GLFW_GAMEPAD_BUTTON_DPAD_DOWN,
|
||||
Collections.singletonList((client, action) -> {
|
||||
ScreenshotUtils.saveScreenshot(client.runDirectory, client.getWindow().getFramebufferWidth(), client.getWindow().getFramebufferHeight(), client.getFramebuffer(),
|
||||
text -> client.execute(() -> client.inGameHud.getChatHud().addMessage(text)));
|
||||
if (action == 0)
|
||||
ScreenshotUtils.saveScreenshot(client.runDirectory, client.getWindow().getFramebufferWidth(), client.getWindow().getFramebufferHeight(), client.getFramebuffer(),
|
||||
text -> client.execute(() -> client.inGameHud.getChatHud().addMessage(text)));
|
||||
return true;
|
||||
}));
|
||||
public static final ButtonBinding SMOOTH_CAMERA = new ButtonBinding("toggle_smooth_camera", -1);
|
||||
|
||||
@@ -80,12 +80,27 @@ public class ControllerInput
|
||||
this.config = mod.config;
|
||||
}
|
||||
|
||||
public void on_tick(@NotNull MinecraftClient client)
|
||||
{
|
||||
if (LambdaControls.BINDING_LOOK_UP.isPressed()) {
|
||||
this.handle_look(client, GLFW_GAMEPAD_AXIS_RIGHT_Y, 0.8F, 2);
|
||||
} else if (LambdaControls.BINDING_LOOK_DOWN.isPressed()) {
|
||||
this.handle_look(client, GLFW_GAMEPAD_AXIS_RIGHT_Y, 0.8F, 1);
|
||||
}
|
||||
|
||||
if (LambdaControls.BINDING_LOOK_RIGHT.isPressed()) {
|
||||
this.handle_look(client, GLFW_GAMEPAD_AXIS_RIGHT_X, 0.8F, 2);
|
||||
} else if (LambdaControls.BINDING_LOOK_LEFT.isPressed()) {
|
||||
this.handle_look(client, GLFW_GAMEPAD_AXIS_RIGHT_X, 0.8F, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called every Minecraft tick.
|
||||
*
|
||||
* @param client The client instance.
|
||||
*/
|
||||
public void on_tick(@NotNull MinecraftClient client)
|
||||
public void on_controller_tick(@NotNull MinecraftClient client)
|
||||
{
|
||||
BUTTON_COOLDOWNS.entrySet().stream().filter(entry -> entry.getValue() > 0).forEach(entry -> BUTTON_COOLDOWNS.put(entry.getKey(), entry.getValue() - 1));
|
||||
AXIS_COOLDOWNS.entrySet().stream().filter(entry -> entry.getValue() > 0).forEach(entry -> AXIS_COOLDOWNS.put(entry.getKey(), entry.getValue() - 1));
|
||||
@@ -344,25 +359,7 @@ public class ControllerInput
|
||||
}
|
||||
|
||||
// Handles the look direction.
|
||||
if (client.player != null) {
|
||||
double pow_value = Math.pow(abs_value, 2.0);
|
||||
if (axis == GLFW_GAMEPAD_AXIS_RIGHT_Y) {
|
||||
if (state == 2) {
|
||||
this.target_pitch = client.player.pitch - this.config.get_right_y_axis_sign() * (this.config.get_rotation_speed() * pow_value) * 0.33D;
|
||||
this.target_pitch = MathHelper.clamp(this.target_pitch, -90.0D, 90.0D);
|
||||
} else if (state == 1) {
|
||||
this.target_pitch = client.player.pitch + this.config.get_right_y_axis_sign() * (this.config.get_rotation_speed() * pow_value) * 0.33D;
|
||||
this.target_pitch = MathHelper.clamp(this.target_pitch, -90.0D, 90.0D);
|
||||
}
|
||||
}
|
||||
if (axis == GLFW_GAMEPAD_AXIS_RIGHT_X) {
|
||||
if (state == 2) {
|
||||
this.target_yaw = client.player.yaw - this.config.get_right_x_axis_sign() * (this.config.get_rotation_speed() * pow_value) * 0.33D;
|
||||
} else if (state == 1) {
|
||||
this.target_yaw = client.player.yaw + this.config.get_right_x_axis_sign() * (this.config.get_rotation_speed() * pow_value) * 0.33D;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.handle_look(client, axis, abs_value, state);
|
||||
} else {
|
||||
boolean allow_mouse_control = true;
|
||||
|
||||
@@ -530,6 +527,38 @@ public class ControllerInput
|
||||
((KeyBindingAccessor) client.options.keySneak).handle_press_state(!client.options.keySneak.isPressed());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the look direction input.
|
||||
*
|
||||
* @param client The client isntance.
|
||||
* @param axis The axis to change.
|
||||
* @param value The value of the look.
|
||||
* @param state The state.
|
||||
*/
|
||||
private void handle_look(@NotNull MinecraftClient client, int axis, float value, int state)
|
||||
{
|
||||
// Handles the look direction.
|
||||
if (client.player != null) {
|
||||
double pow_value = Math.pow(value, 2.0);
|
||||
if (axis == GLFW_GAMEPAD_AXIS_RIGHT_Y) {
|
||||
if (state == 2) {
|
||||
this.target_pitch = client.player.pitch - this.config.get_right_y_axis_sign() * (this.config.get_rotation_speed() * pow_value) * 0.33D;
|
||||
this.target_pitch = MathHelper.clamp(this.target_pitch, -90.0D, 90.0D);
|
||||
} else if (state == 1) {
|
||||
this.target_pitch = client.player.pitch + this.config.get_right_y_axis_sign() * (this.config.get_rotation_speed() * pow_value) * 0.33D;
|
||||
this.target_pitch = MathHelper.clamp(this.target_pitch, -90.0D, 90.0D);
|
||||
}
|
||||
}
|
||||
if (axis == GLFW_GAMEPAD_AXIS_RIGHT_X) {
|
||||
if (state == 2) {
|
||||
this.target_yaw = client.player.yaw - this.config.get_right_x_axis_sign() * (this.config.get_rotation_speed() * pow_value) * 0.33D;
|
||||
} else if (state == 1) {
|
||||
this.target_yaw = client.player.yaw + this.config.get_right_x_axis_sign() * (this.config.get_rotation_speed() * pow_value) * 0.33D;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean change_focus(@NotNull Screen screen, boolean down)
|
||||
{
|
||||
if (!screen.changeFocus(down)) {
|
||||
@@ -544,7 +573,7 @@ public class ControllerInput
|
||||
}
|
||||
}
|
||||
|
||||
static boolean is_screen_interactive(@NotNull Screen screen)
|
||||
private static boolean is_screen_interactive(@NotNull Screen screen)
|
||||
{
|
||||
return !(screen instanceof AdvancementsScreen || screen instanceof AbstractContainerScreen);
|
||||
}
|
||||
|
||||
@@ -11,11 +11,14 @@ package me.lambdaurora.lambdacontrols;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding;
|
||||
import net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.DrawableHelper;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.client.toast.SystemToast;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.util.Identifier;
|
||||
@@ -29,12 +32,20 @@ import org.lwjgl.glfw.GLFW;
|
||||
*/
|
||||
public class LambdaControls implements ClientModInitializer
|
||||
{
|
||||
private static LambdaControls INSTANCE;
|
||||
private static LambdaControls INSTANCE;
|
||||
public static final FabricKeyBinding BINDING_LOOK_UP = FabricKeyBinding.Builder.create(new Identifier("lambdacontrols", "look_up"),
|
||||
InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_8, "key.categories.movement").build();
|
||||
public static final FabricKeyBinding BINDING_LOOK_RIGHT = FabricKeyBinding.Builder.create(new Identifier("lambdacontrols", "look_right"),
|
||||
InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_6, "key.categories.movement").build();
|
||||
public static final FabricKeyBinding BINDING_LOOK_DOWN = FabricKeyBinding.Builder.create(new Identifier("lambdacontrols", "look_down"),
|
||||
InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_2, "key.categories.movement").build();
|
||||
public static final FabricKeyBinding BINDING_LOOK_LEFT = FabricKeyBinding.Builder.create(new Identifier("lambdacontrols", "look_left"),
|
||||
InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_4, "key.categories.movement").build();
|
||||
public static final Identifier CONTROLLER_BUTTONS = new Identifier("lambdacontrols", "textures/gui/controller_buttons.png");
|
||||
public final Logger logger = LogManager.getLogger("LambdaControls");
|
||||
public final LambdaControlsConfig config = new LambdaControlsConfig(this);
|
||||
public final ControllerInput controller_input = new ControllerInput(this);
|
||||
private ControlsMode previous_controls_mode;
|
||||
public final ControllerInput controller_input = new ControllerInput(this);
|
||||
private ControlsMode previous_controls_mode;
|
||||
|
||||
@Override
|
||||
public void onInitializeClient()
|
||||
@@ -42,6 +53,11 @@ public class LambdaControls implements ClientModInitializer
|
||||
INSTANCE = this;
|
||||
this.log("Initializing LambdaControls...");
|
||||
this.config.load();
|
||||
|
||||
KeyBindingRegistry.INSTANCE.register(BINDING_LOOK_UP);
|
||||
KeyBindingRegistry.INSTANCE.register(BINDING_LOOK_RIGHT);
|
||||
KeyBindingRegistry.INSTANCE.register(BINDING_LOOK_DOWN);
|
||||
KeyBindingRegistry.INSTANCE.register(BINDING_LOOK_LEFT);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,8 +88,9 @@ public class LambdaControls implements ClientModInitializer
|
||||
*/
|
||||
public void on_tick(@NotNull MinecraftClient client)
|
||||
{
|
||||
this.controller_input.on_tick(client);
|
||||
if (this.config.get_controls_mode() == ControlsMode.CONTROLLER)
|
||||
this.controller_input.on_tick(client);
|
||||
this.controller_input.on_controller_tick(client);
|
||||
}
|
||||
|
||||
public void on_render(MinecraftClient client)
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
{
|
||||
"key.lambdacontrols.look_down": "Look down",
|
||||
"key.lambdacontrols.look_left": "Look left",
|
||||
"key.lambdacontrols.look_right": "Look right",
|
||||
"key.lambdacontrols.look_up": "Look up",
|
||||
"lambdacontrols.action.attack": "Attack",
|
||||
"lambdacontrols.action.back": "Back",
|
||||
"lambdacontrols.action.chat": "Open Chat",
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
{
|
||||
"key.lambdacontrols.look_down": "Regarder en bas",
|
||||
"key.lambdacontrols.look_left": "Regarder à gauche",
|
||||
"key.lambdacontrols.look_right": "Regarder à droite",
|
||||
"key.lambdacontrols.look_up": "Regarder en haut",
|
||||
"lambdacontrols.action.attack": "Attaquer",
|
||||
"lambdacontrols.action.back": "Reculer",
|
||||
"lambdacontrols.action.chat": "Ouvrir le tchat",
|
||||
|
||||
Reference in New Issue
Block a user