RecipeHelper.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * Roughly Enough Items by Danielshe.
  3. * Licensed under the MIT License.
  4. */
  5. package me.shedaniel.rei.api;
  6. import me.shedaniel.math.api.Rectangle;
  7. import me.shedaniel.rei.RoughlyEnoughItemsCore;
  8. import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen;
  9. import net.minecraft.recipe.Recipe;
  10. import net.minecraft.recipe.RecipeManager;
  11. import net.minecraft.util.Identifier;
  12. import java.util.List;
  13. import java.util.Map;
  14. import java.util.Optional;
  15. import java.util.function.Function;
  16. import java.util.function.Predicate;
  17. public interface RecipeHelper {
  18. @SuppressWarnings("deprecation")
  19. static RecipeHelper getInstance() {
  20. return RoughlyEnoughItemsCore.getRecipeHelper();
  21. }
  22. AutoTransferHandler registerAutoCraftingHandler(AutoTransferHandler handler);
  23. List<AutoTransferHandler> getSortedAutoCraftingHandler();
  24. /**
  25. * Gets the total recipe count registered
  26. *
  27. * @return the recipe count
  28. */
  29. int getRecipeCount();
  30. /**
  31. * @return a list of sorted recipes
  32. */
  33. List<Recipe> getAllSortedRecipes();
  34. /**
  35. * Gets all craftable items from materials.
  36. *
  37. * @param inventoryItems the materials
  38. * @return the list of craftable entries
  39. */
  40. List<EntryStack> findCraftableEntriesByItems(List<EntryStack> inventoryItems);
  41. /**
  42. * Registers a category
  43. *
  44. * @param category the category to register
  45. */
  46. void registerCategory(RecipeCategory<?> category);
  47. /**
  48. * Registers the working stations of a category
  49. *
  50. * @param category the category
  51. * @param workingStations the working stations
  52. */
  53. void registerWorkingStations(Identifier category, List<EntryStack>... workingStations);
  54. /**
  55. * Registers the working stations of a category
  56. *
  57. * @param category the category
  58. * @param workingStations the working stations
  59. */
  60. void registerWorkingStations(Identifier category, EntryStack... workingStations);
  61. List<List<EntryStack>> getWorkingStations(Identifier category);
  62. /**
  63. * Registers a recipe display
  64. *
  65. * @param categoryIdentifier the category to display in
  66. * @param display the recipe display
  67. */
  68. void registerDisplay(Identifier categoryIdentifier, RecipeDisplay display);
  69. /**
  70. * Gets a map of recipes for an entry
  71. *
  72. * @param stack the stack to be crafted
  73. * @return the map of recipes
  74. */
  75. Map<RecipeCategory<?>, List<RecipeDisplay>> getRecipesFor(EntryStack stack);
  76. RecipeCategory getCategory(Identifier identifier);
  77. /**
  78. * Gets the vanilla recipe manager
  79. *
  80. * @return the recipe manager
  81. */
  82. RecipeManager getRecipeManager();
  83. /**
  84. * Gets all registered categories
  85. *
  86. * @return the list of categories
  87. */
  88. List<RecipeCategory<?>> getAllCategories();
  89. /**
  90. * Gets a map of usages for an entry
  91. *
  92. * @param stack the stack to be used
  93. * @return the map of recipes
  94. */
  95. Map<RecipeCategory<?>, List<RecipeDisplay>> getUsagesFor(EntryStack stack);
  96. /**
  97. * Gets the optional of the auto crafting button area from a category
  98. *
  99. * @param category the category of the display
  100. * @return the optional of auto crafting button area
  101. */
  102. Optional<ButtonAreaSupplier> getAutoCraftButtonArea(RecipeCategory<?> category);
  103. /**
  104. * Registers a auto crafting button area
  105. *
  106. * @param category the category of the button area
  107. * @param rectangle the button area
  108. */
  109. void registerAutoCraftButtonArea(Identifier category, ButtonAreaSupplier rectangle);
  110. /**
  111. * Removes the auto crafting button
  112. *
  113. * @param category the category of the button
  114. */
  115. default void removeAutoCraftButton(Identifier category) {
  116. registerAutoCraftButtonArea(category, bounds -> null);
  117. }
  118. /**
  119. * Gets the map of all recipes visible to the player
  120. *
  121. * @return the map of recipes
  122. */
  123. Map<RecipeCategory<?>, List<RecipeDisplay>> getAllRecipes();
  124. List<RecipeDisplay> getAllRecipesFromCategory(RecipeCategory<?> category);
  125. /**
  126. * Registers a recipe visibility handler
  127. *
  128. * @param visibilityHandler the handler to be registered
  129. */
  130. void registerRecipeVisibilityHandler(DisplayVisibilityHandler visibilityHandler);
  131. /**
  132. * Unregisters a recipe visibility handler
  133. *
  134. * @param visibilityHandler the handler to be unregistered
  135. */
  136. void unregisterRecipeVisibilityHandler(DisplayVisibilityHandler visibilityHandler);
  137. /**
  138. * Gets an unmodifiable list of recipe visibility handlers
  139. *
  140. * @return the unmodifiable list of handlers
  141. */
  142. List<DisplayVisibilityHandler> getDisplayVisibilityHandlers();
  143. /**
  144. * Checks if the display is visible by asking recipe visibility handlers
  145. *
  146. * @param display the display to be checked
  147. * @param respectConfig whether it should respect the user's config
  148. * @return whether the display should be visible
  149. * @deprecated {@link RecipeHelper#isDisplayVisible(RecipeDisplay)} )}
  150. */
  151. @Deprecated
  152. boolean isDisplayVisible(RecipeDisplay display, boolean respectConfig);
  153. /**
  154. * Checks if the display is visible by asking recipe visibility handlers
  155. *
  156. * @param display the display to be checked
  157. * @return whether the display should be visible
  158. */
  159. boolean isDisplayVisible(RecipeDisplay display);
  160. <T extends Recipe<?>> void registerRecipes(Identifier category, Predicate<Recipe> recipeFilter, Function<T, RecipeDisplay> mappingFunction);
  161. /**
  162. * Registers a live recipe generator.
  163. *
  164. * @param liveRecipeGenerator the generator to register
  165. * @apiNote Still work in progress
  166. */
  167. void registerLiveRecipeGenerator(LiveRecipeGenerator<?> liveRecipeGenerator);
  168. void registerScreenClickArea(Rectangle rectangle, Class<? extends AbstractContainerScreen<?>> screenClass, Identifier... categories);
  169. <T extends Recipe<?>> void registerRecipes(Identifier category, Class<T> recipeClass, Function<T, RecipeDisplay> mappingFunction);
  170. <T extends Recipe<?>> void registerRecipes(Identifier category, Function<Recipe, Boolean> recipeFilter, Function<T, RecipeDisplay> mappingFunction);
  171. List<RecipeHelper.ScreenClickArea> getScreenClickAreas();
  172. boolean arePluginsLoading();
  173. interface ScreenClickArea {
  174. Class<? extends AbstractContainerScreen> getScreenClass();
  175. Rectangle getRectangle();
  176. Identifier[] getCategories();
  177. }
  178. }