Search in sources :

Example 1 with TranslatableComponent

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;
    });
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) CommandSourceStack(net.minecraft.commands.CommandSourceStack) Commands(net.minecraft.commands.Commands) HashMap(java.util.HashMap) DimensionType(net.minecraft.world.level.dimension.DimensionType) ServerLevel(net.minecraft.server.level.ServerLevel) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Registry(net.minecraft.core.Registry) TextComponent(net.minecraft.network.chat.TextComponent) List(java.util.List) Map(java.util.Map) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) ArgumentBuilder(com.mojang.brigadier.builder.ArgumentBuilder) TextComponent(net.minecraft.network.chat.TextComponent) DimensionType(net.minecraft.world.level.dimension.DimensionType) ServerLevel(net.minecraft.server.level.ServerLevel) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) HashMap(java.util.HashMap) ResourceLocation(net.minecraft.resources.ResourceLocation) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with TranslatableComponent

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;
    }
}
Also used : Consumer(java.util.function.Consumer) TextComponent(net.minecraft.network.chat.TextComponent) FormattedText(net.minecraft.network.chat.FormattedText) ForgeI18n(net.minecraftforge.common.ForgeI18n) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) TextComponent(net.minecraft.network.chat.TextComponent)

Example 3 with TranslatableComponent

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;
    });
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent)

Example 4 with TranslatableComponent

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;
}
Also used : DimensionType(net.minecraft.world.level.dimension.DimensionType) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent)

Example 5 with TranslatableComponent

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;
}
Also used : TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) TooltipComponent(net.minecraft.world.inventory.tooltip.TooltipComponent) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) TextComponent(net.minecraft.network.chat.TextComponent) Component(net.minecraft.network.chat.Component) ClientTooltipComponent(net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent) GuiComponent(net.minecraft.client.gui.GuiComponent)

Aggregations

TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)9 Component (net.minecraft.network.chat.Component)3 TextComponent (net.minecraft.network.chat.TextComponent)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Consumer (java.util.function.Consumer)2 Collectors (java.util.stream.Collectors)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 ServerLevel (net.minecraft.server.level.ServerLevel)2 DimensionType (net.minecraft.world.level.dimension.DimensionType)2 IModInfo (net.minecraftforge.forgespi.language.IModInfo)2 PathResourcePack (net.minecraftforge.resource.PathResourcePack)2 NativeImage (com.mojang.blaze3d.platform.NativeImage)1 RenderSystem (com.mojang.blaze3d.systems.RenderSystem)1 PoseStack (com.mojang.blaze3d.vertex.PoseStack)1 Tesselator (com.mojang.blaze3d.vertex.Tesselator)1 ArgumentBuilder (com.mojang.brigadier.builder.ArgumentBuilder)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1