aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2021-08-28 16:01:34 +0800
committershedaniel <daniel@shedaniel.me>2021-08-28 16:01:42 +0800
commit8a0601c75fa2462494ed949797f04243fe9cb10e (patch)
treed68bb62284aa8f63faecb5060b9803846f33ed72
parent2318a37d8482498bdec25947e15177ba77996cb8 (diff)
downloadRoughlyEnoughItems-8a0601c75fa2462494ed949797f04243fe9cb10e.tar.gz
RoughlyEnoughItems-8a0601c75fa2462494ed949797f04243fe9cb10e.tar.bz2
RoughlyEnoughItems-8a0601c75fa2462494ed949797f04243fe9cb10e.zip
Fix crash if architectury isn't installed, fix replay mod and REI fighting to show GUIs
-rw-r--r--fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinScreen.java12
-rw-r--r--fabric/src/main/java/me/shedaniel/rei/mixin/fabric/REIMixinPlugin.java71
-rw-r--r--fabric/src/main/resources/rei.mixins.json1
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java5
4 files changed, 85 insertions, 4 deletions
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
index a14577a7f..1f2346895 100644
--- a/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinScreen.java
+++ b/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinScreen.java
@@ -27,6 +27,7 @@ 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.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -35,10 +36,17 @@ import java.util.function.Consumer;
@Mixin(Screen.class)
public class MixinScreen {
+ @Unique
+ private static final ThreadLocal<Boolean> REI_IN = ThreadLocal.withInitial(() -> false);
+
@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);
+ if (!REI_IN.get()) {
+ REI_IN.set(true);
+ for (Consumer<Screen> consumer : ErrorDisplayerImpl.consumerList) {
+ consumer.accept((Screen) (Object) this);
+ }
+ REI_IN.set(false);
}
}
}
diff --git a/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/REIMixinPlugin.java b/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/REIMixinPlugin.java
new file mode 100644
index 000000000..12f87038a
--- /dev/null
+++ b/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/REIMixinPlugin.java
@@ -0,0 +1,71 @@
+/*
+ * 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 net.fabricmc.loader.api.FabricLoader;
+import org.objectweb.asm.tree.ClassNode;
+import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
+import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
+
+import java.util.List;
+import java.util.Set;
+
+public class REIMixinPlugin implements IMixinConfigPlugin {
+ @Override
+ public void onLoad(String mixinPackage) {
+
+ }
+
+ @Override
+ public String getRefMapperConfig() {
+ return null;
+ }
+
+ @Override
+ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
+ if (mixinClassName.endsWith("MixinClientPacketListener"))
+ return FabricLoader.getInstance().isModLoaded("architectury");
+ return true;
+ }
+
+ @Override
+ public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
+
+ }
+
+ @Override
+ public List<String> getMixins() {
+ return null;
+ }
+
+ @Override
+ public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
+
+ }
+
+ @Override
+ public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
+
+ }
+}
diff --git a/fabric/src/main/resources/rei.mixins.json b/fabric/src/main/resources/rei.mixins.json
index 7897b4049..0c3ca4a68 100644
--- a/fabric/src/main/resources/rei.mixins.json
+++ b/fabric/src/main/resources/rei.mixins.json
@@ -1,6 +1,7 @@
{
"required": true,
"package": "me.shedaniel.rei.mixin.fabric",
+ "plugin": "me.shedaniel.rei.mixin.fabric.REIMixinPlugin",
"compatibilityLevel": "JAVA_8",
"client": [
"MixinClientPacketListener",
diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java
index 0914ac6f6..c7da5737a 100644
--- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java
+++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java
@@ -26,6 +26,7 @@ package me.shedaniel.rei;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.fabricmc.api.EnvType;
+import java.lang.invoke.MethodHandles;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -63,7 +64,7 @@ public class RoughlyEnoughItemsInitializer {
} catch (NoSuchMethodException ignored) {
}
if (method != null) {
- method.invoke(instance);
+ MethodHandles.lookup().unreflect(method).bindTo(instance).invoke();
}
}
} else {
@@ -72,7 +73,7 @@ public class RoughlyEnoughItemsInitializer {
} catch (NoSuchMethodException ignored) {
}
if (method != null) {
- method.invoke(instance);
+ MethodHandles.lookup().unreflect(method).bindTo(instance).invoke();
}
}
} catch (Throwable e) {