Compare commits

..
2 changed files with 25 additions and 19 deletions

No files matched your search

@@ -88,23 +88,20 @@ public class PositionedStack implements Cloneable {
return this.acceptsLabel;
}
public PositionedStack setBadges(List<Badge> badges) {
public void setBadges(List<Badge> badges) {
this.badges = badges;
return this;
}
public List<Badge> getBadges() {
return this.badges;
}
public PositionedStack setTooltip(List<String> tooltip) {
public void setTooltip(List<String> tooltip) {
this.tooltip = tooltip == null ? null : item -> tooltip;
return this;
}
public PositionedStack setTooltipProvider(Function<ItemStack, List<String>> provider) {
public void setTooltipProvider(Function<ItemStack, List<String>> provider) {
this.tooltip = provider;
return this;
}
public List<String> getTooltip() {
@@ -115,9 +112,8 @@ public class PositionedStack implements Cloneable {
return this.chance;
}
public PositionedStack setChance(int chance) {
public void setChance(int chance) {
this.chance = chance;
return this;
}
public PositionedStack copy() {
@@ -269,20 +269,30 @@ public class StackInfo {
public static ItemStack getItemStackWithMinimumDamage(ItemStack[] stacks) {
ItemStack result = stacks[0];
if (stacks.length > 1) {
for (ItemStack stack : stacks) {
// to optimize compare recipes from permutation, an item with a minimum strId and damage is taken so as
// not to check everything permutation items
if (stack.getItem() != null && !ItemInfo.isHidden(stack)
&& (stack.getItemDamage() < result.getItemDamage()
|| stack.getItemDamage() == result.getItemDamage()
&& Item.itemRegistry.getNameForObject(stack.getItem())
.compareTo(Item.itemRegistry.getNameForObject(result.getItem())) < 0)) {
result = stack;
}
for (int i = 1; i < stacks.length; i++) {
final ItemStack stack = stacks[i];
if (stack.getItem() != null && isLess(stack, result) && !ItemInfo.isHidden(stack)) {
result = stack;
}
}
return result.copy();
}
private static boolean isLess(ItemStack stack, ItemStack other) {
if (stack.getItemDamage() != other.getItemDamage()) {
return stack.getItemDamage() < other.getItemDamage();
}
final String name = getItemName(stack);
if (name == null) return false;
final String otherName = getItemName(other);
return otherName == null || name.compareTo(otherName) < 0;
}
private static String getItemName(ItemStack stack) {
final Item item = stack.getItem();
return item == null ? null : Item.itemRegistry.getNameForObject(item);
}
}