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