use another JEI entrypoint to avoid crashes

This commit is contained in:
Relentless 2023-04-17 16:58:33 +02:00
parent dc5f4633ef
commit 7a8274d044
No known key found for this signature in database
GPG key ID: 50C5FD225130D790
9 changed files with 44 additions and 79 deletions

View file

@ -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.

View file

@ -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 <R> void handleIndicator(PoseStack stack, int mX, int mY, int posX, int posY, IRecipeCategory<R> recipeCategory, R recipe) {
var recipeId = recipeCategory.getRegistryName(recipe);
if (recipeId == null) return;
var link = CRTLookup.getLink(recipeId);
if (link == null) return;

View file

@ -17,8 +17,7 @@ public class AlmostMixinPlugin implements IMixinConfigPlugin {
private static final BooleanSupplier TRUE = () -> true;
private static final Map<String, BooleanSupplier> 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) {

View file

@ -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<R> {
@Shadow(remap = false) @Final
private IRecipeCategory<R> 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);
}
}

View file

@ -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();
}

View file

@ -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<ResourceLocation, RecipeIndicator.RenderEntry> 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<Optional<IRecipeLayoutDrawable<?>>> 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();
}
}

View file

@ -10,8 +10,7 @@
],
"client": [
"ClientPacketListenerMixin",
"JeiRecipesGuiMixin",
"JeiRecipeTransferButtonAccessor"
"JeiRecipeLayoutMixin"
],
"injectors": {
"defaultRequire": 1

View file

@ -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")

View file

@ -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 }