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

     1  package entity
     2  
     3  import (
     4  	"github.com/df-mc/dragonfly/server/block/cube"
     5  	"github.com/df-mc/dragonfly/server/internal/nbtconv"
     6  	"github.com/df-mc/dragonfly/server/world"
     7  	"github.com/df-mc/dragonfly/server/world/particle"
     8  	"github.com/go-gl/mathgl/mgl64"
     9  )
    10  
    11  // NewSnowball creates a snowball entity at a position with an owner entity.
    12  func NewSnowball(pos mgl64.Vec3, owner world.Entity) *Ent {
    13  	return Config{Behaviour: snowballConf.New(owner)}.New(SnowballType{}, pos)
    14  }
    15  
    16  var snowballConf = ProjectileBehaviourConfig{
    17  	Gravity:       0.03,
    18  	Drag:          0.01,
    19  	Particle:      particle.SnowballPoof{},
    20  	ParticleCount: 6,
    21  }
    22  
    23  // SnowballType is a world.EntityType implementation for snowballs.
    24  type SnowballType struct{}
    25  
    26  func (SnowballType) EncodeEntity() string { return "minecraft:snowball" }
    27  func (SnowballType) BBox(world.Entity) cube.BBox {
    28  	return cube.Box(-0.125, 0, -0.125, 0.125, 0.25, 0.125)
    29  }
    30  
    31  func (SnowballType) DecodeNBT(m map[string]any) world.Entity {
    32  	s := NewSnowball(nbtconv.Vec3(m, "Pos"), nil)
    33  	s.vel = nbtconv.Vec3(m, "Motion")
    34  	return s
    35  }
    36  
    37  func (SnowballType) EncodeNBT(e world.Entity) map[string]any {
    38  	s := e.(*Ent)
    39  	return map[string]any{
    40  		"Pos":    nbtconv.Vec3ToFloat32Slice(s.Position()),
    41  		"Motion": nbtconv.Vec3ToFloat32Slice(s.Velocity()),
    42  	}
    43  }