mirror of
https://github.com/TeamMidnightDust/MidnightControls.git
synced 2025-12-13 15:25:08 +01:00
🐛 Fix sneak toggle, arrow keys in chat not working, etc...
This commit is contained in:
@@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
|
|||||||
loader_version=0.7.2+build.174
|
loader_version=0.7.2+build.174
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 1.0.1
|
mod_version = 1.0.2
|
||||||
maven_group = me.lambdaurora
|
maven_group = me.lambdaurora
|
||||||
archives_base_name = lambdacontrols
|
archives_base_name = lambdacontrols
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,12 @@ public class ButtonBinding implements Nameable
|
|||||||
{
|
{
|
||||||
private static final List<ButtonBinding> BINDINGS = new ArrayList<>();
|
private static final List<ButtonBinding> BINDINGS = new ArrayList<>();
|
||||||
private static final List<Category> CATEGORIES = new ArrayList<>();
|
private static final List<Category> CATEGORIES = new ArrayList<>();
|
||||||
|
public static final PressAction DEFAULT_ACTION = (client, button, action) -> {
|
||||||
|
if (action == 2)
|
||||||
|
return false;
|
||||||
|
button.as_key_binding().ifPresent(key_binding -> ((KeyBindingAccessor) key_binding).handle_press_state(button.is_button_down()));
|
||||||
|
return true;
|
||||||
|
};
|
||||||
public static final Category MOVEMENT_CATEGORY;
|
public static final Category MOVEMENT_CATEGORY;
|
||||||
public static final Category GAMEPLAY_CATEGORY;
|
public static final Category GAMEPLAY_CATEGORY;
|
||||||
public static final Category INVENTORY_CATEGORY;
|
public static final Category INVENTORY_CATEGORY;
|
||||||
@@ -52,14 +58,21 @@ public class ButtonBinding implements Nameable
|
|||||||
public static final ButtonBinding PLAYER_LIST = new ButtonBinding("player_list", GLFW.GLFW_GAMEPAD_BUTTON_BACK);
|
public static final ButtonBinding PLAYER_LIST = new ButtonBinding("player_list", GLFW.GLFW_GAMEPAD_BUTTON_BACK);
|
||||||
public static final ButtonBinding RIGHT = new ButtonBinding("right", axis_as_button(GLFW.GLFW_GAMEPAD_AXIS_LEFT_X, true));
|
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,
|
public static final ButtonBinding SCREENSHOT = new ButtonBinding("screenshot", GLFW.GLFW_GAMEPAD_BUTTON_DPAD_DOWN,
|
||||||
Collections.singletonList((client, action) -> {
|
Collections.singletonList((client, button, action) -> {
|
||||||
if (action == 0)
|
if (action == 0)
|
||||||
ScreenshotUtils.saveScreenshot(client.runDirectory, client.getWindow().getFramebufferWidth(), client.getWindow().getFramebufferHeight(), client.getFramebuffer(),
|
ScreenshotUtils.saveScreenshot(client.runDirectory, client.getWindow().getFramebufferWidth(), client.getWindow().getFramebufferHeight(), client.getFramebuffer(),
|
||||||
text -> client.execute(() -> client.inGameHud.getChatHud().addMessage(text)));
|
text -> client.execute(() -> client.inGameHud.getChatHud().addMessage(text)));
|
||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
public static final ButtonBinding SMOOTH_CAMERA = new ButtonBinding("toggle_smooth_camera", -1);
|
public static final ButtonBinding SMOOTH_CAMERA = new ButtonBinding("toggle_smooth_camera", -1);
|
||||||
public static final ButtonBinding SNEAK = new ButtonBinding("sneak", GLFW.GLFW_GAMEPAD_BUTTON_RIGHT_THUMB);
|
public static final ButtonBinding SNEAK = new ButtonBinding("sneak", GLFW.GLFW_GAMEPAD_BUTTON_RIGHT_THUMB,
|
||||||
|
Arrays.asList(DEFAULT_ACTION, (client, button, action) -> {
|
||||||
|
if (client.player != null && !client.player.abilities.flying) {
|
||||||
|
button.as_key_binding().filter(binding -> action == 0).ifPresent(binding -> ((KeyBindingAccessor) binding).handle_press_state(!binding.isPressed()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}));
|
||||||
public static final ButtonBinding SPRINT = new ButtonBinding("sprint", GLFW.GLFW_GAMEPAD_BUTTON_LEFT_THUMB);
|
public static final ButtonBinding SPRINT = new ButtonBinding("sprint", GLFW.GLFW_GAMEPAD_BUTTON_LEFT_THUMB);
|
||||||
public static final ButtonBinding SWAP_HANDS = new ButtonBinding("swap_hands", GLFW.GLFW_GAMEPAD_BUTTON_X);
|
public static final ButtonBinding SWAP_HANDS = new ButtonBinding("swap_hands", GLFW.GLFW_GAMEPAD_BUTTON_X);
|
||||||
public static final ButtonBinding TOGGLE_PERSPECTIVE = new ButtonBinding("toggle_perspective", GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP);
|
public static final ButtonBinding TOGGLE_PERSPECTIVE = new ButtonBinding("toggle_perspective", GLFW.GLFW_GAMEPAD_BUTTON_DPAD_UP);
|
||||||
@@ -69,10 +82,7 @@ public class ButtonBinding implements Nameable
|
|||||||
private int default_button;
|
private int default_button;
|
||||||
private String key;
|
private String key;
|
||||||
private KeyBinding minecraft_key_binding = null;
|
private KeyBinding minecraft_key_binding = null;
|
||||||
private List<PressAction> actions = new ArrayList<>(Collections.singletonList((client, action) -> {
|
private List<PressAction> actions = new ArrayList<>(Collections.singletonList(DEFAULT_ACTION));
|
||||||
this.as_key_binding().ifPresent(key_binding -> ((KeyBindingAccessor) key_binding).handle_press_state(this.is_button_down()));
|
|
||||||
return true;
|
|
||||||
}));
|
|
||||||
private boolean pressed = false;
|
private boolean pressed = false;
|
||||||
|
|
||||||
protected ButtonBinding(@NotNull String key, int default_button, @NotNull List<PressAction> actions)
|
protected ButtonBinding(@NotNull String key, int default_button, @NotNull List<PressAction> actions)
|
||||||
@@ -246,7 +256,7 @@ public class ButtonBinding implements Nameable
|
|||||||
BINDINGS.parallelStream().filter(binding -> binding.button == button)
|
BINDINGS.parallelStream().filter(binding -> binding.button == button)
|
||||||
.forEach(binding -> {
|
.forEach(binding -> {
|
||||||
for (int i = binding.actions.size() - 1; i >= 0; i--) {
|
for (int i = binding.actions.size() - 1; i >= 0; i--) {
|
||||||
if (binding.actions.get(i).press(client, action))
|
if (binding.actions.get(i).press(client, binding, action))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -502,6 +512,6 @@ public class ButtonBinding implements Nameable
|
|||||||
* @param client The client instance.
|
* @param client The client instance.
|
||||||
* @param action The action done.
|
* @param action The action done.
|
||||||
*/
|
*/
|
||||||
boolean press(@NotNull MinecraftClient client, int action);
|
boolean press(@NotNull MinecraftClient client, @NotNull ButtonBinding button, int action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -232,16 +232,17 @@ public class LambdaControls implements ClientModInitializer
|
|||||||
|
|
||||||
public static int draw_button_tip(int x, int y, int button, @NotNull String action, boolean display, @NotNull MinecraftClient client)
|
public static int draw_button_tip(int x, int y, int button, @NotNull String action, boolean display, @NotNull MinecraftClient client)
|
||||||
{
|
{
|
||||||
String translated_action = I18n.translate(action);
|
|
||||||
|
|
||||||
if (display) {
|
if (display) {
|
||||||
int button_width = draw_button(x, y, button, client);
|
int button_width = draw_button(x, y, button, client);
|
||||||
|
|
||||||
|
String translated_action = I18n.translate(action);
|
||||||
int text_y = (15 - client.textRenderer.fontHeight) / 2;
|
int text_y = (15 - client.textRenderer.fontHeight) / 2;
|
||||||
client.textRenderer.drawWithShadow(translated_action, (float) (x + button_width + 5), (float) (y + text_y), 14737632);
|
client.textRenderer.drawWithShadow(translated_action, (float) (x + button_width + 5), (float) (y + text_y), 14737632);
|
||||||
|
|
||||||
|
return get_button_tip_width(translated_action, client.textRenderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return display ? get_button_tip_width(translated_action, client.textRenderer) : -10;
|
return -10;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int get_button_tip_width(@NotNull String action, @NotNull TextRenderer text_renderer)
|
private static int get_button_tip_width(@NotNull String action, @NotNull TextRenderer text_renderer)
|
||||||
|
|||||||
@@ -61,9 +61,11 @@ public class LambdaInput
|
|||||||
private static final Map<Integer, Boolean> AXIS_STATES = new HashMap<>();
|
private static final Map<Integer, Boolean> AXIS_STATES = new HashMap<>();
|
||||||
private static final Map<Integer, Integer> AXIS_COOLDOWNS = new HashMap<>();
|
private static final Map<Integer, Integer> AXIS_COOLDOWNS = new HashMap<>();
|
||||||
private final LambdaControlsConfig config;
|
private final LambdaControlsConfig config;
|
||||||
|
// Cooldowns
|
||||||
private int action_gui_cooldown = 0;
|
private int action_gui_cooldown = 0;
|
||||||
private int ignore_next_a = 0;
|
private int ignore_next_a = 0;
|
||||||
private int last_sneak = 0;
|
// Sneak state.
|
||||||
|
private boolean sneak = false;
|
||||||
private double prev_target_yaw = 0.0;
|
private double prev_target_yaw = 0.0;
|
||||||
private double prev_target_pitch = 0.0;
|
private double prev_target_pitch = 0.0;
|
||||||
private double target_yaw = 0.0;
|
private double target_yaw = 0.0;
|
||||||
@@ -114,9 +116,6 @@ public class LambdaInput
|
|||||||
{
|
{
|
||||||
BUTTON_COOLDOWNS.entrySet().stream().filter(entry -> entry.getValue() > 0).forEach(entry -> BUTTON_COOLDOWNS.put(entry.getKey(), entry.getValue() - 1));
|
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));
|
AXIS_COOLDOWNS.entrySet().stream().filter(entry -> entry.getValue() > 0).forEach(entry -> AXIS_COOLDOWNS.put(entry.getKey(), entry.getValue() - 1));
|
||||||
// Decreases the last_sneak counter which allows to double press to sneak continuously.
|
|
||||||
if (this.last_sneak > 0)
|
|
||||||
--this.last_sneak;
|
|
||||||
// Decreases the cooldown for GUI actions.
|
// Decreases the cooldown for GUI actions.
|
||||||
if (this.action_gui_cooldown > 0)
|
if (this.action_gui_cooldown > 0)
|
||||||
--this.action_gui_cooldown;
|
--this.action_gui_cooldown;
|
||||||
@@ -317,11 +316,6 @@ public class LambdaInput
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handles sneak button.
|
|
||||||
if (SNEAK.is_button(button) && client.player != null) {
|
|
||||||
this.toggle_sneaking(client);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (button == GLFW.GLFW_GAMEPAD_BUTTON_A && client.currentScreen != null && !is_screen_interactive(client.currentScreen) && this.action_gui_cooldown == 0 && this.ignore_next_a == 0) {
|
if (button == GLFW.GLFW_GAMEPAD_BUTTON_A && client.currentScreen != null && !is_screen_interactive(client.currentScreen) && this.action_gui_cooldown == 0 && this.ignore_next_a == 0) {
|
||||||
@@ -336,7 +330,7 @@ public class LambdaInput
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client.currentScreen == null && action != 2) {
|
if (client.currentScreen == null) {
|
||||||
ButtonBinding.handle_button(client, button, action);
|
ButtonBinding.handle_button(client, button, action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -551,16 +545,6 @@ public class LambdaInput
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Toggles whether the player is sneaking.
|
|
||||||
*
|
|
||||||
* @param client The client's instance.
|
|
||||||
*/
|
|
||||||
private void toggle_sneaking(@NotNull MinecraftClient client)
|
|
||||||
{
|
|
||||||
((KeyBindingAccessor) client.options.keySneak).handle_press_state(!client.options.keySneak.isPressed());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the look direction input.
|
* Handles the look direction input.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright © 2019 LambdAurora <aurora42lambda@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of LambdaControls.
|
|
||||||
*
|
|
||||||
* Licensed under the MIT license. For more information,
|
|
||||||
* see the LICENSE file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package me.lambdaurora.lambdacontrols.mixin;
|
|
||||||
|
|
||||||
import net.minecraft.client.gui.ParentElement;
|
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
||||||
|
|
||||||
@Mixin(Screen.class)
|
|
||||||
public abstract class ScreenMixin implements ParentElement
|
|
||||||
{
|
|
||||||
@Inject(method = "keyPressed", at = @At("HEAD"), cancellable = true)
|
|
||||||
private void on_key_pressed(int key_code, int scan_code, int modifiers, CallbackInfoReturnable<Boolean> ci)
|
|
||||||
{
|
|
||||||
if (key_code == GLFW.GLFW_KEY_UP || key_code == GLFW.GLFW_KEY_LEFT) {
|
|
||||||
this.changeFocus(false);
|
|
||||||
ci.setReturnValue(true);
|
|
||||||
ci.cancel();
|
|
||||||
} else if (key_code == GLFW.GLFW_KEY_DOWN || key_code == GLFW.GLFW_KEY_RIGHT) {
|
|
||||||
this.changeFocus(true);
|
|
||||||
ci.setReturnValue(true);
|
|
||||||
ci.cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,7 +12,6 @@
|
|||||||
"KeyBindingMixin",
|
"KeyBindingMixin",
|
||||||
"MinecraftClientMixin",
|
"MinecraftClientMixin",
|
||||||
"MouseMixin",
|
"MouseMixin",
|
||||||
"ScreenMixin",
|
|
||||||
"SettingsScreenMixin"
|
"SettingsScreenMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
|
|||||||
Reference in New Issue
Block a user