diff --git a/paper-server/patches/unapplied/net/minecraft/world/item/enchantment/ItemEnchantments.java.patch b/paper-server/patches/sources/net/minecraft/world/item/enchantment/ItemEnchantments.java.patch similarity index 59% rename from paper-server/patches/unapplied/net/minecraft/world/item/enchantment/ItemEnchantments.java.patch rename to paper-server/patches/sources/net/minecraft/world/item/enchantment/ItemEnchantments.java.patch index 519f69ad9b..d49d59d33a 100644 --- a/paper-server/patches/unapplied/net/minecraft/world/item/enchantment/ItemEnchantments.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/item/enchantment/ItemEnchantments.java.patch @@ -1,60 +1,54 @@ --- a/net/minecraft/world/item/enchantment/ItemEnchantments.java +++ b/net/minecraft/world/item/enchantment/ItemEnchantments.java -@@ -26,12 +26,25 @@ - import net.minecraft.world.item.Item; - import net.minecraft.world.item.TooltipFlag; +@@ -28,10 +_,19 @@ import net.minecraft.world.item.component.TooltipProvider; -+// Paper start -+import it.unimi.dsi.fastutil.objects.Object2IntAVLTreeMap; -+// Paper end public class ItemEnchantments implements TooltipProvider { - public static final ItemEnchantments EMPTY = new ItemEnchantments(new Object2IntOpenHashMap<>(), true); + // Paper start + private static final java.util.Comparator> ENCHANTMENT_ORDER = java.util.Comparator.comparing(Holder::getRegisteredName); -+ public static final ItemEnchantments EMPTY = new ItemEnchantments(new Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER), true); ++ public static final ItemEnchantments EMPTY = new ItemEnchantments(new it.unimi.dsi.fastutil.objects.Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER), true); + // Paper end private static final Codec LEVEL_CODEC = Codec.intRange(1, 255); - private static final Codec>> LEVELS_CODEC = Codec.unboundedMap(Enchantment.CODEC, LEVEL_CODEC) - .xmap(Object2IntOpenHashMap::new, Function.identity()); -+ private static final Codec>> LEVELS_CODEC = Codec.unboundedMap( -+ Enchantment.CODEC, LEVEL_CODEC -+ )// Paper start - sort enchantments ++ // Paper start - sort enchantments ++ private static final Codec>> LEVELS_CODEC = Codec.unboundedMap(Enchantment.CODEC, LEVEL_CODEC) + .xmap(m -> { -+ final Object2IntAVLTreeMap> map = new Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER); ++ final it.unimi.dsi.fastutil.objects.Object2IntAVLTreeMap> map = new it.unimi.dsi.fastutil.objects.Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER); + map.putAll(m); + return map; + }, Function.identity()); + // Paper end - sort enchantments private static final Codec FULL_CODEC = RecordCodecBuilder.create( instance -> instance.group( - LEVELS_CODEC.fieldOf("levels").forGetter(component -> component.enchantments), -@@ -41,16 +54,16 @@ + LEVELS_CODEC.fieldOf("levels").forGetter(itemEnchantments -> itemEnchantments.enchantments), +@@ -41,16 +_,16 @@ ); public static final Codec CODEC = Codec.withAlternative(FULL_CODEC, LEVELS_CODEC, map -> new ItemEnchantments(map, true)); public static final StreamCodec STREAM_CODEC = StreamCodec.composite( - ByteBufCodecs.map(Object2IntOpenHashMap::new, Enchantment.STREAM_CODEC, ByteBufCodecs.VAR_INT), -+ ByteBufCodecs.map((v) -> new Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER), Enchantment.STREAM_CODEC, ByteBufCodecs.VAR_INT), - component -> component.enchantments, ++ ByteBufCodecs.map((v) -> new it.unimi.dsi.fastutil.objects.Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER), Enchantment.STREAM_CODEC, ByteBufCodecs.VAR_INT), // Paper + itemEnchantments -> itemEnchantments.enchantments, ByteBufCodecs.BOOL, - component -> component.showInTooltip, + itemEnchantments -> itemEnchantments.showInTooltip, ItemEnchantments::new ); - final Object2IntOpenHashMap> enchantments; -+ final Object2IntAVLTreeMap> enchantments; // Paper ++ final it.unimi.dsi.fastutil.objects.Object2IntAVLTreeMap> enchantments; // Paper public final boolean showInTooltip; - ItemEnchantments(Object2IntOpenHashMap> enchantments, boolean showInTooltip) { -+ ItemEnchantments(Object2IntAVLTreeMap> enchantments, boolean showInTooltip) { // Paper ++ ItemEnchantments(it.unimi.dsi.fastutil.objects.Object2IntAVLTreeMap> enchantments, boolean showInTooltip) { // Paper this.enchantments = enchantments; this.showInTooltip = showInTooltip; -@@ -139,7 +152,7 @@ +@@ -139,7 +_,7 @@ } public static class Mutable { - private final Object2IntOpenHashMap> enchantments = new Object2IntOpenHashMap<>(); -+ private final Object2IntAVLTreeMap> enchantments = new Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER); // Paper ++ private final it.unimi.dsi.fastutil.objects.Object2IntAVLTreeMap> enchantments = new it.unimi.dsi.fastutil.objects.Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER); // Paper public boolean showInTooltip; - public Mutable(ItemEnchantments enchantmentsComponent) { + public Mutable(ItemEnchantments enchantments) {