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

     1  package session
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/df-mc/dragonfly/server/block"
     6  	"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
     7  )
     8  
     9  // LecternUpdateHandler handles the LecternUpdate packet, sent when a player interacts with a lectern.
    10  type LecternUpdateHandler struct{}
    11  
    12  // Handle ...
    13  func (LecternUpdateHandler) Handle(p packet.Packet, s *Session) error {
    14  	pk := p.(*packet.LecternUpdate)
    15  	if pk.DropBook {
    16  		// This is completely redundant, so ignore this packet.
    17  		return nil
    18  	}
    19  
    20  	pos := blockPosFromProtocol(pk.Position)
    21  	if !canReach(s.c, pos.Vec3Middle()) {
    22  		return fmt.Errorf("block at %v is not within reach", pos)
    23  	}
    24  	if _, ok := s.c.World().Block(pos).(block.Lectern); !ok {
    25  		return fmt.Errorf("block at %v is not a lectern", pos)
    26  	}
    27  	return s.c.TurnLecternPage(pos, int(pk.Page))
    28  }