Skip to content

Commit

Permalink
item/enchantment.go: Make order of Enchantments() stable
Browse files Browse the repository at this point in the history
  • Loading branch information
DaPigGuy committed Dec 29, 2024
1 parent 0ef3670 commit 8171c34
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion server/item/enchantment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit 8171c34

Please sign in to comment.