Search in sources :

Example 26 with MutableText

use of net.minecraft.text.MutableText in project meteor-client by MeteorDevelopment.

the class BindsCommand method getTooltip.

private MutableText getTooltip(Module module) {
    MutableText tooltip = new LiteralText(Utils.nameToTitle(module.title)).formatted(Formatting.BLUE, Formatting.BOLD).append("\n\n");
    tooltip.append(new LiteralText(module.description).formatted(Formatting.WHITE));
    return tooltip;
}
Also used : MutableText(net.minecraft.text.MutableText) LiteralText(net.minecraft.text.LiteralText)

Example 27 with MutableText

use of net.minecraft.text.MutableText in project meteor-client by MeteorDevelopment.

the class BindsCommand method build.

@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
    builder.executes(context -> {
        // Modules
        List<Module> modules = Modules.get().getAll().stream().filter(module -> module.keybind.isSet()).collect(Collectors.toList());
        ChatUtils.info("--- Bound Modules ((highlight)%d(default)) ---", modules.size());
        for (Module module : modules) {
            HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, getTooltip(module));
            MutableText text = new LiteralText(module.title).formatted(Formatting.WHITE);
            text.setStyle(text.getStyle().withHoverEvent(hoverEvent));
            MutableText sep = new LiteralText(" - ");
            sep.setStyle(sep.getStyle().withHoverEvent(hoverEvent));
            text.append(sep.formatted(Formatting.GRAY));
            MutableText key = new LiteralText(module.keybind.toString());
            key.setStyle(key.getStyle().withHoverEvent(hoverEvent));
            text.append(key.formatted(Formatting.GRAY));
            ChatUtils.sendMsg(text);
        }
        return SINGLE_SUCCESS;
    });
}
Also used : LiteralText(net.minecraft.text.LiteralText) HoverEvent(net.minecraft.text.HoverEvent) Collectors(java.util.stream.Collectors) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) CommandSource(net.minecraft.command.CommandSource) SINGLE_SUCCESS(com.mojang.brigadier.Command.SINGLE_SUCCESS) Formatting(net.minecraft.util.Formatting) List(java.util.List) Command(meteordevelopment.meteorclient.systems.commands.Command) Module(meteordevelopment.meteorclient.systems.modules.Module) Modules(meteordevelopment.meteorclient.systems.modules.Modules) MutableText(net.minecraft.text.MutableText) ChatUtils(meteordevelopment.meteorclient.utils.player.ChatUtils) Utils(meteordevelopment.meteorclient.utils.Utils) MutableText(net.minecraft.text.MutableText) HoverEvent(net.minecraft.text.HoverEvent) Module(meteordevelopment.meteorclient.systems.modules.Module) LiteralText(net.minecraft.text.LiteralText)

Example 28 with MutableText

use of net.minecraft.text.MutableText in project FZMM-Mod by Zailer43.

the class ItemStackMixin method getTooltip.

@Inject(method = "getTooltip", at = @At("RETURN"), cancellable = true)
public void getTooltip(PlayerEntity player, TooltipContext context, CallbackInfoReturnable<List<Text>> cir) {
    if (this.hasNbt() && context.isAdvanced()) {
        NbtCompound nbt = this.getNbt();
        assert nbt != null;
        List<String> tags = nbt.getKeys().stream().toList();
        int tagsSize = tags.size();
        MutableText loreText = new LiteralText("Tags: ");
        List<Text> list = cir.getReturnValue();
        list.remove(list.size() - 1);
        for (int i = 0; i != tagsSize; i++) {
            loreText.append(tags.get(i) + (i == tagsSize - 1 ? "" : ", "));
            if (i % 3 == 2) {
                list.add(loreText.setStyle(Style.EMPTY.withColor(Formatting.DARK_GRAY)));
                loreText = new LiteralText("");
            }
        }
        if (!loreText.getString().isEmpty())
            list.add(loreText.setStyle(Style.EMPTY.withColor(Formatting.DARK_GRAY)));
        MutableText lengthText = new LiteralText(FzmmUtils.getNbtLengthInKB(nbt));
        list.add(lengthText.setStyle(Style.EMPTY.withColor(Formatting.GRAY)));
        cir.setReturnValue(list);
    }
}
Also used : MutableText(net.minecraft.text.MutableText) NbtCompound(net.minecraft.nbt.NbtCompound) LiteralText(net.minecraft.text.LiteralText) MutableText(net.minecraft.text.MutableText) Text(net.minecraft.text.Text) LiteralText(net.minecraft.text.LiteralText) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 29 with MutableText

use of net.minecraft.text.MutableText in project carpet-discarpet by replaceitem.

the class DiscarpetCommand method register.

public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
    dispatcher.register(literal("discarpet").requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2)).executes(commandContext -> {
        String version = FabricLoader.getInstance().getModContainer("discarpet").get().getMetadata().getVersion().getFriendlyString();
        MutableText text = new LiteralText("Discarpet version " + version).formatted(Formatting.BLUE);
        text.append("\nFor help, see the ");
        text.append(new LiteralText("documentation").setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/replaceitem/carpet-discarpet/blob/master/docs/Full.md")).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to get to the Discarpet documentation"))).withFormatting(Formatting.UNDERLINE).withColor(Formatting.DARK_BLUE)));
        commandContext.getSource().sendFeedback(text, true);
        return 1;
    }).then(literal("list").executes(commandContext -> {
        Set<String> botIDs = Discarpet.discordBots.keySet();
        final LiteralText t;
        if (botIDs.size() == 0) {
            t = (LiteralText) new LiteralText("There are no bots active:\n").formatted(Formatting.RED);
        } else {
            t = (LiteralText) new LiteralText("There are " + botIDs.size() + " bots active\n").formatted(Formatting.GREEN);
        }
        botIDs.forEach(id -> t.append(new LiteralText(id + "\n").formatted(Formatting.BLUE)));
        commandContext.getSource().sendFeedback(t, true);
        return botIDs.size();
    })).then(literal("getInvite").then(CommandManager.argument("id", StringArgumentType.string()).suggests(BOTS).executes(commandContext -> {
        String id = StringArgumentType.getString(commandContext, "id");
        String invite = Discarpet.discordBots.get(id).getInvite();
        Text text = ((new LiteralText("Click here to get the invite link for the bot")).styled((style) -> {
            return style.withColor(Formatting.BLUE).withFormatting(Formatting.UNDERLINE).withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, invite)).withHoverEvent(new HoverEvent(net.minecraft.text.HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to open the invite link"))).withInsertion(invite);
        }));
        commandContext.getSource().sendFeedback(text, false);
        return 1;
    }))).then(literal("reload").executes(commandContext -> {
        Discarpet.loadConfig(commandContext.getSource());
        return 1;
    })));
}
Also used : Discarpet(Discarpet.Discarpet) FabricLoader(net.fabricmc.loader.api.FabricLoader) LiteralText(net.minecraft.text.LiteralText) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) Set(java.util.Set) CommandManager.literal(net.minecraft.server.command.CommandManager.literal) HoverEvent(net.minecraft.text.HoverEvent) CommandManager(net.minecraft.server.command.CommandManager) CommandSource(net.minecraft.command.CommandSource) StringArgumentType(com.mojang.brigadier.arguments.StringArgumentType) Style(net.minecraft.text.Style) Formatting(net.minecraft.util.Formatting) ClickEvent(net.minecraft.text.ClickEvent) MutableText(net.minecraft.text.MutableText) Text(net.minecraft.text.Text) SuggestionProvider(com.mojang.brigadier.suggestion.SuggestionProvider) MutableText(net.minecraft.text.MutableText) HoverEvent(net.minecraft.text.HoverEvent) ClickEvent(net.minecraft.text.ClickEvent) LiteralText(net.minecraft.text.LiteralText) MutableText(net.minecraft.text.MutableText) Text(net.minecraft.text.Text) LiteralText(net.minecraft.text.LiteralText)

Example 30 with MutableText

use of net.minecraft.text.MutableText in project SpeedRunIGT by RedLime.

the class TimerDrawer method draw.

public void draw() {
    if (!toggle)
        return;
    client.getProfiler().push("create");
    MutableText igtText = getIGTText();
    MutableText rtaText = getRTAText();
    client.getProfiler().swap("font");
    // 폰트 조정
    float fontHeight = 8;
    FontManagerAccessor fontManager = (FontManagerAccessor) ((MinecraftClientAccessor) client).getFontManager();
    if (getTimerFont() != MinecraftClient.DEFAULT_FONT_ID && fontManager.getFontStorages().containsKey(getTimerFont())) {
        rtaText.setStyle(rtaText.getStyle().withFont(getTimerFont()));
        igtText.setStyle(igtText.getStyle().withFont(getTimerFont()));
        fontHeight = fontHeightMap.computeIfAbsent(getTimerFont().toString(), key -> {
            RenderableGlyph glyph = ((FontStorageAccessor) fontManager.getFontStorages().get(getTimerFont())).invokeRenderableGlyph('I');
            return glyph.getHeight() / glyph.getOversample();
        });
    }
    // 초기 값 조정
    client.getProfiler().swap("init");
    TimerElement igtTimerElement = new TimerElement();
    TimerElement rtaTimerElement = new TimerElement();
    rtaTimerElement.init(rtaXPos, rtaYPos, rtaScale, rtaText, rtaColor, rtaDecoration, fontHeight);
    igtTimerElement.init(igtXPos, igtYPos, igtScale, igtText, igtColor, igtDecoration, fontHeight);
    MatrixStack matrixStack = new MatrixStack();
    // 배경 렌더
    client.getProfiler().swap("background");
    if (bgOpacity > 0.01f) {
        Position rtaMin = new Position(rtaTimerElement.getPosition().getX() - rtaPadding, rtaTimerElement.getPosition().getY() - rtaPadding);
        Position rtaMax = new Position(rtaMin.getX() + rtaTimerElement.getScaledTextWidth() + ((rtaPadding - 1) + rtaPadding), rtaMin.getY() + rtaTimerElement.getScaledTextHeight() + ((rtaPadding - 1) + rtaPadding));
        Position igtMin = new Position(igtTimerElement.getPosition().getX() - igtPadding, igtTimerElement.getPosition().getY() - igtPadding);
        Position igtMax = new Position(igtMin.getX() + igtTimerElement.getScaledTextWidth() + ((igtPadding - 1) + igtPadding), igtMin.getY() + igtTimerElement.getScaledTextHeight() + ((igtPadding - 1) + igtPadding));
        int opacity = BackgroundHelper.ColorMixer.getArgb((int) (bgOpacity * 255), 0, 0, 0);
        if (rtaMin.getX() < igtMax.getX() && rtaMin.getY() < igtMax.getY() && igtMin.getX() < rtaMax.getX() && igtMin.getY() < rtaMax.getY()) {
            DrawableHelper.fill(matrixStack, Math.min(rtaMin.getX(), igtMin.getX()), Math.min(rtaMin.getY(), igtMin.getY()), Math.max(rtaMax.getX(), igtMax.getX()), Math.max(rtaMax.getY(), igtMax.getY()), opacity);
        } else {
            if (rtaScale != 0)
                DrawableHelper.fill(matrixStack, rtaMin.getX(), rtaMin.getY(), rtaMax.getX(), rtaMax.getY(), opacity);
            if (igtScale != 0)
                DrawableHelper.fill(matrixStack, igtMin.getX(), igtMin.getY(), igtMax.getX(), igtMax.getY(), opacity);
        }
    }
    // 렌더
    client.getProfiler().swap("draw");
    if (igtScale != 0)
        igtTimerElement.draw(matrixStack, translateZ);
    if (rtaScale != 0)
        rtaTimerElement.draw(matrixStack, translateZ);
    client.getProfiler().pop();
}
Also used : MutableText(net.minecraft.text.MutableText) FontManagerAccessor(com.redlimerl.speedrunigt.mixins.access.FontManagerAccessor) SpeedRunOption(com.redlimerl.speedrunigt.option.SpeedRunOption) SpeedRunOptions(com.redlimerl.speedrunigt.option.SpeedRunOptions) LiteralText(net.minecraft.text.LiteralText) FontStorageAccessor(com.redlimerl.speedrunigt.mixins.access.FontStorageAccessor) MatrixStack(net.minecraft.client.util.math.MatrixStack) HashMap(java.util.HashMap) TimerDecimals(com.redlimerl.speedrunigt.option.SpeedRunOptions.TimerDecimals) MinecraftClientAccessor(com.redlimerl.speedrunigt.mixins.access.MinecraftClientAccessor) DrawableHelper(net.minecraft.client.gui.DrawableHelper) TimerDecoration(com.redlimerl.speedrunigt.option.SpeedRunOptions.TimerDecoration) RenderableGlyph(net.minecraft.client.font.RenderableGlyph) MutableText(net.minecraft.text.MutableText) Identifier(net.minecraft.util.Identifier) MinecraftClient(net.minecraft.client.MinecraftClient) BackgroundHelper(net.minecraft.client.gui.hud.BackgroundHelper) FontManagerAccessor(com.redlimerl.speedrunigt.mixins.access.FontManagerAccessor) MatrixStack(net.minecraft.client.util.math.MatrixStack) RenderableGlyph(net.minecraft.client.font.RenderableGlyph)

Aggregations

MutableText (net.minecraft.text.MutableText)40 LiteralText (net.minecraft.text.LiteralText)34 HoverEvent (net.minecraft.text.HoverEvent)8 ClickEvent (net.minecraft.text.ClickEvent)7 Text (net.minecraft.text.Text)7 Formatting (net.minecraft.util.Formatting)6 List (java.util.List)5 TranslatableText (net.minecraft.text.TranslatableText)5 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)4 CommandSource (net.minecraft.command.CommandSource)3 JsonObject (com.google.gson.JsonObject)2 JsonPrimitive (com.google.gson.JsonPrimitive)2 SINGLE_SUCCESS (com.mojang.brigadier.Command.SINGLE_SUCCESS)2 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)2 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Locale (java.util.Locale)2