ItemAction tweak

This commit is contained in:
fullwall 2023-06-19 01:44:29 +08:00
parent cd550e634e
commit ad442e4bd3

View File

@ -62,6 +62,8 @@ public class ItemAction extends NPCShopAction {
if (tooDamaged(toMatch))
continue;
for (int j = 0; j < items.size(); j++) {
if (toMatch == null)
break;
ItemStack item = items.get(j);
if (req.get(j) <= 0 || !matches(item, toMatch))
continue;
@ -75,6 +77,7 @@ public class ItemAction extends NPCShopAction {
source.setItem(i, res);
}
req.set(j, remaining - taken);
toMatch = res;
}
}
return req.stream().collect(Collectors.summingInt(n -> n)) <= 0;
@ -97,14 +100,6 @@ public class ItemAction extends NPCShopAction {
return description;
}
private boolean tooDamaged(ItemStack toMatch) {
if (!requireUndamaged)
return false;
if (SpigotUtil.isUsing1_13API())
return toMatch.getItemMeta() instanceof Damageable && ((Damageable) toMatch.getItemMeta()).getDamage() != 0;
return toMatch.getDurability() == toMatch.getType().getMaxDurability();
}
@Override
public int getMaxRepeats(Entity entity) {
if (!(entity instanceof InventoryHolder))
@ -216,6 +211,14 @@ public class ItemAction extends NPCShopAction {
});
}
private boolean tooDamaged(ItemStack toMatch) {
if (!requireUndamaged)
return false;
if (SpigotUtil.isUsing1_13API())
return toMatch.getItemMeta() instanceof Damageable && ((Damageable) toMatch.getItemMeta()).getDamage() != 0;
return toMatch.getDurability() == toMatch.getType().getMaxDurability();
}
@Menu(title = "Item editor", dimensions = { 4, 9 })
public static class ItemActionEditor extends InventoryMenuPage {
private ItemAction base;