mirror of
https://github.com/chylex/Better-Controls.git
synced 2025-05-05 19:34:05 +02:00
Minor refactoring
This commit is contained in:
parent
d7d0bf072a
commit
0d1dfdee87
src/main/java/chylex/bettercontrols
gui
input
mixin
AccessCameraFields.javaAccessClientPlayerFields.javaAccessControlsListCategory.javaAccessControlsListKeyBinding.javaAccessCycleButtonFields.javaAccessOptionFields.javaAccessPlayerFields.javaAccessScreenButtons.javaAccessStickyKeyBindingStateGetter.javaHookClientPlayerFOV.javaHookClientPlayerInputTick.javaHookClientPlayerTick.javaHookControlsListWidget.javaHookOpenScreen.javaHookPlayerFlightSpeed.java
player
util
@ -13,6 +13,7 @@ import chylex.bettercontrols.input.SprintMode;
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.KeyMapping;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
import net.minecraft.client.gui.screens.OptionsSubScreen;
|
||||
@ -20,6 +21,7 @@ import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.CommonComponents;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import java.util.ArrayList;
|
||||
@ -31,7 +33,6 @@ import static chylex.bettercontrols.gui.OptionListWidget.ROW_WIDTH;
|
||||
import static chylex.bettercontrols.gui.OptionListWidget.col2;
|
||||
import static chylex.bettercontrols.gui.OptionListWidget.col4;
|
||||
import static chylex.bettercontrols.gui.elements.TextWidget.CENTER;
|
||||
import static chylex.bettercontrols.util.Statics.OPTIONS;
|
||||
|
||||
public class BetterControlsScreen extends OptionsSubScreen {
|
||||
private static TextComponent text(final String text) {
|
||||
@ -229,7 +230,7 @@ public class BetterControlsScreen extends OptionsSubScreen {
|
||||
private final List<KeyBindingWidget> allKeyBindings = new ArrayList<>();
|
||||
|
||||
public BetterControlsScreen(@Nullable final Screen parentScreen) {
|
||||
super(parentScreen, OPTIONS, TITLE);
|
||||
super(parentScreen, Minecraft.getInstance().options, TITLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -261,7 +262,7 @@ public class BetterControlsScreen extends OptionsSubScreen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(final 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) {
|
||||
renderBackground(matrices);
|
||||
optionsWidget.render(matrices, mouseX, mouseY, delta);
|
||||
drawCenteredString(matrices, font, title, width / 2, 8, (255 << 16) | (255 << 8) | 255);
|
||||
|
@ -1,18 +1,19 @@
|
||||
package chylex.bettercontrols.gui;
|
||||
import chylex.bettercontrols.gui.OptionListWidget.Entry;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.AbstractWidget;
|
||||
import net.minecraft.client.gui.components.ContainerObjectSelectionList;
|
||||
import net.minecraft.client.gui.components.Widget;
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
import net.minecraft.client.gui.narration.NarratableEntry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import static chylex.bettercontrols.util.Statics.MINECRAFT;
|
||||
|
||||
public final class OptionListWidget extends ContainerObjectSelectionList<Entry> {
|
||||
public static final int ROW_WIDTH = 408;
|
||||
@ -30,11 +31,11 @@ public final class OptionListWidget extends ContainerObjectSelectionList<Entry>
|
||||
}
|
||||
|
||||
private static Offset getElementOffset(final GuiEventListener element) {
|
||||
if (element instanceof OptionWidget) {
|
||||
return new Offset(((OptionWidget)element).getX(), ((OptionWidget)element).getY());
|
||||
if (element instanceof final OptionWidget widget) {
|
||||
return new Offset(widget.getX(), widget.getY());
|
||||
}
|
||||
else if (element instanceof AbstractWidget) {
|
||||
return new Offset(((AbstractWidget)element).x, ((AbstractWidget)element).y);
|
||||
else if (element instanceof final AbstractWidget widget) {
|
||||
return new Offset(widget.x, widget.y);
|
||||
}
|
||||
else {
|
||||
return new Offset(0, 0);
|
||||
@ -48,18 +49,10 @@ public final class OptionListWidget extends ContainerObjectSelectionList<Entry>
|
||||
void setY(int y);
|
||||
}
|
||||
|
||||
private static final class Offset {
|
||||
public final int x;
|
||||
public final int y;
|
||||
|
||||
private Offset(final int x, final int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
}
|
||||
private record Offset(int x, int y) {}
|
||||
|
||||
public OptionListWidget(final int top, final int bottom, final int width, final int height, final List<GuiEventListener> widgets, final int innerHeight) {
|
||||
super(MINECRAFT, width, height, top, bottom, innerHeight);
|
||||
super(Minecraft.getInstance(), width, height, top, bottom, innerHeight);
|
||||
addEntry(new Entry(widgets));
|
||||
}
|
||||
|
||||
@ -90,33 +83,31 @@ public final class OptionListWidget extends ContainerObjectSelectionList<Entry>
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends GuiEventListener> children() {
|
||||
public @NotNull List<? extends GuiEventListener> children() {
|
||||
return Collections.unmodifiableList(elements);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends NarratableEntry> narratables() {
|
||||
public @NotNull List<? extends NarratableEntry> narratables() {
|
||||
return Collections.unmodifiableList(narratables);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(final PoseStack 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 @NotNull PoseStack 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) {
|
||||
for (final GuiEventListener element : elements) {
|
||||
final Offset offset = offsets.get(element);
|
||||
|
||||
if (element instanceof AbstractWidget) {
|
||||
final AbstractWidget button = (AbstractWidget)element;
|
||||
button.x = x + offset.x;
|
||||
button.y = y + offset.y;
|
||||
if (element instanceof final AbstractWidget widget) {
|
||||
widget.x = x + offset.x;
|
||||
widget.y = y + offset.y;
|
||||
}
|
||||
else if (element instanceof OptionWidget) {
|
||||
final OptionWidget widget = (OptionWidget)element;
|
||||
else if (element instanceof final OptionWidget widget) {
|
||||
widget.setX(x + offset.x);
|
||||
widget.setY(y + offset.y);
|
||||
}
|
||||
|
||||
if (element instanceof Widget) {
|
||||
((Widget)element).render(matrices, mouseX, mouseY, tickDelta);
|
||||
if (element instanceof final Widget widget) {
|
||||
widget.render(matrices, mouseX, mouseY, tickDelta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package chylex.bettercontrols.gui;
|
||||
import chylex.bettercontrols.mixin.AccessCycleButtonFields;
|
||||
import chylex.bettercontrols.mixin.AccessOptionFields;
|
||||
import chylex.bettercontrols.mixin.AccessScreenButtons;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.Option;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.CycleButton;
|
||||
@ -12,7 +13,6 @@ import net.minecraft.client.gui.screens.controls.ControlsScreen;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import static chylex.bettercontrols.util.Statics.MINECRAFT;
|
||||
|
||||
public final class ScreenPatcher {
|
||||
private ScreenPatcher() {}
|
||||
@ -25,7 +25,7 @@ public final class ScreenPatcher {
|
||||
|
||||
if (autoJump != null) {
|
||||
final Button widget = new Button(autoJump.x, autoJump.y, autoJump.getWidth(), autoJump.getHeight(), BetterControlsScreen.TITLE.plainCopy().append("..."), btn -> {
|
||||
MINECRAFT.setScreen(new BetterControlsScreen(screen));
|
||||
Minecraft.getInstance().setScreen(new BetterControlsScreen(screen));
|
||||
});
|
||||
|
||||
accessor.callRemoveWidget(autoJump);
|
||||
@ -44,15 +44,15 @@ public final class ScreenPatcher {
|
||||
for (final GuiEventListener element : elements) {
|
||||
callback.accept(element);
|
||||
|
||||
if (element instanceof ContainerEventHandler) {
|
||||
walkChildren(((ContainerEventHandler)element).children(), callback);
|
||||
if (element instanceof final ContainerEventHandler container) {
|
||||
walkChildren(container.children(), callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Optional<CycleButton<?>> getOptionButton(final GuiEventListener element, final Option option) {
|
||||
if (element instanceof CycleButton<?> && ((AccessOptionFields)option).getCaption().equals(((AccessCycleButtonFields)element).getName())) {
|
||||
return Optional.of((CycleButton<?>)element);
|
||||
if (element instanceof final CycleButton<?> button && ((AccessOptionFields)option).getCaption().equals(((AccessCycleButtonFields)button).getName())) {
|
||||
return Optional.of(button);
|
||||
}
|
||||
else {
|
||||
return Optional.empty();
|
||||
|
@ -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).text(), btn -> {});
|
||||
this.options = options;
|
||||
this.selectedValue = selectedValue;
|
||||
this.onChanged = onChanged;
|
||||
@ -29,8 +29,8 @@ public class CycleButtonWidget<T> extends Button {
|
||||
|
||||
final Option<T> newSelectedOption = options.get(nextIndex);
|
||||
|
||||
selectedValue = newSelectedOption.getValue();
|
||||
selectedValue = newSelectedOption.value();
|
||||
onChanged.accept(selectedValue);
|
||||
setMessage(newSelectedOption.getText());
|
||||
setMessage(newSelectedOption.text());
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ public final class DiscreteValueSliderWidget<T> extends AbstractSliderButton {
|
||||
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, Option.find(options, selectedValue).text(), options.indexOf(Option.find(options, selectedValue)) / (options.size() - 1.0));
|
||||
this.options = options;
|
||||
this.selectedValue = selectedValue;
|
||||
this.onChanged = onChanged;
|
||||
@ -26,12 +26,12 @@ public final class DiscreteValueSliderWidget<T> extends AbstractSliderButton {
|
||||
|
||||
@Override
|
||||
protected void updateMessage() {
|
||||
setMessage(getSelectedOption().getText());
|
||||
setMessage(getSelectedOption().text());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyValue() {
|
||||
final T newSelectedValue = getSelectedOption().getValue();
|
||||
final T newSelectedValue = getSelectedOption().value();
|
||||
|
||||
if (selectedValue != newSelectedValue) {
|
||||
selectedValue = newSelectedValue;
|
||||
|
@ -2,16 +2,17 @@ package chylex.bettercontrols.gui.elements;
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.KeyMapping;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.AbstractButton;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import static chylex.bettercontrols.util.Statics.OPTIONS;
|
||||
|
||||
public final class KeyBindingWidget extends Button {
|
||||
private final KeyMapping binding;
|
||||
@ -40,7 +41,7 @@ public final class KeyBindingWidget extends Button {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MutableComponent createNarrationMessage() {
|
||||
protected @NotNull MutableComponent createNarrationMessage() {
|
||||
return binding.isUnbound() ? new TranslatableComponent("narrator.controls.unbound", bindingName) : new TranslatableComponent("narrator.controls.bound", bindingName, super.createNarrationMessage());
|
||||
}
|
||||
|
||||
@ -69,7 +70,7 @@ public final class KeyBindingWidget extends Button {
|
||||
boolean hasConflict = false;
|
||||
|
||||
if (!binding.isUnbound()) {
|
||||
for (final KeyMapping other : OPTIONS.keyMappings) {
|
||||
for (final KeyMapping other : Minecraft.getInstance().options.keyMappings) {
|
||||
if (binding != other && binding.same(other)) {
|
||||
hasConflict = true;
|
||||
break;
|
||||
|
@ -3,23 +3,7 @@ import net.minecraft.network.chat.Component;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class Option<T> {
|
||||
private final T value;
|
||||
private final Component text;
|
||||
|
||||
public Option(final T value, final Component text) {
|
||||
this.value = value;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Component getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public record Option<T>(T value, Component text) {
|
||||
public static <T> Option<T> find(final List<Option<T>> options, final T value) {
|
||||
return options.stream().filter(it -> Objects.equals(it.value, value)).findFirst().orElseGet(() -> options.get(0));
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
package chylex.bettercontrols.gui.elements;
|
||||
import chylex.bettercontrols.gui.OptionListWidget.OptionWidget;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.util.FormattedCharSequence;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import java.util.List;
|
||||
import static chylex.bettercontrols.util.Statics.MINECRAFT;
|
||||
|
||||
public final class TextWidget extends GuiComponent implements OptionWidget {
|
||||
public static final int LEFT = 0;
|
||||
@ -57,8 +58,8 @@ public final class TextWidget extends GuiComponent implements OptionWidget {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(final PoseStack matrices, final int mouseX, final int mouseY, final float delta) {
|
||||
final Font textRenderer = MINECRAFT.font;
|
||||
public void render(final @NotNull PoseStack matrices, final int mouseX, final int mouseY, final float delta) {
|
||||
final Font textRenderer = Minecraft.getInstance().font;
|
||||
final List<FormattedCharSequence> lines = textRenderer.split(text, width);
|
||||
final int lineHeight = textRenderer.lineHeight + 1;
|
||||
|
||||
|
@ -9,7 +9,7 @@ public class KeyBindingWithModifier extends KeyMapping {
|
||||
public static final String CATEGORY = "key.categories.bettercontrols";
|
||||
|
||||
public static boolean checkCategoryMatches(final Component text) {
|
||||
return text instanceof TranslatableComponent && CATEGORY.equals(((TranslatableComponent)text).getKey());
|
||||
return text instanceof final TranslatableComponent t && CATEGORY.equals(t.getKey());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -5,6 +5,6 @@ import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(Camera.class)
|
||||
public interface AccessCameraFields {
|
||||
@Accessor("eyeHeight")
|
||||
void setCameraY(float y);
|
||||
@Accessor
|
||||
void setEyeHeight(float y);
|
||||
}
|
||||
|
@ -5,6 +5,6 @@ import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(LocalPlayer.class)
|
||||
public interface AccessClientPlayerFields {
|
||||
@Accessor("sprintTriggerTime")
|
||||
void setTicksLeftToDoubleTapSprint(int value);
|
||||
@Accessor
|
||||
void setSprintTriggerTime(int value);
|
||||
}
|
||||
|
@ -6,6 +6,6 @@ import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(CategoryEntry.class)
|
||||
public interface AccessControlsListCategory {
|
||||
@Accessor("name")
|
||||
Component getText();
|
||||
@Accessor
|
||||
Component getName();
|
||||
}
|
||||
|
@ -6,6 +6,6 @@ import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(KeyEntry.class)
|
||||
public interface AccessControlsListKeyBinding {
|
||||
@Accessor("key")
|
||||
KeyMapping getBinding();
|
||||
@Accessor
|
||||
KeyMapping getKey();
|
||||
}
|
||||
|
@ -7,6 +7,6 @@ import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(CycleButton.class)
|
||||
public interface AccessCycleButtonFields {
|
||||
@Accessor("name")
|
||||
@Accessor
|
||||
Component getName();
|
||||
}
|
||||
|
@ -7,6 +7,6 @@ import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(Option.class)
|
||||
public interface AccessOptionFields {
|
||||
@Accessor("caption")
|
||||
@Accessor
|
||||
Component getCaption();
|
||||
}
|
||||
|
@ -5,6 +5,6 @@ import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(Player.class)
|
||||
public interface AccessPlayerFields {
|
||||
@Accessor("jumpTriggerTime")
|
||||
void setTicksLeftToDoubleTapFlight(int value);
|
||||
@Accessor
|
||||
void setJumpTriggerTime(int value);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import net.minecraft.client.gui.screens.Screen;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
@Mixin(Screen.class)
|
||||
public interface AccessScreenButtons {
|
||||
@Invoker
|
||||
|
@ -7,10 +7,10 @@ import java.util.function.BooleanSupplier;
|
||||
|
||||
@Mixin(ToggleKeyMapping.class)
|
||||
public interface AccessStickyKeyBindingStateGetter {
|
||||
@Accessor("needsToggle")
|
||||
BooleanSupplier getToggleGetter();
|
||||
@Accessor
|
||||
BooleanSupplier getNeedsToggle();
|
||||
|
||||
@Accessor("needsToggle")
|
||||
@Accessor
|
||||
@Mutable
|
||||
void setToggleGetter(final BooleanSupplier toggleGetter);
|
||||
void setNeedsToggle(final BooleanSupplier toggleGetter);
|
||||
}
|
||||
|
@ -1,15 +1,14 @@
|
||||
package chylex.bettercontrols.mixin;
|
||||
|
||||
import chylex.bettercontrols.player.PlayerTicker;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.AbstractClientPlayer;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.Slice;
|
||||
import static chylex.bettercontrols.util.Statics.MINECRAFT;
|
||||
|
||||
@SuppressWarnings("MethodMayBeStatic")
|
||||
@Mixin(AbstractClientPlayer.class)
|
||||
public abstract class HookClientPlayerFOV {
|
||||
@Redirect(
|
||||
@ -21,7 +20,7 @@ public abstract class HookClientPlayerFOV {
|
||||
)
|
||||
)
|
||||
private boolean resetFOV(final float movementSpeed) {
|
||||
final LocalPlayer player = MINECRAFT.player;
|
||||
final LocalPlayer player = Minecraft.getInstance().player;
|
||||
return (player != null && PlayerTicker.get(player).shouldResetFOV(player)) || Float.isNaN(movementSpeed);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package chylex.bettercontrols.mixin;
|
||||
import chylex.bettercontrols.player.PlayerTicker;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.Input;
|
||||
import net.minecraft.client.player.KeyboardInput;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
@ -7,15 +8,15 @@ 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.CallbackInfo;
|
||||
import static chylex.bettercontrols.util.Statics.MINECRAFT;
|
||||
import static org.spongepowered.asm.mixin.injection.At.Shift.AFTER;
|
||||
|
||||
@Mixin(KeyboardInput.class)
|
||||
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))
|
||||
private void afterInputTick(final CallbackInfo info) {
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
final Input input = (Input)(Object)this;
|
||||
final LocalPlayer player = MINECRAFT.player;
|
||||
final LocalPlayer player = Minecraft.getInstance().player;
|
||||
|
||||
if (player != null) {
|
||||
PlayerTicker.get(player).afterInputAssignsPressingForward(input);
|
||||
|
@ -18,18 +18,21 @@ public abstract class HookClientPlayerTick extends AbstractClientPlayer {
|
||||
|
||||
@Inject(method = "aiStep()V", at = @At("HEAD"))
|
||||
private void atHead(final CallbackInfo info) {
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
final LocalPlayer player = (LocalPlayer)(Object)this;
|
||||
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))
|
||||
private void afterInputTick(final CallbackInfo info) {
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
final LocalPlayer player = (LocalPlayer)(Object)this;
|
||||
PlayerTicker.get(player).afterInputTick(player);
|
||||
}
|
||||
|
||||
@Inject(method = "aiStep()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/player/AbstractClientPlayer;aiStep()V", ordinal = 0, shift = AFTER))
|
||||
private void afterSuperCall(final CallbackInfo info) {
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
final LocalPlayer player = (LocalPlayer)(Object)this;
|
||||
PlayerTicker.get(player).afterSuperCall(player);
|
||||
}
|
||||
|
@ -23,11 +23,11 @@ public abstract class HookControlsListWidget extends ContainerObjectSelectionLis
|
||||
@Inject(method = "<init>", at = @At("TAIL"))
|
||||
public void init(final ControlsScreen parent, final Minecraft client, final CallbackInfo ci) {
|
||||
children().removeIf(it -> {
|
||||
if (it instanceof CategoryEntry && KeyBindingWithModifier.checkCategoryMatches(((AccessControlsListCategory)it).getText())) {
|
||||
if (it instanceof final CategoryEntry entry && KeyBindingWithModifier.checkCategoryMatches(((AccessControlsListCategory)entry).getName())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (it instanceof KeyEntry && ArrayUtils.contains(BetterControlsCommon.getConfig().getAllKeyBindings(), ((AccessControlsListKeyBinding)it).getBinding())) {
|
||||
if (it instanceof final KeyEntry entry && ArrayUtils.contains(BetterControlsCommon.getConfig().getAllKeyBindings(), ((AccessControlsListKeyBinding)entry).getKey())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -8,14 +8,12 @@ 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.CallbackInfo;
|
||||
import static chylex.bettercontrols.util.Statics.MINECRAFT;
|
||||
|
||||
@SuppressWarnings("MethodMayBeStatic")
|
||||
@Mixin(value = Minecraft.class, priority = 100)
|
||||
public abstract class HookOpenScreen {
|
||||
@Inject(method = "setScreen", at = @At("TAIL"))
|
||||
private void openScreen(final Screen ignore, final CallbackInfo ci) {
|
||||
final Screen screen = MINECRAFT.screen;
|
||||
final Screen screen = Minecraft.getInstance().screen;
|
||||
|
||||
if (screen != null && !Screen.hasAltDown()) {
|
||||
if (screen.getClass() == ControlsScreen.class) {
|
||||
|
@ -8,7 +8,7 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.Slice;
|
||||
|
||||
@SuppressWarnings("MethodMayBeStatic")
|
||||
@SuppressWarnings("SameReturnValue")
|
||||
@Mixin(Player.class)
|
||||
public abstract class HookPlayerFlightSpeed extends LivingEntity {
|
||||
protected HookPlayerFlightSpeed(final EntityType<? extends LivingEntity> type, final Level world) {
|
||||
|
@ -10,18 +10,23 @@ import chylex.bettercontrols.mixin.AccessClientPlayerFields;
|
||||
import chylex.bettercontrols.mixin.AccessPlayerFields;
|
||||
import chylex.bettercontrols.mixin.AccessStickyKeyBindingStateGetter;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.KeyMapping;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.Options;
|
||||
import net.minecraft.client.player.Input;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import static chylex.bettercontrols.util.Statics.KEY_FORWARD;
|
||||
import static chylex.bettercontrols.util.Statics.KEY_JUMP;
|
||||
import static chylex.bettercontrols.util.Statics.KEY_SNEAK;
|
||||
import static chylex.bettercontrols.util.Statics.KEY_SPRINT;
|
||||
import static chylex.bettercontrols.util.Statics.MINECRAFT;
|
||||
import static chylex.bettercontrols.util.Statics.OPTIONS;
|
||||
|
||||
public final class PlayerTicker {
|
||||
private static final Minecraft MINECRAFT = Minecraft.getInstance();
|
||||
private static final Options OPTIONS = MINECRAFT.options;
|
||||
|
||||
private static final KeyMapping KEY_SPRINT = OPTIONS.keySprint;
|
||||
private static final KeyMapping KEY_SNEAK = OPTIONS.keyShift;
|
||||
private static final KeyMapping KEY_FORWARD = OPTIONS.keyUp;
|
||||
private static final KeyMapping KEY_JUMP = OPTIONS.keyJump;
|
||||
|
||||
private static PlayerTicker ticker = new PlayerTicker(null);
|
||||
|
||||
public static PlayerTicker get(final LocalPlayer player) {
|
||||
@ -63,13 +68,13 @@ public final class PlayerTicker {
|
||||
|
||||
private void setup() {
|
||||
final AccessStickyKeyBindingStateGetter sprint = (AccessStickyKeyBindingStateGetter)KEY_SPRINT;
|
||||
BooleanSupplier getter = sprint.getToggleGetter();
|
||||
BooleanSupplier getter = sprint.getNeedsToggle();
|
||||
|
||||
if (getter instanceof SprintPressGetter) {
|
||||
getter = ((SprintPressGetter)getter).getWrapped();
|
||||
if (getter instanceof final SprintPressGetter g) {
|
||||
getter = g.wrapped();
|
||||
}
|
||||
|
||||
sprint.setToggleGetter(new SprintPressGetter(getter, () -> temporarySprintTimer > 0));
|
||||
sprint.setNeedsToggle(new SprintPressGetter(getter, () -> temporarySprintTimer > 0));
|
||||
}
|
||||
|
||||
public void atHead(final LocalPlayer player) {
|
||||
@ -78,11 +83,11 @@ public final class PlayerTicker {
|
||||
}
|
||||
|
||||
if (!cfg().doubleTapForwardToSprint) {
|
||||
((AccessClientPlayerFields)player).setTicksLeftToDoubleTapSprint(0);
|
||||
((AccessClientPlayerFields)player).setSprintTriggerTime(0);
|
||||
}
|
||||
|
||||
if (!cfg().doubleTapJumpToToggleFlight) {
|
||||
((AccessPlayerFields)player).setTicksLeftToDoubleTapFlight(0);
|
||||
((AccessPlayerFields)player).setJumpTriggerTime(0);
|
||||
}
|
||||
|
||||
final SprintMode sprintMode = cfg().sprintMode;
|
||||
@ -282,7 +287,7 @@ public final class PlayerTicker {
|
||||
final Camera camera = MINECRAFT.gameRenderer.getMainCamera();
|
||||
|
||||
if (camera.getEntity() == player) {
|
||||
((AccessCameraFields)camera).setCameraY(player.getEyeHeight());
|
||||
((AccessCameraFields)camera).setEyeHeight(player.getEyeHeight());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,19 +1,7 @@
|
||||
package chylex.bettercontrols.player;
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
final class SprintPressGetter implements BooleanSupplier {
|
||||
private final BooleanSupplier wrapped;
|
||||
private final BooleanSupplier or;
|
||||
|
||||
public SprintPressGetter(final BooleanSupplier wrapped, final BooleanSupplier or) {
|
||||
this.wrapped = wrapped;
|
||||
this.or = or;
|
||||
}
|
||||
|
||||
public BooleanSupplier getWrapped() {
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
record SprintPressGetter(BooleanSupplier wrapped, BooleanSupplier or) implements BooleanSupplier {
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
return wrapped.getAsBoolean() || or.getAsBoolean();
|
||||
|
@ -1,16 +0,0 @@
|
||||
package chylex.bettercontrols.util;
|
||||
import net.minecraft.client.KeyMapping;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.Options;
|
||||
|
||||
public final class Statics {
|
||||
private Statics() {}
|
||||
|
||||
public static final Minecraft MINECRAFT = Minecraft.getInstance();
|
||||
public static final Options OPTIONS = MINECRAFT.options;
|
||||
|
||||
public static final KeyMapping KEY_SPRINT = OPTIONS.keySprint;
|
||||
public static final KeyMapping KEY_SNEAK = OPTIONS.keyShift;
|
||||
public static final KeyMapping KEY_FORWARD = OPTIONS.keyUp;
|
||||
public static final KeyMapping KEY_JUMP = OPTIONS.keyJump;
|
||||
}
|
Loading…
Reference in New Issue
Block a user