1
0
forked from Clones/Controlify

pre1 and less sodium stuff cuz i got a pr merged

This commit is contained in:
isXander
2023-02-22 20:19:48 +00:00
parent a40cd9a2e2
commit f17685535a
19 changed files with 51 additions and 259 deletions

View File

@ -45,7 +45,13 @@ dependencies {
})
modImplementation(libs.fabric.loader)
modImplementation(libs.fabric.api)
listOf(
"fabric-resource-loader-v0",
"fabric-lifecycle-events-v1",
).forEach {
modImplementation(fabricApi.module(it, libs.versions.fabric.api.get()))
}
modImplementation(libs.yet.another.config.lib)
modImplementation(libs.mod.menu)

View File

@ -7,16 +7,16 @@ github_release = "2.+"
machete = "1.+"
grgit = "5.0.+"
minecraft = "23w07a"
minecraft = "1.19.4-pre1"
quilt_mappings = "1"
fabric_loader = "0.14.14"
fabric_loader = "0.14.15"
fabric_api = "0.74.1+1.19.4"
mixin_extras = "0.2.0-beta.1"
yet_another_config_lib = "2.3.0+beta.2+update.1.19.4-SNAPSHOT"
mod_menu = "6.1.0-alpha.1"
hid4java = "0.7.0"
quilt_json5 = "1.0.3"
sodium = "0.4.10+build.209"
sodium = "0.4.10+build.211"
[libraries]
minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" }

View File

@ -1,23 +0,0 @@
package dev.isxander.controlify.compatibility.sodium;
import dev.isxander.controlify.controller.Controller;
import dev.isxander.controlify.screenop.ComponentProcessor;
import dev.isxander.controlify.screenop.ScreenProcessor;
public class ButtonProcessor implements ComponentProcessor {
private final Runnable action;
public ButtonProcessor(Runnable action) {
this.action = action != null ? action : () -> {};
}
@Override
public boolean overrideControllerButtons(ScreenProcessor<?> screen, Controller<?, ?> controller) {
if (controller.bindings().GUI_PRESS.justPressed()) {
action.run();
return true;
}
return false;
}
}

View File

@ -14,7 +14,7 @@ import java.util.Objects;
import java.util.UUID;
public abstract class AbstractController<S extends ControllerState, C extends ControllerConfig> implements Controller<S, C> {
private final int joystickId;
protected final int joystickId;
protected String name;
private final String uid;
private final String guid;
@ -47,11 +47,6 @@ public abstract class AbstractController<S extends ControllerState, C extends Co
this.bindings = new ControllerBindings<>(this);
}
@Override
public int joystickId() {
return this.joystickId;
}
public String name() {
if (config().customName != null)
return config().customName;

View File

@ -15,7 +15,6 @@ import java.util.Map;
public interface Controller<S extends ControllerState, C extends ControllerConfig> {
String uid();
int joystickId();
String guid();
ControllerBindings<S> bindings();
@ -75,11 +74,6 @@ public interface Controller<S extends ControllerState, C extends ControllerConfi
return "NONE";
}
@Override
public int joystickId() {
return -1;
}
@Override
public String guid() {
return "DUMMY";

View File

@ -10,28 +10,12 @@ import org.quiltmc.json5.JsonReader;
import java.io.IOException;
import java.util.*;
public class ControllerType {
public record ControllerType(String friendlyName, String identifier) {
public static final ControllerType UNKNOWN = new ControllerType("Unknown", "unknown");
private static Map<HIDIdentifier, ControllerType> typeMap = null;
private static final ResourceLocation hidDbLocation = new ResourceLocation("controlify", "controllers/controller_identification.json5");
private final String friendlyName;
private final String identifier;
private ControllerType(String friendlyName, String identifier) {
this.friendlyName = friendlyName;
this.identifier = identifier;
}
public String friendlyName() {
return friendlyName;
}
public String identifier() {
return identifier;
}
public static ControllerType getTypeForHID(HIDIdentifier hid) {
if (typeMap != null) return typeMap.getOrDefault(hid, UNKNOWN);

View File

@ -49,7 +49,7 @@ public class GamepadController extends AbstractController<GamepadState, GamepadC
GLFWGamepadState getGamepadState() {
GLFWGamepadState state = GLFWGamepadState.create();
GLFW.glfwGetGamepadState(joystickId(), state);
GLFW.glfwGetGamepadState(joystickId, state);
return state;
}

View File

@ -43,7 +43,7 @@ public class JoystickController extends AbstractController<JoystickState, Joysti
@Override
public void updateState() {
prevState = state;
state = JoystickState.fromJoystick(this);
state = JoystickState.fromJoystick(this, joystickId);
}
public JoystickMapping mapping() {

View File

@ -24,7 +24,7 @@ public class JoystickState implements ControllerState {
private final List<Boolean> buttons;
private final List<HatState> hats;
private JoystickState(JoystickMapping mapping, List<Float> axes, List<Float> rawAxes, List<Boolean> buttons, List<HatState> hats) {
protected JoystickState(JoystickMapping mapping, List<Float> axes, List<Float> rawAxes, List<Boolean> buttons, List<HatState> hats) {
this.mapping = mapping;
this.axes = axes;
this.rawAxes = rawAxes;
@ -58,8 +58,8 @@ public class JoystickState implements ControllerState {
|| hats().stream().anyMatch(hat -> hat != HatState.CENTERED);
}
public static JoystickState fromJoystick(JoystickController joystick) {
FloatBuffer axesBuffer = GLFW.glfwGetJoystickAxes(joystick.joystickId());
public static JoystickState fromJoystick(JoystickController joystick, int joystickId) {
FloatBuffer axesBuffer = GLFW.glfwGetJoystickAxes(joystickId);
List<Float> axes = new ArrayList<>();
List<Float> rawAxes = new ArrayList<>();
if (axesBuffer != null) {
@ -76,7 +76,7 @@ public class JoystickState implements ControllerState {
}
}
ByteBuffer buttonBuffer = GLFW.glfwGetJoystickButtons(joystick.joystickId());
ByteBuffer buttonBuffer = GLFW.glfwGetJoystickButtons(joystickId);
List<Boolean> buttons = new ArrayList<>();
if (buttonBuffer != null) {
while (buttonBuffer.hasRemaining()) {
@ -84,7 +84,7 @@ public class JoystickState implements ControllerState {
}
}
ByteBuffer hatBuffer = GLFW.glfwGetJoystickHats(joystick.joystickId());
ByteBuffer hatBuffer = GLFW.glfwGetJoystickHats(joystickId);
List<JoystickState.HatState> hats = new ArrayList<>();
if (hatBuffer != null) {
while (hatBuffer.hasRemaining()) {

View File

@ -1,24 +0,0 @@
package dev.isxander.controlify.mixins.compat.sodium;
import me.jellysquid.mods.sodium.client.gui.widgets.AbstractWidget;
import net.minecraft.client.gui.ComponentPath;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.navigation.FocusNavigationEvent;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(AbstractWidget.class)
public abstract class AbstractWidgetMixin implements GuiEventListener {
@Shadow protected abstract void drawRect(double x1, double y1, double x2, double y2, int color);
@Shadow protected abstract void playClickSound();
@Shadow public abstract boolean isFocused();
@Nullable
@Override
public ComponentPath nextFocusPath(FocusNavigationEvent focusNavigationEvent) {
return !this.isFocused() ? ComponentPath.leaf(this) : null;
}
}

View File

@ -1,58 +0,0 @@
package dev.isxander.controlify.mixins.compat.sodium;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.mojang.blaze3d.vertex.PoseStack;
import me.jellysquid.mods.sodium.client.gui.options.Option;
import me.jellysquid.mods.sodium.client.gui.options.control.ControlElement;
import me.jellysquid.mods.sodium.client.util.Dim2i;
import net.minecraft.client.gui.ComponentPath;
import net.minecraft.client.gui.navigation.FocusNavigationEvent;
import net.minecraft.client.gui.navigation.ScreenRectangle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ControlElement.class)
public abstract class ControlElementMixin<T> extends AbstractWidgetMixin {
@Shadow @Final protected Option<T> option;
@Shadow @Final protected Dim2i dim;
@Inject(method = "render", at = @At("TAIL"))
private void renderFocusRect(PoseStack matrixStack, int mouseX, int mouseY, float delta, CallbackInfo ci) {
if (this.isFocused()) {
int x1 = this.dim.x();
int y1 = this.dim.y();
int x2 = this.dim.getLimitX();
int y2 = this.dim.getLimitY();
this.drawRect(x1, y1, x2, y1 + 1, -1);
this.drawRect(x1, y2 - 1, x2, y2, -1);
this.drawRect(x1, y1, x1 + 1, y2, -1);
this.drawRect(x2 - 1, y1, x2, y2, -1);;
}
}
@ModifyExpressionValue(method = "render", at = @At(value = "FIELD", target = "Lme/jellysquid/mods/sodium/client/gui/options/control/ControlElement;hovered:Z", opcode = Opcodes.GETFIELD, ordinal = 0))
private boolean shouldShortenName(boolean hovered) {
return hovered || this.isFocused();
}
@Override
public @Nullable ComponentPath nextFocusPath(FocusNavigationEvent focusNavigationEvent) {
if (!this.option.isAvailable())
return null;
return super.nextFocusPath(focusNavigationEvent);
}
@Override
public @NotNull ScreenRectangle getRectangle() {
return new ScreenRectangle(this.dim.x(), this.dim.y(), this.dim.width(), this.dim.height());
}
}

View File

@ -6,26 +6,15 @@ import dev.isxander.controlify.screenop.ComponentProcessorProvider;
import org.spongepowered.asm.mixin.*;
@Pseudo
@Mixin(targets = "me.jellysquid.mods.sodium.client.gui.options.control.CyclingControl$CyclingControlElement")
public abstract class CycleControlElementMixin<T extends Enum<T>> extends ControlElementMixin<T> implements ComponentProcessorProvider {
@Shadow private int currentIndex;
@Final @Shadow private T[] allowedValues;
@Mixin(targets = "me.jellysquid.mods.sodium.client.gui.options.control.CyclingControl$CyclingControlElement", remap = false)
public abstract class CycleControlElementMixin implements ComponentProcessorProvider {
@Shadow public abstract void cycleControl(boolean reverse);
@Unique private final ComponentProcessor controlify$componentProcessor
= new CycleControlProcessor(this::cycle);
= new CycleControlProcessor(this::cycleControl);
@Override
public ComponentProcessor componentProcessor() {
return controlify$componentProcessor;
}
private void cycle(boolean backwards) {
if (backwards) {
this.currentIndex = (this.currentIndex - 1 + this.allowedValues.length) % this.allowedValues.length;
} else {
this.currentIndex = (this.option.getValue().ordinal() + 1) % this.allowedValues.length;
}
this.option.setValue(this.allowedValues[this.currentIndex]);
this.playClickSound();
}
}

View File

@ -1,63 +0,0 @@
package dev.isxander.controlify.mixins.compat.sodium;
import com.mojang.blaze3d.vertex.PoseStack;
import dev.isxander.controlify.compatibility.sodium.ButtonProcessor;
import dev.isxander.controlify.screenop.ComponentProcessor;
import dev.isxander.controlify.screenop.ComponentProcessorProvider;
import me.jellysquid.mods.sodium.client.gui.widgets.FlatButtonWidget;
import me.jellysquid.mods.sodium.client.util.Dim2i;
import net.minecraft.client.gui.ComponentPath;
import net.minecraft.client.gui.navigation.FocusNavigationEvent;
import net.minecraft.client.gui.navigation.ScreenRectangle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(FlatButtonWidget.class)
public abstract class FlatButtonWidgetMixin extends AbstractWidgetMixin implements ComponentProcessorProvider {
@Shadow @Final private Dim2i dim;
@Shadow private boolean visible;
@Shadow private boolean enabled;
@Shadow @Final private Runnable action;
@Unique private final ComponentProcessor controlify$componentProcessor
= new ButtonProcessor(() -> action.run());
@Inject(method = "render", at = @At("TAIL"))
private void renderFocusRect(PoseStack matrixStack, int mouseX, int mouseY, float delta, CallbackInfo ci) {
if (this.enabled && this.isFocused()) {
int x1 = this.dim.x();
int y1 = this.dim.y();
int x2 = this.dim.getLimitX();
int y2 = this.dim.getLimitY();
this.drawRect(x1, y1, x2, y1 + 1, -1);
this.drawRect(x1, y2 - 1, x2, y2, -1);
this.drawRect(x1, y1, x1 + 1, y2, -1);
this.drawRect(x2 - 1, y1, x2, y2, -1);;
}
}
@Override
public @Nullable ComponentPath nextFocusPath(FocusNavigationEvent focusNavigationEvent) {
if (!visible || !enabled)
return null;
return super.nextFocusPath(focusNavigationEvent);
}
@Override
public @NotNull ScreenRectangle getRectangle() {
return new ScreenRectangle(this.dim.x(), this.dim.y(), this.dim.width(), this.dim.height());
}
@Override
public ComponentProcessor componentProcessor() {
return controlify$componentProcessor;
}
}

View File

@ -4,26 +4,26 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import dev.isxander.controlify.compatibility.sodium.SliderControlProcessor;
import dev.isxander.controlify.screenop.ComponentProcessor;
import dev.isxander.controlify.screenop.ComponentProcessorProvider;
import me.jellysquid.mods.sodium.client.gui.options.Option;
import me.jellysquid.mods.sodium.client.gui.options.control.ControlElement;
import me.jellysquid.mods.sodium.client.util.Dim2i;
import net.minecraft.util.Mth;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;
@Mixin(targets = "me.jellysquid.mods.sodium.client.gui.options.control.SliderControl$Button")
public abstract class SliderControlElementMixin extends ControlElementMixin<Integer> implements ComponentProcessorProvider {
@Shadow public abstract int getIntValue();
@Pseudo
@Mixin(targets = "me.jellysquid.mods.sodium.client.gui.options.control.SliderControl$Button", remap = false)
public abstract class SliderControlElementMixin extends ControlElement<Integer> implements ComponentProcessorProvider {
@Shadow @Final private int interval;
@Shadow protected abstract void setValue(double d);
@Shadow public abstract double getThumbPositionForValue(int value);
@Shadow @Final private int min;
@Shadow @Final private int max;
@Unique private final ComponentProcessor controlify$componentProcessor
= new SliderControlProcessor(this::incrementSlider);
@ModifyExpressionValue(method = "render", at = @At(value = "FIELD", target = "Lme/jellysquid/mods/sodium/client/gui/options/control/SliderControl$Button;hovered:Z", opcode = Opcodes.GETFIELD))
private boolean shouldRenderSlider(boolean hovered) {
return hovered || this.isFocused();
public SliderControlElementMixin(Option<Integer> option, Dim2i dim) {
super(option, dim);
}
@Override
@ -32,7 +32,6 @@ public abstract class SliderControlElementMixin extends ControlElementMixin<Inte
}
private void incrementSlider(boolean reverse) {
int inc = reverse ? -1 : 1;
this.setValue(this.getThumbPositionForValue(this.getIntValue() + inc * this.interval));
this.option.setValue(Mth.clamp(this.option.getValue() + (reverse ? -this.interval : this.interval), this.min, this.max));
}
}

View File

@ -3,11 +3,13 @@ package dev.isxander.controlify.mixins.compat.sodium;
import me.jellysquid.mods.sodium.client.gui.SodiumOptionsGUI;
import me.jellysquid.mods.sodium.client.gui.options.OptionPage;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.gen.Accessor;
import java.util.List;
@Mixin(SodiumOptionsGUI.class)
@Pseudo
@Mixin(value = SodiumOptionsGUI.class, remap = false)
public interface SodiumOptionsGUIAccessor {
@Accessor
List<OptionPage> getPages();

View File

@ -7,16 +7,14 @@ import me.jellysquid.mods.sodium.client.gui.SodiumOptionsGUI;
import me.jellysquid.mods.sodium.client.gui.options.control.ControlElement;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.List;
@Pseudo
@Mixin(value = SodiumOptionsGUI.class, remap = false)
public abstract class SodiumOptionsGUIMixin extends Screen implements ScreenProcessorProvider {
@Shadow @Final private List<ControlElement<?>> controls;

View File

@ -5,21 +5,19 @@ import dev.isxander.controlify.screenop.ComponentProcessor;
import dev.isxander.controlify.screenop.ComponentProcessorProvider;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
@Pseudo
@Mixin(targets = "me.jellysquid.mods.sodium.client.gui.options.control.TickBoxControl$TickBoxControlElement")
public abstract class TickBoxControlElementMixin extends ControlElementMixin<Boolean> implements ComponentProcessorProvider {
@Mixin(targets = "me.jellysquid.mods.sodium.client.gui.options.control.TickBoxControl$TickBoxControlElement", remap = false)
public abstract class TickBoxControlElementMixin implements ComponentProcessorProvider {
@Shadow public abstract void toggleControl();
@Unique private final ComponentProcessor controlify$componentProcessor
= new TickBoxControlProcessor(this::toggle);
= new TickBoxControlProcessor(this::toggleControl);
@Override
public ComponentProcessor componentProcessor() {
return controlify$componentProcessor;
}
private void toggle() {
this.option.setValue(!this.option.getValue());
this.playClickSound();
}
}

View File

@ -30,12 +30,10 @@
"controlify.gui.group.advanced.tooltip": "Settings you probably shouldn't touch!.",
"controlify.gui.screen_repeat_navi_delay": "Screen Repeat Navigation Delay",
"controlify.gui.screen_repeat_navi_delay.tooltip": "How fast a screen navigation action repeats.",
"controlify.gui.left_stick_deadzone": "Left Stick Deadzone",
"controlify.gui.left_stick_deadzone.tooltip": "How far the left joystick needs to be pushed before registering input.",
"controlify.gui.right_stick_deadzone": "Right Stick Deadzone",
"controlify.gui.right_stick_deadzone.tooltip": "How far the right joystick needs to be pushed before registering input.",
"controlify.gui.joystick_axis_deadzone": "%s Deadzone",
"controlify.gui.joystick_axis_deadzone.tooltip": "How far '%s' axis needs to be pushed before registering input.",
"controlify.gui.left_stick": "Left Stick",
"controlify.gui.right_stick": "Right Stick",
"controlify.gui.axis_deadzone": "%s Deadzone",
"controlify.gui.axis_deadzone.tooltip": "How far '%s' axis needs to be pushed before registering input.",
"controlify.gui.stickdrift_warning": "Warning: Setting this too low will cause stickdrift! This is where the internals of your controller become mis-calibrated and register small amounts of input when there shouldn't be.",
"controlify.gui.auto_calibration": "Automatic Deadzone Calibration",
"controlify.gui.auto_calibration.tooltip": "Automatically calibrate the deadzone of your controller.",

View File

@ -4,15 +4,12 @@
"minVersion": "0.8",
"compatibilityLevel": "JAVA_17",
"mixins": [
"compat.sodium.ControlElementMixin",
"compat.sodium.CycleControlElementMixin",
"compat.sodium.FlatButtonWidgetMixin",
"compat.sodium.SliderControlElementMixin",
"compat.sodium.TickBoxControlElementMixin",
"core.GLXMixin"
],
"client": [
"compat.sodium.AbstractWidgetMixin",
"compat.sodium.SodiumOptionsGUIAccessor",
"compat.sodium.SodiumOptionsGUIMixin",
"core.ClientPacketListenerMixin",