use of net.minecraft.network.chat.TranslatableComponent in project MinecraftForge by MinecraftForge.
the class DimensionsCommand method register.
static ArgumentBuilder<CommandSourceStack, ?> register() {
return Commands.literal("dimensions").requires(// permission
cs -> cs.hasPermission(0)).executes(ctx -> {
ctx.getSource().sendSuccess(new TranslatableComponent("commands.forge.dimensions.list"), true);
final Registry<DimensionType> reg = ctx.getSource().registryAccess().registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY);
Map<ResourceLocation, List<ResourceLocation>> types = new HashMap<>();
for (ServerLevel dim : ctx.getSource().getServer().getAllLevels()) {
types.computeIfAbsent(reg.getKey(dim.dimensionType()), k -> new ArrayList<>()).add(dim.dimension().location());
}
types.keySet().stream().sorted().forEach(key -> {
ctx.getSource().sendSuccess(new TextComponent(key + ": " + types.get(key).stream().map(ResourceLocation::toString).sorted().collect(Collectors.joining(", "))), false);
});
return 0;
});
}
use of net.minecraft.network.chat.TranslatableComponent in project MinecraftForge by MinecraftForge.
the class TextComponentMessageFormatHandler method handle.
public static int handle(final TranslatableComponent parent, final Consumer<FormattedText> addChild, final Object[] formatArgs, final String format) {
try {
final String formattedString = ForgeI18n.parseFormat(format, formatArgs);
// See MinecraftForge/MinecraftForge#7396
if (format.indexOf('\'') != -1) {
final boolean onlyMissingQuotes = format.chars().filter(ch -> formattedString.indexOf((char) ch) == -1).allMatch(ch -> ch == '\'');
if (onlyMissingQuotes) {
return 0;
}
}
TextComponent component = new TextComponent(formattedString);
component.getStyle().applyTo(parent.getStyle());
addChild.accept(component);
return format.length();
} catch (IllegalArgumentException ex) {
return 0;
}
}
use of net.minecraft.network.chat.TranslatableComponent in project MinecraftForge by MinecraftForge.
the class TPSCommand method register.
static ArgumentBuilder<CommandSourceStack, ?> register() {
return Commands.literal("tps").requires(// permission
cs -> cs.hasPermission(0)).then(Commands.argument("dim", DimensionArgument.dimension()).executes(ctx -> sendTime(ctx.getSource(), DimensionArgument.getDimension(ctx, "dim")))).executes(ctx -> {
for (ServerLevel dim : ctx.getSource().getServer().getAllLevels()) sendTime(ctx.getSource(), dim);
@SuppressWarnings("resource") double meanTickTime = mean(ctx.getSource().getServer().tickTimes) * 1.0E-6D;
double meanTPS = Math.min(1000.0 / meanTickTime, 20);
ctx.getSource().sendSuccess(new TranslatableComponent("commands.forge.tps.summary.all", TIME_FORMATTER.format(meanTickTime), TIME_FORMATTER.format(meanTPS)), false);
return 0;
});
}
use of net.minecraft.network.chat.TranslatableComponent in project MinecraftForge by MinecraftForge.
the class TPSCommand method sendTime.
private static int sendTime(CommandSourceStack cs, ServerLevel dim) throws CommandSyntaxException {
long[] times = cs.getServer().getTickTime(dim.dimension());
if (// Null means the world is unloaded. Not invalid. That's taken car of by DimensionArgument itself.
times == null)
times = UNLOADED;
final Registry<DimensionType> reg = cs.registryAccess().registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY);
double worldTickTime = mean(times) * 1.0E-6D;
double worldTPS = Math.min(1000.0 / worldTickTime, 20);
cs.sendSuccess(new TranslatableComponent("commands.forge.tps.summary.named", dim.dimension().location().toString(), reg.getKey(dim.dimensionType()), TIME_FORMATTER.format(worldTickTime), TIME_FORMATTER.format(worldTPS)), false);
return 1;
}
use of net.minecraft.network.chat.TranslatableComponent in project MinecraftForge by MinecraftForge.
the class ForgeHooksClient method renderMainMenu.
public static void renderMainMenu(TitleScreen gui, PoseStack mStack, Font font, int width, int height, int alpha) {
VersionChecker.Status status = ForgeVersion.getStatus();
if (status == BETA || status == BETA_OUTDATED) {
// render a warning at the top of the screen,
Component line = new TranslatableComponent("forge.update.beta.1", ChatFormatting.RED, ChatFormatting.RESET).withStyle(ChatFormatting.RED);
GuiComponent.drawCenteredString(mStack, font, line, width / 2, 4 + (0 * (font.lineHeight + 1)), 0xFFFFFF | alpha);
line = new TranslatableComponent("forge.update.beta.2");
GuiComponent.drawCenteredString(mStack, font, line, width / 2, 4 + (1 * (font.lineHeight + 1)), 0xFFFFFF | alpha);
}
String line = null;
switch(status) {
// case AHEAD: line = "Using non-recommended Forge build, issues may arise."}; break;
case OUTDATED:
case BETA_OUTDATED:
line = I18n.get("forge.update.newversion", ForgeVersion.getTarget());
break;
default:
break;
}
forgeStatusLine = line;
}
Aggregations