-
Notifications
You must be signed in to change notification settings - Fork 202
server/session: Resend inventories on item release to keep the client in sync #1281
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
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 |
|---|---|---|
|
|
@@ -45,7 +45,7 @@ func (h *InventoryTransactionHandler) Handle(p packet.Packet, s *Session, tx *wo | |
|
|
||
| switch data := pk.TransactionData.(type) { | ||
| case *protocol.NormalTransactionData: | ||
| h.resendInventories(s) | ||
| s.resendInventories() | ||
| // Always resend inventories with normal transactions. Most of the time we do not use these | ||
| // transactions, so we're best off making sure the client and server stay in sync. | ||
| if err := h.handleNormalTransaction(pk, s, c); err != nil { | ||
|
|
@@ -54,7 +54,7 @@ func (h *InventoryTransactionHandler) Handle(p packet.Packet, s *Session, tx *wo | |
| return | ||
| case *protocol.MismatchTransactionData: | ||
| // Just resend the inventory and don't do anything. | ||
| h.resendInventories(s) | ||
| s.resendInventories() | ||
| return | ||
| case *protocol.UseItemOnEntityTransactionData: | ||
| if err = s.VerifyAndSetHeldSlot(int(data.HotBarSlot), stackToItem(s.br, data.HeldItem.Stack), c); err != nil { | ||
|
|
@@ -70,13 +70,13 @@ func (h *InventoryTransactionHandler) Handle(p packet.Packet, s *Session, tx *wo | |
| if err = s.VerifyAndSetHeldSlot(int(data.HotBarSlot), stackToItem(s.br, data.HeldItem.Stack), c); err != nil { | ||
| return | ||
| } | ||
| return h.handleReleaseItemTransaction(c) | ||
| return h.handleReleaseItemTransaction(s, c) | ||
| } | ||
| return fmt.Errorf("unhandled inventory transaction type %T", pk.TransactionData) | ||
| } | ||
|
|
||
| // resendInventories resends all inventories of the player. | ||
| func (h *InventoryTransactionHandler) resendInventories(s *Session) { | ||
| func (s *Session) resendInventories() { | ||
| s.sendInv(s.inv, protocol.WindowIDInventory) | ||
| s.sendInv(s.ui, protocol.WindowIDUI) | ||
| s.sendInv(s.offHand, protocol.WindowIDOffHand) | ||
|
|
@@ -183,7 +183,7 @@ func (h *InventoryTransactionHandler) handleUseItemTransaction(data *protocol.Us | |
| // having done that client-side. | ||
| // Because of the new inventory system, the client will expect a transaction confirmation, but instead of doing that | ||
| // it's much easier to just resend the inventory. | ||
| h.resendInventories(s) | ||
| s.resendInventories() | ||
|
|
||
| switch data.ActionType { | ||
| case protocol.UseItemActionBreakBlock: | ||
|
|
@@ -199,7 +199,11 @@ func (h *InventoryTransactionHandler) handleUseItemTransaction(data *protocol.Us | |
| } | ||
|
|
||
| // handleReleaseItemTransaction ... | ||
| func (h *InventoryTransactionHandler) handleReleaseItemTransaction(c Controllable) error { | ||
| func (h *InventoryTransactionHandler) handleReleaseItemTransaction(s *Session, c Controllable) error { | ||
| // The client predicts the result of releasing an item, such as an arrow being removed from the | ||
| // inventory when a bow is fired. Resend the inventories so that the client stays in sync if the | ||
| // release does not actually consume the predicted items, for example when it is cancelled. | ||
| s.resendInventories() | ||
|
Contributor
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. wrong logic, It won't fix anything, it will only make things worse... |
||
| c.ReleaseItem() | ||
| return nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,11 @@ func handlePlayerAction(action int32, face int32, pos protocol.BlockPos, entityR | |
| case protocol.PlayerActionStartItemUseOn: | ||
| // TODO: Properly utilize these actions. | ||
| case protocol.PlayerActionStopItemUseOn: | ||
| // The client predicts the result of releasing an item, such as an arrow being removed from | ||
|
Collaborator
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 comment could be 1 line |
||
| // the inventory when a bow is fired. Resend the inventories so that the client stays in sync | ||
| // if the release does not actually consume the predicted items, for example when it is | ||
| // cancelled. | ||
| s.resendInventories() | ||
|
Contributor
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. wrong logic... |
||
| c.ReleaseItem() | ||
| case protocol.PlayerActionStartBuildingBlock: | ||
| // Don't do anything for this action. | ||
|
|
||
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.
this comment could be 1 line