From 8e52dbf91539a4ebb1593cf995238e83c7aac932 Mon Sep 17 00:00:00 2001 From: IMarvinTPA Date: Wed, 9 Jun 2021 22:49:43 -0400 Subject: [PATCH 1/2] 2387 and 2385 Original Sort Order --- src/main/java/mezz/jei/config/ClientConfig.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/mezz/jei/config/ClientConfig.java b/src/main/java/mezz/jei/config/ClientConfig.java index 186ee78d1..ab328b64f 100644 --- a/src/main/java/mezz/jei/config/ClientConfig.java +++ b/src/main/java/mezz/jei/config/ClientConfig.java @@ -36,14 +36,14 @@ public final class ClientConfig implements IJEIConfig, IClientConfig { private final ConfigValues values; private List searchColors = Arrays.asList(ColorGetter.getColorDefaults()); public static final List ingredientSorterStagesDefault = Arrays.asList( + IngredientSortStage.MOD_NAME, + IngredientSortStage.INGREDIENT_TYPE, + IngredientSortStage.CREATIVE_MENU, + IngredientSortStage.ALPHABETICAL, IngredientSortStage.WEAPON_DAMAGE, IngredientSortStage.TOOL_TYPE, IngredientSortStage.ARMOR, - IngredientSortStage.TAG, - IngredientSortStage.ALPHABETICAL, - IngredientSortStage.MOD_NAME, - IngredientSortStage.INGREDIENT_TYPE, - IngredientSortStage.CREATIVE_MENU + IngredientSortStage.TAG ); private List ingredientSorterStages = ingredientSorterStagesDefault; From f4556e450ba7d49cc09952ceb2b1925ab162d9d0 Mon Sep 17 00:00:00 2001 From: IMarvinTPA Date: Wed, 9 Jun 2021 23:16:08 -0400 Subject: [PATCH 2/2] Add Sort Order to Config Screen. --- .../java/mezz/jei/config/ClientConfig.java | 114 +++++++++++++++++- .../jei/ingredients/IngredientFilter.java | 17 +-- src/main/resources/assets/jei/lang/en_au.json | 19 +++ src/main/resources/assets/jei/lang/en_us.json | 19 +++ 4 files changed, 161 insertions(+), 8 deletions(-) diff --git a/src/main/java/mezz/jei/config/ClientConfig.java b/src/main/java/mezz/jei/config/ClientConfig.java index ab328b64f..269177575 100644 --- a/src/main/java/mezz/jei/config/ClientConfig.java +++ b/src/main/java/mezz/jei/config/ClientConfig.java @@ -16,13 +16,17 @@ import org.apache.logging.log4j.Logger; import javax.annotation.Nullable; + +import java.util.ArrayList; import java.util.Arrays; +import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Objects; import java.util.Set; import java.util.function.Predicate; import java.util.stream.Collectors; +import java.util.stream.Stream; public final class ClientConfig implements IJEIConfig, IClientConfig { private static final Logger LOGGER = LogManager.getLogger(); @@ -43,10 +47,29 @@ public final class ClientConfig implements IJEIConfig, IClientConfig { IngredientSortStage.WEAPON_DAMAGE, IngredientSortStage.TOOL_TYPE, IngredientSortStage.ARMOR, - IngredientSortStage.TAG + IngredientSortStage.TAG, + IngredientSortStage.MAX_DURABILITY ); private List ingredientSorterStages = ingredientSorterStagesDefault; + private class StageSorterConfig { + public IngredientSortStage stage; + public int initialWeight; + public int requestedWeight; + + public StageSorterConfig(IngredientSortStage assignStage, int weight) { + stage = assignStage; + initialWeight = weight; + requestedWeight = weight; + } + public IngredientSortStage getStage() { return stage; } + public int getInitialWeight() { return initialWeight;} + public int getRequestedWeight() { return requestedWeight;} +} + + private List ingredientSorterWeights; + + // Forge config private final ForgeConfigSpec.BooleanValue debugModeEnabled; private final ForgeConfigSpec.BooleanValue centerSearchBarEnabled; @@ -143,6 +166,24 @@ public void buildSettingsGUI(ConfigGroup group) { values.maxRecipeGuiHeight = v; }, defaultVals.maxRecipeGuiHeight, 1, Integer.MAX_VALUE); + int order = 1; + if (ingredientSorterStages.size() != ingredientSorterStagesDefault.size()) + { + //We need all of them to appear because you can't add them. + //The new default has all of them. + ingredientSorterStages = ingredientSorterStagesDefault; + } + ingredientSorterWeights = new ArrayList(ingredientSorterStages.size()); + for (IngredientSortStage stage : ingredientSorterStages) { + ingredientSorterWeights.add(new StageSorterConfig(stage, order * 10)); + group.addInt(cfgTranslation("sort." + stage.name().toLowerCase()), order * 10, + v -> {setIngredientSorterStages(stage, v);}, + order * 10, + Integer.MIN_VALUE, + Integer.MAX_VALUE + ); + order++; + } } private String cfgTranslation(String name) { @@ -206,6 +247,77 @@ public List getIngredientSorterStages() { return ingredientSorterStages; } + public List getIngredientSorterDefaults() { + return ingredientSorterStagesDefault.stream() + .map(Enum::name) + .collect(Collectors.toList()); + + } + + public String getIngredientSorterDefaultString() { + return ingredientSorterStagesDefault.stream() + .map(Enum::name) + .collect(Collectors.joining(",")); + } + + public String getIngredientSorterStagesString() { + return String.join(",", ingredientSorterStagesCfg.get()); + //ingredientSorterStagesCfg.get().stream().collect(Collectors.joining(",")); + } + + public void setIngredientSorterStringStages(String stagesCSV) { + List stagesList = Stream.of(stagesCSV.split(",", -1)).map(s -> s.trim().toUpperCase()).collect(Collectors.toList()); + setIngredientSorterStringStages(stagesList); + } + + public void setIngredientSorterStringStages(List stagesList) { + ingredientSorterStagesCfg.set(stagesList); + this.ingredientSorterStages = ingredientSorterStagesCfg.get() + .stream() + .map(s -> EnumUtils.getEnum(IngredientSortStage.class, s)) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + if (ingredientSorterStages.isEmpty()) { + this.ingredientSorterStages = ingredientSorterStagesDefault; + } + Internal.getIngredientFilter().invalidateCache(); + } + + public void setIngredientSorterStages(List stagesList) { + this.ingredientSorterStages = stagesList; + if (ingredientSorterStages.isEmpty()) { + this.ingredientSorterStages = ingredientSorterStagesDefault; + } + List stagesStrings = ingredientSorterStages.stream() + .map(Enum::name) + .collect(Collectors.toList()); + this.ingredientSorterStagesCfg.set(stagesStrings); + Internal.getIngredientFilter().invalidateCache(); + } + + public void setIngredientSorterStages(IngredientSortStage setStage, int setWeight) { + boolean saveIt = false; + for (StageSorterConfig sorterWeight : ingredientSorterWeights) { + if (sorterWeight.stage == setStage) { + sorterWeight.requestedWeight = setWeight; + //We shouldn't try to save until we have updated the last one. + saveIt = (sorterWeight.initialWeight == (ingredientSorterStages.size() * 10)); + break; + } + } + + if (saveIt) { + Comparator requestedWeight = Comparator.comparing(StageSorterConfig::getRequestedWeight); + Comparator initalWeight = Comparator.comparing(StageSorterConfig::getInitialWeight); + + List stagesList = ingredientSorterWeights.stream() + .sorted(requestedWeight.thenComparing(initalWeight)) + .map(StageSorterConfig::getStage) + .collect(Collectors.toList()); + setIngredientSorterStages(stagesList); + } + } + private void syncSearchColorsConfig() { final ImmutableMap.Builder searchColorsMapBuilder = ImmutableMap.builder(); for (String entry : searchColors) { diff --git a/src/main/java/mezz/jei/ingredients/IngredientFilter.java b/src/main/java/mezz/jei/ingredients/IngredientFilter.java index 1d2c20ae4..ef73edf5c 100644 --- a/src/main/java/mezz/jei/ingredients/IngredientFilter.java +++ b/src/main/java/mezz/jei/ingredients/IngredientFilter.java @@ -210,17 +210,20 @@ public List> getIngredientListPreSort(Comparator> ingredientList = getIngredientListUncached(""); LoggedTimer filterTimer = new LoggedTimer(); - if (debugMode) { - filterTimer.start("Pre-Sorting."); - } + filterTimer.start("Pre-Sorting."); //Then we sort it. - List> fullSortedList = ingredientList.stream() + List> fullSortedList; + try { + fullSortedList = ingredientList.stream() .sorted(directComparator) .collect(Collectors.toList()); - if (debugMode) { - filterTimer.stop(); - LogManager.getLogger().info("Sort has " + ingredientList.size()); + } catch (Exception e) { + //Be even more defensive. + LogManager.getLogger().error("Error pre-sorting items.", e); + fullSortedList = ingredientList; } + filterTimer.stop(); + LogManager.getLogger().info("Sort has " + ingredientList.size()); return fullSortedList; } diff --git a/src/main/resources/assets/jei/lang/en_au.json b/src/main/resources/assets/jei/lang/en_au.json index a92040e2f..fb5df319c 100644 --- a/src/main/resources/assets/jei/lang/en_au.json +++ b/src/main/resources/assets/jei/lang/en_au.json @@ -89,6 +89,25 @@ "config.jei.advanced.giveMode": "Give Mode", "config.jei.advanced.giveMode.comment": "Choose if JEI should give items direct to the inventory (inventory) or pick them up with the mouse (mouse_pickup).", + "config.jei.advanced.sort.weapon_damage": "Weapon Sort Weight", + "config.jei.advanced.sort.weapon_damage.comment": "Set the sorter priority weight to prioritize how to sort the panel.", + "config.jei.advanced.sort.tool_type": "Tool Sort Weight", + "config.jei.advanced.sort.tool_type.comment": "Set the sorter priority weight to prioritize how to sort the panel.", + "config.jei.advanced.sort.armor": "Armor Sort Weight", + "config.jei.advanced.sort.armor.comment": "Set the sorter priority weight to prioritize how to sort the panel.", + "config.jei.advanced.sort.tag": "Item Tag Sort Weight", + "config.jei.advanced.sort.tab.comment": "Set the sorter priority weight to prioritize how to sort the panel.", + "config.jei.advanced.sort.alphabetical": "Alphabetical Sort Weight", + "config.jei.advanced.sort.alphabetical.comment": "Set the sorter priority weight to prioritize how to sort the panel.", + "config.jei.advanced.sort.mod_name": "Mod Name Sort Weight", + "config.jei.advanced.sort.mod_name.comment": "Set the sorter priority weight to prioritize how to sort the panel.", + "config.jei.advanced.sort.ingredient_type": "Item Java Type Sort Weight", + "config.jei.advanced.sort.ingredient_type.comment": "Set the sorter priority weight to prioritize how to sort the panel.", + "config.jei.advanced.sort.creative_menu": "Creative Panel Order Sort Weight", + "config.jei.advanced.sort.creative_menu.comment": "Set the sorter priority weight to prioritize how to sort the panel.", + "config.jei.advanced.sort.max_durability": "Maximum Durability Sort Weight", + "config.jei.advanced.sort.max_durability.comment": "Set the sorter priority weight to prioritize how to sort the panel.", + "_comment": "Hide Ingredients Mode", "gui.jei.editMode.description": "JEI Hide Ingredients Mode:", "gui.jei.editMode.description.hide": "%s-Click to Hide", diff --git a/src/main/resources/assets/jei/lang/en_us.json b/src/main/resources/assets/jei/lang/en_us.json index 2196a431b..bdeb561b2 100644 --- a/src/main/resources/assets/jei/lang/en_us.json +++ b/src/main/resources/assets/jei/lang/en_us.json @@ -101,6 +101,25 @@ "config.jei.advanced.maxRecipeGuiHeight.comment": "The maximum height of the recipe GUI.", "config.jei.advanced.giveMode": "Give Mode", "config.jei.advanced.giveMode.comment": "Choose if JEI should give ingredients direct to the inventory (inventory) or pick them up with the mouse (mouse_pickup).", + + "config.jei.advanced.sort.weapon_damage": "Weapon Sort Weight", + "config.jei.advanced.sort.weapon_damage.comment": "Set the sorter priority weight to prioritize how to sort the panel.", + "config.jei.advanced.sort.tool_type": "Tool Sort Weight", + "config.jei.advanced.sort.tool_type.comment": "Set the sorter priority weight to prioritize how to sort the panel.", + "config.jei.advanced.sort.armor": "Armor Sort Weight", + "config.jei.advanced.sort.armor.comment": "Set the sorter priority weight to prioritize how to sort the panel.", + "config.jei.advanced.sort.tag": "Item Tag Sort Weight", + "config.jei.advanced.sort.tab.comment": "Set the sorter priority weight to prioritize how to sort the panel.", + "config.jei.advanced.sort.alphabetical": "Alphabetical Sort Weight", + "config.jei.advanced.sort.alphabetical.comment": "Set the sorter priority weight to prioritize how to sort the panel.", + "config.jei.advanced.sort.mod_name": "Mod Name Sort Weight", + "config.jei.advanced.sort.mod_name.comment": "Set the sorter priority weight to prioritize how to sort the panel.", + "config.jei.advanced.sort.ingredient_type": "Item Java Type Sort Weight", + "config.jei.advanced.sort.ingredient_type.comment": "Set the sorter priority weight to prioritize how to sort the panel.", + "config.jei.advanced.sort.creative_menu": "Creative Panel Order Sort Weight", + "config.jei.advanced.sort.creative_menu.comment": "Set the sorter priority weight to prioritize how to sort the panel.", + "config.jei.advanced.sort.max_durability": "Maximum Durability Sort Weight", + "config.jei.advanced.sort.max_durability.comment": "Set the sorter priority weight to prioritize how to sort the panel.", "_comment": "Hide Ingredients Mode", "gui.jei.editMode.description": "JEI Hide Ingredients Mode:",