github.com/df-mc/dragonfly@v0.9.13/server/item/firework_explosion.go (about) 1 package item 2 3 // FireworkExplosion represents an explosion of a firework. 4 type FireworkExplosion struct { 5 // Shape represents the shape of the explosion. 6 Shape FireworkShape 7 // Colour is the colour of the explosion. 8 Colour Colour 9 // Fade is the colour the explosion should fade into. Fades must be set to true in order for this to function. 10 Fade Colour 11 // Fades is true if the explosion should fade into the fade colour. 12 Fades bool 13 // Twinkle is true if the explosion should twinkle on explode. 14 Twinkle bool 15 // Trail is true if the explosion should have a trail. 16 Trail bool 17 } 18 19 // EncodeNBT ... 20 func (f FireworkExplosion) EncodeNBT() map[string]any { 21 data := map[string]any{ 22 "FireworkType": f.Shape.Uint8(), 23 "FireworkColor": [1]uint8{uint8(invertColour(f.Colour))}, 24 "FireworkFade": [0]uint8{}, 25 "FireworkFlicker": boolByte(f.Twinkle), 26 "FireworkTrail": boolByte(f.Trail), 27 } 28 if f.Fades { 29 data["FireworkFade"] = [1]uint8{uint8(invertColour(f.Fade))} 30 } 31 return data 32 } 33 34 // DecodeNBT ... 35 func (f FireworkExplosion) DecodeNBT(data map[string]any) any { 36 f.Shape = FireworkShapes()[data["FireworkType"].(uint8)] 37 f.Twinkle = data["FireworkFlicker"].(uint8) == 1 38 f.Trail = data["FireworkTrail"].(uint8) == 1 39 40 colours := data["FireworkColor"] 41 if diskColour, ok := colours.([1]uint8); ok { 42 f.Colour = invertColourID(int16(diskColour[0])) 43 } else if networkColours, ok := colours.([]any); ok { 44 f.Colour = invertColourID(int16(networkColours[0].(uint8))) 45 } 46 47 if fades, ok := data["FireworkFade"].([1]uint8); ok { 48 f.Fade, f.Fades = invertColourID(int16(fades[0])), true 49 } 50 return f 51 }