mirror of
https://github.com/chylex/Better-Controls.git
synced 2025-09-14 05:32:18 +02:00
Compare commits
10 Commits
1.18
...
2b15c5836c
Author | SHA1 | Date | |
---|---|---|---|
2b15c5836c
|
|||
5ce4f2a975
|
|||
76af39fb18
|
|||
38fb2a1f1e
|
|||
e748c21efe
|
|||
bd9ba27ac3
|
|||
8a7febb76b
|
|||
553cc9c954
|
|||
6a35ef4203
|
|||
2126402d28
|
@@ -4,7 +4,7 @@ val fabricVersion: String by project
|
|||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
idea
|
idea
|
||||||
id("fabric-loom") version "0.10-SNAPSHOT"
|
id("fabric-loom")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
}],
|
}],
|
||||||
|
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": ">=0.7.4",
|
"fabricloader": ">=${minimumFabricVersion}",
|
||||||
"minecraft": ">=1.17"
|
"minecraft": ">=${minimumMinecraftVersion}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,7 @@ import chylex.bettercontrols.gui.BetterControlsScreen;
|
|||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.client.ConfigGuiHandler.ConfigGuiFactory;
|
import net.minecraftforge.client.ConfigScreenHandler.ConfigScreenFactory;
|
||||||
import net.minecraftforge.fml.DistExecutor;
|
import net.minecraftforge.fml.DistExecutor;
|
||||||
import net.minecraftforge.fml.IExtensionPoint.DisplayTest;
|
import net.minecraftforge.fml.IExtensionPoint.DisplayTest;
|
||||||
import net.minecraftforge.fml.ModLoadingContext;
|
import net.minecraftforge.fml.ModLoadingContext;
|
||||||
@@ -16,7 +16,7 @@ import net.minecraftforge.network.NetworkConstants;
|
|||||||
public final class BetterControlsMod {
|
public final class BetterControlsMod {
|
||||||
public BetterControlsMod() {
|
public BetterControlsMod() {
|
||||||
BetterControlsCommon.setConfig(DistExecutor.safeCallWhenOn(Dist.CLIENT, () -> ClientLoader::loadConfig));
|
BetterControlsCommon.setConfig(DistExecutor.safeCallWhenOn(Dist.CLIENT, () -> ClientLoader::loadConfig));
|
||||||
ModLoadingContext.get().registerExtensionPoint(ConfigGuiFactory.class, () -> new ConfigGuiFactory(ClientLoader::createScreen));
|
ModLoadingContext.get().registerExtensionPoint(ConfigScreenFactory.class, () -> new ConfigScreenFactory(ClientLoader::createScreen));
|
||||||
ModLoadingContext.get().registerExtensionPoint(DisplayTest.class, () -> new DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (a, b) -> true));
|
ModLoadingContext.get().registerExtensionPoint(DisplayTest.class, () -> new DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (a, b) -> true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,27 +1,27 @@
|
|||||||
modLoader = "javafml"
|
modLoader = "javafml"
|
||||||
loaderVersion = "[37,)"
|
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}]]
|
||||||
modId = "minecraft"
|
modId = "minecraft"
|
||||||
mandatory = true
|
mandatory = true
|
||||||
versionRange = "[1.17.1,)"
|
versionRange = "[${minimumMinecraftVersion},)"
|
||||||
ordering = "NONE"
|
ordering = "NONE"
|
||||||
side = "BOTH"
|
side = "BOTH"
|
||||||
|
|
||||||
[[dependencies.${id}]]
|
[[dependencies.${id}]]
|
||||||
modId = "forge"
|
modId = "forge"
|
||||||
mandatory = true
|
mandatory = true
|
||||||
versionRange = "[37,)"
|
versionRange = "[${minimumForgeVersion},)"
|
||||||
ordering = "NONE"
|
ordering = "NONE"
|
||||||
side = "BOTH"
|
side = "BOTH"
|
||||||
|
@@ -14,6 +14,10 @@ val modIssuesURL: String by project
|
|||||||
val minecraftVersion: String by project
|
val minecraftVersion: String by project
|
||||||
val mixinVersion: String by project
|
val mixinVersion: String by project
|
||||||
|
|
||||||
|
val minimumMinecraftVersion: String by project
|
||||||
|
val minimumForgeVersion: String by project
|
||||||
|
val minimumFabricVersion: String by project
|
||||||
|
|
||||||
val modNameStripped = modName.replace(" ", "")
|
val modNameStripped = modName.replace(" ", "")
|
||||||
val jarVersion = "$minecraftVersion+v$modVersion"
|
val jarVersion = "$minecraftVersion+v$modVersion"
|
||||||
|
|
||||||
@@ -110,6 +114,9 @@ subprojects {
|
|||||||
inputs.property("license", modLicense)
|
inputs.property("license", modLicense)
|
||||||
inputs.property("sourcesURL", modSourcesURL)
|
inputs.property("sourcesURL", modSourcesURL)
|
||||||
inputs.property("issuesURL", modIssuesURL)
|
inputs.property("issuesURL", modIssuesURL)
|
||||||
|
inputs.property("minimumMinecraftVersion", minimumMinecraftVersion)
|
||||||
|
inputs.property("minimumForgeVersion", minimumForgeVersion)
|
||||||
|
inputs.property("minimumFabricVersion", minimumFabricVersion)
|
||||||
|
|
||||||
from(rootProject.sourceSets.main.get().resources) {
|
from(rootProject.sourceSets.main.get().resources) {
|
||||||
expand(inputs.properties)
|
expand(inputs.properties)
|
||||||
|
@@ -3,16 +3,22 @@ modId=bettercontrols
|
|||||||
modName=Better Controls
|
modName=Better Controls
|
||||||
modDescription=Adds many powerful key bindings and options to control your movement.\\n\\nThe features complement vanilla mechanics without giving unfair advantages, so server use should be fine.
|
modDescription=Adds many powerful key bindings and options to control your movement.\\n\\nThe features complement vanilla mechanics without giving unfair advantages, so server use should be fine.
|
||||||
modAuthor=chylex
|
modAuthor=chylex
|
||||||
modVersion=1.2.3
|
modVersion=1.2.4
|
||||||
modLicense=MPL-2.0
|
modLicense=MPL-2.0
|
||||||
modSourcesURL=https://github.com/chylex/Better-Controls
|
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.18
|
minecraftVersion=1.19.4
|
||||||
forgeVersion=38.0.8
|
forgeVersion=45.0.6
|
||||||
fabricVersion=0.12.8
|
fabricVersion=0.14.17
|
||||||
mixinVersion=0.8.4
|
loomVersion=0.12
|
||||||
|
mixinVersion=0.8.5
|
||||||
|
|
||||||
|
# Constraints
|
||||||
|
minimumMinecraftVersion=1.19.4
|
||||||
|
minimumForgeVersion=45.0.0
|
||||||
|
minimumFabricVersion=0.7.4
|
||||||
|
|
||||||
# Gradle
|
# Gradle
|
||||||
org.gradle.jvmargs=-Xmx3G
|
org.gradle.jvmargs=-Xmx3G
|
||||||
|
@@ -6,6 +6,12 @@ pluginManagement {
|
|||||||
maven(url = "https://maven.fabricmc.net/") { name = "Fabric" }
|
maven(url = "https://maven.fabricmc.net/") { name = "Fabric" }
|
||||||
maven(url = "https://repo.spongepowered.org/repository/maven-public/") { name = "Sponge Snapshots" }
|
maven(url = "https://repo.spongepowered.org/repository/maven-public/") { name = "Sponge Snapshots" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
if (settings.extra.has("loomVersion")) {
|
||||||
|
id("fabric-loom") version "${settings.extra["loomVersion"]}-SNAPSHOT"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.extra.has("forgeVersion")) {
|
if (settings.extra.has("forgeVersion")) {
|
||||||
|
@@ -24,10 +24,12 @@ 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;
|
||||||
|
@@ -8,6 +8,7 @@ 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;
|
||||||
@@ -20,7 +21,6 @@ import net.minecraft.client.gui.screens.OptionsSubScreen;
|
|||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.network.chat.CommonComponents;
|
import net.minecraft.network.chat.CommonComponents;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.network.chat.TextComponent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
@@ -34,10 +34,11 @@ import static chylex.bettercontrols.gui.OptionListWidget.ROW_WIDTH;
|
|||||||
import static chylex.bettercontrols.gui.OptionListWidget.col2;
|
import static chylex.bettercontrols.gui.OptionListWidget.col2;
|
||||||
import static chylex.bettercontrols.gui.OptionListWidget.col4;
|
import static chylex.bettercontrols.gui.OptionListWidget.col4;
|
||||||
import static chylex.bettercontrols.gui.elements.TextWidget.CENTER;
|
import static chylex.bettercontrols.gui.elements.TextWidget.CENTER;
|
||||||
|
import static net.minecraft.network.chat.Component.literal;
|
||||||
|
|
||||||
public class BetterControlsScreen extends OptionsSubScreen {
|
public class BetterControlsScreen extends OptionsSubScreen {
|
||||||
private static TextComponent text(final String text) {
|
private static Component text(final String text) {
|
||||||
return new TextComponent(text);
|
return literal(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Component TITLE = text("Better Controls");
|
public static final Component TITLE = text("Better Controls");
|
||||||
@@ -85,11 +86,10 @@ public class BetterControlsScreen extends OptionsSubScreen {
|
|||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "AutoBoxing", "AutoUnboxing" })
|
|
||||||
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 List<Option<Float>> flightSpeedOptions = Arrays.asList(
|
final ImmutableList<Option<Float>> flightSpeedOptions = ImmutableList.of(
|
||||||
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 +104,7 @@ public class BetterControlsScreen extends OptionsSubScreen {
|
|||||||
new Option<>(Float.valueOf(8.00F), text("8x"))
|
new Option<>(Float.valueOf(8.00F), text("8x"))
|
||||||
);
|
);
|
||||||
|
|
||||||
final List<Option<Float>> flightVerticalBoostOptions = Arrays.asList(
|
final ImmutableList<Option<Float>> flightVerticalBoostOptions = ImmutableList.of(
|
||||||
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,6 +220,7 @@ 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);
|
||||||
}
|
}
|
||||||
@@ -243,7 +244,9 @@ 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;
|
||||||
|
|
||||||
addRenderableWidget(new Button(width / 2 - 99, height - 29, 200, 20, CommonComponents.GUI_DONE, btn -> minecraft.setScreen(lastScreen)));
|
//noinspection DataFlowIssue
|
||||||
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@ import com.mojang.blaze3d.vertex.PoseStack;
|
|||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.components.AbstractWidget;
|
import net.minecraft.client.gui.components.AbstractWidget;
|
||||||
import net.minecraft.client.gui.components.ContainerObjectSelectionList;
|
import net.minecraft.client.gui.components.ContainerObjectSelectionList;
|
||||||
import net.minecraft.client.gui.components.Widget;
|
import net.minecraft.client.gui.components.Renderable;
|
||||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||||
import net.minecraft.client.gui.narration.NarratableEntry;
|
import net.minecraft.client.gui.narration.NarratableEntry;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -35,14 +35,14 @@ public final class OptionListWidget extends ContainerObjectSelectionList<Entry>
|
|||||||
return new Offset(widget.getX(), widget.getY());
|
return new Offset(widget.getX(), widget.getY());
|
||||||
}
|
}
|
||||||
else if (element instanceof final AbstractWidget widget) {
|
else if (element instanceof final AbstractWidget widget) {
|
||||||
return new Offset(widget.x, widget.y);
|
return new Offset(widget.getX(), widget.getY());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return new Offset(0, 0);
|
return new Offset(0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OptionWidget extends GuiEventListener, Widget {
|
public interface OptionWidget extends GuiEventListener, Renderable {
|
||||||
int getX();
|
int getX();
|
||||||
int getY();
|
int getY();
|
||||||
void setX(int x);
|
void setX(int x);
|
||||||
@@ -82,13 +82,15 @@ public final class OptionListWidget extends ContainerObjectSelectionList<Entry>
|
|||||||
this.offsets = elements.stream().collect(Collectors.toMap(Function.identity(), OptionListWidget::getElementOffset));
|
this.offsets = elements.stream().collect(Collectors.toMap(Function.identity(), OptionListWidget::getElementOffset));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<? extends GuiEventListener> children() {
|
public List<? extends GuiEventListener> children() {
|
||||||
return Collections.unmodifiableList(elements);
|
return Collections.unmodifiableList(elements);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<? extends NarratableEntry> narratables() {
|
public List<? extends NarratableEntry> narratables() {
|
||||||
return Collections.unmodifiableList(narratables);
|
return Collections.unmodifiableList(narratables);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,16 +100,16 @@ public final class OptionListWidget extends ContainerObjectSelectionList<Entry>
|
|||||||
final Offset offset = offsets.get(element);
|
final Offset offset = offsets.get(element);
|
||||||
|
|
||||||
if (element instanceof final AbstractWidget widget) {
|
if (element instanceof final AbstractWidget widget) {
|
||||||
widget.x = x + offset.x;
|
widget.setX(x + offset.x);
|
||||||
widget.y = y + offset.y;
|
widget.setY(y + offset.y);
|
||||||
}
|
}
|
||||||
else if (element instanceof final OptionWidget widget) {
|
else if (element instanceof final OptionWidget widget) {
|
||||||
widget.setX(x + offset.x);
|
widget.setX(x + offset.x);
|
||||||
widget.setY(y + offset.y);
|
widget.setY(y + offset.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element instanceof final Widget widget) {
|
if (element instanceof final Renderable renderable) {
|
||||||
widget.render(matrices, mouseX, mouseY, tickDelta);
|
renderable.render(matrices, mouseX, mouseY, tickDelta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,20 +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.network.chat.TranslatableComponent;
|
|
||||||
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 List<Option<T>> options;
|
private final ImmutableList<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 List<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 ImmutableList<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;
|
||||||
@@ -22,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 List<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 ImmutableList<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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,8 +44,9 @@ public final class DiscreteValueSliderWidget<T> extends AbstractSliderButton {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected @NotNull MutableComponent createNarrationMessage() {
|
protected MutableComponent createNarrationMessage() {
|
||||||
return new TranslatableComponent("gui.narrate.slider", narration.plainCopy().append(" ").append(getMessage()));
|
return Component.translatable("gui.narrate.slider", narration.plainCopy().append(" ").append(getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,8 +7,6 @@ import net.minecraft.client.gui.components.AbstractButton;
|
|||||||
import net.minecraft.client.gui.components.Button;
|
import net.minecraft.client.gui.components.Button;
|
||||||
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.network.chat.TextComponent;
|
|
||||||
import net.minecraft.network.chat.TranslatableComponent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -24,7 +22,7 @@ public final class KeyBindingWidget extends Button {
|
|||||||
private boolean isEditing;
|
private boolean isEditing;
|
||||||
|
|
||||||
public KeyBindingWidget(final int x, final int y, final int width, final int height, final Component bindingName, final KeyMapping binding, final Consumer<KeyBindingWidget> onEditingStarted) {
|
public KeyBindingWidget(final int x, final int y, final int width, final int height, final Component bindingName, final KeyMapping binding, final Consumer<KeyBindingWidget> onEditingStarted) {
|
||||||
super(x, y, width, height, TextComponent.EMPTY, btn -> {});
|
super(x, y, width, height, Component.empty(), btn -> {}, DEFAULT_NARRATION);
|
||||||
this.binding = binding;
|
this.binding = binding;
|
||||||
this.bindingName = bindingName;
|
this.bindingName = bindingName;
|
||||||
this.onEditingStarted = onEditingStarted;
|
this.onEditingStarted = onEditingStarted;
|
||||||
@@ -40,9 +38,10 @@ public final class KeyBindingWidget extends Button {
|
|||||||
button.active = !binding.isUnbound();
|
button.active = !binding.isUnbound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected @NotNull MutableComponent createNarrationMessage() {
|
protected MutableComponent createNarrationMessage() {
|
||||||
return binding.isUnbound() ? new TranslatableComponent("narrator.controls.unbound", bindingName) : new TranslatableComponent("narrator.controls.bound", bindingName, super.createNarrationMessage());
|
return binding.isUnbound() ? Component.translatable("narrator.controls.unbound", bindingName) : Component.translatable("narrator.controls.bound", bindingName, super.createNarrationMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -79,13 +78,13 @@ public final class KeyBindingWidget extends Button {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
setMessage((new TextComponent("> ")).append(binding.getTranslatedKeyMessage().copy().withStyle(ChatFormatting.YELLOW)).append(" <").withStyle(ChatFormatting.YELLOW));
|
setMessage(Component.literal("> ").append(binding.getTranslatedKeyMessage().copy().withStyle(ChatFormatting.YELLOW)).append(" <").withStyle(ChatFormatting.YELLOW));
|
||||||
}
|
}
|
||||||
else if (hasConflict) {
|
else if (hasConflict) {
|
||||||
setMessage(binding.getTranslatedKeyMessage().copy().withStyle(ChatFormatting.RED));
|
setMessage(binding.getTranslatedKeyMessage().copy().withStyle(ChatFormatting.RED));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setMessage(binding.isUnbound() ? new TextComponent("(No Binding)") : binding.getTranslatedKeyMessage());
|
setMessage(binding.isUnbound() ? Component.literal("(No Binding)") : binding.getTranslatedKeyMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -57,6 +57,14 @@ 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;
|
||||||
|
@@ -12,7 +12,7 @@ import static org.spongepowered.asm.mixin.injection.At.Shift.AFTER;
|
|||||||
|
|
||||||
@Mixin(KeyboardInput.class)
|
@Mixin(KeyboardInput.class)
|
||||||
public abstract class HookClientPlayerInputTick {
|
public abstract class HookClientPlayerInputTick {
|
||||||
@Inject(method = "tick(Z)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/player/KeyboardInput;up:Z", ordinal = 0, shift = AFTER))
|
@Inject(method = "tick(ZF)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/player/KeyboardInput;up:Z", ordinal = 0, shift = AFTER))
|
||||||
private void afterInputTick(final CallbackInfo info) {
|
private void afterInputTick(final CallbackInfo info) {
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
final Input input = (Input)(Object)this;
|
final Input input = (Input)(Object)this;
|
||||||
|
@@ -23,7 +23,7 @@ public abstract class HookClientPlayerTick extends AbstractClientPlayer {
|
|||||||
PlayerTicker.get(player).atHead(player);
|
PlayerTicker.get(player).atHead(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "aiStep()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/Input;tick(Z)V", ordinal = 0, shift = AFTER))
|
@Inject(method = "aiStep()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/Input;tick(ZF)V", ordinal = 0, shift = AFTER))
|
||||||
private void afterInputTick(final CallbackInfo info) {
|
private void afterInputTick(final CallbackInfo info) {
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
final LocalPlayer player = (LocalPlayer)(Object)this;
|
final LocalPlayer player = (LocalPlayer)(Object)this;
|
||||||
|
@@ -9,7 +9,9 @@ import net.minecraft.client.gui.components.events.GuiEventListener;
|
|||||||
import net.minecraft.client.gui.screens.OptionsSubScreen;
|
import net.minecraft.client.gui.screens.OptionsSubScreen;
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.client.gui.screens.controls.ControlsScreen;
|
import net.minecraft.client.gui.screens.controls.ControlsScreen;
|
||||||
|
import net.minecraft.network.chat.CommonComponents;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.network.chat.MutableComponent;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
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;
|
||||||
@@ -29,25 +31,31 @@ public abstract class HookControlsScreen extends OptionsSubScreen {
|
|||||||
|
|
||||||
int leftBottomY = 0;
|
int leftBottomY = 0;
|
||||||
int rightBottomY = 0;
|
int rightBottomY = 0;
|
||||||
|
AbstractWidget doneButton = null;
|
||||||
|
|
||||||
for (final GuiEventListener child : children()) {
|
for (final GuiEventListener child : children()) {
|
||||||
if (!(child instanceof AbstractWidget widget)) {
|
if (!(child instanceof AbstractWidget widget)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int bottomY = widget.y + widget.getHeight();
|
if (widget instanceof Button button && button.getMessage() == CommonComponents.GUI_DONE) {
|
||||||
|
doneButton = widget;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (widget.x + widget.getWidth() < center) {
|
final int bottomY = widget.getY() + widget.getHeight();
|
||||||
|
|
||||||
|
if (widget.getX() + widget.getWidth() < center) {
|
||||||
leftBottomY = Math.max(leftBottomY, bottomY);
|
leftBottomY = Math.max(leftBottomY, bottomY);
|
||||||
}
|
}
|
||||||
if (widget.x >= center) {
|
if (widget.getX() >= center) {
|
||||||
rightBottomY = Math.max(rightBottomY, bottomY);
|
rightBottomY = Math.max(rightBottomY, bottomY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final int x, y;
|
final int x, y;
|
||||||
|
|
||||||
if (leftBottomY < rightBottomY) {
|
if (leftBottomY <= rightBottomY) {
|
||||||
x = center - 155;
|
x = center - 155;
|
||||||
y = leftBottomY + 4;
|
y = leftBottomY + 4;
|
||||||
}
|
}
|
||||||
@@ -56,6 +64,11 @@ public abstract class HookControlsScreen extends OptionsSubScreen {
|
|||||||
y = rightBottomY + 4;
|
y = rightBottomY + 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
addRenderableWidget(new Button(x, y, 150, 20, BetterControlsScreen.TITLE.plainCopy().append("..."), btn -> Minecraft.getInstance().setScreen(new BetterControlsScreen(screen))));
|
final MutableComponent buttonTitle = BetterControlsScreen.TITLE.plainCopy().append("...");
|
||||||
|
addRenderableWidget(Button.builder(buttonTitle, btn -> Minecraft.getInstance().setScreen(new BetterControlsScreen(screen))).pos(x, y).size(150, 20).build());
|
||||||
|
|
||||||
|
if (doneButton != null) {
|
||||||
|
doneButton.setY(y + 24);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,9 +16,12 @@ public abstract class HookPlayerFlightSpeed extends LivingEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Redirect(
|
@Redirect(
|
||||||
method = "travel",
|
method = "getFlyingSpeed",
|
||||||
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(from = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Abilities;getFlyingSpeed()F"))
|
slice = @Slice(
|
||||||
|
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;
|
||||||
|
@@ -1,23 +1,23 @@
|
|||||||
package chylex.bettercontrols.mixin;
|
package chylex.bettercontrols.mixin;
|
||||||
|
|
||||||
import net.minecraft.client.CycleOption;
|
import net.minecraft.client.OptionInstance;
|
||||||
import net.minecraft.client.Option;
|
|
||||||
import net.minecraft.client.Options;
|
import net.minecraft.client.Options;
|
||||||
import net.minecraft.client.gui.components.AbstractWidget;
|
import net.minecraft.client.gui.components.AbstractWidget;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
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(CycleOption.class)
|
@Mixin(OptionInstance.class)
|
||||||
public abstract class HookToggleOptionButtons {
|
public abstract class HookToggleOptionButtons {
|
||||||
@Inject(method = "createButton", at = @At("RETURN"))
|
@Inject(method = "createButton(Lnet/minecraft/client/Options;IIILjava/util/function/Consumer;)Lnet/minecraft/client/gui/components/AbstractWidget;", at = @At("RETURN"))
|
||||||
private void disableToggleOptions(final Options options, final int x, final int y, final int width, final CallbackInfoReturnable<AbstractWidget> ci) {
|
private <T> void disableToggleOptions(final Options options, final int x, final int y, final int width, final Consumer<T> callback, final CallbackInfoReturnable<AbstractWidget> cir) {
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
final CycleOption<?> me = (CycleOption<?>)(Object)this;
|
final OptionInstance<?> me = (OptionInstance<?>)(Object)this;
|
||||||
|
|
||||||
if (me == Option.TOGGLE_CROUCH || me == Option.TOGGLE_SPRINT) {
|
if (me == options.toggleCrouch() || me == options.toggleSprint()) {
|
||||||
ci.getReturnValue().active = false;
|
cir.getReturnValue().active = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -50,8 +50,8 @@ public final class PlayerTicker {
|
|||||||
|
|
||||||
// Logic
|
// Logic
|
||||||
|
|
||||||
private final ToggleTracker toggleSprint = new ToggleTrackerForStickyKey(cfg().keyToggleSprint, KEY_SPRINT, toggled -> OPTIONS.toggleSprint = toggled);
|
private final ToggleTracker toggleSprint = new ToggleTrackerForStickyKey(cfg().keyToggleSprint, KEY_SPRINT, OPTIONS.toggleSprint()::set);
|
||||||
private final ToggleTracker toggleSneak = new ToggleTrackerForStickyKey(cfg().keyToggleSneak, KEY_SNEAK, toggled -> OPTIONS.toggleCrouch = toggled);
|
private final ToggleTracker toggleSneak = new ToggleTrackerForStickyKey(cfg().keyToggleSneak, KEY_SNEAK, OPTIONS.toggleCrouch()::set);
|
||||||
private final ToggleTracker toggleWalkForward = new ToggleTracker(cfg().keyToggleWalkForward, KEY_FORWARD);
|
private final ToggleTracker toggleWalkForward = new ToggleTracker(cfg().keyToggleWalkForward, KEY_FORWARD);
|
||||||
private final ToggleTracker toggleJump = new ToggleTracker(cfg().keyToggleJump, KEY_JUMP);
|
private final ToggleTracker toggleJump = new ToggleTracker(cfg().keyToggleJump, KEY_JUMP);
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ public final class PlayerTicker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final SprintMode sprintMode = cfg().sprintMode;
|
final SprintMode sprintMode = cfg().sprintMode;
|
||||||
final boolean wasSprintToggled = OPTIONS.toggleSprint;
|
final boolean wasSprintToggled = Boolean.TRUE.equals(OPTIONS.toggleSprint().get());
|
||||||
final boolean isSprintToggled = toggleSprint.tick();
|
final boolean isSprintToggled = toggleSprint.tick();
|
||||||
|
|
||||||
if (temporarySprintTimer > 0) {
|
if (temporarySprintTimer > 0) {
|
||||||
@@ -149,6 +149,7 @@ 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -157,6 +158,7 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user