From 7a8274d044345d6fbf4ecf224c14a77d427bbf2d Mon Sep 17 00:00:00 2001 From: Relentless Date: Mon, 17 Apr 2023 16:58:33 +0200 Subject: [PATCH] use another JEI entrypoint to avoid crashes --- Common/build.gradle.kts | 2 +- .../unified/compat/AlmostJEI.java | 7 ++- .../unified/mixin/AlmostMixinPlugin.java | 3 +- .../unified/mixin/JeiRecipeLayoutMixin.java | 31 ++++++++++ .../JeiRecipeTransferButtonAccessor.java | 13 ----- .../unified/mixin/JeiRecipesGuiMixin.java | 58 ------------------- .../almostunified-common.mixins.json | 3 +- Fabric/build.gradle.kts | 2 +- Forge/build.gradle.kts | 4 +- 9 files changed, 44 insertions(+), 79 deletions(-) create mode 100644 Common/src/main/java/com/almostreliable/unified/mixin/JeiRecipeLayoutMixin.java delete mode 100644 Common/src/main/java/com/almostreliable/unified/mixin/JeiRecipeTransferButtonAccessor.java delete mode 100644 Common/src/main/java/com/almostreliable/unified/mixin/JeiRecipesGuiMixin.java diff --git a/Common/build.gradle.kts b/Common/build.gradle.kts index 7df3297..0a91772 100644 --- a/Common/build.gradle.kts +++ b/Common/build.gradle.kts @@ -31,7 +31,7 @@ dependencies { modCompileOnly("me.shedaniel:RoughlyEnoughItems-api:$reiVersion") // required for common rei plugin compileOnly("me.shedaniel:REIPluginCompatibilities-forge-annotations:9.+") // required to disable rei compat layer on jei plugin testCompileOnly("me.shedaniel:REIPluginCompatibilities-forge-annotations:9.+") // don't question this, it's required for compiling - modCompileOnly("mezz.jei:jei-$minecraftVersion-gui:$jeiVersion") // required for common jei plugin and mixin + modCompileOnly("mezz.jei:jei-$minecraftVersion-lib:$jeiVersion") // required for common jei plugin and mixin modCompileOnly("mezz.jei:jei-$minecraftVersion-common-api:$jeiVersion") // required for common jei plugin and mixin // The Fabric loader is required here to use the @Environment annotations and to get the mixin dependencies. diff --git a/Common/src/main/java/com/almostreliable/unified/compat/AlmostJEI.java b/Common/src/main/java/com/almostreliable/unified/compat/AlmostJEI.java index f3d10d0..f58d5c4 100644 --- a/Common/src/main/java/com/almostreliable/unified/compat/AlmostJEI.java +++ b/Common/src/main/java/com/almostreliable/unified/compat/AlmostJEI.java @@ -11,6 +11,7 @@ import me.shedaniel.rei.plugincompatibilities.api.REIPluginCompatIgnore; import mezz.jei.api.IModPlugin; import mezz.jei.api.JeiPlugin; import mezz.jei.api.constants.VanillaTypes; +import mezz.jei.api.recipe.category.IRecipeCategory; import mezz.jei.api.runtime.IJeiRuntime; import net.minecraft.client.renderer.Rect2i; import net.minecraft.resources.ResourceLocation; @@ -43,7 +44,11 @@ public class AlmostJEI implements IModPlugin { } } - public static void handleIndicator(PoseStack stack, int mX, int mY, int posX, int posY, ResourceLocation recipeId) { + public static void handleIndicator(PoseStack stack, int mX, int mY, int posX, int posY, IRecipeCategory recipeCategory, R recipe) { + var recipeId = recipeCategory.getRegistryName(recipe); + if (recipeId == null) return; + + var link = CRTLookup.getLink(recipeId); if (link == null) return; diff --git a/Common/src/main/java/com/almostreliable/unified/mixin/AlmostMixinPlugin.java b/Common/src/main/java/com/almostreliable/unified/mixin/AlmostMixinPlugin.java index 1ea393f..2f4676c 100644 --- a/Common/src/main/java/com/almostreliable/unified/mixin/AlmostMixinPlugin.java +++ b/Common/src/main/java/com/almostreliable/unified/mixin/AlmostMixinPlugin.java @@ -17,8 +17,7 @@ public class AlmostMixinPlugin implements IMixinConfigPlugin { private static final BooleanSupplier TRUE = () -> true; private static final Map CONDITIONS = ImmutableMap.of( - "com.almostreliable.unified.mixin.JeiRecipesGuiMixin", modLoaded(ModConstants.JEI), - "com.almostreliable.unified.mixin.JeiRecipeTransferButtonAccessor", modLoaded(ModConstants.JEI) + "com.almostreliable.unified.mixin.JeiRecipeLayoutMixin", modLoaded(ModConstants.JEI) ); private static BooleanSupplier modLoaded(String id) { diff --git a/Common/src/main/java/com/almostreliable/unified/mixin/JeiRecipeLayoutMixin.java b/Common/src/main/java/com/almostreliable/unified/mixin/JeiRecipeLayoutMixin.java new file mode 100644 index 0000000..565e785 --- /dev/null +++ b/Common/src/main/java/com/almostreliable/unified/mixin/JeiRecipeLayoutMixin.java @@ -0,0 +1,31 @@ +package com.almostreliable.unified.mixin; + +import com.almostreliable.unified.compat.AlmostJEI; +import com.almostreliable.unified.compat.RecipeIndicator; +import com.mojang.blaze3d.vertex.PoseStack; +import mezz.jei.api.gui.drawable.IDrawable; +import mezz.jei.api.recipe.category.IRecipeCategory; +import mezz.jei.library.gui.recipes.RecipeLayout; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +@Mixin(RecipeLayout.class) +public abstract class JeiRecipeLayoutMixin { + + @Shadow(remap = false) @Final + private IRecipeCategory recipeCategory; + @Shadow(remap = false) @Final + private R recipe; + + @Inject(method = "drawRecipe", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;pushPose()V", ordinal = 1), locals = LocalCapture.CAPTURE_FAILHARD) + private void unified$catchLayoutInfo(PoseStack stack, int mouseX, int mouseY, CallbackInfo ci, IDrawable background, int mX, int mY, int x, int y) { + var posX = x - RecipeIndicator.RENDER_SIZE; + var posY = y - RecipeIndicator.RENDER_SIZE; + AlmostJEI.handleIndicator(stack, mX, mY, posX, posY, recipeCategory, recipe); + } +} diff --git a/Common/src/main/java/com/almostreliable/unified/mixin/JeiRecipeTransferButtonAccessor.java b/Common/src/main/java/com/almostreliable/unified/mixin/JeiRecipeTransferButtonAccessor.java deleted file mode 100644 index f52b6bf..0000000 --- a/Common/src/main/java/com/almostreliable/unified/mixin/JeiRecipeTransferButtonAccessor.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.almostreliable.unified.mixin; - -import mezz.jei.api.gui.IRecipeLayoutDrawable; -import mezz.jei.gui.recipes.RecipeTransferButton; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(RecipeTransferButton.class) -public interface JeiRecipeTransferButtonAccessor { - - @Accessor(value = "recipeLayout", remap = false) - IRecipeLayoutDrawable getRecipeLayout(); -} diff --git a/Common/src/main/java/com/almostreliable/unified/mixin/JeiRecipesGuiMixin.java b/Common/src/main/java/com/almostreliable/unified/mixin/JeiRecipesGuiMixin.java deleted file mode 100644 index 8fa7234..0000000 --- a/Common/src/main/java/com/almostreliable/unified/mixin/JeiRecipesGuiMixin.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.almostreliable.unified.mixin; - -import com.almostreliable.unified.compat.AlmostJEI; -import com.almostreliable.unified.compat.RecipeIndicator; -import com.almostreliable.unified.utils.Utils; -import com.mojang.blaze3d.vertex.PoseStack; -import mezz.jei.api.gui.IRecipeLayoutDrawable; -import mezz.jei.gui.recipes.RecipeTransferButton; -import mezz.jei.gui.recipes.RecipesGui; -import net.minecraft.client.Minecraft; -import net.minecraft.resources.ResourceLocation; -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; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Optional; - -@Mixin(RecipesGui.class) -public abstract class JeiRecipesGuiMixin { - - @Unique - private static final Map RENDER_QUEUE = new HashMap<>(); - - @Inject(method = "drawLayouts", at = @At(value = "INVOKE", target = "Lmezz/jei/gui/recipes/RecipeTransferButton;render(Lcom/mojang/blaze3d/vertex/PoseStack;IIF)V"), locals = LocalCapture.CAPTURE_FAILHARD) - private void unified$setupIndicators(PoseStack stack, int mX, int mY, CallbackInfoReturnable>> cir, IRecipeLayoutDrawable hoveredLayout, Minecraft mc, float partial, Iterator iterator, RecipeTransferButton button) { - var recipeLayout = ((JeiRecipeTransferButtonAccessor) button).getRecipeLayout(); - var recipeId = recipeLayout.getRecipeCategory().getRegistryName(Utils.cast(recipeLayout.getRecipe())); - if (recipeId == null) return; - - int posX; - int posY; - if (button.visible) { - posX = button.x + (button.getWidth() - RecipeIndicator.RENDER_SIZE) / 2; - posY = button.y - RecipeIndicator.RENDER_SIZE - 2; - } else { - var area = recipeLayout.getRect(); - posX = area.getX() + area.getWidth() - RecipeIndicator.RENDER_SIZE / 2 + 2; - posY = area.getY() + area.getHeight() - RecipeIndicator.RENDER_SIZE / 2 + 2; - } - - RENDER_QUEUE.put(recipeId, new RecipeIndicator.RenderEntry(posX, posY)); - } - - @Inject(method = "render", at = @At(value = "INVOKE", target = "Lmezz/jei/gui/recipes/RecipeGuiTabs;draw(Lnet/minecraft/client/Minecraft;Lcom/mojang/blaze3d/vertex/PoseStack;IILmezz/jei/api/helpers/IModIdHelper;)V")) - private void unified$flushQueue(PoseStack stack, int mX, int mY, float partial, CallbackInfo ci) { - RENDER_QUEUE.forEach((recipeId, entry) -> { - AlmostJEI.handleIndicator(stack, mX, mY, entry.pX(), entry.pY(), recipeId); - }); - RENDER_QUEUE.clear(); - } -} diff --git a/Common/src/main/resources/almostunified-common.mixins.json b/Common/src/main/resources/almostunified-common.mixins.json index 743600f..b5bd0da 100644 --- a/Common/src/main/resources/almostunified-common.mixins.json +++ b/Common/src/main/resources/almostunified-common.mixins.json @@ -10,8 +10,7 @@ ], "client": [ "ClientPacketListenerMixin", - "JeiRecipesGuiMixin", - "JeiRecipeTransferButtonAccessor" + "JeiRecipeLayoutMixin" ], "injectors": { "defaultRequire": 1 diff --git a/Fabric/build.gradle.kts b/Fabric/build.gradle.kts index fd502ee..1c6366c 100644 --- a/Fabric/build.gradle.kts +++ b/Fabric/build.gradle.kts @@ -35,7 +35,7 @@ dependencies { modCompileOnly("me.shedaniel:RoughlyEnoughItems-api-fabric:$reiVersion") // required for common rei plugin compileOnly("me.shedaniel:REIPluginCompatibilities-forge-annotations:9.+") // required to disable rei compat layer on jei plugin testCompileOnly("me.shedaniel:REIPluginCompatibilities-forge-annotations:9.+") // don't question this, it's required for compiling - modCompileOnly("mezz.jei:jei-$minecraftVersion-fabric:$jeiVersion") // required for common jei plugin and mixin + modCompileOnly("mezz.jei:jei-$minecraftVersion-fabric-api:$jeiVersion") // required for common jei plugin and mixin when (fabricRecipeViewer) { // runtime only "rei" -> modLocalRuntime("me.shedaniel:RoughlyEnoughItems-fabric:$reiVersion") "jei" -> modLocalRuntime("mezz.jei:jei-$minecraftVersion-fabric:$jeiVersion") diff --git a/Forge/build.gradle.kts b/Forge/build.gradle.kts index b19027c..b7c4145 100644 --- a/Forge/build.gradle.kts +++ b/Forge/build.gradle.kts @@ -46,7 +46,9 @@ dependencies { modCompileOnly("me.shedaniel:RoughlyEnoughItems-forge:$reiVersion") // required for common rei plugin | api does not work here compileOnly("me.shedaniel:REIPluginCompatibilities-forge-annotations:9.+") // required to disable rei compat layer on jei plugin testCompileOnly("me.shedaniel:REIPluginCompatibilities-forge-annotations:9.+") // don't question this, it's required for compiling - modCompileOnly("mezz.jei:jei-$minecraftVersion-forge:$jeiVersion") { isTransitive = false } // required for common jei plugin and mixin, transitivity is off because it breaks the forge runtime + modCompileOnly("mezz.jei:jei-$minecraftVersion-forge-api:$jeiVersion") { + isTransitive = false + } // required for common jei plugin and mixin, transitivity is off because it breaks the forge runtime when (forgeRecipeViewer) { // runtime only "rei" -> modLocalRuntime("me.shedaniel:RoughlyEnoughItems-forge:$reiVersion") "jei" -> modLocalRuntime("mezz.jei:jei-$minecraftVersion-forge:$jeiVersion") { isTransitive = false }