Files
mc/server/session/handler_mob_equipment.go
T
TarnaWijaya 26ed99fda6
Build and deploy / Build (push) Has been cancelled
Build and deploy / Update Contributors (push) Has been cancelled
Build and deploy / Deploy (push) Has been cancelled
up3
2026-07-09 08:33:57 +08:00

30 lines
889 B
Go

package session
import (
"fmt"
"github.com/df-mc/dragonfly/server/world"
"github.com/sandertv/gophertunnel/minecraft/protocol"
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
)
// MobEquipmentHandler handles the MobEquipment packet.
type MobEquipmentHandler struct{}
// Handle ...
func (*MobEquipmentHandler) Handle(p packet.Packet, s *Session, tx *world.Tx, c Controllable) error {
pk := p.(*packet.MobEquipment)
if pk.EntityRuntimeID != selfEntityRuntimeID {
return errSelfRuntimeID
}
switch pk.WindowID {
case protocol.WindowIDOffHand:
// This window ID is expected, but we don't handle it.
return nil
case protocol.WindowIDInventory:
return s.VerifyAndSetHeldSlot(int(pk.InventorySlot), stackToItem(s.br, pk.NewItem.Stack), c)
default:
return fmt.Errorf("only main inventory should be involved in slot change, got window ID %v", pk.WindowID)
}
}