Search in sources :

Example 1 with Formatting

use of net.minecraft.util.Formatting in project meteor-client by MeteorDevelopment.

the class BetterTab method getPlayerName.

public Text getPlayerName(PlayerListEntry playerListEntry) {
    Text name;
    Color color = null;
    name = playerListEntry.getDisplayName();
    if (name == null)
        name = new LiteralText(playerListEntry.getProfile().getName());
    if (playerListEntry.getProfile().getId().toString().equals(mc.player.getGameProfile().getId().toString()) && self.get()) {
        color = selfColor.get();
    } else if (friends.get() && Friends.get().get(playerListEntry.getProfile().getName()) != null) {
        Friend friend = Friends.get().get(playerListEntry.getProfile().getName());
        if (friend != null)
            color = Friends.get().color;
    }
    if (color != null) {
        String nameString = name.getString();
        for (Formatting format : Formatting.values()) {
            if (format.isColor())
                nameString = nameString.replace(format.toString(), "");
        }
        name = new LiteralText(nameString).setStyle(name.getStyle().withColor(new TextColor(color.getPacked())));
    }
    return name;
}
Also used : Friend(meteordevelopment.meteorclient.systems.friends.Friend) Color(meteordevelopment.meteorclient.utils.render.color.Color) SettingColor(meteordevelopment.meteorclient.utils.render.color.SettingColor) TextColor(net.minecraft.text.TextColor) Formatting(net.minecraft.util.Formatting) LiteralText(net.minecraft.text.LiteralText) Text(net.minecraft.text.Text) TextColor(net.minecraft.text.TextColor) LiteralText(net.minecraft.text.LiteralText)

Example 2 with Formatting

use of net.minecraft.util.Formatting in project KiwiClient by TangyKiwi.

the class BetterTab method getPlayerName.

public Text getPlayerName(PlayerListEntry playerListEntry) {
    Text name;
    Color color = null;
    name = playerListEntry.getDisplayName();
    if (name == null)
        name = new LiteralText(playerListEntry.getProfile().getName());
    if (color != null) {
        String nameString = name.getString();
        for (Formatting format : Formatting.values()) {
            if (format.isColor())
                nameString = nameString.replace(format.toString(), "");
        }
        name = new LiteralText(nameString).setStyle(name.getStyle().withColor(TextColor.fromRgb(color.getRGB())));
    }
    return name;
}
Also used : TextColor(net.minecraft.text.TextColor) Formatting(net.minecraft.util.Formatting) LiteralText(net.minecraft.text.LiteralText) Text(net.minecraft.text.Text) LiteralText(net.minecraft.text.LiteralText)

Example 3 with Formatting

use of net.minecraft.util.Formatting in project CITResewn by SHsuperCM.

the class CITResewnConfigScreenFactory method create.

public static Screen create(Screen parent) {
    CITResewnConfig currentConfig = CITResewnConfig.INSTANCE(), defaultConfig = new CITResewnConfig();
    ConfigBuilder builder = ConfigBuilder.create().setParentScreen(parent).setTitle(new TranslatableText("config.citresewn.title")).setSavingRunnable(currentConfig::write);
    ConfigCategory category = builder.getOrCreateCategory(new LiteralText(""));
    ConfigEntryBuilder entryBuilder = builder.entryBuilder();
    category.addEntry(entryBuilder.startBooleanToggle(new TranslatableText("config.citresewn.enabled.title"), currentConfig.enabled).setTooltip(new TranslatableText("config.citresewn.enabled.tooltip")).setSaveConsumer(newConfig -> {
        if (currentConfig.enabled != newConfig) {
            currentConfig.enabled = newConfig;
            MinecraftClient.getInstance().reloadResources();
        }
    }).setDefaultValue(defaultConfig.enabled).build());
    category.addEntry(entryBuilder.startBooleanToggle(new TranslatableText("config.citresewn.mute_errors.title"), currentConfig.mute_errors).setTooltip(new TranslatableText("config.citresewn.mute_errors.tooltip")).setSaveConsumer(newConfig -> currentConfig.mute_errors = newConfig).setDefaultValue(defaultConfig.mute_errors).build());
    category.addEntry(entryBuilder.startBooleanToggle(new TranslatableText("config.citresewn.mute_warns.title"), currentConfig.mute_warns).setTooltip(new TranslatableText("config.citresewn.mute_warns.tooltip")).setSaveConsumer(newConfig -> currentConfig.mute_warns = newConfig).setDefaultValue(defaultConfig.mute_warns).build());
    category.addEntry(entryBuilder.startFloatField(new TranslatableText("config.citresewn.citenchantment_scroll_multiplier.title"), currentConfig.citenchantment_scroll_multiplier).setTooltip(new TranslatableText("config.citresewn.citenchantment_scroll_multiplier.tooltip")).setSaveConsumer(newConfig -> currentConfig.citenchantment_scroll_multiplier = newConfig).setDefaultValue(defaultConfig.citenchantment_scroll_multiplier).setMin(0f).build());
    category.addEntry(entryBuilder.startIntSlider(new TranslatableText("config.citresewn.cache_ms.title"), currentConfig.cache_ms / 50, 0, 5 * 20).setTooltip(new TranslatableText("config.citresewn.cache_ms.tooltip")).setSaveConsumer(newConfig -> currentConfig.cache_ms = newConfig * 50).setDefaultValue(currentConfig.cache_ms / 50).setTextGetter(ticks -> {
        if (ticks <= 1)
            return new TranslatableText("config.citresewn.cache_ms.ticks." + ticks).formatted(Formatting.AQUA);
        Formatting color = Formatting.DARK_RED;
        if (ticks <= 40)
            color = Formatting.RED;
        if (ticks <= 20)
            color = Formatting.GOLD;
        if (ticks <= 10)
            color = Formatting.DARK_GREEN;
        if (ticks <= 5)
            color = Formatting.GREEN;
        return new TranslatableText("config.citresewn.cache_ms.ticks.any", ticks).formatted(color);
    }).build());
    category.addEntry(entryBuilder.startBooleanToggle(new TranslatableText("config.citresewn.broken_paths.title"), currentConfig.broken_paths).setTooltip(new TranslatableText("config.citresewn.broken_paths.tooltip")).setSaveConsumer(newConfig -> currentConfig.broken_paths = newConfig).setDefaultValue(defaultConfig.broken_paths).requireRestart().build());
    return builder.build();
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) LiteralText(net.minecraft.text.LiteralText) Formatting(net.minecraft.util.Formatting) Screen(net.minecraft.client.gui.screen.Screen) TranslatableText(net.minecraft.text.TranslatableText) MinecraftClient(net.minecraft.client.MinecraftClient) ConfigBuilder(me.shedaniel.clothconfig2.api.ConfigBuilder) ConfigCategory(me.shedaniel.clothconfig2.api.ConfigCategory) ConfigEntryBuilder(me.shedaniel.clothconfig2.api.ConfigEntryBuilder) ConfigCategory(me.shedaniel.clothconfig2.api.ConfigCategory) Formatting(net.minecraft.util.Formatting) ConfigBuilder(me.shedaniel.clothconfig2.api.ConfigBuilder) ConfigEntryBuilder(me.shedaniel.clothconfig2.api.ConfigEntryBuilder) LiteralText(net.minecraft.text.LiteralText)

Example 4 with Formatting

use of net.minecraft.util.Formatting in project AdvancedChatBox by DarkKronicle.

the class ColorCodeFormatter method format.

@Override
public Optional<FluidText> format(FluidText text, @Nullable ParseResults<CommandSource> parse) {
    if (parse != null) {
        return Optional.empty();
    }
    String string = text.getString();
    if (!string.contains("&")) {
        return Optional.empty();
    }
    SearchResult search = SearchResult.searchOf(string, "(?i)&[0-9A-FK-OR]", FindType.REGEX);
    if (search.size() == 0) {
        return Optional.empty();
    }
    int index = 0;
    Style last = Style.EMPTY;
    FluidText formatted = new FluidText();
    for (StringMatch match : search.getMatches()) {
        formatted.append(text.truncate(new StringMatch("", index, match.start)).fillStyle(last));
        Formatting format = Formatting.byCode(match.match.charAt(1));
        last = last.withFormatting(format);
        index = match.start;
    }
    FluidText small = text.truncate(new StringMatch("", index, string.length()));
    if (small != null && !small.getString().isEmpty()) {
        formatted.append(small.fillStyle(last));
    }
    return Optional.of(formatted);
}
Also used : FluidText(io.github.darkkronicle.advancedchatcore.util.FluidText) Formatting(net.minecraft.util.Formatting) Style(net.minecraft.text.Style) StringMatch(io.github.darkkronicle.advancedchatcore.util.StringMatch) SearchResult(io.github.darkkronicle.advancedchatcore.util.SearchResult)

Example 5 with Formatting

use of net.minecraft.util.Formatting in project EarthMCEssentials by EarthMC-Stats.

the class NearbyCommand method register.

public static void register() {
    ClientCommandManager.DISPATCHER.register(ClientCommandManager.literal("nearby").executes(c -> {
        MinecraftClient client = MinecraftClient.getInstance();
        if (client.player == null)
            return -1;
        Formatting headingFormatting = Formatting.byName(instance().getConfig().nearby.headingTextColour.name());
        Formatting textFormatting = Formatting.byName(instance().getConfig().nearby.playerTextColour.name());
        MsgUtils.sendPlayer("text_nearby_header", false, headingFormatting, false);
        for (int i = 0; i < instance().getNearbyPlayers().size(); i++) {
            JsonObject currentPlayer = instance().getNearbyPlayers().get(i).getAsJsonObject();
            JsonElement xElement = currentPlayer.get("x");
            JsonElement zElement = currentPlayer.get("z");
            if (xElement == null || zElement == null)
                continue;
            int distance = Math.abs(xElement.getAsInt() - (int) client.player.getX()) + Math.abs(zElement.getAsInt() - (int) client.player.getZ());
            String prefix = "";
            if (instance().getConfig().nearby.showRank) {
                if (!currentPlayer.has("town"))
                    prefix = new TranslatableText("text_nearby_rank_townless").toString();
                else
                    prefix = "(" + currentPlayer.get("rank").getAsString() + ") ";
            }
            MsgUtils.sendPlayer(prefix + currentPlayer.get("name").getAsString() + ": " + distance + "m", false, textFormatting, false);
        }
        return 1;
    }).then(ClientCommandManager.literal("refresh").executes(c -> {
        instance().scheduler().stop();
        instance().scheduler().start();
        MsgUtils.sendPlayer("msg_nearby_refresh", false, Formatting.AQUA, true);
        return 1;
    })).then(ClientCommandManager.literal("clear").executes(c -> {
        instance().setNearbyPlayers(new JsonArray());
        MsgUtils.sendPlayer("msg_nearby_clear", false, Formatting.AQUA, true);
        return 1;
    })));
}
Also used : JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) Formatting(net.minecraft.util.Formatting) TranslatableText(net.minecraft.text.TranslatableText) EarthMCEssentials(net.emc.emce.EarthMCEssentials) MsgUtils(net.emc.emce.utils.MsgUtils) MinecraftClient(net.minecraft.client.MinecraftClient) EarthMCEssentials.instance(net.emc.emce.EarthMCEssentials.instance) ClientCommandManager(net.fabricmc.fabric.api.client.command.v1.ClientCommandManager) TranslatableText(net.minecraft.text.TranslatableText) JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) MinecraftClient(net.minecraft.client.MinecraftClient) Formatting(net.minecraft.util.Formatting) JsonObject(com.google.gson.JsonObject)

Aggregations

Formatting (net.minecraft.util.Formatting)10 LiteralText (net.minecraft.text.LiteralText)4 TranslatableText (net.minecraft.text.TranslatableText)4 Text (net.minecraft.text.Text)3 TextColor (net.minecraft.text.TextColor)3 MinecraftClient (net.minecraft.client.MinecraftClient)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 FluidText (io.github.darkkronicle.advancedchatcore.util.FluidText)1 SearchResult (io.github.darkkronicle.advancedchatcore.util.SearchResult)1 StringMatch (io.github.darkkronicle.advancedchatcore.util.StringMatch)1 Enemy (mathax.client.systems.enemies.Enemy)1 Friend (mathax.client.systems.friends.Friend)1 Color (mathax.client.utils.render.color.Color)1 SettingColor (mathax.client.utils.render.color.SettingColor)1 ConfigBuilder (me.shedaniel.clothconfig2.api.ConfigBuilder)1 ConfigCategory (me.shedaniel.clothconfig2.api.ConfigCategory)1 ConfigEntryBuilder (me.shedaniel.clothconfig2.api.ConfigEntryBuilder)1 Friend (meteordevelopment.meteorclient.systems.friends.Friend)1