Skip to content

Commit

Permalink
Adds new CUTS sorting option for Jewels to allow getting these cut …
Browse files Browse the repository at this point in the history
…jewels in top.
  • Loading branch information
BONNe committed Jul 31, 2024
1 parent 0aa56c2 commit 98d0edb
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ sophisticated_backpacks_version=4637292
# The version of Sophisticated Backpacks Mod
storage_network_version=3868680
# The mod version. See https://semver.org/
mod_version=2.5.0
mod_version=2.5.1
# The change Log
changelog=Check changelog in CurseForge page.
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,26 @@ else if (leftId == ModItems.JEWEL.getRegistryName())
return switch (sortOrder) {
case NAME -> SortingHelper.compareJewels(leftName,
leftData,
leftTag.getInt("freeCuts"),
rightName,
rightData,
rightTag.getInt("freeCuts"),
VaultJewelSorting.CONFIGURATION.getJewelSortingByName(),
ascending);
case AMOUNT -> SortingHelper.compareJewels(leftName,
leftData,
leftTag.getInt("freeCuts"),
rightName,
rightData,
rightTag.getInt("freeCuts"),
VaultJewelSorting.CONFIGURATION.getJewelSortingByAmount(),
ascending);
case MOD -> SortingHelper.compareJewels(leftName,
leftData,
leftTag.getInt("freeCuts"),
rightName,
rightData,
rightTag.getInt("freeCuts"),
VaultJewelSorting.CONFIGURATION.getJewelSortingByMod(),
ascending);
};
Expand All @@ -139,20 +145,26 @@ else if (leftId == ModItems.JEWEL.getRegistryName())
return switch (sortOrder) {
case NAME -> SortingHelper.compareJewels(leftName,
leftTag.getCompound("clientCache"),
leftTag.getInt("freeCuts"),
rightName,
rightTag.getCompound("clientCache"),
rightTag.getInt("freeCuts"),
VaultJewelSorting.CONFIGURATION.getJewelSortingByName(),
ascending);
case AMOUNT -> SortingHelper.compareJewels(leftName,
leftTag.getCompound("clientCache"),
leftTag.getInt("freeCuts"),
rightName,
rightTag.getCompound("clientCache"),
rightTag.getInt("freeCuts"),
VaultJewelSorting.CONFIGURATION.getJewelSortingByAmount(),
ascending);
case MOD -> SortingHelper.compareJewels(leftName,
leftTag.getCompound("clientCache"),
leftTag.getInt("freeCuts"),
rightName,
rightTag.getCompound("clientCache"),
rightTag.getInt("freeCuts"),
VaultJewelSorting.CONFIGURATION.getJewelSortingByMod(),
ascending);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,28 @@ public Configuration()

this.jewelSortingByName = builder.
comment("The order of Jewels if they are sorted by the name.").
comment("Supported Values: NAME, ATTRIBUTE, ATTRIBUTE_VALUE, SIZE, LEVEL, ATTRIBUTE_WEIGHT").
comment("Supported Values: NAME, ATTRIBUTE, ATTRIBUTE_VALUE, SIZE, LEVEL, ATTRIBUTE_WEIGHT, CUTS").
defineList("jewel_sorting_by_name",
Arrays.asList(SortingHelper.JewelOptions.NAME.name(),
SortingHelper.JewelOptions.ATTRIBUTE.name(),
SortingHelper.JewelOptions.ATTRIBUTE_VALUE.name(),
SortingHelper.JewelOptions.SIZE.name(),
SortingHelper.JewelOptions.LEVEL.name()),
SortingHelper.JewelOptions.LEVEL.name(),
SortingHelper.JewelOptions.CUTS.name()),
entry -> entry instanceof String value &&
Enums.getIfPresent(SortingHelper.JewelOptions.class, value.toUpperCase()).isPresent());

this.jewelSortingByAmount = builder.
comment("The order of Jewels if they are sorted by the amount/size.").
comment("Supported Values: NAME, ATTRIBUTE, ATTRIBUTE_VALUE, SIZE, LEVEL, ATTRIBUTE_WEIGHT").
comment("Supported Values: NAME, ATTRIBUTE, ATTRIBUTE_VALUE, SIZE, LEVEL, ATTRIBUTE_WEIGHT, CUTS").
defineList("jewel_sorting_by_amount",
Collections.emptyList(),
entry -> entry instanceof String value &&
Enums.getIfPresent(SortingHelper.JewelOptions.class, value.toUpperCase()).isPresent());

this.jewelSortingByMod = builder.
comment("The order of Jewels if they are sorted by the mod.").
comment("Supported Values: NAME, ATTRIBUTE, ATTRIBUTE_VALUE, SIZE, LEVEL, ATTRIBUTE_WEIGHT").
comment("Supported Values: NAME, ATTRIBUTE, ATTRIBUTE_VALUE, SIZE, LEVEL, ATTRIBUTE_WEIGHT, CUTS").
defineList("jewel_sorting_by_mod",
Collections.emptyList(),
entry -> entry instanceof String value &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,26 @@ private static int compareItems(ItemStack firstItem,
return switch (instance) {
case NAME -> SortingHelper.compareJewels(leftName,
leftData,
firstItem.getOrCreateTag().getInt("freeCuts"),
rightName,
rightData,
secondItem.getOrCreateTag().getInt("freeCuts"),
VaultJewelSorting.CONFIGURATION.getJewelSortingByName(),
ascending);
case SIZE -> SortingHelper.compareJewels(leftName,
leftData,
firstItem.getOrCreateTag().getInt("freeCuts"),
rightName,
rightData,
secondItem.getOrCreateTag().getInt("freeCuts"),
VaultJewelSorting.CONFIGURATION.getJewelSortingByAmount(),
ascending);
case MOD -> SortingHelper.compareJewels(leftName,
leftData,
firstItem.getOrCreateTag().getInt("freeCuts"),
rightName,
rightData,
secondItem.getOrCreateTag().getInt("freeCuts"),
VaultJewelSorting.CONFIGURATION.getJewelSortingByMod(),
ascending);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ private static void stackCompare(ItemStack stack1, ItemStack stack2, CallbackInf
callbackInfoReturnable.setReturnValue(
SortingHelper.compareJewels(stack1.getDisplayName().getString(),
VaultGearData.read(stack1),
stack1.getOrCreateTag().getInt("freeCuts"),
stack2.getDisplayName().getString(),
VaultGearData.read(stack2),
stack2.getOrCreateTag().getInt("freeCuts"),
VaultJewelSorting.CONFIGURATION.getJewelSortingByName(),
true));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ else if (leftStack.getItem() == ModItems.JEWEL)

callbackInfoReturnable.setReturnValue(SortingHelper.compareJewels(left.getName(),
GearDataCache.of(leftStack),
leftStack.getOrCreateTag().getInt("freeCuts"),
right.getName(),
GearDataCache.of(rightStack),
rightStack.getOrCreateTag().getInt("freeCuts"),
VaultJewelSorting.CONFIGURATION.getJewelSortingByMod(),
sortingDirection == SortingDirection.ASCENDING));
callbackInfoReturnable.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ else if (leftStack.getItem() == ModItems.JEWEL)

callbackInfoReturnable.setReturnValue(SortingHelper.compareJewels(left.getName(),
GearDataCache.of(leftStack),
leftStack.getOrCreateTag().getInt("freeCuts"),
right.getName(),
GearDataCache.of(rightStack),
rightStack.getOrCreateTag().getInt("freeCuts"),
VaultJewelSorting.CONFIGURATION.getJewelSortingByName(),
sortingDirection == SortingDirection.ASCENDING));
callbackInfoReturnable.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ else if (leftStack.getItem() == ModItems.JEWEL)
callbackInfoReturnable.setReturnValue(SortingHelper.compareJewels(
left.getName(),
GearDataCache.of(leftStack),
leftStack.getOrCreateTag().getInt("freeCuts"),
right.getName(),
GearDataCache.of(rightStack),
rightStack.getOrCreateTag().getInt("freeCuts"),
VaultJewelSorting.CONFIGURATION.getJewelSortingByAmount(),
sortingDirection == SortingDirection.ASCENDING));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ else if (firstStack.getItem() == ModItems.JEWEL)
return SortingHelper.compareJewels(
firstStack.getDisplayName().getString(),
VaultGearData.read(firstStack),
firstStack.getOrCreateTag().getInt("freeCuts"),
secondStack.getDisplayName().getString(),
VaultGearData.read(secondStack),
secondStack.getOrCreateTag().getInt("freeCuts"),
VaultJewelSorting.CONFIGURATION.getJewelSortingByAmount(),
true);
}
Expand Down Expand Up @@ -200,8 +202,10 @@ else if (firstStack.getItem() == ModItems.JEWEL)
return SortingHelper.compareJewels(
firstStack.getDisplayName().getString(),
VaultGearData.read(firstStack),
firstStack.getOrCreateTag().getInt("freeCuts"),
secondStack.getDisplayName().getString(),
VaultGearData.read(secondStack),
secondStack.getOrCreateTag().getInt("freeCuts"),
VaultJewelSorting.CONFIGURATION.getJewelSortingByName(),
true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,26 @@ else if (first.getItem() == ModItems.JEWEL)
return switch (this.gui.getSort()) {
case NAME -> SortingHelper.compareJewels(leftName,
leftData,
first.getOrCreateTag().getInt("freeCuts"),
rightName,
rightData,
second.getOrCreateTag().getInt("freeCuts"),
VaultJewelSorting.CONFIGURATION.getJewelSortingByName(),
this.gui.getDownwards());
case AMOUNT -> SortingHelper.compareJewels(leftName,
leftData,
first.getOrCreateTag().getInt("freeCuts"),
rightName,
rightData,
second.getOrCreateTag().getInt("freeCuts"),
VaultJewelSorting.CONFIGURATION.getJewelSortingByAmount(),
this.gui.getDownwards());
case MOD -> SortingHelper.compareJewels(leftName,
leftData,
first.getOrCreateTag().getInt("freeCuts"),
rightName,
rightData,
second.getOrCreateTag().getInt("freeCuts"),
VaultJewelSorting.CONFIGURATION.getJewelSortingByMod(),
this.gui.getDownwards());
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ public static int compareRegistryNames(ResourceLocation leftReg,
public static int compareJewels(
String leftName,
VaultGearData leftData,
int leftCuts,
String rightName,
VaultGearData rightData,
int rightCuts,
List<JewelOptions> sortingOrder,
boolean ascending)
{
Expand Down Expand Up @@ -118,6 +120,7 @@ public static int compareJewels(
case SIZE -> SortingHelper.compareSizeAttribute(leftData, rightData);
case ATTRIBUTE_WEIGHT -> SortingHelper.compareAttributeValueWeight(leftData, leftAttribute, rightData, rightAttribute);
case LEVEL -> SortingHelper.compareLevel(leftData, rightData);
case CUTS -> SortingHelper.compareIntegerValue(rightCuts, leftCuts);
};
}

Expand All @@ -139,8 +142,10 @@ public static int compareJewels(
public static int compareJewels(
String leftName,
GearDataCache leftData,
int leftCuts,
String rightName,
GearDataCache rightData,
int rightCuts,
List<JewelOptions> sortingOrder,
boolean ascending)
{
Expand All @@ -164,6 +169,7 @@ public static int compareJewels(
case ATTRIBUTE_WEIGHT -> SortingHelper.compareAttributeValueWeight(leftExtraCache, rightExtraCache);
case LEVEL -> SortingHelper.compareIntegerValue(leftExtraCache.getExtraGearLevel(),
rightExtraCache.getExtraGearLevel());
case CUTS -> SortingHelper.compareIntegerValue(rightCuts, leftCuts);
};
}

Expand All @@ -185,8 +191,10 @@ public static int compareJewels(
public static int compareJewels(
String leftName,
CompoundTag leftData,
int leftCuts,
String rightName,
CompoundTag rightData,
int rightCuts,
List<JewelOptions> sortingOrder,
boolean ascending)
{
Expand All @@ -212,6 +220,7 @@ public static int compareJewels(
}
case LEVEL -> SortingHelper.compareIntegerValue(leftData.getInt(EXTRA_GEAR_LEVEL),
rightData.getInt(EXTRA_GEAR_LEVEL));
case CUTS -> SortingHelper.compareIntegerValue(rightCuts, leftCuts);
};
}

Expand Down Expand Up @@ -1304,7 +1313,11 @@ public enum JewelOptions
/**
* The level of the item
*/
LEVEL
LEVEL,
/**
* Number of free cuts applied to gear
*/
CUTS
}


Expand Down

0 comments on commit 98d0edb

Please sign in to comment.