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

     1  package item
     2  
     3  import (
     4  	"github.com/df-mc/dragonfly/server/world"
     5  	"github.com/df-mc/dragonfly/server/world/sound"
     6  	"time"
     7  )
     8  
     9  // EnderPearl is a smooth, greenish-blue item used to teleport and to make an eye of ender.
    10  type EnderPearl struct{}
    11  
    12  // Use ...
    13  func (e EnderPearl) Use(w *world.World, user User, ctx *UseContext) bool {
    14  	create := w.EntityRegistry().Config().EnderPearl
    15  	w.AddEntity(create(eyePosition(user), user.Rotation().Vec3().Mul(1.5), user))
    16  	w.PlaySound(user.Position(), sound.ItemThrow{})
    17  
    18  	ctx.SubtractFromCount(1)
    19  	return true
    20  }
    21  
    22  // Cooldown ...
    23  func (EnderPearl) Cooldown() time.Duration {
    24  	return time.Second
    25  }
    26  
    27  // MaxCount ...
    28  func (EnderPearl) MaxCount() int {
    29  	return 16
    30  }
    31  
    32  // EncodeItem ...
    33  func (EnderPearl) EncodeItem() (name string, meta int16) {
    34  	return "minecraft:ender_pearl", 0
    35  }