1111import com .mojang .serialization .JsonOps ;
1212import com .mojang .serialization .MapCodec ;
1313import com .mojang .serialization .codecs .RecordCodecBuilder ;
14- import java .io .IOException ;
1514import java .util .Collections ;
1615import java .util .List ;
1716import java .util .Map ;
3736import net .kyori .adventure .text .event .DataComponentValue ;
3837import net .kyori .adventure .text .event .HoverEvent ;
3938import net .kyori .adventure .text .format .NamedTextColor ;
39+ import net .kyori .adventure .text .format .ShadowColor ;
4040import net .kyori .adventure .text .format .Style ;
4141import net .kyori .adventure .text .format .TextColor ;
4242import net .kyori .adventure .text .format .TextDecoration ;
@@ -79,6 +79,11 @@ public final class AdventureCodecs {
7979 public static final Codec <Component > COMPONENT_CODEC = recursive ("adventure Component" , AdventureCodecs ::createCodec );
8080 public static final StreamCodec <RegistryFriendlyByteBuf , Component > STREAM_COMPONENT_CODEC = ByteBufCodecs .fromCodecWithRegistriesTrusted (COMPONENT_CODEC );
8181
82+ static final Codec <ShadowColor > SHADOW_COLOR_CODEC = Codec .INT .comapFlatMap (s -> {
83+ @ Nullable ShadowColor value = ShadowColor .shadowColor (s );
84+ return value != null ? DataResult .success (value ) : DataResult .error (() -> "Cannot convert " + s + " to adventure ShadowColor" );
85+ }, ShadowColor ::value );
86+
8287 static final Codec <TextColor > TEXT_COLOR_CODEC = Codec .STRING .comapFlatMap (s -> {
8388 if (s .startsWith ("#" )) {
8489 @ Nullable TextColor value = TextColor .fromHexString (s );
@@ -228,8 +233,9 @@ public String getSerializedName() {
228233 CLICK_EVENT_CODEC .optionalFieldOf ("clickEvent" ).forGetter (nullableGetter (Style ::clickEvent )),
229234 HOVER_EVENT_CODEC .optionalFieldOf ("hoverEvent" ).forGetter (nullableGetter (Style ::hoverEvent )),
230235 Codec .STRING .optionalFieldOf ("insertion" ).forGetter (nullableGetter (Style ::insertion )),
231- KEY_CODEC .optionalFieldOf ("font" ).forGetter (nullableGetter (Style ::font ))
232- ).apply (instance , (textColor , bold , italic , underlined , strikethrough , obfuscated , clickEvent , hoverEvent , insertion , font ) -> {
236+ KEY_CODEC .optionalFieldOf ("font" ).forGetter (nullableGetter (Style ::font )),
237+ SHADOW_COLOR_CODEC .optionalFieldOf ("shadow_color" ).forGetter (nullableGetter (Style ::shadowColor ))
238+ ).apply (instance , (textColor , bold , italic , underlined , strikethrough , obfuscated , clickEvent , hoverEvent , insertion , font , shadowColor ) -> {
233239 return Style .style (builder -> {
234240 textColor .ifPresent (builder ::color );
235241 bold .ifPresent (styleBooleanConsumer (builder , TextDecoration .BOLD ));
@@ -241,6 +247,7 @@ public String getSerializedName() {
241247 hoverEvent .ifPresent (builder ::hoverEvent );
242248 insertion .ifPresent (builder ::insertion );
243249 font .ifPresent (builder ::font );
250+ shadowColor .ifPresent (builder ::shadowColor );
244251 });
245252 });
246253 });
0 commit comments