Skip to content

Commit

Permalink
Separate ToolCategoryRegistry#get() branches for readability, use Obj…
Browse files Browse the repository at this point in the history
…ect#equals() to compare NBT values to better support nullable inputs

Previous conditions would only check for NBT if it was defined by the category meaning categories without NBT would get ignored if they had a lower priority. Using Object#equals() will now allow non-NBT-declaring, low priority categories to be considered if all other categories are not applicable, as is the expected result
  • Loading branch information
2008Choco committed Aug 25, 2023
1 parent c6f2f02 commit 7d92e19
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;

import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -47,8 +48,21 @@ public VeinMinerToolCategory get(@NotNull String id) {
private VeinMinerToolCategory get(@NotNull ItemType itemType, @Nullable String itemNbtValue, @NotNull Predicate<VeinMinerToolCategory> categoryPredicate) {
VeinMinerToolCategory resultCategory = null;
for (VeinMinerToolCategory category : categories.values()) {
if (!category.containsItem(itemType)) {
continue;
}

String nbtValue = category.getNBTValue();
if (category.containsItem(itemType) && (nbtValue == null || nbtValue.equals(itemNbtValue)) && (resultCategory == null || category.compareTo(resultCategory) > 1) && categoryPredicate.test(category)) {
if (!Objects.equals(nbtValue, itemNbtValue)) {
continue;
}

// If the category's priority is lower than the currently returnable category, ignore it
if (resultCategory != null && category.compareTo(category) <= 0) {
continue;
}

if (categoryPredicate.test(category)) {
resultCategory = category;
}
}
Expand Down

0 comments on commit 7d92e19

Please sign in to comment.