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

     1  package session
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/sandertv/gophertunnel/minecraft/protocol"
     6  	"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
     7  )
     8  
     9  // MobEquipmentHandler handles the MobEquipment packet.
    10  type MobEquipmentHandler struct{}
    11  
    12  // Handle ...
    13  func (*MobEquipmentHandler) Handle(p packet.Packet, s *Session) error {
    14  	pk := p.(*packet.MobEquipment)
    15  
    16  	if pk.EntityRuntimeID != selfEntityRuntimeID {
    17  		return errSelfRuntimeID
    18  	}
    19  	switch pk.WindowID {
    20  	case protocol.WindowIDOffHand:
    21  		// This window ID is expected, but we don't handle it.
    22  		return nil
    23  	case protocol.WindowIDInventory:
    24  		return s.UpdateHeldSlot(int(pk.InventorySlot), stackToItem(pk.NewItem.Stack))
    25  	default:
    26  		return fmt.Errorf("only main inventory should be involved in slot chnage, got window ID %v", pk.WindowID)
    27  	}
    28  }