Search in sources :

Example 11 with Style

use of net.minecraft.text.Style in project AdvancedChatBox by DarkKronicle.

the class ChatSuggestorGui method showUsages.

private void showUsages(Formatting formatting) {
    CommandContextBuilder<CommandSource> commandContextBuilder = this.suggestor.getParse().getContext();
    SuggestionContext<CommandSource> suggestionContext = commandContextBuilder.findSuggestionContext(this.textField.getCursor());
    Map<CommandNode<CommandSource>, String> map = this.client.player.networkHandler.getCommandDispatcher().getSmartUsage(suggestionContext.parent, this.client.player.networkHandler.getCommandSource());
    List<OrderedText> list = new ArrayList<>();
    int i = 0;
    Style style = Style.EMPTY.withColor(formatting);
    for (Map.Entry<CommandNode<CommandSource>, String> commandNodeStringEntry : map.entrySet()) {
        if (!(commandNodeStringEntry.getKey() instanceof LiteralCommandNode)) {
            list.add(OrderedText.styledForwardsVisitedString(commandNodeStringEntry.getValue(), style));
            i = Math.max(i, this.textRenderer.getWidth(commandNodeStringEntry.getValue()));
        }
    }
    if (!list.isEmpty()) {
        this.messages.addAll(list);
        this.x = MathHelper.clamp(this.textField.getCharacterX(suggestionContext.startPos), 0, this.textField.getCharacterX(0) + this.textField.getInnerWidth() - i);
        this.width = i;
    }
}
Also used : LiteralCommandNode(com.mojang.brigadier.tree.LiteralCommandNode) CommandNode(com.mojang.brigadier.tree.CommandNode) ArrayList(java.util.ArrayList) CommandSource(net.minecraft.command.CommandSource) LiteralCommandNode(com.mojang.brigadier.tree.LiteralCommandNode) OrderedText(net.minecraft.text.OrderedText) Style(net.minecraft.text.Style) Map(java.util.Map)

Aggregations

Style (net.minecraft.text.Style)11 LiteralText (net.minecraft.text.LiteralText)5 ClickEvent (net.minecraft.text.ClickEvent)3 TextColor (net.minecraft.text.TextColor)3 CommandDispatcher (com.mojang.brigadier.CommandDispatcher)2 FluidText (io.github.darkkronicle.advancedchatcore.util.FluidText)2 StringMatch (io.github.darkkronicle.advancedchatcore.util.StringMatch)2 CommandSource (net.minecraft.command.CommandSource)2 CommandManager.literal (net.minecraft.server.command.CommandManager.literal)2 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)2 OrderedText (net.minecraft.text.OrderedText)2 Formatting (net.minecraft.util.Formatting)2 Discarpet (Discarpet.Discarpet)1 StringArgumentType (com.mojang.brigadier.arguments.StringArgumentType)1 StringRange (com.mojang.brigadier.context.StringRange)1 SuggestionProvider (com.mojang.brigadier.suggestion.SuggestionProvider)1 CommandNode (com.mojang.brigadier.tree.CommandNode)1 LiteralCommandNode (com.mojang.brigadier.tree.LiteralCommandNode)1 APIResponse (gs.mclo.java.APIResponse)1 ChatFormatterRegistry (io.github.darkkronicle.advancedchatbox.registry.ChatFormatterRegistry)1