Renamed and commented functions
This commit is contained in:
parent
980448f9e7
commit
5ac582261c
|
|
@ -37,16 +37,23 @@ public class Utilities {
|
|||
* @param item to calculate price for
|
||||
* @return price or int < 0 for error
|
||||
*/
|
||||
public static double price(ItemStack item) {
|
||||
public static double getWorth(ItemStack item) {
|
||||
if (WorthConfig.prices.containsKey(item.getType()))
|
||||
return Utilities.round(WorthConfig.prices.getDouble(item.getType()) * item.getAmount(), 2);
|
||||
|
||||
WorthConfig.prices.put(item.getType(), Utilities.round(getPrice(item, null), 2));
|
||||
WorthConfig.prices.put(item.getType(), Utilities.round(getWorth(item, null), 2));
|
||||
|
||||
return WorthConfig.prices.getDouble(item.getType()) * item.getAmount();
|
||||
}
|
||||
|
||||
private static double getPrice(ItemStack item, Material blockedMaterial) {
|
||||
/**
|
||||
* Get the worth of the material an ItemStack consists of
|
||||
*
|
||||
* @param item to get the worth of
|
||||
* @param blockedMaterial Material to ignore set to null on initial call
|
||||
* @return Worth of the item as a double
|
||||
*/
|
||||
private static double getWorth(ItemStack item, Material blockedMaterial) {
|
||||
if (WorthConfig.prices.containsKey(item.getType()))
|
||||
return WorthConfig.prices.getDouble(item.getType());
|
||||
double price = -1;
|
||||
|
|
@ -57,17 +64,17 @@ public class Utilities {
|
|||
Collection<ItemStack> values = shapedRecipe.getIngredientMap().values();
|
||||
if (values.stream().anyMatch(itemStack -> itemStack.getType().equals(blockedMaterial)))
|
||||
continue;
|
||||
possiblePrice = getPrice(values.stream().toList(), item.getType());
|
||||
possiblePrice = getWorth(values.stream().toList(), item.getType());
|
||||
if (price == -1 || price > possiblePrice)
|
||||
price = possiblePrice;
|
||||
} else if (recipe instanceof ShapelessRecipe shapelessRecipe) {
|
||||
if (shapelessRecipe.getIngredientList().stream().anyMatch(itemStack -> itemStack.getType().equals(blockedMaterial)))
|
||||
continue;
|
||||
possiblePrice = getPrice(shapelessRecipe.getIngredientList(), item.getType());
|
||||
possiblePrice = getWorth(shapelessRecipe.getIngredientList(), item.getType());
|
||||
if (price == -1 || price > possiblePrice)
|
||||
price = possiblePrice;
|
||||
} else if (recipe instanceof FurnaceRecipe furnaceRecipe) {
|
||||
possiblePrice = getPrice(furnaceRecipe.getInput(), item.getType());
|
||||
possiblePrice = getWorth(furnaceRecipe.getInput(), item.getType());
|
||||
if (price == -1 || price > possiblePrice)
|
||||
price = possiblePrice;
|
||||
}
|
||||
|
|
@ -75,10 +82,17 @@ public class Utilities {
|
|||
return price;
|
||||
}
|
||||
|
||||
private static double getPrice(List<ItemStack> items, Material blockedMaterial) {
|
||||
/**
|
||||
* Get the total worth of a list of ItemStack's (amount of items in ItemStack is ignored)
|
||||
*
|
||||
* @param items Items to get the worth of
|
||||
* @param blockedMaterial Material to ignore set to null on initial call
|
||||
* @return Worth of ItemStack as a double
|
||||
*/
|
||||
private static double getWorth(List<ItemStack> items, Material blockedMaterial) {
|
||||
double price = 0;
|
||||
for (ItemStack item : items) {
|
||||
double tmp = getPrice(item, blockedMaterial);
|
||||
double tmp = getWorth(item, blockedMaterial);
|
||||
if (tmp == -1)
|
||||
return -1;
|
||||
price += tmp;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user