Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Commit 9680ad8

Browse files
committed
[ci skip] clean up unsafe enchants diff
1 parent d8aadde commit 9680ad8

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

purpur-server/minecraft-patches/sources/net/minecraft/world/inventory/AnvilMenu.java.patch

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
ItemStack itemStack = item.copy();
6565
ItemStack item1 = this.inputSlots.getItem(1);
6666
ItemEnchantments.Mutable mutable = new ItemEnchantments.Mutable(EnchantmentHelper.getEnchantmentsForCrafting(itemStack));
67-
@@ -191,23 +_,36 @@
67+
@@ -191,23 +_,34 @@
6868
int intValue = entry.getIntValue();
6969
intValue = level == intValue ? intValue + 1 : Math.max(intValue, level);
7070
Enchantment enchantment = holder.value();
@@ -77,25 +77,21 @@
7777
canEnchant = true;
7878
}
7979

80-
- for (Holder<Enchantment> holder1 : mutable.keySet()) {
81-
+ // Purpur start - Config to allow unsafe enchants
82-
+ java.util.Iterator<Holder<Enchantment>> mutableIterator = mutable.keySet().iterator();
83-
+ while (mutableIterator.hasNext()) {
84-
+ Holder<Enchantment> holder1 = mutableIterator.next();
85-
+ // Purpur end - Config to allow unsafe enchants
80+
+ java.util.Set<Holder<Enchantment>> removedEnchantments = new java.util.HashSet<>(); // Purpur - Config to allow unsafe enchants
81+
for (Holder<Enchantment> holder1 : mutable.keySet()) {
8682
if (!holder1.equals(holder) && !Enchantment.areCompatible(holder, holder1)) {
8783
- canEnchant = false;
88-
- i++;
89-
+ canEnchant1 = this.canDoUnsafeEnchants || org.purpurmc.purpur.PurpurConfig.allowIncompatibleEnchants; // Purpur - Anvil API // Purpur - flag3 -> canEnchant1 - Config to allow unsafe enchants
84+
+ canEnchant1 = this.canDoUnsafeEnchants || org.purpurmc.purpur.PurpurConfig.allowIncompatibleEnchants; // Purpur - Anvil API // Purpur - canEnchant -> canEnchant1 - Config to allow unsafe enchants
9085
+ // Purpur start - Config to allow unsafe enchants
9186
+ if (!canEnchant1 && org.purpurmc.purpur.PurpurConfig.replaceIncompatibleEnchants) {
92-
+ mutableIterator.remove(); // replace current enchant with the incompatible one trying to be applied // TODO: is this needed?
87+
+ removedEnchantments.add(holder1);
9388
+ canEnchant1 = true;
9489
+ }
9590
+ // Purpur end - Config to allow unsafe enchants
96-
+ ++i;
91+
i++;
9792
}
9893
}
94+
+ mutable.removeIf(removedEnchantments::contains); // Purpur - Config to allow unsafe enchants
9995

10096
- if (!canEnchant) {
10197
+ if (!canEnchant || !canEnchant1) { // Purpur - Config to allow unsafe enchants

0 commit comments

Comments
 (0)