-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Held Slot handler #430
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,13 @@ package player | |
|
||
import ( | ||
"fmt" | ||
"math" | ||
"math/rand" | ||
"net" | ||
"strings" | ||
"sync" | ||
"time" | ||
|
||
"github.com/df-mc/dragonfly/server/block" | ||
"github.com/df-mc/dragonfly/server/block/cube" | ||
"github.com/df-mc/dragonfly/server/cmd" | ||
|
@@ -28,12 +35,6 @@ import ( | |
"github.com/google/uuid" | ||
"go.uber.org/atomic" | ||
"golang.org/x/text/language" | ||
"math" | ||
"math/rand" | ||
"net" | ||
"strings" | ||
"sync" | ||
"time" | ||
) | ||
|
||
// Player is an implementation of a player entity. It has methods that implement the behaviour that players | ||
|
@@ -367,6 +368,37 @@ func (p *Player) Transfer(address string) (err error) { | |
return | ||
} | ||
|
||
// SetHeldSlot updates the held slot of the player with the slot passed. It also verifies that the item within the spot | ||
// is the correct item. | ||
// This invokes the HandleHeldSlotChange handler. | ||
func (p *Player) SetHeldSlot(slot int, expected item.Stack) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Passing an expected item stack no longer makes sense here, should be removed. |
||
if slot > 8 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why'd you remove all the documentation for this method? |
||
return fmt.Errorf("new held slot exceeds hotbar range 0-8: slot is %v", slot) | ||
} | ||
|
||
if p.heldSlot.Swap(uint32(slot)) == uint32(slot) { | ||
return nil | ||
} | ||
|
||
p.ReleaseItem() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should just set |
||
|
||
clientSideItem := expected | ||
actual, _ := p.inv.Item(slot) | ||
|
||
if !clientSideItem.Equal(actual) { | ||
return fmt.Errorf("client side item isn't equal to expected slot item") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code no longer belongs here now that it's a player method, should be moved to packet handling (check a0bb8dd). |
||
} | ||
|
||
ctx := event.C() | ||
p.handler().HandleHeldSlotChange(ctx, slot) | ||
|
||
ctx.Continue(func() { | ||
p.session().SetHeldSlot(slot) | ||
}) | ||
|
||
return nil | ||
} | ||
|
||
// SendCommandOutput sends the output of a command to the player. | ||
func (p *Player) SendCommandOutput(output *cmd.Output) { | ||
p.session().SendCommandOutput(output) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should remove the middle sentence in this doc.