aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2021-05-17 21:41:03 +0800
committershedaniel <daniel@shedaniel.me>2021-05-17 21:41:03 +0800
commit745f78a4aa7d23fe03e7420eb3fe06b8c418db35 (patch)
tree1d4960dbb5b575975602f23b557f7d3246f21e96
parent1e8f7022d4a82a6210c9d4080f3bc49d8129d20a (diff)
downloadRoughlyEnoughItems-745f78a4aa7d23fe03e7420eb3fe06b8c418db35.tar.gz
RoughlyEnoughItems-745f78a4aa7d23fe03e7420eb3fe06b8c418db35.tar.bz2
RoughlyEnoughItems-745f78a4aa7d23fe03e7420eb3fe06b8c418db35.zip
Implement ErrorDisplayer on Fabric properly
-rw-r--r--api/build.gradle2
-rw-r--r--default-plugin/build.gradle2
-rw-r--r--fabric/src/main/java/me/shedaniel/rei/fabric/RoughlyEnoughItemsInitializerImpl.java7
-rw-r--r--fabric/src/main/java/me/shedaniel/rei/impl/client/fabric/ErrorDisplayerImpl.java38
-rw-r--r--fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinScreen.java44
-rw-r--r--fabric/src/main/resources/fabric.mod.json3
-rw-r--r--fabric/src/main/resources/rei.mixins.json14
-rw-r--r--forge/src/main/java/me/shedaniel/rei/forge/RoughlyEnoughItemsInitializerImpl.java12
-rw-r--r--forge/src/main/java/me/shedaniel/rei/impl/client/forge/ErrorDisplayerImpl.java33
-rw-r--r--forge/src/main/resources/META-INF/mods.toml7
-rw-r--r--runtime/build.gradle2
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java8
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java9
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/ErrorDisplayer.java12
14 files changed, 180 insertions, 13 deletions
diff --git a/api/build.gradle b/api/build.gradle
index 44fe15010..40ea8f83d 100644
--- a/api/build.gradle
+++ b/api/build.gradle
@@ -1,3 +1,5 @@
+archivesBaseName = rootProject.name + "-" + project.name
+
dependencies {
modCompileOnly("net.fabricmc:fabric-loader:${project.fabricloader_version}")
modCompileOnly("me.shedaniel.cloth:cloth-config:${cloth_config_version}")
diff --git a/default-plugin/build.gradle b/default-plugin/build.gradle
index 88bf7f1f4..1f0d45a41 100644
--- a/default-plugin/build.gradle
+++ b/default-plugin/build.gradle
@@ -1,3 +1,5 @@
+archivesBaseName = rootProject.name + "-" + project.name
+
loom {
accessWidener = gradle.rootProject.project("fabric").file("src/main/resources/roughlyenoughitems.accessWidener")
}
diff --git a/fabric/src/main/java/me/shedaniel/rei/fabric/RoughlyEnoughItemsInitializerImpl.java b/fabric/src/main/java/me/shedaniel/rei/fabric/RoughlyEnoughItemsInitializerImpl.java
index d7200f47c..47f671dc0 100644
--- a/fabric/src/main/java/me/shedaniel/rei/fabric/RoughlyEnoughItemsInitializerImpl.java
+++ b/fabric/src/main/java/me/shedaniel/rei/fabric/RoughlyEnoughItemsInitializerImpl.java
@@ -57,6 +57,9 @@ public class RoughlyEnoughItemsInitializerImpl {
break;
}
}
+ if (!FabricLoader.getInstance().isModLoaded("architectury")) {
+ RoughlyEnoughItemsState.error("Architectury API is not installed!", "https://www.curseforge.com/minecraft/mc-mods/architectury-fabric/files/all");
+ }
if (isClient()) {
try {
if (!FabricLoader.getInstance().isModLoaded("cloth-config2")) {
@@ -69,4 +72,8 @@ public class RoughlyEnoughItemsInitializerImpl {
}
}
}
+
+ public static boolean isDev() {
+ return FabricLoader.getInstance().isDevelopmentEnvironment();
+ }
}
diff --git a/fabric/src/main/java/me/shedaniel/rei/impl/client/fabric/ErrorDisplayerImpl.java b/fabric/src/main/java/me/shedaniel/rei/impl/client/fabric/ErrorDisplayerImpl.java
new file mode 100644
index 000000000..ae6a0f9f3
--- /dev/null
+++ b/fabric/src/main/java/me/shedaniel/rei/impl/client/fabric/ErrorDisplayerImpl.java
@@ -0,0 +1,38 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021 shedaniel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package me.shedaniel.rei.impl.client.fabric;
+
+import net.minecraft.client.gui.screens.Screen;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.function.Consumer;
+
+public class ErrorDisplayerImpl {
+ public static List<Consumer<Screen>> consumerList = new ArrayList<>();
+
+ public static void registerGuiInit(Consumer<Screen> consumer) {
+ consumerList.add(consumer);
+ }
+}
diff --git a/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinScreen.java b/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinScreen.java
new file mode 100644
index 000000000..a14577a7f
--- /dev/null
+++ b/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinScreen.java
@@ -0,0 +1,44 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021 shedaniel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package me.shedaniel.rei.mixin.fabric;
+
+import me.shedaniel.rei.impl.client.fabric.ErrorDisplayerImpl;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.screens.Screen;
+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 java.util.function.Consumer;
+
+@Mixin(Screen.class)
+public class MixinScreen {
+ @Inject(method = "init(Lnet/minecraft/client/Minecraft;II)V", at = @At("HEAD"))
+ private void init(Minecraft minecraft, int i, int j, CallbackInfo ci) {
+ for (Consumer<Screen> consumer : ErrorDisplayerImpl.consumerList) {
+ consumer.accept((Screen) (Object) this);
+ }
+ }
+}
diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json
index bf7bf3d6b..3f1c179a0 100644
--- a/fabric/src/main/resources/fabric.mod.json
+++ b/fabric/src/main/resources/fabric.mod.json
@@ -29,6 +29,9 @@
]
},
"accessWidener": "roughlyenoughitems.accessWidener",
+ "mixins": [
+ "rei.mixins.json"
+ ],
"custom": {
"rei:translators": {
"English": ["shedaniel"],
diff --git a/fabric/src/main/resources/rei.mixins.json b/fabric/src/main/resources/rei.mixins.json
new file mode 100644
index 000000000..b7d1e7c81
--- /dev/null
+++ b/fabric/src/main/resources/rei.mixins.json
@@ -0,0 +1,14 @@
+{
+ "required": true,
+ "package": "me.shedaniel.rei.mixin.fabric",
+ "compatibilityLevel": "JAVA_8",
+ "client": [
+ "MixinScreen"
+ ],
+ "mixins": [
+ ],
+ "injectors": {
+ "maxShiftBy": 5,
+ "defaultRequire": 1
+ }
+}
diff --git a/forge/src/main/java/me/shedaniel/rei/forge/RoughlyEnoughItemsInitializerImpl.java b/forge/src/main/java/me/shedaniel/rei/forge/RoughlyEnoughItemsInitializerImpl.java
index fa282697a..6baa7fd5c 100644
--- a/forge/src/main/java/me/shedaniel/rei/forge/RoughlyEnoughItemsInitializerImpl.java
+++ b/forge/src/main/java/me/shedaniel/rei/forge/RoughlyEnoughItemsInitializerImpl.java
@@ -23,10 +23,9 @@
package me.shedaniel.rei.forge;
-import me.shedaniel.rei.RoughlyEnoughItemsState;
import net.minecraftforge.api.distmarker.Dist;
-import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.loading.FMLEnvironment;
+import net.minecraftforge.fml.loading.FMLLoader;
public class RoughlyEnoughItemsInitializerImpl {
public static boolean isClient() {
@@ -34,10 +33,9 @@ public class RoughlyEnoughItemsInitializerImpl {
}
public static void checkMods() {
- if (isClient()) {
- if (!ModList.get().isLoaded("cloth-config")) {
- RoughlyEnoughItemsState.error("Cloth Config is not installed!", "https://www.curseforge.com/minecraft/mc-mods/cloth-config/files/all");
- }
- }
+ }
+
+ public static boolean isDev() {
+ return !FMLLoader.isProduction();
}
}
diff --git a/forge/src/main/java/me/shedaniel/rei/impl/client/forge/ErrorDisplayerImpl.java b/forge/src/main/java/me/shedaniel/rei/impl/client/forge/ErrorDisplayerImpl.java
new file mode 100644
index 000000000..5186c7884
--- /dev/null
+++ b/forge/src/main/java/me/shedaniel/rei/impl/client/forge/ErrorDisplayerImpl.java
@@ -0,0 +1,33 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021 shedaniel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package me.shedaniel.rei.impl.client.forge;
+
+import net.minecraft.client.gui.screens.Screen;
+
+import java.util.function.Consumer;
+
+public class ErrorDisplayerImpl {
+ public static void registerGuiInit(Consumer<Screen> consumer) {
+ }
+}
diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml
index 30ac8e0af..6aebf09b4 100644
--- a/forge/src/main/resources/META-INF/mods.toml
+++ b/forge/src/main/resources/META-INF/mods.toml
@@ -27,3 +27,10 @@ mandatory = true
versionRange = "[1.10.139,)"
ordering = "NONE"
side = "BOTH"
+
+[[dependencies.roughlyenoughitems]]
+modId = "cloth-config"
+mandatory = true
+versionRange = "[4.11.18,)"
+ordering = "NONE"
+side = "BOTH"
diff --git a/runtime/build.gradle b/runtime/build.gradle
index 3048fb3b7..4d7034ed3 100644
--- a/runtime/build.gradle
+++ b/runtime/build.gradle
@@ -1,3 +1,5 @@
+archivesBaseName = rootProject.name + "-" + project.name
+
architectury {
common(forgeEnabled.toBoolean())
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java
index 8ba328334..78f118501 100644
--- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java
+++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java
@@ -24,12 +24,15 @@
package me.shedaniel.rei;
import me.shedaniel.architectury.annotations.ExpectPlatform;
+import net.fabricmc.api.EnvType;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class RoughlyEnoughItemsInitializer {
public static void onInitialize() {
+ RoughlyEnoughItemsState.env = isClient() ? EnvType.CLIENT : EnvType.SERVER;
+ RoughlyEnoughItemsState.isDev = isDev();
checkMods();
if (RoughlyEnoughItemsState.getErrors().isEmpty()) {
@@ -83,6 +86,11 @@ public class RoughlyEnoughItemsInitializer {
}
@ExpectPlatform
+ public static boolean isDev() {
+ throw new AssertionError();
+ }
+
+ @ExpectPlatform
public static void checkMods() {
throw new AssertionError();
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java
index 468ac0988..7ca37778f 100644
--- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java
+++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java
@@ -23,8 +23,7 @@
package me.shedaniel.rei;
-import me.shedaniel.architectury.platform.Platform;
-import me.shedaniel.architectury.utils.Env;
+import net.fabricmc.api.EnvType;
import net.minecraft.util.Tuple;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -41,6 +40,8 @@ public class RoughlyEnoughItemsState {
public static final Logger LOGGER = LogManager.getFormatterLogger("REI");
+ public static EnvType env;
+ public static boolean isDev;
private static List<Tuple<String, String>> errors = new ArrayList<>();
private static List<Tuple<String, String>> warnings = new ArrayList<>();
private static Set<String> errorSet = new LinkedHashSet<>();
@@ -48,7 +49,7 @@ public class RoughlyEnoughItemsState {
private static List<Runnable> continueCallbacks = new ArrayList<>();
public static void error(String reason) {
- if (Platform.getEnvironment() == Env.SERVER || Platform.isDevelopmentEnvironment())
+ if (env == EnvType.SERVER || isDev)
throw new RuntimeException(reason);
if (RoughlyEnoughItemsState.errorSet.add(reason + " " + null)) {
RoughlyEnoughItemsState.errors.add(new Tuple<>(reason, null));
@@ -57,7 +58,7 @@ public class RoughlyEnoughItemsState {
}
public static void error(String reason, String link) {
- if (Platform.getEnvironment() == Env.SERVER || Platform.isDevelopmentEnvironment())
+ if (env == EnvType.SERVER || isDev)
throw new RuntimeException(reason + " " + link);
if (RoughlyEnoughItemsState.errorSet.add(reason + " " + link)) {
RoughlyEnoughItemsState.errors.add(new Tuple<>(reason, link));
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/ErrorDisplayer.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/ErrorDisplayer.java
index e007f0ec8..b9e512bc9 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/ErrorDisplayer.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/ErrorDisplayer.java
@@ -23,15 +23,19 @@
package me.shedaniel.rei.impl.client;
+import me.shedaniel.architectury.annotations.ExpectPlatform;
import me.shedaniel.architectury.event.events.GuiEvent;
import me.shedaniel.rei.RoughlyEnoughItemsState;
import me.shedaniel.rei.impl.client.gui.screen.WarningAndErrorScreen;
import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.screens.Screen;
import net.minecraft.world.InteractionResult;
+import java.util.function.Consumer;
+
public class ErrorDisplayer {
public void onInitializeClient() {
- GuiEvent.INIT_PRE.register((screen, widgets, children) -> {
+ registerGuiInit((screen) -> {
Minecraft minecraft = Minecraft.getInstance();
if ((!RoughlyEnoughItemsState.getErrors().isEmpty() || !RoughlyEnoughItemsState.getWarnings().isEmpty()) && !(screen instanceof WarningAndErrorScreen)) {
WarningAndErrorScreen warningAndErrorScreen = new WarningAndErrorScreen("initialization", RoughlyEnoughItemsState.getWarnings(), RoughlyEnoughItemsState.getErrors(), (parent) -> {
@@ -51,7 +55,11 @@ public class ErrorDisplayer {
minecraft.screen = null;
minecraft.setScreen(warningAndErrorScreen);
}
- return InteractionResult.PASS;
});
}
+
+ @ExpectPlatform
+ public static void registerGuiInit(Consumer<Screen> consumer) {
+ throw new AssertionError();
+ }
}