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

     1  package item
     2  
     3  import (
     4  	"github.com/df-mc/dragonfly/server/item/potion"
     5  	"github.com/df-mc/dragonfly/server/world"
     6  	"github.com/df-mc/dragonfly/server/world/sound"
     7  )
     8  
     9  // LingeringPotion is a variant of a splash potion that can be thrown to leave clouds with status effects that linger on
    10  // the ground in an area.
    11  type LingeringPotion struct {
    12  	// Type is the type of lingering potion.
    13  	Type potion.Potion
    14  }
    15  
    16  // MaxCount ...
    17  func (l LingeringPotion) MaxCount() int {
    18  	return 1
    19  }
    20  
    21  // Use ...
    22  func (l LingeringPotion) Use(w *world.World, user User, ctx *UseContext) bool {
    23  	create := w.EntityRegistry().Config().LingeringPotion
    24  	w.AddEntity(create(eyePosition(user), user.Rotation().Vec3().Mul(0.5), l.Type, user))
    25  	w.PlaySound(user.Position(), sound.ItemThrow{})
    26  
    27  	ctx.SubtractFromCount(1)
    28  	return true
    29  }
    30  
    31  // EncodeItem ...
    32  func (l LingeringPotion) EncodeItem() (name string, meta int16) {
    33  	return "minecraft:lingering_potion", int16(l.Type.Uint8())
    34  }