From 8171c3473cf42a52a0931cffed5c6e7b41837137 Mon Sep 17 00:00:00 2001 From: DaPigGuy Date: Sun, 29 Dec 2024 03:35:06 -0800 Subject: [PATCH] item/enchantment.go: Make order of `Enchantments()` stable --- server/item/enchantment.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/item/enchantment.go b/server/item/enchantment.go index 85c67518e..20c538d30 100644 --- a/server/item/enchantment.go +++ b/server/item/enchantment.go @@ -3,6 +3,7 @@ package item import ( "github.com/df-mc/dragonfly/server/world" "golang.org/x/exp/maps" + "sort" ) // Enchantment is an enchantment that can be applied to a Stack. It holds an EnchantmentType and level that influences @@ -86,5 +87,11 @@ func EnchantmentID(e EnchantmentType) (int, bool) { // Enchantments returns a slice of all registered enchantments. func Enchantments() []EnchantmentType { - return maps.Values(enchantmentsMap) + e := maps.Values(enchantmentsMap) + sort.Slice(e, func(i, j int) bool { + id1, _ := EnchantmentID(e[i]) + id2, _ := EnchantmentID(e[j]) + return id1 < id2 + }) + return e }