Hack around JEI focuses not using recipe subtypes
@@ -8,6 +8,7 @@ import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.helpers.IGuiHelper;
+import mezz.jei.api.recipe.IFocus;
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.RecipeIngredientRole;
import mezz.jei.api.recipe.RecipeType;
@@ -25,6 +26,7 @@ import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.InventoryMenu;
+import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.ForgeI18n;
import slimeknights.mantle.client.model.NBTKeyModel;
@@ -207,24 +209,29 @@ public class ModifierRecipeCategory implements IRecipeCategory<IDisplayModifierR
.setCustomRenderer(TConstructJEIConstants.MODIFIER_TYPE, modifierRenderer)
.addIngredient(TConstructJEIConstants.MODIFIER_TYPE, recipe.getDisplayResult());
// tool
- builder.addSlot(RecipeIngredientRole.CATALYST, 25, 38).addItemStacks(recipe.getToolWithoutModifier());
- builder.addSlot(RecipeIngredientRole.CATALYST, 105, 34).addItemStacks(recipe.getToolWithModifier());
-
- // TODO: still needed?
- // if focusing on a tool, filter out other tools
-// IFocus<ItemStack> focus = layout.getFocus(VanillaTypes.ITEM_STACK);
-// List<ItemStack> output = recipe.getToolWithModifier();
-// items.set(-1, output);
-// if (focus != null) {
-// Item item = focus.getValue().getItem();
-// if (TinkerTags.Items.MODIFIABLE.contains(item)) {
-// List<List<ItemStack>> allItems = recipe.getDisplayItems();
-// if (allItems.size() >= 1) {
-// allItems.get(0).stream().filter(stack -> stack.getItem() == item)
-// .findFirst().ifPresent(stack -> items.set(0, stack));
-// }
-// output.stream().filter(stack -> stack.getItem() == item).findFirst().ifPresent(stack -> items.set(-1, stack));
-// }
-// }
+ List<ItemStack> toolWithoutModifier = recipe.getToolWithoutModifier();
+ List<ItemStack> toolWithModifier = recipe.getToolWithModifier();
+
+ // JEI is currently being dumb and using ingredient subtypes within recipe focuses
+ // we use a more strict subtype for tools in ingredients so they all show in JEI, but do not care in recipes
+ // thus, manually handle the focuses
+ IFocus<ItemStack> focus = focuses.getFocuses(VanillaTypes.ITEM_STACK).filter(f -> f.getRole() == RecipeIngredientRole.CATALYST).findFirst().orElse(null);
+ if (focus != null) {
+ Item item = focus.getTypedValue().getIngredient().getItem();
+ for (ItemStack stack : toolWithoutModifier) {
+ if (stack.getItem() == item) {
+ toolWithoutModifier = List.of(stack);
+ break;
+ }
+ }
+ for (ItemStack stack : toolWithModifier) {
+ if (stack.getItem() == item) {
+ toolWithModifier = List.of(stack);
+ break;
+ }
+ }
+ }
+ builder.addSlot(RecipeIngredientRole.CATALYST, 25, 38).addItemStacks(toolWithoutModifier);
+ builder.addSlot(RecipeIngredientRole.CATALYST, 105, 34).addItemStacks(toolWithModifier);
}
}
