1
0
mirror of https://github.com/chylex/Better-Controls.git synced 2024-11-26 04:42:45 +01:00

Compare commits

..

No commits in common. "2b15c5836c8b6414aa105d9be1535998f37733f7" and "76af39fb181122d45577803b9bd48b77dc140e29" have entirely different histories.

9 changed files with 18 additions and 38 deletions

View File

@ -1,15 +1,15 @@
modLoader = "javafml" modLoader = "javafml"
loaderVersion = "[0,)" loaderVersion = "[0,)"
authors = "${author}"
license = "${license}" license = "${license}"
issueTrackerURL = "${issuesURL}" issueTrackerURL = "${issuesURL}"
[[mods]] [[mods]]
modId = "${id}" modId = "${id}"
version = "${version}"
displayName = "${name}" displayName = "${name}"
description = "${description}" description = "${description}"
authors = "${author}"
version = "${version}"
logoFile = "icon.png" logoFile = "icon.png"
[[dependencies.${id}]] [[dependencies.${id}]]

View File

@ -9,15 +9,15 @@ modSourcesURL=https://github.com/chylex/Better-Controls
modIssuesURL=https://github.com/chylex/Better-Controls/issues modIssuesURL=https://github.com/chylex/Better-Controls/issues
# Dependencies # Dependencies
minecraftVersion=1.19.4 minecraftVersion=1.19.3
forgeVersion=45.0.6 forgeVersion=44.0.11
fabricVersion=0.14.17 fabricVersion=0.14.11
loomVersion=0.12 loomVersion=0.12
mixinVersion=0.8.5 mixinVersion=0.8.5
# Constraints # Constraints
minimumMinecraftVersion=1.19.4 minimumMinecraftVersion=1.19.3
minimumForgeVersion=45.0.0 minimumForgeVersion=44.0.0
minimumFabricVersion=0.7.4 minimumFabricVersion=0.7.4
# Gradle # Gradle

View File

@ -24,12 +24,10 @@ final class Json {
return obj.has(key) ? obj.get(key).getAsBoolean() : defaultValue; return obj.has(key) ? obj.get(key).getAsBoolean() : defaultValue;
} }
@SuppressWarnings("SameParameterValue")
static <T extends Enum<T>> void setEnum(final JsonObject obj, final String key, final T value) { static <T extends Enum<T>> void setEnum(final JsonObject obj, final String key, final T value) {
obj.addProperty(key, value.name()); obj.addProperty(key, value.name());
} }
@SuppressWarnings("SameParameterValue")
static <T extends Enum<T>> T getEnum(final JsonObject obj, final String key, final T defaultValue, final Class<T> enumClass) { static <T extends Enum<T>> T getEnum(final JsonObject obj, final String key, final T defaultValue, final Class<T> enumClass) {
if (!obj.has(key)) { if (!obj.has(key)) {
return defaultValue; return defaultValue;

View File

@ -8,7 +8,6 @@ import chylex.bettercontrols.gui.elements.TextWidget;
import chylex.bettercontrols.input.KeyBindingWithModifier; import chylex.bettercontrols.input.KeyBindingWithModifier;
import chylex.bettercontrols.input.ModifierKey; import chylex.bettercontrols.input.ModifierKey;
import chylex.bettercontrols.input.SprintMode; import chylex.bettercontrols.input.SprintMode;
import com.google.common.collect.ImmutableList;
import com.mojang.blaze3d.platform.InputConstants; import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import it.unimi.dsi.fastutil.booleans.BooleanConsumer; import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
@ -89,7 +88,7 @@ public class BetterControlsScreen extends OptionsSubScreen {
private int generateFlightOptions(int y, final List<GuiEventListener> elements) { private int generateFlightOptions(int y, final List<GuiEventListener> elements) {
final BetterControlsConfig cfg = BetterControlsCommon.getConfig(); final BetterControlsConfig cfg = BetterControlsCommon.getConfig();
final ImmutableList<Option<Float>> flightSpeedOptions = ImmutableList.of( final List<Option<Float>> flightSpeedOptions = Arrays.asList(
new Option<>(Float.valueOf(0.25F), text("0.25x")), new Option<>(Float.valueOf(0.25F), text("0.25x")),
new Option<>(Float.valueOf(0.50F), text("0.5x")), new Option<>(Float.valueOf(0.50F), text("0.5x")),
new Option<>(Float.valueOf(0.75F), text("0.75x")), new Option<>(Float.valueOf(0.75F), text("0.75x")),
@ -104,7 +103,7 @@ public class BetterControlsScreen extends OptionsSubScreen {
new Option<>(Float.valueOf(8.00F), text("8x")) new Option<>(Float.valueOf(8.00F), text("8x"))
); );
final ImmutableList<Option<Float>> flightVerticalBoostOptions = ImmutableList.of( final List<Option<Float>> flightVerticalBoostOptions = Arrays.asList(
new Option<>(Float.valueOf(0.00F), text("None")), new Option<>(Float.valueOf(0.00F), text("None")),
new Option<>(Float.valueOf(0.25F), text("+25%")), new Option<>(Float.valueOf(0.25F), text("+25%")),
new Option<>(Float.valueOf(0.50F), text("+50%")), new Option<>(Float.valueOf(0.50F), text("+50%")),
@ -220,7 +219,6 @@ public class BetterControlsScreen extends OptionsSubScreen {
private KeyBindingWidget editingKeyBinding; private KeyBindingWidget editingKeyBinding;
private final List<KeyBindingWidget> allKeyBindings = new ArrayList<>(); private final List<KeyBindingWidget> allKeyBindings = new ArrayList<>();
@SuppressWarnings("DataFlowIssue")
public BetterControlsScreen(@Nullable final Screen parentScreen) { public BetterControlsScreen(@Nullable final Screen parentScreen) {
super(parentScreen, Minecraft.getInstance().options, TITLE); super(parentScreen, Minecraft.getInstance().options, TITLE);
} }
@ -244,9 +242,7 @@ public class BetterControlsScreen extends OptionsSubScreen {
elements.add(new TextWidget(0, y, ROW_WIDTH, ROW_HEIGHT, text("Miscellaneous"), CENTER)); elements.add(new TextWidget(0, y, ROW_WIDTH, ROW_HEIGHT, text("Miscellaneous"), CENTER));
y = generateMiscellaneousOptions(y + ROW_HEIGHT, elements) + TITLE_MARGIN_TOP; y = generateMiscellaneousOptions(y + ROW_HEIGHT, elements) + TITLE_MARGIN_TOP;
//noinspection DataFlowIssue
addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, btn -> minecraft.setScreen(lastScreen)).pos(width / 2 - 99, height - 29).size(200, 20).build()); addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, btn -> minecraft.setScreen(lastScreen)).pos(width / 2 - 99, height - 29).size(200, 20).build());
addWidget(optionsWidget = new OptionListWidget(21, height - 32, width, height, elements, y - TITLE_MARGIN_TOP + BOTTOM_PADDING)); addWidget(optionsWidget = new OptionListWidget(21, height - 32, width, height, elements, y - TITLE_MARGIN_TOP + BOTTOM_PADDING));
} }

View File

@ -1,19 +1,19 @@
package chylex.bettercontrols.gui.elements; package chylex.bettercontrols.gui.elements;
import com.google.common.collect.ImmutableList;
import net.minecraft.client.gui.components.AbstractSliderButton; import net.minecraft.client.gui.components.AbstractSliderButton;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.MutableComponent;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
public final class DiscreteValueSliderWidget<T> extends AbstractSliderButton { public final class DiscreteValueSliderWidget<T> extends AbstractSliderButton {
private final Component narration; private final Component narration;
private final ImmutableList<Option<T>> options; private final List<Option<T>> options;
private final Consumer<T> onChanged; private final Consumer<T> onChanged;
private T selectedValue; private T selectedValue;
public DiscreteValueSliderWidget(final int x, final int y, final int width, final int height, final Component narration, final ImmutableList<Option<T>> options, final T selectedValue, final Consumer<T> onChanged) { public DiscreteValueSliderWidget(final int x, final int y, final int width, final int height, final Component narration, final List<Option<T>> options, final T selectedValue, final Consumer<T> onChanged) {
super(x, y, width, height, Option.find(options, selectedValue).text(), options.indexOf(Option.find(options, selectedValue)) / (options.size() - 1.0)); super(x, y, width, height, Option.find(options, selectedValue).text(), options.indexOf(Option.find(options, selectedValue)) / (options.size() - 1.0));
this.narration = narration; this.narration = narration;
this.options = options; this.options = options;
@ -21,7 +21,7 @@ public final class DiscreteValueSliderWidget<T> extends AbstractSliderButton {
this.onChanged = onChanged; this.onChanged = onChanged;
} }
public DiscreteValueSliderWidget(final int x, final int y, final int width, final Component narration, final ImmutableList<Option<T>> options, final T selectedValue, final Consumer<T> onChanged) { public DiscreteValueSliderWidget(final int x, final int y, final int width, final Component narration, final List<Option<T>> options, final T selectedValue, final Consumer<T> onChanged) {
this(x, y, width, 20, narration, options, selectedValue, onChanged); this(x, y, width, 20, narration, options, selectedValue, onChanged);
} }

View File

@ -57,14 +57,6 @@ public final class TextWidget extends GuiComponent implements OptionWidget {
this.y = y; this.y = y;
} }
@Override
public void setFocused(final boolean focused) {}
@Override
public boolean isFocused() {
return false;
}
@Override @Override
public void render(final @NotNull PoseStack matrices, final int mouseX, final int mouseY, final float delta) { public void render(final @NotNull PoseStack matrices, final int mouseX, final int mouseY, final float delta) {
final Font textRenderer = Minecraft.getInstance().font; final Font textRenderer = Minecraft.getInstance().font;

View File

@ -16,12 +16,9 @@ public abstract class HookPlayerFlightSpeed extends LivingEntity {
} }
@Redirect( @Redirect(
method = "getFlyingSpeed", method = "travel",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;isSprinting()Z"), at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;isSprinting()Z"),
slice = @Slice( slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Abilities;getFlyingSpeed()F"))
from = @At(value = "FIELD", target = "Lnet/minecraft/world/entity/player/Abilities;flying:Z"),
to = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Abilities;getFlyingSpeed()F")
)
) )
private boolean disableVanillaSprintBoost(final Player player) { private boolean disableVanillaSprintBoost(final Player player) {
return false; return false;

View File

@ -7,17 +7,16 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.function.Consumer;
@Mixin(OptionInstance.class) @Mixin(OptionInstance.class)
public abstract class HookToggleOptionButtons { public abstract class HookToggleOptionButtons {
@Inject(method = "createButton(Lnet/minecraft/client/Options;IIILjava/util/function/Consumer;)Lnet/minecraft/client/gui/components/AbstractWidget;", at = @At("RETURN")) @Inject(method = "createButton", at = @At("RETURN"))
private <T> void disableToggleOptions(final Options options, final int x, final int y, final int width, final Consumer<T> callback, final CallbackInfoReturnable<AbstractWidget> cir) { private void disableToggleOptions(final Options options, final int x, final int y, final int width, final CallbackInfoReturnable<AbstractWidget> ci) {
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
final OptionInstance<?> me = (OptionInstance<?>)(Object)this; final OptionInstance<?> me = (OptionInstance<?>)(Object)this;
if (me == options.toggleCrouch() || me == options.toggleSprint()) { if (me == options.toggleCrouch() || me == options.toggleSprint()) {
cir.getReturnValue().active = false; ci.getReturnValue().active = false;
} }
} }
} }

View File

@ -149,7 +149,6 @@ public final class PlayerTicker {
public void afterInputAssignsPressingForward(final Input input) { public void afterInputAssignsPressingForward(final Input input) {
if (MINECRAFT.screen == null) { if (MINECRAFT.screen == null) {
//noinspection NonShortCircuitBooleanExpression
input.up |= toggleWalkForward.tick(); input.up |= toggleWalkForward.tick();
} }
} }
@ -158,7 +157,6 @@ public final class PlayerTicker {
final Input input = player.input; final Input input = player.input;
if (MINECRAFT.screen == null && !player.getAbilities().flying) { if (MINECRAFT.screen == null && !player.getAbilities().flying) {
//noinspection NonShortCircuitBooleanExpression
input.jumping |= toggleJump.tick(); input.jumping |= toggleJump.tick();
} }