Skip to content

Commit

Permalink
block/ender_chest.go: Use sync/atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
DaPigGuy committed Dec 10, 2023
1 parent 300aead commit 48bba03
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ require (
github.com/sandertv/gophertunnel v1.34.0
github.com/segmentio/fasthash v1.0.3
github.com/sirupsen/logrus v1.9.0
go.uber.org/atomic v1.10.0
golang.org/x/exp v0.0.0-20230206171751-46f607a40771
golang.org/x/text v0.7.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE=
Expand Down
8 changes: 4 additions & 4 deletions server/block/ender_chest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/df-mc/dragonfly/server/world"
"github.com/df-mc/dragonfly/server/world/sound"
"github.com/go-gl/mathgl/mgl64"
"go.uber.org/atomic"
"sync/atomic"
)

// enderChestOwner represents an entity that has an ender chest inventory.
Expand All @@ -32,7 +32,7 @@ type EnderChest struct {

// NewEnderChest creates a new initialised ender chest.
func NewEnderChest() EnderChest {
return EnderChest{viewers: atomic.NewInt64(0)}
return EnderChest{viewers: &atomic.Int64{}}
}

// BreakInfo ...
Expand Down Expand Up @@ -75,7 +75,7 @@ func (c EnderChest) Activate(pos cube.Pos, _ cube.Face, _ *world.World, u item.U

// AddViewer ...
func (c EnderChest) AddViewer(w *world.World, pos cube.Pos) {
if c.viewers.Inc() == 1 {
if c.viewers.Add(1) == 1 {
c.open(w, pos)
}
}
Expand All @@ -85,7 +85,7 @@ func (c EnderChest) RemoveViewer(w *world.World, pos cube.Pos) {
if c.viewers.Load() == 0 {
return
}
if c.viewers.Dec() == 0 {
if c.viewers.Add(-1) == 0 {
c.close(w, pos)
}
}
Expand Down

0 comments on commit 48bba03

Please sign in to comment.