shedaniel 5 жил өмнө
parent
commit
0d4ad1a22c

+ 2 - 2
build.gradle

@@ -40,8 +40,7 @@ dependencies {
     modImplementation "io.github.prospector:modmenu:${modmenu_version}"
     compileOnly "com.google.code.findbugs:jsr305:3.0.2"
     //https://github.com/natanfudge/Not-Enough-Crashes/blob/master/README.md
-    modImplementation "com.lettuce.fudge:notenoughcrashes-api:$nec_api_version"
-    include "com.lettuce.fudge:notenoughcrashes-api:$nec_api_version"
+    modCompileOnly "com.lettuce.fudge:notenoughcrashes:$nec_version"
 }
 
 bintray {
@@ -93,6 +92,7 @@ task javadocs(type: Javadoc) {
 
 task javadocsJar(type: Jar, dependsOn: javadocs) {
     classifier = "javadocs"
+    javadocs.failOnError false
     from javadocs.destinationDir
 }
 

+ 2 - 2
gradle.properties

@@ -2,6 +2,6 @@ minecraft_version=1.15
 yarn_version=1.15+build.1
 fabric_loader_version=0.7.2+build.174
 fabric_version=0.4.20+build.273-1.15
-mod_version=2.6.1
+mod_version=2.6.3
 modmenu_version=1.7.14-unstable.19w42a+build.10
-nec_api_version=1.0.0
+nec_version=1.1.5+1.15.1

+ 10 - 7
src/main/java/me/shedaniel/clothconfig2/impl/ScissorsHandlerImpl.java

@@ -1,10 +1,11 @@
 package me.shedaniel.clothconfig2.impl;
 
 import com.google.common.collect.Lists;
-import fudge.notenoughcrashes.api.MinecraftCrashes;
 import me.shedaniel.clothconfig2.ClothConfigInitializer;
 import me.shedaniel.clothconfig2.api.ScissorsHandler;
+import me.shedaniel.math.api.Executor;
 import me.shedaniel.math.api.Rectangle;
+import net.fabricmc.loader.api.FabricLoader;
 import net.minecraft.client.MinecraftClient;
 import net.minecraft.client.util.Window;
 import org.lwjgl.opengl.GL11;
@@ -17,12 +18,14 @@ public final class ScissorsHandlerImpl implements ScissorsHandler {
     @Deprecated public static final ScissorsHandler INSTANCE = new ScissorsHandlerImpl();
 
     static {
-        MinecraftCrashes.onEveryCrash(() -> {
-            try {
-                ScissorsHandler.INSTANCE.clearScissors();
-            } catch (Throwable t) {
-                ClothConfigInitializer.LOGGER.error("[ClothConfig] Failed clear scissors on game crash!", t);
-            }
+        Executor.runIf(() -> FabricLoader.getInstance().isModLoaded("notenoughcrashes"), () -> () -> {
+            fudge.notenoughcrashes.api.NotEnoughCrashesApi.onEveryCrash(() -> {
+                try {
+                    ScissorsHandler.INSTANCE.clearScissors();
+                } catch (Throwable t) {
+                    ClothConfigInitializer.LOGGER.error("[ClothConfig] Failed clear scissors on game crash!", t);
+                }
+            });
         });
     }
 

+ 56 - 0
src/main/java/me/shedaniel/math/api/Executor.java

@@ -0,0 +1,56 @@
+package me.shedaniel.math.api;
+
+import net.fabricmc.api.EnvType;
+import net.fabricmc.loader.api.FabricLoader;
+
+import java.util.Optional;
+import java.util.concurrent.Callable;
+import java.util.function.Supplier;
+
+public class Executor {
+    
+    private Executor() {}
+    
+    public static void run(Supplier<Runnable> runnableSupplier) {
+        runnableSupplier.get().run();
+    }
+    
+    public static void runIf(Supplier<Boolean> predicate, Supplier<Runnable> runnableSupplier) {
+        if (predicate.get())
+            runnableSupplier.get().run();
+    }
+    
+    public static void runIfEnv(EnvType env, Supplier<Runnable> runnableSupplier) {
+        if (FabricLoader.getInstance().getEnvironmentType() == env)
+            runnableSupplier.get().run();
+    }
+    
+    public static <T> T call(Supplier<Callable<T>> runnableSupplier) {
+        try {
+            return runnableSupplier.get().call();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+    
+    public static <T> Optional<T> callIf(Supplier<Boolean> predicate, Supplier<Callable<T>> runnableSupplier) {
+        if (predicate.get())
+            try {
+                return Optional.of(runnableSupplier.get().call());
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        return Optional.empty();
+    }
+    
+    public static <T> Optional<T> callIfEnv(EnvType env, Supplier<Callable<T>> runnableSupplier) {
+        if (FabricLoader.getInstance().getEnvironmentType() == env)
+            try {
+                return Optional.of(runnableSupplier.get().call());
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        return Optional.empty();
+    }
+    
+}