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

     1  package entity
     2  
     3  import (
     4  	"github.com/df-mc/dragonfly/server/block/cube"
     5  	"github.com/df-mc/dragonfly/server/entity/effect"
     6  	"github.com/df-mc/dragonfly/server/internal/nbtconv"
     7  	"github.com/df-mc/dragonfly/server/item/potion"
     8  	"github.com/df-mc/dragonfly/server/world"
     9  	"github.com/df-mc/dragonfly/server/world/particle"
    10  	"github.com/go-gl/mathgl/mgl64"
    11  )
    12  
    13  // NewLingeringPotion creates a new lingering potion. LingeringPotion is a
    14  // variant of a splash potion that can be thrown to leave clouds with status
    15  // effects that linger on the ground in an area.
    16  func NewLingeringPotion(pos mgl64.Vec3, owner world.Entity, t potion.Potion) *Ent {
    17  	colour, _ := effect.ResultingColour(t.Effects())
    18  
    19  	conf := splashPotionConf
    20  	conf.Potion = t
    21  	conf.Particle = particle.Splash{Colour: colour}
    22  	conf.Hit = potionSplash(0.25, t, true)
    23  	return Config{Behaviour: conf.New(owner)}.New(LingeringPotionType{}, pos)
    24  }
    25  
    26  // LingeringPotionType is a world.EntityType implementation for LingeringPotion.
    27  type LingeringPotionType struct{}
    28  
    29  func (LingeringPotionType) EncodeEntity() string {
    30  	return "minecraft:lingering_potion"
    31  }
    32  func (LingeringPotionType) Glint() bool { return true }
    33  func (LingeringPotionType) BBox(world.Entity) cube.BBox {
    34  	return cube.Box(-0.125, 0, -0.125, 0.125, 0.25, 0.125)
    35  }
    36  
    37  func (LingeringPotionType) DecodeNBT(m map[string]any) world.Entity {
    38  	pot := NewLingeringPotion(nbtconv.Vec3(m, "Pos"), nil, potion.From(nbtconv.Int32(m, "PotionId")))
    39  	pot.vel = nbtconv.Vec3(m, "Motion")
    40  	return pot
    41  }
    42  
    43  func (LingeringPotionType) EncodeNBT(e world.Entity) map[string]any {
    44  	pot := e.(*Ent)
    45  	return map[string]any{
    46  		"Pos":      nbtconv.Vec3ToFloat32Slice(pot.Position()),
    47  		"Motion":   nbtconv.Vec3ToFloat32Slice(pot.Velocity()),
    48  		"PotionId": int32(pot.conf.Behaviour.(*ProjectileBehaviour).conf.Potion.Uint8()),
    49  	}
    50  }