Skip to content

Commit

Permalink
Implemented handleDestroy event
Browse files Browse the repository at this point in the history
  • Loading branch information
Erkam246 committed Dec 20, 2023
1 parent 21eb18f commit ec27ec6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions server/item/inventory/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type Handler interface {
HandlePlace(ctx *event.Context, slot int, it item.Stack)
// HandleDrop handles the dropping of an item.Stack in a slot out of the inventory.
HandleDrop(ctx *event.Context, slot int, it item.Stack)
// HandleDestroy handles the destroying of an item.Stack in a creative inventory.
HandleDestroy(ctx *event.Context, slot int, it item.Stack)
}

// Check to make sure NopHandler implements Handler.
Expand All @@ -24,6 +26,7 @@ var _ Handler = NopHandler{}
// Handler of an Inventory.
type NopHandler struct{}

func (NopHandler) HandleTake(*event.Context, int, item.Stack) {}
func (NopHandler) HandlePlace(*event.Context, int, item.Stack) {}
func (NopHandler) HandleDrop(*event.Context, int, item.Stack) {}
func (NopHandler) HandleTake(*event.Context, int, item.Stack) {}
func (NopHandler) HandlePlace(*event.Context, int, item.Stack) {}
func (NopHandler) HandleDrop(*event.Context, int, item.Stack) {}
func (NopHandler) HandleDestroy(*event.Context, int, item.Stack) {}
4 changes: 4 additions & 0 deletions server/session/handler_item_stack_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ func (h *ItemStackRequestHandler) handleDestroy(a *protocol.DestroyStackRequestA
return fmt.Errorf("client attempted to destroy %v items, but only %v present", a.Count, i.Count())
}

if err := call(event.C(), int(a.Source.Slot), i.Grow(int(a.Count)-i.Count()), s.inv.Handler().HandleDestroy); err != nil {
return err
}

h.setItemInSlot(a.Source, i.Grow(-int(a.Count)), s)
return nil
}
Expand Down

0 comments on commit ec27ec6

Please sign in to comment.