Skip to content

Commit

Permalink
optimize check order
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Aug 6, 2024
1 parent 9f0b517 commit fd4c9e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,19 @@ public ItemLegality legalityOf(ItemStack itemStack) {
final Set<Enchantment> enchantments = itemStack.getEnchantments().keySet();

if (!enchantments.isEmpty()) {
if (enchantments.contains(BINDING_CURSE.getEnchant()) && enchantments.contains(VANISHING_CURSE.getEnchant()))
return ItemLegality.ILLEGAL;
if (enchantments.contains(INFINITY.getEnchant()) && enchantments.contains(MENDING.getEnchant()))
return ItemLegality.ILLEGAL;
if (enchantments.contains(SILK_TOUCH.getEnchant()) && enchantments.contains(FORTUNE.getEnchant()))
return ItemLegality.ILLEGAL;
if (enchantments.contains(DEPTH_STRIDER.getEnchant()) && enchantments.contains(FROST_WALKER.getEnchant()))
return ItemLegality.ILLEGAL;
if (enchantments.contains(MULTISHOT.getEnchant()) && enchantments.contains(PIERCING.getEnchant()))
if (enchantments.contains(INFINITY.getEnchant()) && enchantments.contains(MENDING.getEnchant()))
return ItemLegality.ILLEGAL;
if (enchantments.contains(BINDING_CURSE.getEnchant()) && enchantments.contains(VANISHING_CURSE.getEnchant()))
return ItemLegality.ILLEGAL;
if (enchantments.contains(RIPTIDE.getEnchant())
&& (enchantments.contains(LOYALTY.getEnchant()) || enchantments.contains(CHANNELING.getEnchant())))
return ItemLegality.ILLEGAL;
if (enchantments.contains(MULTISHOT.getEnchant()) && enchantments.contains(PIERCING.getEnchant()))
return ItemLegality.ILLEGAL;

int dmgEnchCount = 0;
for (Enchantment damageEnchant : DAMAGE_ENCHANTS) {
Expand Down Expand Up @@ -147,18 +147,18 @@ public void handleItem(ItemStack itemStack, ItemLegality legality) {

final Set<Enchantment> enchantments = itemStack.getEnchantments().keySet();

if (enchantments.contains(SILK_TOUCH.getEnchant()) && enchantments.contains(FORTUNE.getEnchant()))
itemStack.removeEnchantment(FORTUNE.getEnchant());
if (enchantments.contains(DEPTH_STRIDER.getEnchant()) && enchantments.contains(FROST_WALKER.getEnchant()))
itemStack.removeEnchantment(FROST_WALKER.getEnchant());
if (enchantments.contains(INFINITY.getEnchant()) && enchantments.contains(MENDING.getEnchant()))
itemStack.removeEnchantment(INFINITY.getEnchant());
if (enchantments.contains(BINDING_CURSE.getEnchant()) && enchantments.contains(VANISHING_CURSE.getEnchant()))
itemStack.removeEnchantment(BINDING_CURSE.getEnchant());
if (enchantments.contains(MULTISHOT.getEnchant()) && enchantments.contains(PIERCING.getEnchant()))
itemStack.removeEnchantment(MULTISHOT.getEnchant());
if (enchantments.contains(RIPTIDE.getEnchant()) && (enchantments.contains(LOYALTY.getEnchant()) || enchantments.contains(CHANNELING.getEnchant())))
itemStack.removeEnchantment(RIPTIDE.getEnchant());
if (enchantments.contains(INFINITY.getEnchant()) && enchantments.contains(MENDING.getEnchant()))
itemStack.removeEnchantment(INFINITY.getEnchant());
if (enchantments.contains(SILK_TOUCH.getEnchant()) && enchantments.contains(FORTUNE.getEnchant()))
itemStack.removeEnchantment(FORTUNE.getEnchant());
if (enchantments.contains(DEPTH_STRIDER.getEnchant()) && enchantments.contains(FROST_WALKER.getEnchant()))
itemStack.removeEnchantment(FROST_WALKER.getEnchant());

if (enchantments.contains(SHARPNESS.getEnchant())) { // Prefer keeping sharpness enchantment if present
for (Enchantment dmgEnchant : DAMAGE_ENCHANTS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ public ItemLegality legalityOf(ItemStack itemStack) {
final Set<Enchantment> enchantments = itemStack.getEnchantments().keySet();

if (!enchantments.isEmpty()) {
if (enchantments.contains(BINDING_CURSE.getEnchant()) && enchantments.contains(VANISHING_CURSE.getEnchant()))
return ItemLegality.ILLEGAL;
if (enchantments.contains(INFINITY.getEnchant()) && enchantments.contains(MENDING.getEnchant()))
return ItemLegality.ILLEGAL;
if (enchantments.contains(SILK_TOUCH.getEnchant()) && enchantments.contains(FORTUNE.getEnchant()))
return ItemLegality.ILLEGAL;
if (enchantments.contains(DEPTH_STRIDER.getEnchant()) && enchantments.contains(FROST_WALKER.getEnchant()))
return ItemLegality.ILLEGAL;
if (enchantments.contains(INFINITY.getEnchant()) && enchantments.contains(MENDING.getEnchant()))
return ItemLegality.ILLEGAL;
if (enchantments.contains(BINDING_CURSE.getEnchant()) && enchantments.contains(VANISHING_CURSE.getEnchant()))
return ItemLegality.ILLEGAL;
if (MULTISHOT.isSupported()) {
if (enchantments.contains(MULTISHOT.getEnchant()) && enchantments.contains(PIERCING.getEnchant()))
return ItemLegality.ILLEGAL;
Expand Down Expand Up @@ -151,22 +151,23 @@ public void handleItem(ItemStack itemStack, ItemLegality legality) {

final Set<Enchantment> enchantments = itemStack.getEnchantments().keySet();

if (enchantments.contains(BINDING_CURSE.getEnchant()) && enchantments.contains(VANISHING_CURSE.getEnchant()))
itemStack.removeEnchantment(BINDING_CURSE.getEnchant());
if (enchantments.contains(INFINITY.getEnchant()) && enchantments.contains(MENDING.getEnchant()))
itemStack.removeEnchantment(INFINITY.getEnchant());
if (enchantments.contains(SILK_TOUCH.getEnchant()) && enchantments.contains(FORTUNE.getEnchant()))
itemStack.removeEnchantment(FORTUNE.getEnchant());
if (enchantments.contains(DEPTH_STRIDER.getEnchant()) && enchantments.contains(FROST_WALKER.getEnchant()))
itemStack.removeEnchantment(FROST_WALKER.getEnchant());
if (enchantments.contains(INFINITY.getEnchant()) && enchantments.contains(MENDING.getEnchant()))
itemStack.removeEnchantment(INFINITY.getEnchant());
if (enchantments.contains(BINDING_CURSE.getEnchant()) && enchantments.contains(VANISHING_CURSE.getEnchant()))
itemStack.removeEnchantment(BINDING_CURSE.getEnchant());
if (RIPTIDE.isSupported()) { // 1.12 doesn't have tridents
if (enchantments.contains(RIPTIDE.getEnchant())
&& (enchantments.contains(LOYALTY.getEnchant()) || enchantments.contains(CHANNELING.getEnchant())))
itemStack.removeEnchantment(RIPTIDE.getEnchant());
}
if (MULTISHOT.isSupported()) { // 1.12 doesn't have crossbows
if (enchantments.contains(MULTISHOT.getEnchant()) && enchantments.contains(PIERCING.getEnchant()))
itemStack.removeEnchantment(MULTISHOT.getEnchant());
}
if (RIPTIDE.isSupported()) { // 1.12 doesn't have tridents
if (enchantments.contains(RIPTIDE.getEnchant()) && (enchantments.contains(LOYALTY.getEnchant()) || enchantments.contains(CHANNELING.getEnchant())))
itemStack.removeEnchantment(RIPTIDE.getEnchant());
}

if (enchantments.contains(SHARPNESS.getEnchant())) { // Prefer keeping sharpness enchantment if present
for (Enchantment dmgEnchant : DAMAGE_ENCHANTS) {
Expand Down

0 comments on commit fd4c9e1

Please sign in to comment.