Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inventory Tweaks Tree sorting 1.16 #2380

Open
wants to merge 17 commits into
base: 1.16
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ changelog.html
*.launch
/**/build/
/**/logs
/.vscode/*
1 change: 1 addition & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
The MIT License (MIT)

Copyright (c) 2014-2015 mezz
Copyright (c) 2011-2013 Marwane Kalam-Alami (Inventory Tree code from Inventory Tweaks.)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
76 changes: 76 additions & 0 deletions src/api/java/mezz/jei/api/ingredients/tree/IItemTree.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2013 Andrew Crocker
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package mezz.jei.api.ingredients.tree;

import net.minecraft.nbt.CompoundNBT;

import java.util.Collection;
import java.util.List;
import java.util.Random;

@SuppressWarnings("unused")
public interface IItemTree {
void registerOre(String category, String name, String oreName, int order, String path);

boolean matches(List<IItemTreeItem> items, String keyword);

boolean isKeywordValid(String keyword);

Collection<IItemTreeCategory> getAllCategories();

IItemTreeCategory getRootCategory();

void setRootCategory(IItemTreeCategory category);

IItemTreeCategory getCategory(String keyword);

boolean isItemUnknown(String id, int damage);

List<IItemTreeItem> getItems(String id, int damage, CompoundNBT extra);

List<IItemTreeItem> getItems(String id, int damage);

List<IItemTreeItem> getItems(String name);

IItemTreeItem getRandomItem(Random r);

boolean containsItem(String name);

boolean containsCategory(String name);

IItemTreeCategory addCategory(String parentCategory, String newCategory) throws NullPointerException;

void addCategory(String parentCategory, IItemTreeCategory newCategory) throws NullPointerException;

IItemTreeItem addItem(String parentCategory, String name, String id, int damage, int order)
throws NullPointerException;

IItemTreeItem addItem(String parentCategory, String name, String id, int damage, CompoundNBT extra, int order)
throws NullPointerException;

void addItem(String parentCategory, IItemTreeItem newItem) throws NullPointerException;

int getKeywordDepth(String keyword);

int getKeywordOrder(String keyword);
}
49 changes: 49 additions & 0 deletions src/api/java/mezz/jei/api/ingredients/tree/IItemTreeCategory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2013 Andrew Crocker
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package mezz.jei.api.ingredients.tree;

import java.util.Collection;
import java.util.List;

@SuppressWarnings("unused")
public interface IItemTreeCategory {
boolean contains(IItemTreeItem item);

void addCategory(IItemTreeCategory category);

void addItem(IItemTreeItem item);

Collection<IItemTreeCategory> getSubCategories();

Collection<List<IItemTreeItem>> getItems();

String getName();

int getCategoryOrder();

int findCategoryOrder(String keyword);

int findKeywordDepth(String keyword);

public String findKeywordPath(String keyword);
}
40 changes: 40 additions & 0 deletions src/api/java/mezz/jei/api/ingredients/tree/IItemTreeItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2013 Andrew Crocker
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package mezz.jei.api.ingredients.tree;

import net.minecraft.nbt.CompoundNBT;

@SuppressWarnings("unused")
public interface IItemTreeItem extends Comparable<IItemTreeItem> {
String getName();

String getId();

int getDamage();

CompoundNBT getExtraData();

int getOrder();

public String getPath();
}
30 changes: 30 additions & 0 deletions src/api/java/mezz/jei/api/ingredients/tree/IItemTreeListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2013 Andrew Crocker
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package mezz.jei.api.ingredients.tree;

import java.util.EventListener;

@SuppressWarnings("unused")
public interface IItemTreeListener extends EventListener {
void onTreeLoaded(IItemTree tree);
}
116 changes: 111 additions & 5 deletions src/main/java/mezz/jei/config/ClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
import org.apache.logging.log4j.Logger;

import javax.annotation.Nullable;

import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
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();
Expand All @@ -38,16 +41,19 @@ public final class ClientConfig implements IJEIConfig, IClientConfig {

private static final GiveMode defaultGiveMode = GiveMode.MOUSE_PICKUP;
private static final boolean defaultCenterSearchBar = false;
private static final boolean defaultUseJeiTreeFile = false;

public static final List<IngredientSortStage> ingredientSorterStagesDefault = Arrays.asList(
IngredientSortStage.MOD_NAME,
IngredientSortStage.INGREDIENT_TYPE,
IngredientSortStage.CREATIVE_MENU,
IngredientSortStage.ALPHABETICAL,
IngredientSortStage.ITEM_TREE,
IngredientSortStage.WEAPON_DAMAGE,
IngredientSortStage.TOOL_TYPE,
IngredientSortStage.ARMOR,
IngredientSortStage.TAG
IngredientSortStage.TAG,
IngredientSortStage.ALPHABETICAL,
IngredientSortStage.MOD_NAME,
IngredientSortStage.INGREDIENT_TYPE,
IngredientSortStage.CREATIVE_MENU,
IngredientSortStage.MAX_DURABILITY
);
private List<IngredientSortStage> ingredientSorterStages = ingredientSorterStagesDefault;

Expand All @@ -62,6 +68,26 @@ public final class ClientConfig implements IJEIConfig, IClientConfig {
private final ForgeConfigSpec.IntValue maxRecipeGuiHeight;
private final ForgeConfigSpec.ConfigValue<List<? extends String>> searchColorsCfg;
private final ForgeConfigSpec.ConfigValue<List<? extends String>> ingredientSorterStagesCfg;
private final ForgeConfigSpec.BooleanValue useJeiTreeFile;

private class StageSorterConfig {
public IngredientSortStage stage;
public int initialWeight;
public int requestedWeight;
public int sortingWeight;

public StageSorterConfig(IngredientSortStage assignStage, int weight) {
stage = assignStage;
initialWeight = weight;
requestedWeight = weight;
sortingWeight = weight;
}
public IngredientSortStage getStage() { return stage; }
public int getInitialWeight() { return initialWeight;}
public int getRequestedWeight() { return requestedWeight;}
}

private List<StageSorterConfig> ingredientSorterWeights;

public ClientConfig(ForgeConfigSpec.Builder builder) {
instance = this;
Expand Down Expand Up @@ -109,6 +135,9 @@ public ClientConfig(ForgeConfigSpec.Builder builder) {
.collect(Collectors.toList());
Predicate<Object> elementValidator = validEnumElement(IngredientSortStage.class);
ingredientSorterStagesCfg = builder.defineList("IngredientSortStages", defaults, elementValidator);

builder.comment("Force the use of the JEI InvTweaksTree.txt file vs try Inventory Tweaks's file.");
useJeiTreeFile = builder.define("JeiSortTree", defaultUseJeiTreeFile);
}
builder.pop();
}
Expand Down Expand Up @@ -183,6 +212,83 @@ public List<IngredientSortStage> getIngredientSorterStages() {
return ingredientSorterStages;
}

public List<String> 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<String> stagesList = Stream.of(stagesCSV.split(",", -1)).map(s -> s.trim().toUpperCase()).collect(Collectors.toList());
setIngredientSorterStringStages(stagesList);
}

public void setIngredientSorterStringStages(List<String> 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<IngredientSortStage> stagesList) {
this.ingredientSorterStages = stagesList;
if (ingredientSorterStages.isEmpty()) {
this.ingredientSorterStages = ingredientSorterStagesDefault;
}
List<String> 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<StageSorterConfig> requestedWeight = Comparator.comparing(StageSorterConfig::getRequestedWeight);
Comparator<StageSorterConfig> initalWeight = Comparator.comparing(StageSorterConfig::getInitialWeight);

List<IngredientSortStage> stagesList = ingredientSorterWeights.stream()
.sorted(requestedWeight.thenComparing(initalWeight))
.map(StageSorterConfig::getStage)
.collect(Collectors.toList());
setIngredientSorterStages(stagesList);
}
}


@Override
public boolean getUseJeiTreeFile() {
return useJeiTreeFile.get();
}

private void syncSearchColorsConfig() {
final ImmutableMap.Builder<Integer, String> searchColorsMapBuilder = ImmutableMap.builder();
List<? extends String> searchColors = searchColorsCfg.get();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/mezz/jei/config/IClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ public interface IClientConfig {
int getMaxRecipeGuiHeight();

List<IngredientSortStage> getIngredientSorterStages();

boolean getUseJeiTreeFile();
}
Loading