1
0
mirror of https://github.com/chylex/Better-Controls.git synced 2025-08-17 16:31:49 +02:00

14 Commits

19 changed files with 75 additions and 69 deletions

View File

@@ -21,8 +21,8 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'org.spongepowered.mixin'
apply plugin: 'eclipse'
def mcversion = "1.16.4"
def forgeversion = "35.0.1"
def mcversion = "1.15.2"
def forgeversion = "31.2.45"
def prefixName = 'displayName = '
def prefixVersion = 'version = '
@@ -38,7 +38,7 @@ archivesBaseName = metaName.replaceAll('\\s', '')
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
minecraft {
mappings channel: 'snapshot', version: '20201028-1.16.3'
mappings channel: 'snapshot', version: '20201030-1.15.1'
runs {
client {
@@ -74,7 +74,7 @@ dependencies {
}
jar {
archiveName = archivesBaseName + '-' + mcversion + '+v' + version + '.jar'
archiveName = archivesBaseName + '-' + mcversion + '-v' + version + '.jar'
from('./') {
include 'LICENSE'

View File

@@ -12,12 +12,11 @@ import chylex.bettercontrols.input.ModifierKey;
import chylex.bettercontrols.input.SprintMode;
import chylex.bettercontrols.util.Key;
import chylex.bettercontrols.util.LiteralText;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.gui.DialogTexts;
import net.minecraft.client.gui.IGuiEventListener;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.SettingsScreen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.settings.KeyBinding;
import org.lwjgl.glfw.GLFW;
import javax.annotation.Nullable;
@@ -247,21 +246,21 @@ public class BetterControlsScreen extends SettingsScreen{
elements.add(new TextWidget(0, y, ROW_WIDTH, ROW_HEIGHT, text("Miscellaneous"), CENTER));
y = generateMiscellaneousOptions(y + ROW_HEIGHT, elements) + TITLE_MARGIN_TOP;
addButton(new Button(width / 2 - 99, height - 29, 200, 20, DialogTexts.GUI_DONE, btn -> minecraft.displayGuiScreen(parentScreen)));
addListener(optionsWidget = new OptionListWidget(21, height - 32, width, height, elements, y - TITLE_MARGIN_TOP + BOTTOM_PADDING));
addButton(new Button(width / 2 - 99, height - 29, 200, 20, I18n.format("gui.done"), btn -> minecraft.displayGuiScreen(parentScreen)));
children.add(optionsWidget = new OptionListWidget(21, height - 32, width, height, elements, y - TITLE_MARGIN_TOP + BOTTOM_PADDING));
}
@Override
public void onClose(){
public void removed(){
BetterControlsMod.config.save();
}
@Override
public void render(final MatrixStack matrices, final int mouseX, final int mouseY, final float delta){
renderBackground(matrices);
optionsWidget.render(matrices, mouseX, mouseY, delta);
drawCenteredString(matrices, font, title, width / 2, 8, (255 << 16) | (255 << 8) | 255);
super.render(matrices, mouseX, mouseY, delta);
public void render(final int mouseX, final int mouseY, final float delta){
renderBackground();
optionsWidget.render(mouseX, mouseY, delta);
drawCenteredString(font, title.getString(), width / 2, 8, (255 << 16) | (255 << 8) | 255);
super.render(mouseX, mouseY, delta);
}
private void startEditingKeyBinding(final KeyBindingWidget widget){

View File

@@ -1,6 +1,5 @@
package chylex.bettercontrols.gui;
import chylex.bettercontrols.gui.OptionListWidget.Entry;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.gui.IGuiEventListener;
import net.minecraft.client.gui.IRenderable;
import net.minecraft.client.gui.widget.list.AbstractOptionList;
@@ -62,7 +61,7 @@ public final class OptionListWidget extends AbstractOptionList<Entry>{
}
@Override
public int getRowLeft(){
protected int getRowLeft(){
return super.getRowLeft() - ROW_PADDING;
}
@@ -86,12 +85,12 @@ public final class OptionListWidget extends AbstractOptionList<Entry>{
}
@Override
public List<? extends IGuiEventListener> getEventListeners(){
public List<? extends IGuiEventListener> children(){
return Collections.unmodifiableList(elements);
}
@Override
public void render(final MatrixStack matrices, final int index, final int y, final int x, final int entryWidth, final int entryHeight, final int mouseX, final int mouseY, final boolean hovered, final float tickDelta){
public void render(final int index, final int y, final int x, final int entryWidth, final int entryHeight, final int mouseX, final int mouseY, final boolean hovered, final float tickDelta){
for(final IGuiEventListener element : elements){
final Offset offset = offsets.get(element);
@@ -107,7 +106,7 @@ public final class OptionListWidget extends AbstractOptionList<Entry>{
}
if (element instanceof IRenderable){
((IRenderable)element).render(matrices, mouseX, mouseY, tickDelta);
((IRenderable)element).render(mouseX, mouseY, tickDelta);
}
}
}

View File

@@ -1,6 +1,6 @@
package chylex.bettercontrols.gui;
import chylex.bettercontrols.mixin.AccessOptionButtonWidgetOption;
import chylex.bettercontrols.mixin.AccessScreenButtons;
import net.minecraft.client.AbstractOption;
import net.minecraft.client.gui.AccessibilityScreen;
import net.minecraft.client.gui.IGuiEventListener;
import net.minecraft.client.gui.INestedGuiEventHandler;
@@ -8,6 +8,7 @@ import net.minecraft.client.gui.screen.ControlsScreen;
import net.minecraft.client.gui.widget.button.AbstractButton;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.gui.widget.button.OptionButton;
import net.minecraft.client.settings.AbstractOption;
import java.util.List;
import java.util.function.Consumer;
import static chylex.bettercontrols.util.Statics.MINECRAFT;
@@ -18,12 +19,12 @@ public final class ScreenPatcher{
public static void onControlsScreenOpened(final ControlsScreen screen){
final AccessScreenButtons accessor = (AccessScreenButtons)screen;
final List<? extends IGuiEventListener> children = screen.getEventListeners();
final List<? extends IGuiEventListener> children = screen.children();
final List<AbstractButton> buttons = accessor.getButtons();
final AbstractButton autoJump = buttons
.stream()
.filter(it -> it instanceof OptionButton && ((OptionButton)it).func_238517_a_() == AbstractOption.AUTO_JUMP)
.filter(it -> it instanceof OptionButton && ((AccessOptionButtonWidgetOption)it).getOption() == AbstractOption.AUTO_JUMP)
.findAny()
.orElse(null);
@@ -31,17 +32,17 @@ public final class ScreenPatcher{
children.remove(autoJump);
buttons.remove(autoJump);
accessor.callAddButton(new Button(autoJump.x, autoJump.y, autoJump.getWidth(), 20, BetterControlsScreen.TITLE.copy().appendString("..."), btn -> {
accessor.callAddButton(new Button(autoJump.x, autoJump.y, autoJump.getWidth(), 20, BetterControlsScreen.TITLE.copy().appendText("...").getString(), btn -> {
MINECRAFT.displayGuiScreen(new BetterControlsScreen(screen));
}));
}
}
public static void onAccessibilityScreenOpened(final AccessibilityScreen screen){
walkChildren(screen.getEventListeners(), it -> {
walkChildren(screen.children(), it -> {
if (it instanceof OptionButton){
final OptionButton button = (OptionButton)it;
final AbstractOption option = button.func_238517_a_();
final AbstractOption option = ((AccessOptionButtonWidgetOption)button).getOption();
if (option == AbstractOption.SPRINT || option == AbstractOption.SNEAK){
button.active = false;
@@ -55,7 +56,7 @@ public final class ScreenPatcher{
callback.accept(listener);
if (listener instanceof INestedGuiEventHandler){
walkChildren(((INestedGuiEventHandler)listener).getEventListeners(), callback);
walkChildren(((INestedGuiEventHandler)listener).children(), callback);
}
}
}

View File

@@ -1,14 +1,14 @@
package chylex.bettercontrols.gui.elements;
import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
import net.minecraft.client.gui.DialogTexts;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.resources.I18n;
public final class BooleanValueWidget extends Button{
private final BooleanConsumer onChanged;
private boolean value;
public BooleanValueWidget(final int x, final int y, final int width, final int height, final boolean currentValue, final BooleanConsumer onChanged){
super(x, y, width, height, currentValue ? DialogTexts.OPTIONS_ON : DialogTexts.OPTIONS_OFF, ignore -> {});
super(x, y, width, height, I18n.format(currentValue ? "options.on" : "options.off"), ignore -> {});
this.value = currentValue;
this.onChanged = onChanged;
}
@@ -21,7 +21,7 @@ public final class BooleanValueWidget extends Button{
public void onPress(){
super.onPress();
value = !value;
setMessage(value ? DialogTexts.OPTIONS_ON : DialogTexts.OPTIONS_OFF);
setMessage(I18n.format(value ? "options.on" : "options.off"));
onChanged.accept(value);
}
}

View File

@@ -9,7 +9,7 @@ public class CycleButtonWidget<T> extends Button{
private T selectedValue;
public CycleButtonWidget(final int x, final int y, final int width, final int height, final List<Option<T>> options, final T selectedValue, final Consumer<T> onChanged){
super(x, y, width, height, Option.find(options, selectedValue).getText(), btn -> {});
super(x, y, width, height, Option.find(options, selectedValue).getText().getString(), btn -> {});
this.options = options;
this.selectedValue = selectedValue;
this.onChanged = onChanged;
@@ -31,6 +31,6 @@ public class CycleButtonWidget<T> extends Button{
selectedValue = newSelectedOption.getValue();
onChanged.accept(selectedValue);
setMessage(newSelectedOption.getText());
setMessage(newSelectedOption.getText().getString());
}
}

View File

@@ -10,10 +10,11 @@ public final class DiscreteValueSliderWidget<T> extends AbstractSlider{
private T selectedValue;
public DiscreteValueSliderWidget(final int x, final int y, final int width, final int height, final List<Option<T>> options, final T selectedValue, final Consumer<T> onChanged){
super(x, y, width, height, Option.find(options, selectedValue).getText(), options.indexOf(Option.find(options, selectedValue)) / (options.size() - 1.0));
super(x, y, width, height, options.indexOf(Option.find(options, selectedValue)) / (options.size() - 1.0));
this.options = options;
this.selectedValue = selectedValue;
this.onChanged = onChanged;
updateMessage();
}
public DiscreteValueSliderWidget(final int x, final int y, final int width, final List<Option<T>> options, final T selectedValue, final Consumer<T> onChanged){
@@ -21,16 +22,16 @@ public final class DiscreteValueSliderWidget<T> extends AbstractSlider{
}
public Option<T> getSelectedOption(){
return options.get(MathHelper.floor(MathHelper.clampedLerp(0.0, options.size() - 1.0, sliderValue)));
return options.get(MathHelper.floor(MathHelper.clampedLerp(0.0, options.size() - 1.0, value)));
}
@Override
protected void func_230979_b_(){
setMessage(getSelectedOption().getText());
protected void updateMessage(){
setMessage(getSelectedOption().getText().getString());
}
@Override
protected void func_230972_a_(){
protected void applyValue(){
final T newSelectedValue = getSelectedOption().getValue();
if (selectedValue != newSelectedValue){

View File

@@ -2,11 +2,10 @@ package chylex.bettercontrols.gui.elements;
import chylex.bettercontrols.util.Key;
import net.minecraft.client.gui.widget.button.AbstractButton;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.client.util.InputMappings;
import net.minecraft.util.text.IFormattableTextComponent;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import java.util.ArrayList;
@@ -24,7 +23,7 @@ public final class KeyBindingWidget extends Button{
private boolean isEditing;
public KeyBindingWidget(final int x, final int y, final int width, final int height, final KeyBinding binding, final Consumer<KeyBindingWidget> onEditingStarted){
super(x, y, width, height, StringTextComponent.EMPTY, btn -> {});
super(x, y, width, height, "", btn -> {});
this.binding = binding;
this.bindingName = new TranslationTextComponent(binding.getTranslationKey());
this.onEditingStarted = onEditingStarted;
@@ -41,8 +40,8 @@ public final class KeyBindingWidget extends Button{
}
@Override
protected IFormattableTextComponent getNarrationMessage(){
return Key.isUnbound(binding) ? new TranslationTextComponent("narrator.controls.unbound", bindingName) : new TranslationTextComponent("narrator.controls.bound", bindingName, super.getNarrationMessage());
protected String getNarrationMessage(){
return Key.isUnbound(binding) ? I18n.format("narrator.controls.unbound", bindingName) : I18n.format("narrator.controls.bound", bindingName, super.getNarrationMessage());
}
@Override
@@ -79,13 +78,13 @@ public final class KeyBindingWidget extends Button{
}
if (isEditing){
setMessage((new StringTextComponent("> ")).append(Key.getBoundKeyText(binding).deepCopy().mergeStyle(TextFormatting.YELLOW)).appendString(" <").mergeStyle(TextFormatting.YELLOW));
setMessage(TextFormatting.WHITE + "> " + TextFormatting.YELLOW + Key.getBoundKeyText(binding) + TextFormatting.WHITE + " <");
}
else if (hasConflict){
setMessage(Key.getBoundKeyText(binding).deepCopy().mergeStyle(TextFormatting.RED));
setMessage(TextFormatting.RED + Key.getBoundKeyText(binding));
}
else{
setMessage(Key.isUnbound(binding) ? new StringTextComponent("(No Binding)") : Key.getBoundKeyText(binding));
setMessage(Key.isUnbound(binding) ? "(No Binding)" : Key.getBoundKeyText(binding));
}
}
}

View File

@@ -1,10 +1,8 @@
package chylex.bettercontrols.gui.elements;
import chylex.bettercontrols.gui.OptionListWidget.Widget;
import chylex.bettercontrols.util.LiteralText;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.util.IReorderingProcessor;
import java.util.List;
import static chylex.bettercontrols.util.Statics.MINECRAFT;
@@ -57,17 +55,17 @@ public final class TextWidget extends AbstractGui implements Widget{
}
@Override
public void render(final MatrixStack matrices, final int mouseX, final int mouseY, final float delta){
public void render(final int mouseX, final int mouseY, final float delta){
final FontRenderer textRenderer = MINECRAFT.fontRenderer;
final List<IReorderingProcessor> lines = textRenderer.trimStringToWidth(text, width);
final List<String> lines = textRenderer.listFormattedStringToWidth(text.getString(), width);
final int lineHeight = textRenderer.FONT_HEIGHT + 1;
final int finalX = align == CENTER ? x + (width / 2) - (lines.stream().mapToInt(textRenderer::func_243245_a).max().orElse(0) / 2) : x;
final int finalX = align == CENTER ? x + (width / 2) - (lines.stream().mapToInt(textRenderer::getStringWidth).max().orElse(0) / 2) : x;
final int finalY = y + (height / 2) - (lineHeight * lines.size() / 2) + 1;
for(int i = 0; i < lines.size(); i++){
final IReorderingProcessor line = lines.get(i);
textRenderer.func_238407_a_(matrices, line, finalX, finalY + (i * lineHeight), (255 << 16) | (255 << 8) | 255);
final String line = lines.get(i);
textRenderer.drawStringWithShadow(line, finalX, finalY + (i * lineHeight), (255 << 16) | (255 << 8) | 255);
}
}
}

View File

@@ -1,15 +1,14 @@
package chylex.bettercontrols.input;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.client.util.InputMappings.Type;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import javax.annotation.Nullable;
public class KeyBindingWithModifier extends KeyBinding{
public static final String CATEGORY = "key.categories.bettercontrols";
public static boolean checkCategoryMatches(final ITextComponent text){
return text instanceof TranslationTextComponent && CATEGORY.equals(((TranslationTextComponent)text).getKey());
public static boolean checkCategoryMatches(final String text){
return I18n.format(CATEGORY).equals(text);
}
@Nullable

View File

@@ -1,11 +1,10 @@
package chylex.bettercontrols.mixin;
import net.minecraft.client.gui.widget.list.KeyBindingList.CategoryEntry;
import net.minecraft.util.text.ITextComponent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(CategoryEntry.class)
public interface AccessControlsListCategory{
@Accessor("labelText")
ITextComponent getText();
String getText();
}

View File

@@ -0,0 +1,11 @@
package chylex.bettercontrols.mixin;
import net.minecraft.client.gui.widget.button.OptionButton;
import net.minecraft.client.settings.AbstractOption;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(OptionButton.class)
public interface AccessOptionButtonWidgetOption{
@Accessor("enumOptions")
AbstractOption getOption();
}

View File

@@ -12,7 +12,7 @@ import static org.spongepowered.asm.mixin.injection.At.Shift.AFTER;
@Mixin(MovementInputFromOptions.class)
public abstract class HookClientPlayerInputTick{
@Inject(method = "tickMovement(Z)V", at = @At(value = "FIELD", target = "Lnet/minecraft/util/MovementInputFromOptions;forwardKeyDown:Z", ordinal = 0, shift = AFTER))
@Inject(method = "func_225607_a_(Z)V", at = @At(value = "FIELD", target = "Lnet/minecraft/util/MovementInputFromOptions;forwardKeyDown:Z", ordinal = 0, shift = AFTER))
private void afterInputTick(final CallbackInfo info){
final MovementInput input = (MovementInput)(Object)this;
final ClientPlayerEntity player = MINECRAFT.player;

View File

@@ -22,7 +22,7 @@ public abstract class HookClientPlayerTick extends AbstractClientPlayerEntity{
PlayerTicker.get(player).atHead(player);
}
@Inject(method = "livingTick()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/MovementInput;tickMovement(Z)V", ordinal = 0, shift = AFTER))
@Inject(method = "livingTick()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/MovementInput;func_225607_a_(Z)V", ordinal = 0, shift = AFTER))
private void afterInputTick(final CallbackInfo info){
final ClientPlayerEntity player = (ClientPlayerEntity)(Object)this;
PlayerTicker.get(player).afterInputTick(player);

View File

@@ -22,7 +22,7 @@ public abstract class HookControlsListWidget extends AbstractOptionList<Entry>{
@Inject(method = "<init>", at = @At("TAIL"))
public void init(final ControlsScreen parent, final Minecraft client, final CallbackInfo ci){
getEventListeners().removeIf(it -> {
children().removeIf(it -> {
if (it instanceof CategoryEntry && KeyBindingWithModifier.checkCategoryMatches(((AccessControlsListCategory)it).getText())){
return true;
}

View File

@@ -75,7 +75,7 @@ public final class PlayerTicker{
public void atHead(final ClientPlayerEntity player){
if (FlightHelper.shouldFlyOnGround(player)){
player.setOnGround(false);
player.onGround = false;
}
if (!cfg().doubleTapForwardToSprint){
@@ -209,7 +209,7 @@ public final class PlayerTicker{
public void afterSuperCall(final ClientPlayerEntity player){
if (FlightHelper.shouldFlyOnGround(player)){
final boolean isSneaking = player.isSneaking();
final boolean isOnGround = player.isOnGround();
final boolean isOnGround = player.onGround;
if (!isSneaking){
wasSneakingBeforeTouchingGround = false;
@@ -236,7 +236,7 @@ public final class PlayerTicker{
}
if (cancelLanding){
player.setOnGround(false);
player.onGround = false;
}
}
}
@@ -275,7 +275,7 @@ public final class PlayerTicker{
}
else{
--temporaryFlyOnGroundTimer;
player.setOnGround(false);
player.onGround = false;
}
}
}

View File

@@ -2,7 +2,6 @@ package chylex.bettercontrols.util;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.client.util.InputMappings;
import net.minecraft.client.util.InputMappings.Input;
import net.minecraft.util.text.ITextComponent;
public final class Key{
private Key(){}
@@ -21,8 +20,8 @@ public final class Key{
return binding.isPressed();
}
public static ITextComponent getBoundKeyText(final KeyBinding binding){
return binding.func_238171_j_();
public static String getBoundKeyText(final KeyBinding binding){
return binding.getLocalizedName();
}
public static void bind(final KeyBinding binding, final Input input){

View File

@@ -18,13 +18,13 @@ The features complement vanilla mechanics without giving unfair advantages, so s
[[dependencies.bettercontrols]]
modId = "minecraft"
mandatory = true
versionRange = "[1.16.3,)"
versionRange = "[1.15.2,1.16)"
ordering = "NONE"
side = "BOTH"
[[dependencies.bettercontrols]]
modId = "forge"
mandatory = true
versionRange = "[31,)"
versionRange = "[31.2.44,)"
ordering = "NONE"
side = "BOTH"

View File

@@ -10,6 +10,7 @@
"AccessControlsListKeyBinding",
"AccessGameRendererFields",
"AccessKeyBindingFields",
"AccessOptionButtonWidgetOption",
"AccessPlayerFields",
"AccessScreenButtons",
"AccessStickyKeyBindingStateGetter",