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;
}
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;
}
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();
}
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);
}
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;
})));
}
Aggregations