1
0
forked from Clones/Controlify

[BROKEN] Abstract controller manager system

This commit is contained in:
isXander
2023-11-03 17:17:50 +00:00
parent 9960fedad1
commit b07066e097
39 changed files with 531 additions and 286 deletions

View File

@ -5,6 +5,9 @@ import dev.isxander.controlify.controller.ControllerType;
import dev.isxander.controlify.controller.gamepad.GamepadController;
import dev.isxander.controlify.hid.ControllerHIDService;
import dev.isxander.controlify.hid.HIDDevice;
import net.minecraft.CrashReport;
import net.minecraft.CrashReportCategory;
import net.minecraft.ReportedException;
import net.minecraft.util.Mth;
import org.joml.Vector2f;
@ -29,6 +32,19 @@ public class ControllerUtils {
);
}
public static void wrapControllerError(Runnable runnable, String errorTitle, Controller<?, ?> controller) {
try {
runnable.run();
} catch (Throwable e) {
CrashReport crashReport = CrashReport.forThrowable(e, errorTitle);
CrashReportCategory category = crashReport.addCategory("Affected controller");
category.setDetail("Controller name", controller.name());
category.setDetail("Controller identification", controller.type().toString());
category.setDetail("Controller type", controller.getClass().getCanonicalName());
throw new ReportedException(crashReport);
}
}
public static float deadzone(float value, float deadzone) {
return (value - Math.copySign(Math.min(deadzone, Math.abs(value)), value)) / (1 - deadzone);
}