|
@@ -16,11 +16,17 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
public class RecipeHelperImpl implements RecipeHelper {
|
|
|
|
|
|
+ private static final Comparator VISIBILITY_HANDLER_COMPARATOR = Comparator.comparingDouble(value -> {
|
|
|
+ if (value instanceof DisplayVisibilityHandler)
|
|
|
+ return (double) ((DisplayVisibilityHandler) value).getPriority();
|
|
|
+ return -Double.MAX_VALUE;
|
|
|
+ }).reversed();
|
|
|
private final AtomicInteger recipeCount = new AtomicInteger();
|
|
|
private final Map<Identifier, List<RecipeDisplay>> recipeCategoryListMap = Maps.newHashMap();
|
|
|
private final List<RecipeCategory> categories = Lists.newArrayList();
|
|
|
private final Map<Identifier, ButtonAreaSupplier> speedCraftAreaSupplierMap = Maps.newHashMap();
|
|
|
private final Map<Identifier, List<SpeedCraftFunctional>> speedCraftFunctionalMap = Maps.newHashMap();
|
|
|
+ private final List<DisplayVisibilityHandler> displayVisibilityHandlers = Lists.newArrayList();
|
|
|
private RecipeManager recipeManager;
|
|
|
|
|
|
@Override
|
|
@@ -81,8 +87,11 @@ public class RecipeHelperImpl implements RecipeHelper {
|
|
|
Map<RecipeCategory, List<RecipeDisplay>> recipeCategoryListMap = Maps.newLinkedHashMap();
|
|
|
categories.forEach(category -> {
|
|
|
if (categoriesMap.containsKey(category.getIdentifier()) && !categoriesMap.get(category.getIdentifier()).isEmpty())
|
|
|
- recipeCategoryListMap.put(category, categoriesMap.get(category.getIdentifier()).stream().filter(display -> category.canDisplay(display)).collect(Collectors.toList()));
|
|
|
+ recipeCategoryListMap.put(category, categoriesMap.get(category.getIdentifier()).stream().filter(display -> isDisplayVisible(display, true)).collect(Collectors.toList()));
|
|
|
});
|
|
|
+ for(RecipeCategory category : Lists.newArrayList(recipeCategoryListMap.keySet()))
|
|
|
+ if (recipeCategoryListMap.get(category).isEmpty())
|
|
|
+ recipeCategoryListMap.remove(category);
|
|
|
return recipeCategoryListMap;
|
|
|
}
|
|
|
|
|
@@ -119,8 +128,11 @@ public class RecipeHelperImpl implements RecipeHelper {
|
|
|
Map<RecipeCategory, List<RecipeDisplay>> recipeCategoryListMap = Maps.newLinkedHashMap();
|
|
|
categories.forEach(category -> {
|
|
|
if (categoriesMap.containsKey(category.getIdentifier()) && !categoriesMap.get(category.getIdentifier()).isEmpty())
|
|
|
- recipeCategoryListMap.put(category, categoriesMap.get(category.getIdentifier()).stream().filter(display -> category.canDisplay(display)).collect(Collectors.toList()));
|
|
|
+ recipeCategoryListMap.put(category, categoriesMap.get(category.getIdentifier()).stream().filter(display -> isDisplayVisible(display, true)).collect(Collectors.toList()));
|
|
|
});
|
|
|
+ for(RecipeCategory category : Lists.newArrayList(recipeCategoryListMap.keySet()))
|
|
|
+ if (recipeCategoryListMap.get(category).isEmpty())
|
|
|
+ recipeCategoryListMap.remove(category);
|
|
|
return recipeCategoryListMap;
|
|
|
}
|
|
|
|
|
@@ -132,7 +144,7 @@ public class RecipeHelperImpl implements RecipeHelper {
|
|
|
@Override
|
|
|
public Optional<ButtonAreaSupplier> getSpeedCraftButtonArea(RecipeCategory category) {
|
|
|
if (!speedCraftAreaSupplierMap.containsKey(category.getIdentifier()))
|
|
|
- return Optional.of(bounds -> new Rectangle((int) bounds.getMaxX() - 16, (int) bounds.getMaxY() - 16, 10, 10));
|
|
|
+ return Optional.empty();
|
|
|
return Optional.ofNullable(speedCraftAreaSupplierMap.get(category.getIdentifier()));
|
|
|
}
|
|
|
|
|
@@ -141,6 +153,11 @@ public class RecipeHelperImpl implements RecipeHelper {
|
|
|
speedCraftAreaSupplierMap.put(category, rectangle);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void registerDefaultSpeedCraftButtonArea(Identifier category) {
|
|
|
+ registerSpeedCraftButtonArea(category, bounds -> new Rectangle((int) bounds.getMaxX() - 16, (int) bounds.getMaxY() - 16, 10, 10));
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<SpeedCraftFunctional> getSpeedCraftFunctional(RecipeCategory category) {
|
|
|
if (speedCraftFunctionalMap.get(category.getIdentifier()) == null)
|
|
@@ -163,6 +180,8 @@ public class RecipeHelperImpl implements RecipeHelper {
|
|
|
this.categories.clear();
|
|
|
this.speedCraftAreaSupplierMap.clear();
|
|
|
this.speedCraftFunctionalMap.clear();
|
|
|
+ this.displayVisibilityHandlers.clear();
|
|
|
+
|
|
|
List<REIPlugin> plugins = new LinkedList<>(RoughlyEnoughItemsCore.getPlugins());
|
|
|
plugins.sort((first, second) -> {
|
|
|
return second.getPriority() - first.getPriority();
|
|
@@ -181,9 +200,23 @@ public class RecipeHelperImpl implements RecipeHelper {
|
|
|
plugin.registerPluginCategories(this);
|
|
|
if (pluginDisabler.isFunctionEnabled(identifier, PluginFunction.REGISTER_RECIPE_DISPLAYS))
|
|
|
plugin.registerRecipeDisplays(this);
|
|
|
- if (pluginDisabler.isFunctionEnabled(identifier, PluginFunction.REGISTER_SPEED_CRAFT))
|
|
|
+ if (RoughlyEnoughItemsCore.getConfigManager().getConfig().enableLegacySpeedCraftSupport && pluginDisabler.isFunctionEnabled(identifier, PluginFunction.REGISTER_SPEED_CRAFT))
|
|
|
plugin.registerSpeedCraft(this);
|
|
|
+ if (pluginDisabler.isFunctionEnabled(identifier, PluginFunction.REGISTER_OTHERS))
|
|
|
+ plugin.registerOthers(this);
|
|
|
});
|
|
|
+ if (getDisplayVisibilityHandlers().size() == 0)
|
|
|
+ registerRecipeVisibilityHandler(new DisplayVisibilityHandler() {
|
|
|
+ @Override
|
|
|
+ public DisplayVisibility handleDisplay(RecipeCategory category, RecipeDisplay display) {
|
|
|
+ return DisplayVisibility.ALWAYS_VISIBLE;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public float getPriority() {
|
|
|
+ return -1f;
|
|
|
+ }
|
|
|
+ });
|
|
|
RoughlyEnoughItemsCore.LOGGER.info("[REI] Registered Categories: " + String.join(", ", categories.stream().map(RecipeCategory::getCategoryName).collect(Collectors.toList())));
|
|
|
RoughlyEnoughItemsCore.LOGGER.info("[REI] Registered %d recipes.", recipeCount.get());
|
|
|
}
|
|
@@ -200,9 +233,43 @@ public class RecipeHelperImpl implements RecipeHelper {
|
|
|
recipeCategoryListMap.forEach((identifier, recipeDisplays) -> tempMap.put(identifier, new LinkedList<>(recipeDisplays)));
|
|
|
categories.forEach(category -> {
|
|
|
if (tempMap.containsKey(category.getIdentifier()))
|
|
|
- map.put(category, tempMap.get(category.getIdentifier()).stream().filter(display -> category.canDisplay(display)).collect(Collectors.toList()));
|
|
|
+ map.put(category, tempMap.get(category.getIdentifier()).stream().filter(display -> isDisplayVisible(display, true)).collect(Collectors.toList()));
|
|
|
});
|
|
|
+ for(RecipeCategory category : Lists.newArrayList(map.keySet()))
|
|
|
+ if (map.get(category).isEmpty())
|
|
|
+ map.remove(category);
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void registerRecipeVisibilityHandler(DisplayVisibilityHandler visibilityHandler) {
|
|
|
+ displayVisibilityHandlers.add(visibilityHandler);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void unregisterRecipeVisibilityHandler(DisplayVisibilityHandler visibilityHandler) {
|
|
|
+ displayVisibilityHandlers.remove(visibilityHandler);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<DisplayVisibilityHandler> getDisplayVisibilityHandlers() {
|
|
|
+ return Collections.unmodifiableList(displayVisibilityHandlers);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean isDisplayVisible(RecipeDisplay display, boolean respectConfig) {
|
|
|
+ RecipeCategory category = getCategory(display.getRecipeCategory());
|
|
|
+ List<DisplayVisibilityHandler> list = Lists.newArrayList(getDisplayVisibilityHandlers());
|
|
|
+ list.sort((o1, o2) -> VISIBILITY_HANDLER_COMPARATOR.compare(o1, o2));
|
|
|
+ for(DisplayVisibilityHandler displayVisibilityHandler : list) {
|
|
|
+ DisplayVisibility visibility = displayVisibilityHandler.handleDisplay(category, display);
|
|
|
+ if (visibility != DisplayVisibility.PASS) {
|
|
|
+ if (visibility == DisplayVisibility.CONFIG_OPTIONAL)
|
|
|
+ return RoughlyEnoughItemsCore.getConfigManager().getConfig().preferVisibleRecipes || !respectConfig;
|
|
|
+ return visibility == DisplayVisibility.ALWAYS_VISIBLE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
}
|