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