github.com/df-mc/dragonfly@v0.9.13/server/session/handler_stonecutter.go (about)

     1  package session
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/df-mc/dragonfly/server/item/recipe"
     6  	"github.com/sandertv/gophertunnel/minecraft/protocol"
     7  )
     8  
     9  // stonecutterInputSlot is the slot index of the input item in the stonecutter.
    10  const stonecutterInputSlot = 0x03
    11  
    12  // handleStonecutting handles a CraftRecipe stack request action made using a stonecutter.
    13  func (h *ItemStackRequestHandler) handleStonecutting(a *protocol.CraftRecipeStackRequestAction, s *Session) error {
    14  	craft, ok := s.recipes[a.RecipeNetworkID]
    15  	if !ok {
    16  		return fmt.Errorf("recipe with network id %v does not exist", a.RecipeNetworkID)
    17  	}
    18  	if _, shapeless := craft.(recipe.Shapeless); !shapeless {
    19  		return fmt.Errorf("recipe with network id %v is not a shapeless recipe", a.RecipeNetworkID)
    20  	}
    21  	if craft.Block() != "stonecutter" {
    22  		return fmt.Errorf("recipe with network id %v is not a stonecutter recipe", a.RecipeNetworkID)
    23  	}
    24  
    25  	expectedInputs := craft.Input()
    26  	input, _ := h.itemInSlot(protocol.StackRequestSlotInfo{
    27  		ContainerID: protocol.ContainerStonecutterInput,
    28  		Slot:        stonecutterInputSlot,
    29  	}, s)
    30  	if !matchingStacks(input, expectedInputs[0]) {
    31  		return fmt.Errorf("input item is not the same as expected input")
    32  	}
    33  
    34  	output := craft.Output()
    35  	h.setItemInSlot(protocol.StackRequestSlotInfo{
    36  		ContainerID: protocol.ContainerStonecutterInput,
    37  		Slot:        stonecutterInputSlot,
    38  	}, input.Grow(-1), s)
    39  	return h.createResults(s, output...)
    40  }