|
|
|
@ -11,7 +11,6 @@ import com.mojang.serialization.DynamicOps;
|
|
|
|
import com.mojang.serialization.JsonOps;
|
|
|
|
import com.mojang.serialization.JsonOps;
|
|
|
|
import com.mojang.serialization.MapCodec;
|
|
|
|
import com.mojang.serialization.MapCodec;
|
|
|
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
|
|
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
@ -37,6 +36,7 @@ import net.kyori.adventure.text.event.ClickEvent;
|
|
|
|
import net.kyori.adventure.text.event.DataComponentValue;
|
|
|
|
import net.kyori.adventure.text.event.DataComponentValue;
|
|
|
|
import net.kyori.adventure.text.event.HoverEvent;
|
|
|
|
import net.kyori.adventure.text.event.HoverEvent;
|
|
|
|
import net.kyori.adventure.text.format.NamedTextColor;
|
|
|
|
import net.kyori.adventure.text.format.NamedTextColor;
|
|
|
|
|
|
|
|
import net.kyori.adventure.text.format.ShadowColor;
|
|
|
|
import net.kyori.adventure.text.format.Style;
|
|
|
|
import net.kyori.adventure.text.format.Style;
|
|
|
|
import net.kyori.adventure.text.format.TextColor;
|
|
|
|
import net.kyori.adventure.text.format.TextColor;
|
|
|
|
import net.kyori.adventure.text.format.TextDecoration;
|
|
|
|
import net.kyori.adventure.text.format.TextDecoration;
|
|
|
|
@ -79,6 +79,8 @@ public final class AdventureCodecs {
|
|
|
|
public static final Codec<Component> COMPONENT_CODEC = recursive("adventure Component", AdventureCodecs::createCodec);
|
|
|
|
public static final Codec<Component> COMPONENT_CODEC = recursive("adventure Component", AdventureCodecs::createCodec);
|
|
|
|
public static final StreamCodec<RegistryFriendlyByteBuf, Component> STREAM_COMPONENT_CODEC = ByteBufCodecs.fromCodecWithRegistriesTrusted(COMPONENT_CODEC);
|
|
|
|
public static final StreamCodec<RegistryFriendlyByteBuf, Component> STREAM_COMPONENT_CODEC = ByteBufCodecs.fromCodecWithRegistriesTrusted(COMPONENT_CODEC);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static final Codec<ShadowColor> SHADOW_COLOR_CODEC = ExtraCodecs.ARGB_COLOR_CODEC.xmap(ShadowColor::shadowColor, ShadowColor::value);
|
|
|
|
|
|
|
|
|
|
|
|
static final Codec<TextColor> TEXT_COLOR_CODEC = Codec.STRING.comapFlatMap(s -> {
|
|
|
|
static final Codec<TextColor> TEXT_COLOR_CODEC = Codec.STRING.comapFlatMap(s -> {
|
|
|
|
if (s.startsWith("#")) {
|
|
|
|
if (s.startsWith("#")) {
|
|
|
|
@Nullable TextColor value = TextColor.fromHexString(s);
|
|
|
|
@Nullable TextColor value = TextColor.fromHexString(s);
|
|
|
|
@ -220,6 +222,7 @@ public final class AdventureCodecs {
|
|
|
|
public static final MapCodec<Style> STYLE_MAP_CODEC = mapCodec((instance) -> {
|
|
|
|
public static final MapCodec<Style> STYLE_MAP_CODEC = mapCodec((instance) -> {
|
|
|
|
return instance.group(
|
|
|
|
return instance.group(
|
|
|
|
TEXT_COLOR_CODEC.optionalFieldOf("color").forGetter(nullableGetter(Style::color)),
|
|
|
|
TEXT_COLOR_CODEC.optionalFieldOf("color").forGetter(nullableGetter(Style::color)),
|
|
|
|
|
|
|
|
SHADOW_COLOR_CODEC.optionalFieldOf("shadow_color").forGetter(nullableGetter(Style::shadowColor)),
|
|
|
|
Codec.BOOL.optionalFieldOf("bold").forGetter(decorationGetter(TextDecoration.BOLD)),
|
|
|
|
Codec.BOOL.optionalFieldOf("bold").forGetter(decorationGetter(TextDecoration.BOLD)),
|
|
|
|
Codec.BOOL.optionalFieldOf("italic").forGetter(decorationGetter(TextDecoration.ITALIC)),
|
|
|
|
Codec.BOOL.optionalFieldOf("italic").forGetter(decorationGetter(TextDecoration.ITALIC)),
|
|
|
|
Codec.BOOL.optionalFieldOf("underlined").forGetter(decorationGetter(TextDecoration.UNDERLINED)),
|
|
|
|
Codec.BOOL.optionalFieldOf("underlined").forGetter(decorationGetter(TextDecoration.UNDERLINED)),
|
|
|
|
@ -229,9 +232,10 @@ public final class AdventureCodecs {
|
|
|
|
HOVER_EVENT_CODEC.optionalFieldOf("hoverEvent").forGetter(nullableGetter(Style::hoverEvent)),
|
|
|
|
HOVER_EVENT_CODEC.optionalFieldOf("hoverEvent").forGetter(nullableGetter(Style::hoverEvent)),
|
|
|
|
Codec.STRING.optionalFieldOf("insertion").forGetter(nullableGetter(Style::insertion)),
|
|
|
|
Codec.STRING.optionalFieldOf("insertion").forGetter(nullableGetter(Style::insertion)),
|
|
|
|
KEY_CODEC.optionalFieldOf("font").forGetter(nullableGetter(Style::font))
|
|
|
|
KEY_CODEC.optionalFieldOf("font").forGetter(nullableGetter(Style::font))
|
|
|
|
).apply(instance, (textColor, bold, italic, underlined, strikethrough, obfuscated, clickEvent, hoverEvent, insertion, font) -> {
|
|
|
|
).apply(instance, (textColor, shadowColor, bold, italic, underlined, strikethrough, obfuscated, clickEvent, hoverEvent, insertion, font) -> {
|
|
|
|
return Style.style(builder -> {
|
|
|
|
return Style.style(builder -> {
|
|
|
|
textColor.ifPresent(builder::color);
|
|
|
|
textColor.ifPresent(builder::color);
|
|
|
|
|
|
|
|
shadowColor.ifPresent(builder::shadowColor);
|
|
|
|
bold.ifPresent(styleBooleanConsumer(builder, TextDecoration.BOLD));
|
|
|
|
bold.ifPresent(styleBooleanConsumer(builder, TextDecoration.BOLD));
|
|
|
|
italic.ifPresent(styleBooleanConsumer(builder, TextDecoration.ITALIC));
|
|
|
|
italic.ifPresent(styleBooleanConsumer(builder, TextDecoration.ITALIC));
|
|
|
|
underlined.ifPresent(styleBooleanConsumer(builder, TextDecoration.UNDERLINED));
|
|
|
|
underlined.ifPresent(styleBooleanConsumer(builder, TextDecoration.UNDERLINED));
|
|
|
|
|