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

     1  package block
     2  
     3  import (
     4  	"github.com/df-mc/dragonfly/server/internal/nbtconv"
     5  	"github.com/df-mc/dragonfly/server/item"
     6  )
     7  
     8  // BannerPatternLayer is a wrapper over BannerPatternType with a colour property.
     9  type BannerPatternLayer struct {
    10  	// Type represents the type of banner pattern.
    11  	Type BannerPatternType
    12  	// Colour is the colour the pattern should be rendered in.
    13  	Colour item.Colour
    14  }
    15  
    16  // EncodeNBT encodes the given BannerPatternLayer into an NBT map.
    17  func (b BannerPatternLayer) EncodeNBT() map[string]any {
    18  	return map[string]any{
    19  		"Pattern": bannerPatternID(b.Type),
    20  		"Color":   int32(invertColour(b.Colour)),
    21  	}
    22  }
    23  
    24  // DecodeNBT decodes the given NBT map into a BannerPatternLayer and returns it.
    25  func (b BannerPatternLayer) DecodeNBT(data map[string]any) any {
    26  	b.Type = BannerPatternByID(nbtconv.String(data, "Pattern"))
    27  	b.Colour = invertColourID(int16(nbtconv.Int32(data, "Color")))
    28  	return b
    29  }