RecipeHelperImpl.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. /*
  2. * Roughly Enough Items by Danielshe.
  3. * Licensed under the MIT License.
  4. */
  5. package me.shedaniel.rei.impl;
  6. import com.google.common.collect.Lists;
  7. import com.google.common.collect.Maps;
  8. import com.google.common.collect.Sets;
  9. import me.shedaniel.math.api.Rectangle;
  10. import me.shedaniel.rei.RoughlyEnoughItemsCore;
  11. import me.shedaniel.rei.api.*;
  12. import me.shedaniel.rei.api.plugins.REIPluginV0;
  13. import me.shedaniel.rei.utils.CollectionUtils;
  14. import net.fabricmc.loader.api.FabricLoader;
  15. import net.fabricmc.loader.api.SemanticVersion;
  16. import net.fabricmc.loader.api.Version;
  17. import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen;
  18. import net.minecraft.recipe.Recipe;
  19. import net.minecraft.recipe.RecipeManager;
  20. import net.minecraft.util.ActionResult;
  21. import net.minecraft.util.Identifier;
  22. import org.jetbrains.annotations.ApiStatus;
  23. import java.util.*;
  24. import java.util.function.Function;
  25. import java.util.function.Predicate;
  26. import java.util.stream.Collectors;
  27. @ApiStatus.Internal
  28. public class RecipeHelperImpl implements RecipeHelper {
  29. private static final Comparator<DisplayVisibilityHandler> VISIBILITY_HANDLER_COMPARATOR;
  30. @SuppressWarnings("rawtypes")
  31. private static final Comparator<Recipe> RECIPE_COMPARATOR = Comparator.comparing((Recipe o) -> o.getId().getNamespace()).thenComparing(o -> o.getId().getPath());
  32. static {
  33. Comparator<DisplayVisibilityHandler> comparator = Comparator.comparingDouble(DisplayVisibilityHandler::getPriority);
  34. VISIBILITY_HANDLER_COMPARATOR = comparator.reversed();
  35. }
  36. private final List<AutoTransferHandler> autoTransferHandlers = Lists.newLinkedList();
  37. private final List<RecipeFunction> recipeFunctions = Lists.newLinkedList();
  38. private final List<ScreenClickArea> screenClickAreas = Lists.newLinkedList();
  39. private final int[] recipeCount = {0};
  40. private final Map<Identifier, List<RecipeDisplay>> recipeCategoryListMap = Maps.newLinkedHashMap();
  41. private final Map<RecipeCategory<?>, Identifier> categories = Maps.newLinkedHashMap();
  42. private final Map<Identifier, RecipeCategory<?>> reversedCategories = Maps.newHashMap();
  43. private final Map<Identifier, ButtonAreaSupplier> autoCraftAreaSupplierMap = Maps.newLinkedHashMap();
  44. private final Map<Identifier, List<List<EntryStack>>> categoryWorkingStations = Maps.newLinkedHashMap();
  45. private final List<DisplayVisibilityHandler> displayVisibilityHandlers = Lists.newLinkedList();
  46. private final List<LiveRecipeGenerator<RecipeDisplay>> liveRecipeGenerators = Lists.newLinkedList();
  47. private RecipeManager recipeManager;
  48. private boolean arePluginsLoading = false;
  49. @Override
  50. public List<EntryStack> findCraftableEntriesByItems(List<EntryStack> inventoryItems) {
  51. List<EntryStack> craftables = new ArrayList<>();
  52. for (List<RecipeDisplay> value : recipeCategoryListMap.values())
  53. for (RecipeDisplay recipeDisplay : value) {
  54. int slotsCraftable = 0;
  55. List<List<EntryStack>> requiredInput = recipeDisplay.getRequiredEntries();
  56. for (List<EntryStack> slot : requiredInput) {
  57. if (slot.isEmpty()) {
  58. slotsCraftable++;
  59. continue;
  60. }
  61. back:
  62. for (EntryStack possibleType : inventoryItems) {
  63. for (EntryStack slotPossible : slot)
  64. if (possibleType.equals(slotPossible)) {
  65. slotsCraftable++;
  66. break back;
  67. }
  68. }
  69. }
  70. if (slotsCraftable == recipeDisplay.getRequiredEntries().size())
  71. craftables.addAll(recipeDisplay.getOutputEntries());
  72. }
  73. return craftables.stream().distinct().collect(Collectors.toList());
  74. }
  75. @Override
  76. public boolean arePluginsLoading() {
  77. return arePluginsLoading;
  78. }
  79. @Override
  80. public void registerCategory(RecipeCategory<?> category) {
  81. categories.put(category, category.getIdentifier());
  82. reversedCategories.put(category.getIdentifier(), category);
  83. recipeCategoryListMap.put(category.getIdentifier(), Lists.newArrayList());
  84. categoryWorkingStations.put(category.getIdentifier(), Lists.newArrayList());
  85. }
  86. @SafeVarargs
  87. @Override
  88. public final void registerWorkingStations(Identifier category, List<EntryStack>... workingStations) {
  89. categoryWorkingStations.get(category).addAll(Arrays.asList(workingStations));
  90. }
  91. @Override
  92. public void registerWorkingStations(Identifier category, EntryStack... workingStations) {
  93. categoryWorkingStations.get(category).addAll(Arrays.stream(workingStations).map(Collections::singletonList).collect(Collectors.toList()));
  94. }
  95. @Override
  96. public List<List<EntryStack>> getWorkingStations(Identifier category) {
  97. return categoryWorkingStations.get(category);
  98. }
  99. @Override
  100. public void registerDisplay(Identifier categoryIdentifier, RecipeDisplay display) {
  101. if (!recipeCategoryListMap.containsKey(categoryIdentifier))
  102. return;
  103. recipeCount[0]++;
  104. recipeCategoryListMap.get(categoryIdentifier).add(display);
  105. }
  106. private void registerDisplay(Identifier categoryIdentifier, RecipeDisplay display, int index) {
  107. if (!recipeCategoryListMap.containsKey(categoryIdentifier))
  108. return;
  109. recipeCount[0]++;
  110. recipeCategoryListMap.get(categoryIdentifier).add(index, display);
  111. }
  112. @Override
  113. public Map<RecipeCategory<?>, List<RecipeDisplay>> getRecipesFor(EntryStack stack) {
  114. Map<RecipeCategory<?>, List<RecipeDisplay>> result = Maps.newLinkedHashMap();
  115. for (Map.Entry<RecipeCategory<?>, Identifier> entry : categories.entrySet()) {
  116. RecipeCategory<?> category = entry.getKey();
  117. Identifier categoryId = entry.getValue();
  118. Set<RecipeDisplay> set = Sets.newLinkedHashSet();
  119. for (RecipeDisplay display : recipeCategoryListMap.get(categoryId)) {
  120. for (EntryStack outputStack : display.getOutputEntries())
  121. if (stack.equals(outputStack) && isDisplayVisible(display)) {
  122. set.add(display);
  123. break;
  124. }
  125. }
  126. if (!set.isEmpty())
  127. CollectionUtils.getOrPutEmptyList(result, category).addAll(set);
  128. }
  129. for (LiveRecipeGenerator<RecipeDisplay> liveRecipeGenerator : liveRecipeGenerators) {
  130. RecipeCategory<?> category = getCategory(liveRecipeGenerator.getCategoryIdentifier());
  131. Optional<List<RecipeDisplay>> recipeFor = liveRecipeGenerator.getRecipeFor(stack);
  132. if (recipeFor.isPresent()) {
  133. Set<RecipeDisplay> set = Sets.newLinkedHashSet();
  134. for (RecipeDisplay display : recipeFor.get()) {
  135. if (isDisplayVisible(display))
  136. set.add(display);
  137. }
  138. if (!set.isEmpty())
  139. CollectionUtils.getOrPutEmptyList(result, category).addAll(set);
  140. }
  141. }
  142. return result;
  143. }
  144. @Override
  145. public RecipeCategory<?> getCategory(Identifier identifier) {
  146. return reversedCategories.get(identifier);
  147. }
  148. @Override
  149. public RecipeManager getRecipeManager() {
  150. return recipeManager;
  151. }
  152. private boolean isStackWorkStationOfCategory(Identifier category, EntryStack stack) {
  153. for (List<EntryStack> stacks : getWorkingStations(category)) {
  154. for (EntryStack entryStack : stacks) {
  155. if (entryStack.equalsIgnoreTagsAndAmount(stack))
  156. return true;
  157. }
  158. }
  159. return false;
  160. }
  161. @Override
  162. public Map<RecipeCategory<?>, List<RecipeDisplay>> getUsagesFor(EntryStack stack) {
  163. Map<RecipeCategory<?>, List<RecipeDisplay>> result = Maps.newLinkedHashMap();
  164. for (Map.Entry<RecipeCategory<?>, Identifier> entry : categories.entrySet()) {
  165. Set<RecipeDisplay> set = Sets.newLinkedHashSet();
  166. RecipeCategory<?> category = entry.getKey();
  167. Identifier categoryId = entry.getValue();
  168. for (RecipeDisplay display : recipeCategoryListMap.get(categoryId)) {
  169. back:
  170. for (List<EntryStack> input : display.getInputEntries()) {
  171. for (EntryStack otherEntry : input) {
  172. if (otherEntry.equals(stack)) {
  173. if (isDisplayVisible(display))
  174. set.add(display);
  175. break back;
  176. }
  177. }
  178. }
  179. }
  180. if (isStackWorkStationOfCategory(categoryId, stack)) {
  181. set.addAll(recipeCategoryListMap.get(categoryId));
  182. }
  183. if (!set.isEmpty())
  184. CollectionUtils.getOrPutEmptyList(result, category).addAll(set);
  185. }
  186. for (LiveRecipeGenerator<RecipeDisplay> liveRecipeGenerator : liveRecipeGenerators) {
  187. RecipeCategory<?> category = getCategory(liveRecipeGenerator.getCategoryIdentifier());
  188. Optional<List<RecipeDisplay>> recipeFor = liveRecipeGenerator.getUsageFor(stack);
  189. if (recipeFor.isPresent()) {
  190. Set<RecipeDisplay> set = Sets.newLinkedHashSet();
  191. for (RecipeDisplay display : recipeFor.get()) {
  192. if (isDisplayVisible(display))
  193. set.add(display);
  194. }
  195. if (!set.isEmpty())
  196. CollectionUtils.getOrPutEmptyList(result, category).addAll(set);
  197. }
  198. }
  199. return result;
  200. }
  201. @Override
  202. public List<RecipeCategory<?>> getAllCategories() {
  203. return Lists.newArrayList(categories.keySet());
  204. }
  205. @Override
  206. public Optional<ButtonAreaSupplier> getAutoCraftButtonArea(RecipeCategory<?> category) {
  207. if (!autoCraftAreaSupplierMap.containsKey(category.getIdentifier()))
  208. return Optional.ofNullable(bounds -> new Rectangle(bounds.getMaxX() - 16, bounds.getMaxY() - 16, 10, 10));
  209. return Optional.ofNullable(autoCraftAreaSupplierMap.get(category.getIdentifier()));
  210. }
  211. @Override
  212. public void registerAutoCraftButtonArea(Identifier category, ButtonAreaSupplier rectangle) {
  213. if (rectangle == null) {
  214. autoCraftAreaSupplierMap.remove(category);
  215. } else
  216. autoCraftAreaSupplierMap.put(category, rectangle);
  217. }
  218. public void recipesLoaded(RecipeManager recipeManager) {
  219. long startTime = System.currentTimeMillis();
  220. arePluginsLoading = true;
  221. ScreenHelper.clearData();
  222. recipeCount[0] = 0;
  223. this.recipeManager = recipeManager;
  224. this.recipeCategoryListMap.clear();
  225. this.categories.clear();
  226. this.reversedCategories.clear();
  227. this.autoCraftAreaSupplierMap.clear();
  228. this.screenClickAreas.clear();
  229. this.categoryWorkingStations.clear();
  230. this.recipeFunctions.clear();
  231. this.displayVisibilityHandlers.clear();
  232. this.liveRecipeGenerators.clear();
  233. this.autoTransferHandlers.clear();
  234. ((DisplayHelperImpl) DisplayHelper.getInstance()).resetData();
  235. ((DisplayHelperImpl) DisplayHelper.getInstance()).resetCache();
  236. BaseBoundsHandler baseBoundsHandler = new BaseBoundsHandlerImpl();
  237. DisplayHelper.getInstance().registerBoundsHandler(baseBoundsHandler);
  238. ((DisplayHelperImpl) DisplayHelper.getInstance()).setBaseBoundsHandler(baseBoundsHandler);
  239. List<REIPluginEntry> plugins = RoughlyEnoughItemsCore.getPlugins();
  240. plugins.sort(Comparator.comparingInt(REIPluginEntry::getPriority).reversed());
  241. RoughlyEnoughItemsCore.LOGGER.info("[REI] Loading %d plugins: %s", plugins.size(), plugins.stream().map(REIPluginEntry::getPluginIdentifier).map(Identifier::toString).collect(Collectors.joining(", ")));
  242. Collections.reverse(plugins);
  243. ((EntryRegistryImpl) EntryRegistry.getInstance()).reset();
  244. @SuppressWarnings("OptionalGetWithoutIsPresent")
  245. Version reiVersion = FabricLoader.getInstance().getModContainer("roughlyenoughitems").get().getMetadata().getVersion();
  246. if (!(reiVersion instanceof SemanticVersion))
  247. RoughlyEnoughItemsCore.LOGGER.warn("[REI] Roughly Enough Items is not using semantic versioning, will be ignoring plugins' minimum versions!");
  248. List<REIPluginV0> reiPluginV0s = new ArrayList<>();
  249. for (REIPluginEntry plugin : plugins) {
  250. try {
  251. if (reiVersion instanceof SemanticVersion)
  252. if (plugin.getMinimumVersion() == null) {
  253. RoughlyEnoughItemsCore.LOGGER.warn("[REI] Plugin " + plugin.getPluginIdentifier().toString() + " did not provide a minimum version, skipping version check!");
  254. } else if (plugin.getMinimumVersion().compareTo((SemanticVersion) reiVersion) > 0) {
  255. throw new IllegalStateException("Requires " + plugin.getMinimumVersion().getFriendlyString() + " version of REI!");
  256. }
  257. if (plugin instanceof REIPluginV0) {
  258. ((REIPluginV0) plugin).preRegister();
  259. reiPluginV0s.add((REIPluginV0) plugin);
  260. }
  261. } catch (Throwable e) {
  262. RoughlyEnoughItemsCore.LOGGER.error("[REI] " + plugin.getPluginIdentifier().toString() + " plugin failed to pre register!", e);
  263. }
  264. }
  265. for (REIPluginV0 plugin : reiPluginV0s) {
  266. Identifier identifier = plugin.getPluginIdentifier();
  267. try {
  268. plugin.registerBounds(DisplayHelper.getInstance());
  269. plugin.registerEntries(EntryRegistry.getInstance());
  270. plugin.registerPluginCategories(this);
  271. plugin.registerRecipeDisplays(this);
  272. plugin.registerOthers(this);
  273. } catch (Throwable e) {
  274. RoughlyEnoughItemsCore.LOGGER.error("[REI] " + identifier.toString() + " plugin failed to load!", e);
  275. }
  276. }
  277. for (REIPluginV0 plugin : reiPluginV0s) {
  278. Identifier identifier = plugin.getPluginIdentifier();
  279. try {
  280. plugin.postRegister();
  281. } catch (Throwable e) {
  282. RoughlyEnoughItemsCore.LOGGER.error("[REI] " + identifier.toString() + " plugin failed to post register!", e);
  283. }
  284. }
  285. if (!recipeFunctions.isEmpty()) {
  286. @SuppressWarnings("rawtypes") List<Recipe> allSortedRecipes = getAllSortedRecipes();
  287. Collections.reverse(allSortedRecipes);
  288. for (RecipeFunction recipeFunction : recipeFunctions) {
  289. try {
  290. for (Recipe<?> recipe : CollectionUtils.filter(allSortedRecipes, recipe -> recipeFunction.recipeFilter.test(recipe))) {
  291. registerDisplay(recipeFunction.category, (RecipeDisplay) recipeFunction.mappingFunction.apply(recipe), 0);
  292. }
  293. } catch (Exception e) {
  294. RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to add recipes!", e);
  295. }
  296. }
  297. }
  298. if (getDisplayVisibilityHandlers().isEmpty())
  299. registerRecipeVisibilityHandler(new DisplayVisibilityHandler() {
  300. @Override
  301. public ActionResult handleDisplay(RecipeCategory<?> category, RecipeDisplay display) {
  302. return ActionResult.SUCCESS;
  303. }
  304. @Override
  305. public float getPriority() {
  306. return -1f;
  307. }
  308. });
  309. // Clear Cache
  310. ((DisplayHelperImpl) DisplayHelper.getInstance()).resetCache();
  311. ScreenHelper.getOptionalOverlay().ifPresent(overlay -> overlay.shouldReInit = true);
  312. arePluginsLoading = false;
  313. // Remove duplicate entries
  314. ((EntryRegistryImpl) EntryRegistry.getInstance()).distinct();
  315. // Clear Cache Again!
  316. ((DisplayHelperImpl) DisplayHelper.getInstance()).resetCache();
  317. ScreenHelper.getOptionalOverlay().ifPresent(overlay -> overlay.shouldReInit = true);
  318. displayVisibilityHandlers.sort(VISIBILITY_HANDLER_COMPARATOR);
  319. long usedTime = System.currentTimeMillis() - startTime;
  320. RoughlyEnoughItemsCore.LOGGER.info("[REI] Registered %d stack entries, %d recipes displays, %d exclusion zones suppliers, %d bounds handler, %d visibility handlers and %d categories (%s) in %d ms.", EntryRegistry.getInstance().getStacksList().size(), recipeCount[0], DisplayHelper.getInstance().getBaseBoundsHandler().supplierSize(), DisplayHelper.getInstance().getAllBoundsHandlers().size(), getDisplayVisibilityHandlers().size(), categories.size(), categories.keySet().stream().map(RecipeCategory::getCategoryName).collect(Collectors.joining(", ")), usedTime);
  321. }
  322. @Override
  323. public AutoTransferHandler registerAutoCraftingHandler(AutoTransferHandler handler) {
  324. autoTransferHandlers.add(handler);
  325. return handler;
  326. }
  327. @Override
  328. public List<AutoTransferHandler> getSortedAutoCraftingHandler() {
  329. return autoTransferHandlers.stream().sorted(Comparator.comparingDouble(AutoTransferHandler::getPriority).reversed()).collect(Collectors.toList());
  330. }
  331. @Override
  332. public int getRecipeCount() {
  333. return recipeCount[0];
  334. }
  335. @Override
  336. @SuppressWarnings("rawtypes")
  337. public List<Recipe> getAllSortedRecipes() {
  338. return getRecipeManager().values().stream().sorted(RECIPE_COMPARATOR).collect(Collectors.toList());
  339. }
  340. @Override
  341. public Map<RecipeCategory<?>, List<RecipeDisplay>> getAllRecipes() {
  342. Map<RecipeCategory<?>, List<RecipeDisplay>> result = Maps.newLinkedHashMap();
  343. for (Map.Entry<RecipeCategory<?>, Identifier> entry : categories.entrySet()) {
  344. RecipeCategory<?> category = entry.getKey();
  345. Identifier categoryId = entry.getValue();
  346. List<RecipeDisplay> displays = recipeCategoryListMap.get(categoryId);
  347. if (displays != null) {
  348. displays.removeIf(this::isDisplayNotVisible);
  349. if (!displays.isEmpty())
  350. result.put(category, Lists.newArrayList(displays));
  351. }
  352. }
  353. return result;
  354. }
  355. @Override
  356. public List<RecipeDisplay> getAllRecipesFromCategory(RecipeCategory<?> category) {
  357. return recipeCategoryListMap.get(category.getIdentifier());
  358. }
  359. @Override
  360. public void registerRecipeVisibilityHandler(DisplayVisibilityHandler visibilityHandler) {
  361. displayVisibilityHandlers.add(visibilityHandler);
  362. }
  363. @Override
  364. public void unregisterRecipeVisibilityHandler(DisplayVisibilityHandler visibilityHandler) {
  365. displayVisibilityHandlers.remove(visibilityHandler);
  366. }
  367. @Override
  368. public List<DisplayVisibilityHandler> getDisplayVisibilityHandlers() {
  369. return Collections.unmodifiableList(displayVisibilityHandlers);
  370. }
  371. @Override
  372. public boolean isDisplayNotVisible(RecipeDisplay display) {
  373. return !isDisplayVisible(display);
  374. }
  375. @Override
  376. public boolean isDisplayVisible(RecipeDisplay display) {
  377. RecipeCategory<?> category = getCategory(display.getRecipeCategory());
  378. try {
  379. for (DisplayVisibilityHandler displayVisibilityHandler : displayVisibilityHandlers) {
  380. ActionResult visibility = displayVisibilityHandler.handleDisplay(category, display);
  381. if (visibility != ActionResult.PASS)
  382. return visibility == ActionResult.SUCCESS;
  383. }
  384. } catch (Throwable throwable) {
  385. RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to check if the recipe is visible!", throwable);
  386. }
  387. return true;
  388. }
  389. @Override
  390. public void registerScreenClickArea(Rectangle rectangle, Class<? extends AbstractContainerScreen<?>> screenClass, Identifier... categories) {
  391. this.screenClickAreas.add(new ScreenClickAreaImpl(screenClass, rectangle, categories));
  392. }
  393. @Override
  394. public <T extends Recipe<?>> void registerRecipes(Identifier category, Class<T> recipeClass, Function<T, RecipeDisplay> mappingFunction) {
  395. recipeFunctions.add(new RecipeFunction(category, recipe -> recipeClass.isAssignableFrom(recipe.getClass()), mappingFunction));
  396. }
  397. @Override
  398. public <T extends Recipe<?>> void registerRecipes(Identifier category,
  399. @SuppressWarnings("rawtypes") Function<Recipe, Boolean> recipeFilter, Function<T, RecipeDisplay> mappingFunction) {
  400. recipeFunctions.add(new RecipeFunction(category, recipeFilter::apply, mappingFunction));
  401. }
  402. @Override
  403. public <T extends Recipe<?>> void registerRecipes(Identifier category,
  404. @SuppressWarnings("rawtypes") Predicate<Recipe> recipeFilter, Function<T, RecipeDisplay> mappingFunction) {
  405. recipeFunctions.add(new RecipeFunction(category, recipeFilter, mappingFunction));
  406. }
  407. @Override
  408. public void registerLiveRecipeGenerator(LiveRecipeGenerator<?> liveRecipeGenerator) {
  409. liveRecipeGenerators.add((LiveRecipeGenerator<RecipeDisplay>) liveRecipeGenerator);
  410. }
  411. @Override
  412. public List<ScreenClickArea> getScreenClickAreas() {
  413. return screenClickAreas;
  414. }
  415. private static class ScreenClickAreaImpl implements ScreenClickArea {
  416. Class<? extends AbstractContainerScreen<?>> screenClass;
  417. Rectangle rectangle;
  418. Identifier[] categories;
  419. private ScreenClickAreaImpl(Class<? extends AbstractContainerScreen<?>> screenClass, Rectangle rectangle, Identifier[] categories) {
  420. this.screenClass = screenClass;
  421. this.rectangle = rectangle;
  422. this.categories = categories;
  423. }
  424. public Class<? extends AbstractContainerScreen<?>> getScreenClass() {
  425. return screenClass;
  426. }
  427. public Rectangle getRectangle() {
  428. return rectangle;
  429. }
  430. public Identifier[] getCategories() {
  431. return categories;
  432. }
  433. }
  434. @SuppressWarnings("rawtypes")
  435. private static class RecipeFunction {
  436. Identifier category;
  437. Predicate<Recipe> recipeFilter;
  438. Function mappingFunction;
  439. public RecipeFunction(Identifier category, Predicate<Recipe> recipeFilter, Function<?, RecipeDisplay> mappingFunction) {
  440. this.category = category;
  441. this.recipeFilter = recipeFilter;
  442. this.mappingFunction = mappingFunction;
  443. }
  444. }
  445. }