mirror of
https://github.com/TeamMidnightDust/MidnightControls.git
synced 2025-12-13 23:25:10 +01:00
✨ Add new unfocused input option, improve front block placing.
This commit is contained in:
@@ -105,7 +105,7 @@ public class LambdaControlsClient extends LambdaControls implements ClientModIni
|
||||
public void on_tick(@NotNull MinecraftClient client)
|
||||
{
|
||||
this.input.on_tick(client);
|
||||
if (this.config.get_controls_mode() == ControlsMode.CONTROLLER)
|
||||
if (this.config.get_controls_mode() == ControlsMode.CONTROLLER && (client.isWindowFocused() || this.config.has_unfocused_input()))
|
||||
this.input.on_controller_tick(client);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ public class LambdaControlsConfig
|
||||
private static final double DEFAULT_DEAD_ZONE = 0.25;
|
||||
private static final double DEFAULT_ROTATION_SPEED = 40.0;
|
||||
private static final double DEFAULT_MOUSE_SPEED = 25.0;
|
||||
private static final boolean DEFAULT_UNFOCUSED_INPUT = false;
|
||||
|
||||
private static final Pattern BUTTON_BINDING_PATTERN = Pattern.compile("(-?\\d+)\\+?");
|
||||
|
||||
@@ -60,6 +61,7 @@ public class LambdaControlsConfig
|
||||
private double dead_zone;
|
||||
private double rotation_speed;
|
||||
private double mouse_speed;
|
||||
private boolean unfocused_input;
|
||||
|
||||
public LambdaControlsConfig(@NotNull LambdaControlsClient mod)
|
||||
{
|
||||
@@ -83,6 +85,7 @@ public class LambdaControlsConfig
|
||||
this.dead_zone = this.config.getOrElse("controller.dead_zone", DEFAULT_DEAD_ZONE);
|
||||
this.rotation_speed = this.config.getOrElse("controller.rotation_speed", DEFAULT_ROTATION_SPEED);
|
||||
this.mouse_speed = this.config.getOrElse("controller.mouse_speed", DEFAULT_MOUSE_SPEED);
|
||||
this.unfocused_input = this.config.getOrElse("controller.unfocused_input", DEFAULT_UNFOCUSED_INPUT);
|
||||
// Controller controls.
|
||||
InputManager.load_button_bindings(this);
|
||||
}
|
||||
@@ -95,6 +98,7 @@ public class LambdaControlsConfig
|
||||
this.config.set("controller.dead_zone", this.dead_zone);
|
||||
this.config.set("controller.rotation_speed", this.rotation_speed);
|
||||
this.config.set("controller.mouse_speed", this.mouse_speed);
|
||||
this.config.set("controller.unfocused_input", this.unfocused_input);
|
||||
this.config.save();
|
||||
this.mod.log("Configuration saved.");
|
||||
}
|
||||
@@ -130,6 +134,7 @@ public class LambdaControlsConfig
|
||||
this.set_dead_zone(DEFAULT_DEAD_ZONE);
|
||||
this.set_rotation_speed(DEFAULT_ROTATION_SPEED);
|
||||
this.set_mouse_speed(DEFAULT_MOUSE_SPEED);
|
||||
this.set_unfocused_input(DEFAULT_UNFOCUSED_INPUT);
|
||||
|
||||
// Collect prevents concurrent modification.
|
||||
InputManager.stream_bindings().collect(Collectors.toList()).forEach(binding -> this.set_button_binding(binding, binding.get_default_button()));
|
||||
@@ -445,6 +450,26 @@ public class LambdaControlsConfig
|
||||
this.config.set("controller.invert_right_y_axis", invert);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether unfocused controller input is allowed or not.
|
||||
*
|
||||
* @return True if unfocused controller input is allowed, else false.
|
||||
*/
|
||||
public boolean has_unfocused_input()
|
||||
{
|
||||
return this.unfocused_input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether unfocused controller input is allowed or not.
|
||||
*
|
||||
* @param unfocused_input True if unfocused controller input is allowed, else false.
|
||||
*/
|
||||
public void set_unfocused_input(boolean unfocused_input)
|
||||
{
|
||||
this.unfocused_input = unfocused_input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the right X axis sign.
|
||||
*
|
||||
|
||||
@@ -55,6 +55,7 @@ public class LambdaControlsSettingsScreen extends Screen
|
||||
private final Option dead_zone_option;
|
||||
private final Option inverts_right_x_axis;
|
||||
private final Option inverts_right_y_axis;
|
||||
private final Option unfocused_input_option;
|
||||
// Hud options
|
||||
private final Option hud_enable_option;
|
||||
private final Option hud_side_option;
|
||||
@@ -70,7 +71,7 @@ public class LambdaControlsSettingsScreen extends Screen
|
||||
this.hide_controls = hide_controls;
|
||||
// General options
|
||||
this.auto_switch_mode_option = new SpruceBooleanOption("lambdacontrols.menu.auto_switch_mode", game_options -> this.mod.config.has_auto_switch_mode(),
|
||||
(game_options, new_value) -> this.mod.config.set_auto_switch_mode(new_value), new TranslatableText("lambdacontrols.tooltip.auto_switch_mode"));
|
||||
(game_options, new_value) -> this.mod.config.set_auto_switch_mode(new_value), new TranslatableText("lambdacontrols.tooltip.auto_switch_mode"), true);
|
||||
this.rotation_speed_option = new SpruceDoubleOption("lambdacontrols.menu.rotation_speed", 0.0, 150.0, 0.5F, game_options -> this.mod.config.get_rotation_speed(),
|
||||
(game_options, new_value) -> {
|
||||
synchronized (this.mod.config) {
|
||||
@@ -92,9 +93,9 @@ public class LambdaControlsSettingsScreen extends Screen
|
||||
});
|
||||
// Gameplay options
|
||||
this.front_block_placing_option = new SpruceBooleanOption("lambdacontrols.menu.front_block_placing", game_options -> this.mod.config.has_front_block_placing(),
|
||||
(game_options, new_value) -> this.mod.config.set_front_block_placing(new_value), new TranslatableText("lambdacontrols.tooltip.front_block_placing"));
|
||||
(game_options, new_value) -> this.mod.config.set_front_block_placing(new_value), new TranslatableText("lambdacontrols.tooltip.front_block_placing"), true);
|
||||
this.fly_drifting_option = new SpruceBooleanOption("lambdacontrols.menu.fly_drifting", game_options -> this.mod.config.has_fly_drifting(),
|
||||
(game_options, new_value) -> this.mod.config.set_fly_drifting(new_value), new TranslatableText("lambdacontrols.tooltip.fly_drifting"));
|
||||
(game_options, new_value) -> this.mod.config.set_fly_drifting(new_value), new TranslatableText("lambdacontrols.tooltip.fly_drifting"), true);
|
||||
// Controller options
|
||||
this.controller_option = new CyclingOption("lambdacontrols.menu.controller", (game_options, amount) -> {
|
||||
int current_id = this.mod.config.get_controller().get_id();
|
||||
@@ -146,16 +147,18 @@ public class LambdaControlsSettingsScreen extends Screen
|
||||
synchronized (this.mod.config) {
|
||||
this.mod.config.set_invert_right_x_axis(new_value);
|
||||
}
|
||||
}, null);
|
||||
}, null, true);
|
||||
this.inverts_right_y_axis = new SpruceBooleanOption("lambdacontrols.menu.invert_right_y_axis", game_options -> this.mod.config.does_invert_right_y_axis(),
|
||||
(game_options, new_value) -> {
|
||||
synchronized (this.mod.config) {
|
||||
this.mod.config.set_invert_right_y_axis(new_value);
|
||||
}
|
||||
}, null);
|
||||
}, null, true);
|
||||
this.unfocused_input_option = new SpruceBooleanOption("lambdacontrols.menu.unfocused_input", (game_options) -> this.mod.config.has_unfocused_input(),
|
||||
(game_options, new_value) -> this.mod.config.set_unfocused_input(new_value), new TranslatableText("lambdacontrols.tooltip.unfocused_input"), true);
|
||||
// HUD options
|
||||
this.hud_enable_option = new SpruceBooleanOption("lambdacontrols.menu.hud_enable", (game_options) -> this.mod.config.is_hud_enabled(),
|
||||
(game_options, new_value) -> this.mod.config.set_hud_enabled(new_value), new TranslatableText("lambdacontrols.tooltip.hud_enable"));
|
||||
(game_options, new_value) -> this.mod.config.set_hud_enabled(new_value), new TranslatableText("lambdacontrols.tooltip.hud_enable"), true);
|
||||
this.hud_side_option = new SpruceCyclingOption("lambdacontrols.menu.hud_side",
|
||||
(game_options, amount) -> this.mod.config.set_hud_side(this.mod.config.get_hud_side().next()),
|
||||
(game_options, option) -> option.getDisplayPrefix() + this.mod.config.get_hud_side().get_translated_name(),
|
||||
@@ -220,6 +223,7 @@ public class LambdaControlsSettingsScreen extends Screen
|
||||
this.list.addSingleOptionEntry(this.second_controller_option);
|
||||
this.list.addOptionEntry(this.controller_type_option, this.dead_zone_option);
|
||||
this.list.addOptionEntry(this.inverts_right_x_axis, this.inverts_right_y_axis);
|
||||
this.list.addSingleOptionEntry(this.unfocused_input_option);
|
||||
this.list.addSingleOptionEntry(new ReloadControllerMappingsOption());
|
||||
// HUD options
|
||||
this.list.addSingleOptionEntry(new SpruceSeparatorOption("lambdacontrols.menu.title.hud", true, null));
|
||||
|
||||
@@ -108,7 +108,7 @@ public abstract class MinecraftClientMixin
|
||||
private void lambdacontrols_on_item_use(CallbackInfo ci, Hand[] hands, int hand_count, int hand_index, Hand hand, ItemStack stack_in_hand)
|
||||
{
|
||||
LambdaControlsClient mod = LambdaControlsClient.get();
|
||||
if (!stack_in_hand.isEmpty() && this.player.pitch > 0.0F && mod.config.has_front_block_placing()) {
|
||||
if (!stack_in_hand.isEmpty() && this.player.pitch > 35.0F && mod.config.has_front_block_placing()) {
|
||||
if (this.crosshairTarget != null && this.crosshairTarget.getType() == HitResult.Type.MISS && this.player.onGround) {
|
||||
if (!stack_in_hand.isEmpty() && stack_in_hand.getItem() instanceof BlockItem) {
|
||||
BlockPos player_pos = this.player.getBlockPos().down();
|
||||
@@ -119,12 +119,8 @@ public abstract class MinecraftClientMixin
|
||||
Direction direction = player.getHorizontalFacing();
|
||||
|
||||
BlockState adjacent_block_state = this.world.getBlockState(block_pos.offset(direction.getOpposite()));
|
||||
if (adjacent_block_state.isAir() || adjacent_block_state.getBlock() instanceof FluidBlock) {
|
||||
adjacent_block_state = this.world.getBlockState(player_pos.offset(direction.getOpposite()));
|
||||
if (adjacent_block_state.isAir() || adjacent_block_state.getBlock() instanceof FluidBlock)
|
||||
return;
|
||||
else
|
||||
block_pos = player_pos;
|
||||
if (adjacent_block_state.isAir() || adjacent_block_state.getBlock() instanceof FluidBlock || (vector.getX() == 0 && vector.getZ() == 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
BlockHitResult hit_result = new BlockHitResult(this.crosshairTarget.getPos(), direction.getOpposite(), block_pos, false);
|
||||
|
||||
@@ -96,6 +96,7 @@
|
||||
"lambdacontrols.menu.title.general": "General Options",
|
||||
"lambdacontrols.menu.title.hud": "HUD Options",
|
||||
"lambdacontrols.menu.unbound": "Unbound",
|
||||
"lambdacontrols.menu.unfocused_input": "Unfocused Input",
|
||||
"lambdacontrols.narrator.unbound": "Unbound %s",
|
||||
"lambdacontrols.not_bound": "Not bound",
|
||||
"lambdacontrols.tooltip.auto_switch_mode": "If the controls mode should be switched to Controller automatically if one is connected.",
|
||||
@@ -109,5 +110,6 @@
|
||||
"lambdacontrols.tooltip.hud_side": "The position of the HUD.",
|
||||
"lambdacontrols.tooltip.mouse_speed": "The controller's emulated mouse speed.",
|
||||
"lambdacontrols.tooltip.rotation_speed": "The camera rotation speed in controller mode.",
|
||||
"lambdacontrols.tooltip.reload_controller_mappings": "Reloads the controller mappings file."
|
||||
"lambdacontrols.tooltip.reload_controller_mappings": "Reloads the controller mappings file.",
|
||||
"lambdacontrols.tooltip.unfocused_input": "Allow controller input when the window is not focused."
|
||||
}
|
||||
@@ -96,6 +96,7 @@
|
||||
"lambdacontrols.menu.title.general": "Options générales",
|
||||
"lambdacontrols.menu.title.hud": "Options du HUD",
|
||||
"lambdacontrols.menu.unbound": "Délier",
|
||||
"lambdacontrols.menu.unfocused_input": "Entrée en fond",
|
||||
"lambdacontrols.narrator.unbound": "Délier %s",
|
||||
"lambdacontrols.not_bound": "Non défini",
|
||||
"lambdacontrols.tooltip.auto_switch_mode": "Détermine si le mode de contrôle doit automatiquement changer sur Manette si une manette est connectée et inversement.",
|
||||
@@ -109,5 +110,6 @@
|
||||
"lambdacontrols.tooltip.hud_side": "Change la position du HUD.",
|
||||
"lambdacontrols.tooltip.mouse_speed": "Change la vitesse de la souris émulée par la manette.",
|
||||
"lambdacontrols.tooltip.rotation_speed": "Change la vitesse de rotation de la caméra.",
|
||||
"lambdacontrols.tooltip.reload_controller_mappings": "Recharge le fichier de configuration des manettes."
|
||||
"lambdacontrols.tooltip.reload_controller_mappings": "Recharge le fichier de configuration des manettes.",
|
||||
"lambdacontrols.tooltip.unfocused_input": "Autorise les entrées manette quand la fenêtre n'est pas sélectionnée."
|
||||
}
|
||||
@@ -96,6 +96,7 @@
|
||||
"lambdacontrols.menu.title.general": "Options générales",
|
||||
"lambdacontrols.menu.title.hud": "Options du HUD",
|
||||
"lambdacontrols.menu.unbound": "Délier",
|
||||
"lambdacontrols.menu.unfocused_input": "Entrée en fond",
|
||||
"lambdacontrols.narrator.unbound": "Délier %s",
|
||||
"lambdacontrols.not_bound": "Non défini",
|
||||
"lambdacontrols.tooltip.auto_switch_mode": "Détermine si le mode de contrôle doit automatiquement changer sur Manette si une manette est connectée et inversement.",
|
||||
@@ -109,5 +110,6 @@
|
||||
"lambdacontrols.tooltip.hud_side": "Change la position du HUD.",
|
||||
"lambdacontrols.tooltip.mouse_speed": "Change la vitesse de la souris émulée par la manette.",
|
||||
"lambdacontrols.tooltip.rotation_speed": "Change la vitesse de rotation de la caméra.",
|
||||
"lambdacontrols.tooltip.reload_controller_mappings": "Recharge le fichier de configuration des manettes."
|
||||
"lambdacontrols.tooltip.reload_controller_mappings": "Recharge le fichier de configuration des manettes.",
|
||||
"lambdacontrols.tooltip.unfocused_input": "Autorise les entrées manette quand la fenêtre n'est pas sélectionnée."
|
||||
}
|
||||
@@ -36,6 +36,8 @@ auto_switch_mode = false
|
||||
invert_right_x_axis = false
|
||||
# Inverts the right Y axis.
|
||||
invert_right_y_axis = false
|
||||
# Allow unfocused input.
|
||||
unfocused_input = false
|
||||
# Controller controls.
|
||||
[controller.controls]
|
||||
# Attack control.
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
"fabricloader": ">=0.4.0",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.15.x",
|
||||
"spruceui": ">=1.0.3"
|
||||
"spruceui": ">=1.1.0"
|
||||
},
|
||||
"recommends": {
|
||||
"modmenu": ">=1.8.0+build.16",
|
||||
|
||||
Reference in New Issue
Block a user