Search in sources :

Example 96 with Text

use of net.minecraft.text.Text in project soulbound-armory by auoeke.

the class SkillWidget method tick.

@Override
public void tick() {
    if (this.isFocused()) {
        var cost = this.skill.cost();
        var genericSections = new ReferenceArrayList<Text>();
        if (this.skill.learned()) {
            if (this.skill.skill.isTiered()) {
                genericSections.add(this.skill.skill.maxLevel < 0 ? Translations.guiLevel.format(this.skill.level()) : Translations.guiLevelFinite.format(this.skill.level(), this.skill.skill.maxLevel));
                if (this.skill.canUpgrade()) {
                    genericSections.add(Translations.guiSkillUpgradeCost.format(cost));
                }
            }
        } else if (this.skill.dependenciesFulfilled()) {
            genericSections.add(Translations.guiSkillLearnCost.format(cost));
        }
        var sections = ReferenceArrayList.<List<? extends StringVisitable>>of();
        var tooltipWidth = Math.max(36 + Math.max(108, textRenderer.getWidth(this.skill.name())), 12 + genericSections.stream().peek(section -> sections.add(List.of(section))).mapToInt(textRenderer::getWidth).max().orElse(0));
        var tooltip = wrap(this.skill.tooltip(), tooltipWidth - 8);
        sections.add(0, tooltip);
        var height = 1 + (1 + tooltip.size()) * fontHeight();
        var y = this.y() - 4 > this.tab.insideCenterY ? -56 : -7;
        var textY = 7;
        this.clear();
        for (var section : sections) {
            this.tooltip(new ScalableWidget<>().grayRectangle().x(-4).y(1, y).width(tooltipWidth).height(height).present(this::isFocused).with(new TextWidget().alignStart().x(5).y(textY).color(0x999999).with(t -> section.forEach(t::text))));
            y += height;
            textY = 6;
            height = 20;
        }
        this.tooltip(new ScalableWidget<>().blueRectangle().x(-4).y(0.5).centerY().width(tooltipWidth).height(20).present(this::isFocused).with(new TextWidget().x(32).y(6).shadow().text(this.skill.name())));
        this.add(this.frame);
    }
    super.tick();
}
Also used : List(java.util.List) StringVisitable(net.minecraft.text.StringVisitable) GraphicWidget(soulboundarmory.module.gui.widget.GraphicWidget) Widget(soulboundarmory.module.gui.widget.Widget) ReferenceArrayList(it.unimi.dsi.fastutil.objects.ReferenceArrayList) TextWidget(soulboundarmory.module.gui.widget.TextWidget) Text(net.minecraft.text.Text) SkillInstance(soulboundarmory.skill.SkillInstance) Translations(soulboundarmory.client.i18n.Translations) ScalableWidget(soulboundarmory.module.gui.widget.scalable.ScalableWidget) TextWidget(soulboundarmory.module.gui.widget.TextWidget) StringVisitable(net.minecraft.text.StringVisitable) List(java.util.List) ReferenceArrayList(it.unimi.dsi.fastutil.objects.ReferenceArrayList) ScalableWidget(soulboundarmory.module.gui.widget.scalable.ScalableWidget) ReferenceArrayList(it.unimi.dsi.fastutil.objects.ReferenceArrayList)

Example 97 with Text

use of net.minecraft.text.Text in project mc-discord-bridge by Selicre.

the class DiscordFormattingConverter method discordUserToMinecraft.

public static Text discordUserToMinecraft(User user, Guild guild, boolean asMention) {
    @Nullable Member member = guild.getMember(user);
    LiteralText tooltip = new LiteralText(user.getAsTag());
    String userName = user.getName();
    Style style = Style.EMPTY;
    boolean online = false;
    ServerPlayerEntity player = DiscordBot.instance().getPlayer(user);
    if (player != null) {
        style = style.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/tell " + player.getGameProfile().getName() + " "));
        online = true;
    }
    if (online) {
        tooltip.append("\nIn-game");
    } else {
        tooltip.append("\nOn Discord");
    }
    if (member != null) {
        userName = member.getEffectiveName();
        style = style.withColor(member.getColorRaw());
        List<Role> roles = Lists.newArrayList(member.getRoles());
        // Roles are ordered higher value for higher role positioning, so we need to reverse the default
        // comparison order.This is effectively 'comparing(Role::getPosition).reversed()' without boxing
        roles.sort(Comparator.comparingInt(role -> -role.getPosition()));
        for (Role role : roles) {
            tooltip.append("\n- ");
            tooltip.append(new LiteralText(role.getName()).setStyle(Style.EMPTY.withColor(role.getColorRaw())));
        }
    }
    if (asMention) {
        userName = "@" + userName;
    }
    return new LiteralText(userName).setStyle(style.withInsertion("@" + user.getAsTag()).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, tooltip)));
}
Also used : Role(net.dv8tion.jda.api.entities.Role) LiteralText(net.minecraft.text.LiteralText) BiFunction(java.util.function.BiFunction) LocalDateTime(java.time.LocalDateTime) Member(net.dv8tion.jda.api.entities.Member) TextChannel(net.dv8tion.jda.api.entities.TextChannel) HoverEvent(net.minecraft.text.HoverEvent) Function(java.util.function.Function) User(net.dv8tion.jda.api.entities.User) ArrayList(java.util.ArrayList) Style(net.minecraft.text.Style) Lists(com.google.common.collect.Lists) Guild(net.dv8tion.jda.api.entities.Guild) Matcher(java.util.regex.Matcher) Role(net.dv8tion.jda.api.entities.Role) ClickEvent(net.minecraft.text.ClickEvent) Map(java.util.Map) ZoneOffset(java.time.ZoneOffset) Timestamp(net.dv8tion.jda.api.utils.Timestamp) Nullable(javax.annotation.Nullable) EnumSet(java.util.EnumSet) Message(net.dv8tion.jda.api.entities.Message) ImmutableMap(com.google.common.collect.ImmutableMap) CaseFormat(com.google.common.base.CaseFormat) GuildChannel(net.dv8tion.jda.api.entities.GuildChannel) Set(java.util.Set) TimeFormat(net.dv8tion.jda.api.utils.TimeFormat) Maps(com.google.common.collect.Maps) List(java.util.List) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Text(net.minecraft.text.Text) Pattern(java.util.regex.Pattern) Comparator(java.util.Comparator) Emote(net.dv8tion.jda.api.entities.Emote) HoverEvent(net.minecraft.text.HoverEvent) ClickEvent(net.minecraft.text.ClickEvent) Style(net.minecraft.text.Style) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Member(net.dv8tion.jda.api.entities.Member) Nullable(javax.annotation.Nullable) LiteralText(net.minecraft.text.LiteralText)

Example 98 with Text

use of net.minecraft.text.Text in project mc-discord-bridge by Selicre.

the class PlayerManagerMixin method onPlayerConnect.

@Inject(method = "onPlayerConnect(Lnet/minecraft/network/ClientConnection;Lnet/minecraft/server/network/ServerPlayerEntity;)V", at = @At("RETURN"), require = 1, allow = 1)
private void onPlayerConnect(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) {
    DiscordBot bot = DiscordBot.instance();
    bot.onPlayersChanged();
    bot.onPlayerConnected(player.getGameProfile());
    if (bot.getConfig().listDiscordUsers) {
        for (Member member : bot.getChannelMembers()) {
            String name = "@" + member.getUser().getName();
            if (name.length() > 16 || member.getUser().isBot()) {
                continue;
            }
            PlayerListS2CPacket packet = new PlayerListS2CPacket(PlayerListS2CPacket.Action.ADD_PLAYER);
            GameProfile profile = new GameProfile(PlayerEntity.getOfflinePlayerUuid(member.getId()), name);
            int latency = member.getOnlineStatus() == OnlineStatus.OFFLINE ? -1 : 10000;
            Text displayName = DiscordFormattingConverter.discordUserToMinecraft(member.getUser(), member.getGuild(), false);
            packet.getEntries().add(new PlayerListS2CPacket.Entry(profile, latency, GameMode.SPECTATOR, displayName));
            connection.send(packet);
        }
    }
}
Also used : PlayerListS2CPacket(net.minecraft.network.packet.s2c.play.PlayerListS2CPacket) GameProfile(com.mojang.authlib.GameProfile) DiscordBot(selic.re.discordbridge.DiscordBot) Text(net.minecraft.text.Text) Member(net.dv8tion.jda.api.entities.Member) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 99 with Text

use of net.minecraft.text.Text in project owo-lib by gliscowo.

the class Owo method onInitialize.

@Override
public void onInitialize() {
    CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
        dispatcher.register(literal("dumpdata").then(literal("item").executes(context -> {
            if (!context.getSource().getPlayer().getMainHandStack().hasTag()) {
                context.getSource().sendError(Text.of("This item has no tag"));
            } else {
                Text message = context.getSource().getPlayer().getMainHandStack().getTag().toText();
                context.getSource().getPlayer().sendMessage(message, false);
            }
            return 0;
        })).then(literal("block").executes(context -> {
            final ServerCommandSource source = context.getSource();
            final ServerPlayerEntity player = source.getPlayer();
            HitResult target = player.raycast(5, 0, false);
            if (target.getType() != HitResult.Type.BLOCK) {
                source.sendError(Text.of("You're not looking at a block"));
                return 1;
            }
            BlockPos pos = ((BlockHitResult) target).getBlockPos();
            String blockState = player.getServerWorld().getBlockState(pos).toString();
            String blockId = blockState.split(Pattern.quote("["))[0];
            blockId = blockId.substring(6, blockId.length() - 1);
            if (blockState.contains("[")) {
                String stateInfo = "[" + blockState.split(Pattern.quote("["))[1];
                source.sendFeedback(Text.of("Block ID: §b" + blockId), false);
                source.sendFeedback(Text.of("BlockState: §b" + stateInfo), false);
            } else {
                source.sendFeedback(Text.of("Block ID: §b" + blockId), false);
            }
            if (player.getServerWorld().getBlockEntity(pos) != null) {
                source.sendFeedback(new LiteralText("Tag: ").append(player.getServerWorld().getBlockEntity(pos).toTag(new CompoundTag()).toText()), false);
            }
            return 0;
        })));
    });
}
Also used : HitResult(net.minecraft.util.hit.HitResult) LiteralText(net.minecraft.text.LiteralText) CompoundTag(net.minecraft.nbt.CompoundTag) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) CommandRegistrationCallback(net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Text(net.minecraft.text.Text) BlockPos(net.minecraft.util.math.BlockPos) Pattern(java.util.regex.Pattern) ModInitializer(net.fabricmc.api.ModInitializer) CommandManager.literal(net.minecraft.server.command.CommandManager.literal) HitResult(net.minecraft.util.hit.HitResult) BlockHitResult(net.minecraft.util.hit.BlockHitResult) LiteralText(net.minecraft.text.LiteralText) Text(net.minecraft.text.Text) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) CompoundTag(net.minecraft.nbt.CompoundTag) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) LiteralText(net.minecraft.text.LiteralText)

Example 100 with Text

use of net.minecraft.text.Text in project ViaFabric by ViaVersion.

the class MixinServerEntry method addServerVer.

@Redirect(method = "render", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/client/gui/screen/multiplayer/MultiplayerScreen;setTooltip(Ljava/util/List;)V"))
private void addServerVer(MultiplayerScreen multiplayerScreen, List<Text> tooltipText) {
    ProtocolVersion proto = ProtocolVersion.getProtocol(((ViaServerInfo) this.server).getViaServerVer());
    List<Text> lines = new ArrayList<>(tooltipText);
    lines.add(new TranslatableText("gui.ping_version.translated", proto.getName()));
    multiplayerScreen.setTooltip(lines);
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) ArrayList(java.util.ArrayList) TranslatableText(net.minecraft.text.TranslatableText) Text(net.minecraft.text.Text) ProtocolVersion(com.viaversion.viaversion.api.protocol.version.ProtocolVersion) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

Text (net.minecraft.text.Text)108 LiteralText (net.minecraft.text.LiteralText)70 TranslatableText (net.minecraft.text.TranslatableText)35 Inject (org.spongepowered.asm.mixin.injection.Inject)14 ArrayList (java.util.ArrayList)13 ItemStack (net.minecraft.item.ItemStack)12 MinecraftClient (net.minecraft.client.MinecraftClient)11 MutableText (net.minecraft.text.MutableText)10 Formatting (net.minecraft.util.Formatting)10 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)9 List (java.util.List)7 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)6 HoverEvent (net.minecraft.text.HoverEvent)6 TextColor (net.minecraft.text.TextColor)6 Mixin (org.spongepowered.asm.mixin.Mixin)6 At (org.spongepowered.asm.mixin.injection.At)6 ButtonWidget (net.minecraft.client.gui.widget.ButtonWidget)5 Redirect (org.spongepowered.asm.mixin.injection.Redirect)5 JsonObject (com.google.gson.JsonObject)4 GameProfile (com.mojang.authlib.GameProfile)4