Skip to content

Creating Plugins [1.13 and Up]

mezz edited this page Jun 17, 2022 · 4 revisions

Creating a JEI Plugin

Now that you're done with gradle in Getting Started, it's time to create your plugin.

JEI plugins implement the IModPlugin and are annotated with @JeiPlugin.

Under Forge, JEI uses the @JeiPlugin annotation to find your mod plugin class, and then creates an instance at runtime.

Under Fabric, JEI uses fabric.mod.json entrypoints. Add your plugin's location to a "jei_mod_plugin" entrypoint. In this example, three plugins are added:

  "entrypoints": {
    "main": [
      "mezz.jei.fabric.JustEnoughItems"
    ],
    "client": [
      "mezz.jei.fabric.JustEnoughItemsClient"
    ],
    "jei_mod_plugin": [
      "mezz.jei.common.plugins.vanilla.VanillaPlugin",
      "mezz.jei.common.plugins.jei.JeiInternalPlugin",
      "mezz.jei.common.plugins.debug.JeiDebugPlugin"
    ]
  },

Loading this way has the advantage that you can keep all references to JEI in your plugin, separate from your other code.
The plugin code will only get called when JEI is there, so it will never crash from missing classes.

Implementation

Plugins are broken into many stages, each with a specific purpose. Although there are many stages to a JEI plugin, not all of them are necessarily needed for your plugin!

  1. registerItemSubtypes
  • This is where plugins tell JEI how to handle items that have subtypes that depend on NBT or capabilities instead of meta.
  • See the page on Item Subtypes.
  1. registerIngredients
  • This is an advanced section where plugins tell JEI about ingredients.
  • The Vanilla plugin registers ItemStack and FluidStack as ingredients here.
  • Just about anything can be an ingredient. To add your own, see Non-Item Ingredients (WARNING, link not for 1.13 and up!).
  1. registerCategories
  • This is where plugins tell JEI about custom recipe categories.
  • The Vanilla plugin uses this to register all of the Vanilla crafting categories (regular crafting, smelting, etc.)
  1. registerVanillaCategoryExtensions
  • This is where plugins can tell JEI about any extensions to pre-existing Vanilla categories.
  1. registerRecipes
  • This is where recipes for any recipe categories (whether modded or vanilla) are registered.
  • More precisely, this is where you should register any custom recipes that JEI does not automatically handle (custom machine recipes, etc.).
  1. registerRecipeTransferHandlers
  • This is where you should register any custom transfer handlers.
  • Put simply, a transfer handler is what allows the + button in JEI to transfer items to the appropriate slots.
  1. registerRecipeCatalysts
  • This is where you should register any items that are used to craft recipes.
  • For example, if your mod introduces a custom machine that has its own recipes, you should register your machine here to be the catalyst in making said recipes.
  1. registerGuiHandlers
  • Used to register custom GUIs to be used in JEI.
  1. registerAdvanced
  • This is where a mod should register recipe managers.
  • This is generally not needed to have basic JEI integration, but it's here in case if you do!
  1. onRuntimeAvailable
  • Allows mods to interact with the JEI runtime directly through the IJeiRuntime interface