diff --git a/server/item/inventory/handler.go b/server/item/inventory/handler.go index 041f66c26..b95bb4b96 100644 --- a/server/item/inventory/handler.go +++ b/server/item/inventory/handler.go @@ -15,6 +15,9 @@ 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. + // slot will return -1 when it comes from the cursor inventory otherwise the correct inventory slot. + HandleDestroy(ctx *event.Context, slot int, it item.Stack) } // Check to make sure NopHandler implements Handler. @@ -24,6 +27,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) {} diff --git a/server/session/handler_item_stack_request.go b/server/session/handler_item_stack_request.go index 79b40e447..ab18ae444 100644 --- a/server/session/handler_item_stack_request.go +++ b/server/session/handler_item_stack_request.go @@ -233,6 +233,16 @@ func (h *ItemStackRequestHandler) handleDestroy(a *protocol.DestroyStackRequestA if i.Count() < int(a.Count) { return fmt.Errorf("client attempted to destroy %v items, but only %v present", a.Count, i.Count()) } + slot := func() int { + if a.Source.ContainerID == protocol.ContainerCursor { + return -1 + } + + return int(a.Source.Slot) + } + if err := call(event.C(), 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