Roughly Enough Items (REI) Documentation

repository·19.x-1.21.5·Indexed 19 days ago

https://github.com/shedaniel/roughlyenoughitems

A Minecraft mod for versions 1.13 - 1.18 that allows users to view items and recipes. It supports Forge, Fabric, and Rift mod loaders. The documentation covers Maven repository configuration, dependency setup for various platforms, and API usage for the RecipeFinder and DisplayAdditionReasons interfaces.

Tokens
2.6K
Snippets
10
Records
10
Agent score
66%

What's inside Roughly Enough Items

  1. Configure REI dependencies for Fabric

    19.x-1.21.5

    For Fabric projects, REI recommends declaring a modCompileOnly dependency on the API and a modRuntimeOnly dependency on the full package. If you need to interact with built-in plugins, also include the default plugin as a compile dependency.

    dependencies {
        modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:VERSION"
        modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-fabric:VERSION"
    }
    
    // Optional: To interact with built-in plugins
    dependencies {
        modCompileOnly "me.shedaniel:RoughlyEnoughItems-default-plugin-fabric:VERSION"
    }
  2. Configure REI dependencies for Forge (Architectury Loom)

    19.x-1.21.5

    For Forge projects using Architectury Loom, declare a modCompileOnly dependency on the API and a modRuntimeOnly dependency on the full package. If you need to interact with built-in plugins, include the default plugin as a compile dependency.

    dependencies {
        modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-forge:VERSION"
        modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-forge:VERSION"
    }
    
    // Optional: To interact with built-in plugins
    dependencies {
        modCompileOnly "me.shedaniel:RoughlyEnoughItems-default-plugin-forge:VERSION"
    }
  3. Add the REI Maven repository

    19.x-1.21.5

    To use Roughly Enough Items (REI) in your project, you must first add the Shedaniel Maven repository to your repositories block in Gradle. Note that if you already have the Architectury Maven configured, you do not need to add this one as they are the same repository.

    repositories {
        maven { url "https://maven.shedaniel.me" }
    }
  4. Configure REI dependencies for Architectury

    19.x-1.21.5

    When using Architectury, declare the common API in your common subproject. Then, declare the platform-specific full package in your individual platform subprojects (Fabric or Forge). To interact with built-in plugins, declare the default plugin in the common subproject.

    // Common
    dependencies {
        modCompileOnly "me.shedaniel:RoughlyEnoughItems-api:VERSION"
    }
    
    // Optional: To interact with built-in plugins in Common
    dependencies {
        modCompileOnly "me.shedaniel:RoughlyEnoughItems-default-plugin:VERSION"
    }
    
    // Fabric
    dependencies {
        modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-fabric:VERSION"
    }
    
    // Forge
    dependencies {
        modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-forge:VERSION"
    }
  5. Reference: REI Maven Artifacts

    19.x-1.21.5

    The following artifacts are available in the me.shedaniel group for various platforms and purposes.

    - me.shedaniel:RoughlyEnoughItems-api: REI API for Architectury Common
    - me.shedaniel:RoughlyEnoughItems-default-plugin: REI Default Plugin for Architectury Common
    - me.shedaniel:RoughlyEnoughItems-runtime: REI Runtime for Architectury Common
    - me.shedaniel:RoughlyEnoughItems-api-fabric: REI API for Fabric
    - me.shedaniel:RoughlyEnoughItems-default-plugin-fabric: REI Default Plugin for Fabric
    - me.shedaniel:RoughlyEnoughItems-runtime-fabric: REI Runtime for Fabric
    - me.shedaniel:RoughlyEnoughItems-api-forge: REI API for Forge
    - me.shedaniel:RoughlyEnoughItems-default-plugin-forge: REI Default Plugin for Forge
    - me.shedaniel:RoughlyEnoughItems-runtime-forge: REI Runtime for Forge
    - me.shedaniel:RoughlyEnoughItems-fabric: Full REI for Fabric
    - me.shedaniel:RoughlyEnoughItems-forge: Full REI for Forge
  6. Manage item amounts in RecipeFinder

    19.x-1.21.5

    The RecipeFinder maintains an internal map of item types to their available quantities via the amounts field (a Reference2IntOpenHashMap).

    Key methods for managing quantities:

    • put(T item, int amount): Adds the specified amount of an item to the finder.
    • take(T item, int amount): Removes the specified amount from the finder. Throws an IllegalStateException if the amount to be taken exceeds the available amount.
    • contains(T item): Returns true if the item exists in the finder with an amount greater than 0.
    • clear(): Resets all item amounts to zero.

    Note: amounts is a public field of type Reference2IntOpenHashMap<T>.

    RecipeFinder<MyItem, MyIngredient> finder = new RecipeFinder<>();
    finder.put(myStack, 64);
    if (finder.contains(myStack)) {
        finder.take(myStack, 1);
    }
  7. Use RecipeFinder to find and filter recipes

    19.x-1.21.5

    The RecipeFinder class is used to manage a collection of items (amounts) and determine if a set of required ingredients can be satisfied by those items through available recipes. It can find a single valid recipe configuration or calculate the maximum number of crafts possible.

    To use it:

    1. Instantiate RecipeFinder<T, I> where T is your item type and I is an implementation of Ingredient<T>.
    2. Populate the finder with available items using put(item, amount).
    3. Use findRecipe to attempt to pick a recipe that satisfies the ingredients.
    4. Use countRecipeCrafts to find the maximum number of times the ingredients can be crafted simultaneously.
    // Example setup
    RecipeFinder<MyItem, MyIngredient> finder = new RecipeFinder<>();
    finder.put(itemA, 10);
    finder.put(itemB, 5);
    
    // Attempt to find a recipe for a list of ingredients
    List<MyIngredient> ingredients = List.of(ingredient1, ingredient2);
    boolean success = finder.findRecipe(ingredients, 1, (item, ingredient) -> {
        System.out.println("Found recipe using " + item);
    });
    
    // Count maximum possible crafts
    int maxCrafts = finder.countRecipeCrafts(ingredients, 10, null);
  8. Query display addition reasons using DisplayAdditionReasons

    19.x-1.21.5

    The DisplayAdditionReasons interface allows you to query the reasons why an item or recipe is being displayed in the REI interface. This is useful when you need to inspect the metadata associated with a display entry to determine its source or purpose.

    You can check for the presence of a specific reason or retrieve the reason instance itself using either the class type or a specific instance.

    Note: This API is marked as @ApiStatus.Experimental and may change in future versions.

    // Check if a specific reason class is present
    boolean hasReason = reasons.has(MyCustomReason.class);
    
    // Retrieve a specific reason instance by class
    MyCustomReason reason = reasons.get(MyCustomReason.class);
    
    // Check if a specific reason instance is present
    boolean hasInstance = reasons.has(someReasonInstance);
    
    // Retrieve a specific reason instance by instance
    MyCustomReason found = reasons.get(someReasonInstance);
  9. Implement the Ingredient interface

    19.x-1.21.5

    To use RecipeFinder, you must provide a list of ingredients. Each ingredient must implement the Ingredient<T> interface, where T is the item type.

    public interface Ingredient<T> {
        List<T> elements();
    }

    elements() should return a list of items that satisfy that specific ingredient requirement.

    public class MyIngredient implements RecipeFinder.Ingredient<MyItem> {
        private final List<MyItem> items;
    
        public MyIngredient(List<MyItem> items) {
            this.items = items;
        }
    
        @Override
        public List<MyItem> elements() {
            return items;
        }
    }