Skip to content

Commit

Permalink
server: Replace exp/maps and exp/slices with maps and slices.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandertv committed Dec 29, 2024
1 parent 8171c34 commit 9601e5c
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 16 deletions.
5 changes: 3 additions & 2 deletions server/entity/effect.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"fmt"
"github.com/df-mc/dragonfly/server/entity/effect"
"github.com/df-mc/dragonfly/server/world"
"golang.org/x/exp/maps"
"maps"
"reflect"
"slices"
)

// EffectManager manages the effects of an entity. The effect manager will only store effects that last for
Expand Down Expand Up @@ -77,7 +78,7 @@ func (m *EffectManager) Effect(e effect.Type) (effect.Effect, bool) {
// Effects returns a list of all effects currently present in the effect manager. This will never include
// effects that have expired.
func (m *EffectManager) Effects() []effect.Effect {
return maps.Values(m.effects)
return slices.Collect(maps.Values(m.effects))
}

// Tick ticks the EffectManager, applying all of its effects to the Living entity passed when applicable and
Expand Down
2 changes: 1 addition & 1 deletion server/internal/blockinternal/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package blockinternal

import (
"github.com/df-mc/dragonfly/server/item/category"
"golang.org/x/exp/maps"
"maps"
"slices"
)

Expand Down
2 changes: 1 addition & 1 deletion server/internal/iteminternal/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package iteminternal

import (
"github.com/df-mc/dragonfly/server/item/category"
"golang.org/x/exp/maps"
"maps"
"strings"
)

Expand Down
5 changes: 3 additions & 2 deletions server/item/enchantment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package item

import (
"github.com/df-mc/dragonfly/server/world"
"golang.org/x/exp/maps"
"maps"
"slices"
"sort"
)

Expand Down Expand Up @@ -87,7 +88,7 @@ func EnchantmentID(e EnchantmentType) (int, bool) {

// Enchantments returns a slice of all registered enchantments.
func Enchantments() []EnchantmentType {
e := maps.Values(enchantmentsMap)
e := slices.Collect(maps.Values(enchantmentsMap))
sort.Slice(e, func(i, j int) bool {
id1, _ := EnchantmentID(e[i])
id2, _ := EnchantmentID(e[j])
Expand Down
9 changes: 5 additions & 4 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ import (
"github.com/sandertv/gophertunnel/minecraft/protocol"
"github.com/sandertv/gophertunnel/minecraft/protocol/login"
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
"golang.org/x/exp/maps"
"golang.org/x/text/language"
"iter"
"maps"
"os"
"os/exec"
"os/signal"
"runtime"
"runtime/debug"
"slices"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -252,7 +253,7 @@ func (srv *Server) Player(uuid uuid.UUID) (*world.EntityHandle, bool) {
// found, the entity handle is returned and the bool returned holds a true
// value. If not, the bool is false and the handle is nil
func (srv *Server) PlayerByName(name string) (*world.EntityHandle, bool) {
if p, ok := sliceutil.SearchValue(maps.Values(srv.p), func(p *onlinePlayer) bool {
if p, ok := sliceutil.SearchValue(slices.Collect(maps.Values(srv.p)), func(p *onlinePlayer) bool {
return p.name == name
}); ok {
return p.handle, true
Expand All @@ -264,7 +265,7 @@ func (srv *Server) PlayerByName(name string) (*world.EntityHandle, bool) {
// found, the entity handle is returned and the bool returned is true. If no
// player with the XUID was found, nil and false are returned.
func (srv *Server) PlayerByXUID(xuid string) (*world.EntityHandle, bool) {
if p, ok := sliceutil.SearchValue(maps.Values(srv.p), func(p *onlinePlayer) bool {
if p, ok := sliceutil.SearchValue(slices.Collect(maps.Values(srv.p)), func(p *onlinePlayer) bool {
return p.xuid == xuid
}); ok {
return p.handle, true
Expand Down Expand Up @@ -376,7 +377,7 @@ func (srv *Server) startListening() {
// registered custom blocks. It allows block components to be created only once
// at startup.
func (srv *Server) makeBlockEntries() {
custom := maps.Values(world.CustomBlocks())
custom := slices.Collect(maps.Values(world.CustomBlocks()))
srv.customBlocks = make([]protocol.BlockEntry, len(custom))

for i, b := range custom {
Expand Down
2 changes: 1 addition & 1 deletion server/session/session_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/google/uuid"
"github.com/sandertv/gophertunnel/minecraft/protocol"
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
"golang.org/x/exp/slices"
"slices"
"sync"
)

Expand Down
5 changes: 3 additions & 2 deletions server/world/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/go-gl/mathgl/mgl64"
"github.com/google/uuid"
"golang.org/x/exp/maps"
"io"
"maps"
"slices"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -400,7 +401,7 @@ func (reg EntityRegistry) Lookup(name string) (EntityType, bool) {

// Types returns all EntityTypes passed upon construction of the EntityRegistry.
func (reg EntityRegistry) Types() []EntityType {
return maps.Values(reg.ent)
return slices.Collect(maps.Values(reg.ent))
}

func readVec3(x map[string]any, k string) mgl64.Vec3 {
Expand Down
4 changes: 2 additions & 2 deletions server/world/tick.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package world
import (
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/internal/sliceutil"
"golang.org/x/exp/maps"
"maps"
"math/rand"
"slices"
"time"
Expand Down Expand Up @@ -129,7 +129,7 @@ func (t ticker) tickBlocksRandomly(tx *Tx, loaders []*Loader, tick int64) {
// No loaders in this chunk that are within the simulation distance, so proceed to the next.
continue
}
blockEntities = append(blockEntities, maps.Keys(c.BlockEntities)...)
blockEntities = append(blockEntities, slices.Collect(maps.Keys(c.BlockEntities))...)

cx, cz := int(pos[0]<<4), int(pos[1]<<4)

Expand Down
2 changes: 1 addition & 1 deletion server/world/world.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"iter"
"maps"
"math/rand"
"sync"
"time"
Expand All @@ -19,7 +20,6 @@ import (
"github.com/df-mc/dragonfly/server/world/chunk"
"github.com/go-gl/mathgl/mgl64"
"github.com/google/uuid"
"golang.org/x/exp/maps"
"sync/atomic"
)

Expand Down

0 comments on commit 9601e5c

Please sign in to comment.