github.com/df-mc/dragonfly@v0.9.13/server/player/skin/model_config.go (about) 1 package skin 2 3 import ( 4 "encoding/json" 5 ) 6 7 // ModelConfig specifies the way that the model (geometry data) is used to form the complete skin. It does 8 // this by setting model names for specific keys found in the struct. 9 type ModelConfig struct { 10 // Default is the 'default' model to use. This model is essentially the model of the skin that will be 11 // used at all times, when nothing special is being done. (For example, an animation) 12 // The field holds the name of one of the models present in the JSON of the skin's model. 13 // This field should always be filled out. 14 Default string `json:"default"` 15 // AnimatedFace is the model of an animation played over the face. This field should be set if the model 16 // contains the model of an animation, in which case this field should hold the name of that model. 17 AnimatedFace string `json:"animated_face,omitempty"` 18 } 19 20 // modelConfigContainer is a container of the model config data when encoded. 21 type modelConfigContainer struct { 22 Geometry ModelConfig `json:"geometry"` 23 } 24 25 // Encode encodes a ModelConfig into its JSON representation. 26 func (cfg ModelConfig) Encode() []byte { 27 b, _ := json.Marshal(modelConfigContainer{Geometry: cfg}) 28 return b 29 } 30 31 // DecodeModelConfig attempts to decode a ModelConfig from the JSON data passed. If not successful, an error 32 // is returned. 33 func DecodeModelConfig(b []byte) (ModelConfig, error) { 34 var m modelConfigContainer 35 err := json.Unmarshal(b, &m) 36 return m.Geometry, err 37 }