From 2f19f0fb7b1db54dde18c1a53837d2ab77a4d07e Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Fri, 26 Apr 2024 18:06:35 -0700 Subject: [PATCH] fix enchantment order issue --- .../0077-Handle-Item-Meta-Inconsistencies.patch | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/patches/server/0077-Handle-Item-Meta-Inconsistencies.patch b/patches/server/0077-Handle-Item-Meta-Inconsistencies.patch index 50ab2f09d7..ef76b801d9 100644 --- a/patches/server/0077-Handle-Item-Meta-Inconsistencies.patch +++ b/patches/server/0077-Handle-Item-Meta-Inconsistencies.patch @@ -18,10 +18,10 @@ For consistency, the old API methods now forward to use the ItemMeta API equivalents, and should deprecate the old API's. diff --git a/src/main/java/net/minecraft/world/item/enchantment/ItemEnchantments.java b/src/main/java/net/minecraft/world/item/enchantment/ItemEnchantments.java -index b49eb019cce58049c2b3a0e80e3d08998b16f7ea..dd6bf199f22476ef1d0f704883b748be97b0065e 100644 +index b49eb019cce58049c2b3a0e80e3d08998b16f7ea..af18de11dd55938b6091f5ab183bd3fe4e8df152 100644 --- a/src/main/java/net/minecraft/world/item/enchantment/ItemEnchantments.java +++ b/src/main/java/net/minecraft/world/item/enchantment/ItemEnchantments.java -@@ -27,15 +27,21 @@ import net.minecraft.tags.TagKey; +@@ -27,15 +27,27 @@ import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.component.TooltipProvider; @@ -42,11 +42,17 @@ index b49eb019cce58049c2b3a0e80e3d08998b16f7ea..dd6bf199f22476ef1d0f704883b748be BuiltInRegistries.ENCHANTMENT.holderByNameCodec(), LEVEL_CODEC ) - .xmap(Object2IntOpenHashMap::new, Function.identity()); -+ .xmap(Object2IntAVLTreeMap::new, Function.identity()); // Paper ++ // Paper start - sort enchantments ++ .xmap(m -> { ++ final Object2IntAVLTreeMap> map = new 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), -@@ -45,16 +51,16 @@ public class ItemEnchantments implements TooltipProvider { +@@ -45,16 +57,16 @@ public class ItemEnchantments implements TooltipProvider { ); public static final Codec CODEC = Codec.withAlternative(FULL_CODEC, LEVELS_CODEC, map -> new ItemEnchantments(map, true)); public static final StreamCodec STREAM_CODEC = StreamCodec.composite( @@ -66,7 +72,7 @@ index b49eb019cce58049c2b3a0e80e3d08998b16f7ea..dd6bf199f22476ef1d0f704883b748be this.enchantments = enchantments; this.showInTooltip = showInTooltip; -@@ -145,7 +151,7 @@ public class ItemEnchantments implements TooltipProvider { +@@ -145,7 +157,7 @@ public class ItemEnchantments implements TooltipProvider { } public static class Mutable {