close

Troubles with JEI Integration? Solving Common Problems

Setting Up Your Development Environment and Project

Dependency Management

Before diving into JEI integration, you need to ensure your development environment is correctly set up. This involves setting up your modding environment, including the appropriate IDE (like IntelliJ IDEA), the correct Minecraft Forge or Fabric development environment, and a well-structured project. This is the fundamental groundwork for your mod.

The heart of successful JEI integration lies in proper dependency management. This means including the JEI API as a dependency in your project’s build file. This is often a `build.gradle` file if you’re using Gradle or a similar configuration file depending on your development tool. Ensuring your project correctly references the JEI API enables you to use its classes and methods. Failing to declare this dependency will leave you stranded and your integration efforts unsuccessful.

A basic dependency setup in a `build.gradle` (Groovy DSL) would look something like this:


dependencies {
    // Your mod's dependencies
    implementation 'net.minecraftforge:forge:' // Replace  with your forge version

    // JEI Dependency - Add the proper version compatible with your Minecraft version.
    implementation 'mezz.jei:jei:'  // Replace  with the correct JEI version.
}

It’s imperative that the JEI version you choose is compatible with both your Minecraft version and your chosen mod loader (Forge or Fabric). Mismatched versions are a common source of problems when integrating JEI into your mod. Always consult the official JEI documentation and forums for version compatibility matrices.

Configuration and Initialization

The primary mechanism for integrating with JEI is through an `IModPlugin`. This is a critical component that tells JEI how to interface with your mod. Your plugin is essentially a bridge, enabling JEI to access your mod’s items, recipes, and categories.

To use it, you create a class that implements the `IModPlugin` interface. This class becomes your central point of interaction with JEI. You need to tell JEI about this plugin so that it knows to use it. This is typically done during the initialization of your mod, like the `ModSetupEvent` or an equivalent mod loading phase.

In your `ModInitializer` or equivalent entry point for your mod loader, you would call `JEIPlugin.register()` like so.


@Mod("yourmodid")
public class YourMod {

    public YourMod() {
        IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
        // ... other mod setup ...
        bus.register(this); //Register the event bus
        MinecraftForge.EVENT_BUS.register(this);
        FMLJavaModLoadingContext.get().getModEventBus().register(new JEIPlugin()); //Register the JEI Plugin

    }
    // ... rest of your mod code ...
}

Crafting Your JEIPlugin Class

Your `JEIPlugin` class will implement the `IModPlugin` interface. This interface requires you to implement several methods, most notably:

  • `registerCategories()`: This is where you register the recipe categories used by your mod. Categories are used to organize recipes within JEI (e.g., crafting, smelting, etc.).
  • `registerRecipes()`: This is where you register all the recipes from your mod. You inform JEI about what inputs, outputs, and crafting requirements there are.
  • `registerIngredients()`: This method registers all of your mod’s custom ingredient types, if you have any beyond the standard ones like `ItemStack` and `FluidStack`.

A basic structure of your `JEIPlugin` class looks like this:


@JEIPlugin
public class JEIPlugin implements IModPlugin {

    @Override
    public void registerCategories(IRecipeCategoryRegistration registration) {
        // Register your recipe categories here
    }

    @Override
    public void registerRecipes(IRecipeRegistration registration) {
        // Register your recipes here
    }

    @Override
    public void registerIngredients(IModIngredientRegistration registration) {
        // Register your custom ingredients here, if you have any
    }

    @Override
    public ResourceLocation getPluginUid() {
        return new ResourceLocation("yourmodid", "jeiplugin");
    }
}

Troubleshooting Configuration Problems

  • Plugin Not Loading: If your plugin doesn’t seem to be registering, check your logs for errors. Ensure your `IModPlugin` implementation is correctly registered with the event bus. Ensure the JEI API dependency is properly included. Double-check the version compatibility of JEI with your Minecraft version and mod loader.
  • Class Loading Issues: Ensure your plugin class is in a location that’s accessible by the mod loader. Double-check package names for typos.
  • Type Mismatches: The registration methods take parameters like `IRecipeRegistration` and `IRecipeCategoryRegistration`. Make sure your code uses the appropriate types and avoids any class casting issues.

Registering Items and Ingredients

Once you have your plugin set up, the next step involves registering your mod’s items and ingredients with JEI.

The Importance of Item Registration

This is the cornerstone of your JEI integration. Without correctly registering items and ingredients, they won’t show up in JEI, and players won’t be able to see recipes that use them.

Ingredient Types

JEI supports several ingredient types out of the box. The most common are:

  • `ItemStack`: Represents a standard item and stack.
  • `FluidStack`: Represents a fluid.

You can create your own custom ingredients if you have specific needs, but we will explore that later.

Here’s a basic example of how you might register an `ItemStack` inside of your `registerIngredients()` method.


@Override
public void registerIngredients(IModIngredientRegistration registration) {
    registration.getIngredientTypes().forEach(ingredientType -> {
        if (ingredientType == VanillaTypes.ITEM_STACK) {
           registration.register(
               VanillaTypes.ITEM_STACK,
               List.of(new ItemStack(YourMod.yourItem)),
               VanillaTypes.ITEM_STACK.getUid()
           );
        }
    });
}

Ensure that the `YourMod.yourItem` is a valid item instance. Also, do not forget that you also need to import all the required classes.

Troubleshooting Item Registration Problems

  • Items Not Appearing: This is a common problem. First, make sure that your items are actually registered with Minecraft. Then, verify that you’ve correctly registered them with JEI in the `registerIngredients` method. Double-check your item IDs and the item objects you’re passing.
  • Incorrect Item Properties: This can happen if you don’t correctly associate the item properties in your registration with JEI. Make sure to associate the display name, textures, and any other relevant information to your item in the right places.
  • Missing Textures: JEI uses the textures defined for your items in Minecraft. Ensure your textures are located in the correct folder and that your item model is correctly defined. Verify there are no typos in the file names or paths.

Recipe Handling

Now that your items are registered, the focus shifts to showing your mod’s recipes in JEI.

Understanding Recipes

Recipes define the process of how players can obtain your mod’s items. They specify ingredients, crafting requirements, and output items. Different recipe types exist: Crafting, Smelting, Brewing, etc.

Registering Recipe Categories

Recipe categories are crucial for organizing recipes within JEI. They visually group similar recipes together. For instance, crafting recipes go under the “Crafting” category. To register a category, you need to create an `IRecipeCategory`.

Here’s how to create a recipe category.


public class YourRecipeCategory implements IRecipeCategory<YourRecipe> {
  private final IDrawable background;
  private final IDrawable icon;
  private final Component localizedName;
  private static final ResourceLocation GUI = new ResourceLocation("yourmodid", "textures/gui/jei_gui.png"); // example

  public YourRecipeCategory(IGuiHelper guiHelper) {
        this.localizedName = Component.translatable("yourmodid.jei.category.yourrecipe"); // Use the translation key for the name.
        this.icon = guiHelper.createDrawableIngredient(new ItemStack(YourMod.yourItem)); // Use your item as an icon.
        this.background = guiHelper.createDrawable(GUI, 0, 0, 160, 80);  // Your GUI background (adjust dimensions as needed).
  }

    @Override
    public ResourceLocation getUid() {
        return new ResourceLocation("yourmodid", "yourrecipe"); //Unique identifier.
    }

    @Override
    public Class<? extends YourRecipe> getRecipeClass() {
        return YourRecipe.class; //The recipe class to be shown.
    }

    @Override
    public Component getTitle() {
        return this.localizedName; //Show your translation key.
    }

    @Override
    public IDrawable getBackground() {
        return this.background; //Show your GUI background
    }

    @Override
    public IDrawable getIcon() {
        return this.icon; //Show the icon on the sidebar.
    }

    @Override
    public void draw(YourRecipe recipe, IRecipeSlotsView recipeSlotsView, PoseStack poseStack, double mouseX, double mouseY) {
        IRecipeCategory.super.draw(recipe, recipeSlotsView, poseStack, mouseX, mouseY);
    }

    @Override
    public void setRecipe(IRecipeLayoutBuilder builder, YourRecipe recipe, IFocusGroup focuses) {
        // Create slots for ingredients and outputs.
    }
}

And in your `registerCategories` method, register the category.


@Override
    public void registerCategories(IRecipeCategoryRegistration registry) {
        registry.addRecipeCategories(new YourRecipeCategory(registry.getJeiHelpers().getGuiHelper()));
    }

Registering Recipes

Registering recipes is the core of making your mod’s recipes visible in JEI. This is done within the `registerRecipes` method.


@Override
public void registerRecipes(IRecipeRegistration registration) {
    registration.addRecipes(new ResourceLocation("yourmodid", "yourrecipe"), List.of(new YourRecipe())); //Register YourRecipe class.
}

This simple example assumes you have created a `YourRecipe` class which stores your recipe information.

You can register many different recipe types, from crafting table recipes to furnace smelting recipes.

Troubleshooting Recipe Problems

  • Recipes Not Appearing: The most common issue. Double-check:
    • That you’ve registered the recipe with JEI.
    • That your category is registered.
    • That all ingredients are correctly registered.
    • That your recipe’s data (ingredients, outputs) is correct.
  • Incorrect Ingredients/Outputs: Verify the ingredients and outputs in your recipe implementation. Make sure you are not using the incorrect instances or quantities.
  • Recipe Display Issues: Ensure the recipe layout is correct. If you are using custom categories, verify the background texture is correctly sized and located.

Recipe Category and Ingredient Renderers

You can customize how your recipes look in JEI.

Customizing the Recipe Category

You control how the recipes of the category look. For example, the icons and background of the recipe category. You can use the `IRecipeCategory` to customize these aspects.

Ingredient Renderers

Ingredient Renderers are used to display the ingredients. JEI offers default renderers for many ingredient types.

Advanced Techniques and Optimization

While the basics cover most of the integration, certain advanced techniques and optimization strategies can further improve your mod.

Implementing Custom JEI Ingredients

If your mod uses specialized ingredient types beyond basic items or fluids, you need custom ingredients and renderers.

Filtering/Hiding Items and Recipes

Sometimes you’ll want to hide items or recipes. This can be useful to hide certain developmental or testing items.


@Override
public void registerRecipes(IRecipeRegistration registration) {
    registration.getRecipeManager().hideRecipe(new ResourceLocation("yourmodid", "hidden_recipe")); // Example: Hide a recipe
}

Performance Considerations

JEI integration can impact performance. Optimize your code by using caching, avoiding unnecessary computations, and efficient data structures.

Common Problems and Solutions

Let’s revisit some recurring issues with solutions.

  • JEI Not Loading: Ensure you have the JEI API dependency. Check your logs for any startup exceptions.
  • Items or Recipes Missing: Verify proper registration. Check for typos. Ensure your mod’s initialization and recipe registration is complete.
  • Incorrect Information: Double-check item and recipe data. Review logs for any potential errors.

Throughout the entire integration process, review the logs. It is a great way to debug your code.

Examples and Code Snippets

Throughout the article, we have provided examples, but for brevity, we will not repeat the same examples. But the main thing to remember is that code examples are crucial. Include relevant code snippets that illustrate your concepts. Show best practices by offering working code examples.

Conclusion

Integrating JEI into your Minecraft mod is an essential step in providing a great player experience. While it may present initial challenges, by understanding the common problems when integrating JEI into your mod and implementing the proper solutions, you can create seamless integration.

Remember to review the official JEI documentation and community resources for updated information.

This guide is intended to act as a starting point, so experiment with the code provided.

By correctly configuring your development environment, managing dependencies, and handling item and recipe registration effectively, you’ll offer players the information they need to enjoy your mod fully.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
close