forked from Clones/Controlify
fix many crashes
This commit is contained in:
@ -17,7 +17,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "dev.isxander"
|
||||
version = "1.1.0-beta.3+1.19.4"
|
||||
version = "1.1.0-beta.4+1.19.4"
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
@ -176,6 +176,10 @@ tasks {
|
||||
dependsOn("publish")
|
||||
dependsOn("githubRelease")
|
||||
}
|
||||
|
||||
named("modrinth") {
|
||||
dependsOn("optimizeOutputsOfRemapJar")
|
||||
}
|
||||
}
|
||||
|
||||
val changelogText = file("changelogs/${project.version}.md").takeIf { it.exists() }?.readText() ?: "No changelog provided."
|
||||
@ -241,11 +245,10 @@ publishing {
|
||||
publications {
|
||||
create<MavenPublication>("mod") {
|
||||
groupId = "dev.isxander"
|
||||
artifactId = base.archivesName.get()
|
||||
artifactId = "controlify"
|
||||
|
||||
from(components["java"])
|
||||
artifact(tasks["remapJar"])
|
||||
artifact(tasks["remapSourcesJar"])
|
||||
artifact(tasks["javadocJar"])
|
||||
}
|
||||
}
|
||||
|
||||
|
1
changelogs/1.1.0-beta.4+1.19.4.md
Normal file
1
changelogs/1.1.0-beta.4+1.19.4.md
Normal file
@ -0,0 +1 @@
|
||||
- Fix many crashes
|
@ -35,10 +35,12 @@ import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Queue;
|
||||
|
||||
@ -62,7 +64,7 @@ public class Controlify implements ControlifyApi {
|
||||
private int consecutiveInputSwitches = 0;
|
||||
private double lastInputSwitchTime = 0;
|
||||
|
||||
private Controller<?, ?> switchableController = null;
|
||||
private @Nullable Controller<?, ?> switchableController = null;
|
||||
private double askSwitchTime = 0;
|
||||
private ToastUtils.ControlifyToast askSwitchToast = null;
|
||||
|
||||
@ -98,7 +100,7 @@ public class Controlify implements ControlifyApi {
|
||||
|
||||
config().loadOrCreateControllerData(controller);
|
||||
|
||||
if (config().currentControllerUid().equals(controller.uid()))
|
||||
if (controller.uid().equals(config().currentControllerUid()))
|
||||
setCurrentController(controller);
|
||||
|
||||
if (controller.config().allowVibrations && !config().globalSettings().loadVibrationNatives) {
|
||||
@ -199,13 +201,12 @@ public class Controlify implements ControlifyApi {
|
||||
|
||||
if (switchableController != null && Blaze3D.getTime() - askSwitchTime <= 10000) {
|
||||
if (switchableController.state().hasAnyInput()) {
|
||||
this.setCurrentController(switchableController);
|
||||
switchableController.clearState();
|
||||
this.setCurrentController(switchableController); // setCurrentController sets switchableController to null
|
||||
if (askSwitchToast != null) {
|
||||
askSwitchToast.remove();
|
||||
askSwitchToast = null;
|
||||
}
|
||||
switchableController.clearState();
|
||||
switchableController = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -355,7 +356,7 @@ public class Controlify implements ControlifyApi {
|
||||
return Optional.ofNullable(currentController);
|
||||
}
|
||||
|
||||
public void setCurrentController(Controller<?, ?> controller) {
|
||||
public void setCurrentController(@Nullable Controller<?, ?> controller) {
|
||||
if (this.currentController == controller) return;
|
||||
|
||||
this.currentController = controller;
|
||||
@ -375,7 +376,7 @@ public class Controlify implements ControlifyApi {
|
||||
|
||||
DebugLog.log("Updated current controller to {}({})", controller.name(), controller.uid());
|
||||
|
||||
if (!config().currentControllerUid().equals(controller.uid())) {
|
||||
if (!controller.uid().equals(config().currentControllerUid())) {
|
||||
config().save();
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import dev.isxander.controlify.controller.Controller;
|
||||
import dev.isxander.controlify.controller.joystick.CompoundJoystickInfo;
|
||||
import dev.isxander.controlify.utils.DebugLog;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
@ -125,7 +126,8 @@ public class ControlifyConfig {
|
||||
.collect(Collectors.toMap(info -> info.type().mappingId(), Function.identity()));
|
||||
|
||||
if (object.has("current_controller")) {
|
||||
currentControllerUid = object.get("current_controller").getAsString();
|
||||
JsonElement element = object.get("current_controller");
|
||||
currentControllerUid = element.isJsonNull() ? null : element.getAsString();
|
||||
} else {
|
||||
currentControllerUid = controlify.getCurrentController().map(Controller::uid).orElse(null);
|
||||
setDirty();
|
||||
@ -177,6 +179,7 @@ public class ControlifyConfig {
|
||||
return firstLaunch;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String currentControllerUid() {
|
||||
return currentControllerUid;
|
||||
}
|
||||
|
@ -40,6 +40,10 @@ public class ControllerHIDService {
|
||||
}
|
||||
|
||||
public ControllerHIDInfo fetchType() {
|
||||
if (disabled) {
|
||||
return new ControllerHIDInfo(ControllerType.UNKNOWN, Optional.empty());
|
||||
}
|
||||
|
||||
doScanOnThisThread();
|
||||
|
||||
Pair<HidDevice, HIDIdentifier> hid = unconsumedControllerHIDs.poll();
|
||||
|
Reference in New Issue
Block a user