aboutsummaryrefslogtreecommitdiff
path: root/fabric/src
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2023-05-30 12:32:54 +0800
committershedaniel <daniel@shedaniel.me>2023-06-01 16:55:08 +0800
commit6acbfba77bce42994f462fdcc06ffd985d8642af (patch)
tree1a74988166790783bb6af153b02146106bce2e60 /fabric/src
parentaf164bc5db24d46f129ddfca6388e748267f6cce (diff)
downloadRoughlyEnoughItems-6acbfba77bce42994f462fdcc06ffd985d8642af.tar.gz
RoughlyEnoughItems-6acbfba77bce42994f462fdcc06ffd985d8642af.tar.bz2
RoughlyEnoughItems-6acbfba77bce42994f462fdcc06ffd985d8642af.zip
Fix #1398
Diffstat (limited to 'fabric/src')
-rw-r--r--fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinInputConstantsKey.java58
-rw-r--r--fabric/src/main/resources/rei.mixins.json1
2 files changed, 59 insertions, 0 deletions
diff --git a/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinInputConstantsKey.java b/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinInputConstantsKey.java
new file mode 100644
index 000000000..99a4b3ee1
--- /dev/null
+++ b/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinInputConstantsKey.java
@@ -0,0 +1,58 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 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 com.mojang.blaze3d.platform.InputConstants;
+import com.mojang.blaze3d.systems.RenderSystem;
+import me.shedaniel.rei.api.client.config.ConfigObject;
+import net.minecraft.network.chat.Component;
+import net.minecraft.network.chat.TranslatableComponent;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
+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.CallbackInfoReturnable;
+
+@Mixin(InputConstants.Key.class)
+public abstract class MixinInputConstantsKey {
+ @Shadow
+ public abstract String getName();
+
+ @Inject(method = "getDisplayName", at = @At("HEAD"), cancellable = true)
+ private void getDisplayName(CallbackInfoReturnable<Component> cir) {
+ if (isPatchingAsyncThreadCrash() && !RenderSystem.isOnRenderThread()) {
+ cir.setReturnValue(new TranslatableComponent(getName()));
+ }
+ }
+
+ @Unique
+ private static boolean isPatchingAsyncThreadCrash() {
+ try {
+ return ConfigObject.getInstance().isPatchingAsyncThreadCrash();
+ } catch (Throwable throwable) {
+ return false;
+ }
+ }
+}
diff --git a/fabric/src/main/resources/rei.mixins.json b/fabric/src/main/resources/rei.mixins.json
index 89a733346..8e34cc178 100644
--- a/fabric/src/main/resources/rei.mixins.json
+++ b/fabric/src/main/resources/rei.mixins.json
@@ -7,6 +7,7 @@
"MixinClientPacketListener",
"MixinEffectRenderingInventoryScreen",
"MixinInputConstants",
+ "MixinInputConstantsKey",
"MixinRecipeToast",
"MixinScreen"
],