Skip to content

Commit

Permalink
feat: Expose using the non-wrapping serializer without game context
Browse files Browse the repository at this point in the history
  • Loading branch information
zml2008 committed Oct 23, 2024
1 parent 62ce846 commit bd0ba84
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.mojang.authlib.GameProfile;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;
import net.kyori.adventure.chat.SignedMessage;
import net.kyori.adventure.identity.Identified;
Expand All @@ -49,6 +50,7 @@
import net.kyori.adventure.text.renderer.ComponentRenderer;
import net.kyori.adventure.text.serializer.ComponentSerializer;
import net.kyori.adventure.util.ComponentMessageThrowable;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.component.DataComponentType;
import net.minecraft.network.chat.MessageSignature;
import net.minecraft.network.chat.PlayerChatMessage;
Expand Down Expand Up @@ -154,6 +156,22 @@ static Sound.Emitter asEmitter(final Entity entity) {
return (Sound.Emitter) entity;
}

/**
* Return a ComponentSerializer instance that will do deep conversions between
* Adventure {@link Component Components} and Minecraft {@link net.minecraft.network.chat.Component Components}.
*
* <p>This serializer will never wrap text, and can provide {@link net.minecraft.network.chat.MutableComponent}
* instances suitable for passing around the game. This variant is available to create such a serializer without game context.
* For in-game use, {@link #nonWrappingSerializer()} may be simpler.</p>
*
* @param provider a provider of registry information
* @return a serializer instance
* @since 6.1.0
*/
static @NotNull ComponentSerializer<Component, Component, net.minecraft.network.chat.Component> nonWrappingSerializer(final Supplier<HolderLookup.Provider> provider) {
return new NonWrappingComponentSerializer(provider);
}

/**
* Expose a Brigadier CommandSyntaxException's message using the adventure-provided interface for rich-message exceptions.
*
Expand All @@ -170,7 +188,7 @@ default ComponentMessageThrowable asComponentThrowable(final CommandSyntaxExcept
}

/**
* Return a TextSerializer instance that will do deep conversions between
* Return a ComponentSerializer instance that will do deep conversions between
* Adventure {@link Component Components} and Minecraft {@link net.minecraft.network.chat.Component Components}.
*
* <p>This serializer will never wrap text, and can provide {@link net.minecraft.network.chat.MutableComponent}
Expand Down

0 comments on commit bd0ba84

Please sign in to comment.