github.com/df-mc/dragonfly@v0.9.13/server/entity/text.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/go-gl/mathgl/mgl64" 8 ) 9 10 // NewText creates and returns a new Text entity with the text and position provided. 11 func NewText(text string, pos mgl64.Vec3) *Ent { 12 e := Config{Behaviour: textConf.New()}.New(TextType{}, pos) 13 e.SetNameTag(text) 14 return e 15 } 16 17 var textConf StationaryBehaviourConfig 18 19 // TextType is a world.EntityType implementation for Text. 20 type TextType struct{} 21 22 func (TextType) EncodeEntity() string { return "dragonfly:text" } 23 func (TextType) BBox(world.Entity) cube.BBox { return cube.BBox{} } 24 func (TextType) NetworkEncodeEntity() string { return "minecraft:falling_block" } 25 26 func (TextType) DecodeNBT(m map[string]any) world.Entity { 27 return NewText(nbtconv.String(m, "Text"), nbtconv.Vec3(m, "Pos")) 28 } 29 30 func (TextType) EncodeNBT(e world.Entity) map[string]any { 31 t := e.(*Ent) 32 return map[string]any{ 33 "Pos": nbtconv.Vec3ToFloat32Slice(t.Position()), 34 "Text": t.NameTag(), 35 } 36 }