use of net.minecraft.text.Text in project FZMM-Mod by Zailer43.
the class ItemStackMixin method getTooltip.
@Inject(method = "getTooltip", at = @At("RETURN"), cancellable = true)
public void getTooltip(PlayerEntity player, TooltipContext context, CallbackInfoReturnable<List<Text>> cir) {
if (this.hasNbt() && context.isAdvanced()) {
NbtCompound nbt = this.getNbt();
assert nbt != null;
List<String> tags = nbt.getKeys().stream().toList();
int tagsSize = tags.size();
MutableText loreText = new LiteralText("Tags: ");
List<Text> list = cir.getReturnValue();
list.remove(list.size() - 1);
for (int i = 0; i != tagsSize; i++) {
loreText.append(tags.get(i) + (i == tagsSize - 1 ? "" : ", "));
if (i % 3 == 2) {
list.add(loreText.setStyle(Style.EMPTY.withColor(Formatting.DARK_GRAY)));
loreText = new LiteralText("");
}
}
if (!loreText.getString().isEmpty())
list.add(loreText.setStyle(Style.EMPTY.withColor(Formatting.DARK_GRAY)));
MutableText lengthText = new LiteralText(FzmmUtils.getNbtLengthInKB(nbt));
list.add(lengthText.setStyle(Style.EMPTY.withColor(Formatting.GRAY)));
cir.setReturnValue(list);
}
}
use of net.minecraft.text.Text in project BlockMeter by ModProg.
the class BlockMeterClient method handleServerBoxList.
/**
* handles the BoxList of other Players
*/
private void handleServerBoxList(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf data, PacketSender responseSender) {
Map<Text, List<ClientMeasureBox>> receivedBoxes = new HashMap<>();
int playerCount = data.readInt();
for (int i = 0; i < playerCount; i++) {
Text playerName = data.readText();
int boxCount = data.readInt();
List<ClientMeasureBox> boxes = new ArrayList<ClientMeasureBox>(boxCount);
for (int j = 0; j < boxCount; j++) {
boxes.add(ClientMeasureBox.fromPacketByteBuf(data));
}
receivedBoxes.put(playerName, boxes);
}
client.executeTask(() -> {
otherUsersBoxes = receivedBoxes;
});
}
use of net.minecraft.text.Text in project ThonkUtil by LimeAppleBoat.
the class ModChecker method onInitialize.
@Override
public void onInitialize() {
ThonkUtilModCheckerConfigManager.initializeConfig();
ServerLoginConnectionEvents.QUERY_START.register(this::onLoginStart);
ServerLoginNetworking.registerGlobalReceiver(UNIVERSAL_PKT, (server, handler, understood, buf, synchronizer, sender) -> {
if (understood) {
System.out.println("Understood response from client in " + UNIVERSAL_PKT);
String str = buf.readString();
String[] universalModList = str.split("\\|")[0].split("~");
String[] clientModList = str.split("\\|")[1].split("~");
List<String> collection = new ArrayList<>();
List<String> client_collection = new ArrayList<>();
for (String mod : universalModList) {
if (getBlackListedMods().contains(mod) && !collection.contains(mod)) {
collection.add(mod);
}
// System.out.println(mod);
}
for (String mod : clientModList) {
if (getBlackListedMods().contains(mod) && !collection.contains(mod)) {
client_collection.add(mod);
}
// System.out.println(mod);
}
if (!collection.isEmpty() || !client_collection.isEmpty()) {
String pth = "";
for (int i = 0; i < collection.toArray().length; i++) {
if (i == collection.toArray().length - 1) {
pth = pth + collection.toArray()[i];
} else if (i == collection.toArray().length - 2) {
pth = pth + collection.toArray()[i] + "\n";
} else {
pth = pth + collection.toArray()[i] + "\n";
}
}
String pt = "";
for (int i = 0; i < client_collection.toArray().length; i++) {
if (i == client_collection.toArray().length - 1) {
pt = pt + client_collection.toArray()[i];
} else if (i == collection.toArray().length - 2) {
pt = pt + client_collection.toArray()[i] + "\n";
} else {
pt = pt + client_collection.toArray()[i] + "\n";
}
}
Text kickMsg = new LiteralText("The following mods are blacklisted:\n\n").append(new LiteralText("Universal Mods:\n").formatted(Formatting.BOLD)).append(pth + "\n\n").append(new LiteralText("Client Side Mods:\n").formatted(Formatting.BOLD)).append(pt + "\n\n").append("Please uninstall all of these mods to join.");
handler.disconnect(kickMsg);
}
} else {
System.err.println("Client did not understand response query message with channel name " + UNIVERSAL_PKT);
handler.disconnect(new LiteralText(""));
}
});
if (CheckerUtil.isClient()) {
// Client-side here
} else {
// Server-side here
}
}
use of net.minecraft.text.Text in project ThonkUtil by LimeAppleBoat.
the class ThonkUtil method showMessage.
@SubscribeEvent
@Environment(EnvType.CLIENT)
public static void showMessage(TitleScreenRenderEvent event) {
if (state.equals(State.RELEASE))
return;
Text text = new LiteralText("").append(new TranslatableText("thonkutil.warning.1").formatted(Formatting.RED)).append(new TranslatableText("thonkutil." + state).formatted(state.formatting)).append(new TranslatableText("thonkutil.warning.1.1").formatted(Formatting.RED));
DrawableHelper.drawCenteredText(event.matrices(), MinecraftClient.getInstance().textRenderer, text, event.screen().width / 2, 4 + (0 * (MinecraftClient.getInstance().textRenderer.fontHeight + 1)), 0xFFFFFF | event.alpha());
text = new TranslatableText(state.translationKeyDesc);
DrawableHelper.drawCenteredText(event.matrices(), MinecraftClient.getInstance().textRenderer, text, event.screen().width / 2, 4 + (1 * (MinecraftClient.getInstance().textRenderer.fontHeight + 1)), 0xFFFFFF | event.alpha());
text = new TranslatableText("thonkutil.warning.3");
DrawableHelper.drawCenteredText(event.matrices(), MinecraftClient.getInstance().textRenderer, text, event.screen().width / 2, 4 + (2 * (MinecraftClient.getInstance().textRenderer.fontHeight + 1)), 0xFFFFFF | event.alpha());
}
use of net.minecraft.text.Text in project carpet-discarpet by replaceitem.
the class DiscarpetCommand method register.
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(literal("discarpet").requires(serverCommandSource -> serverCommandSource.hasPermissionLevel(2)).executes(commandContext -> {
String version = FabricLoader.getInstance().getModContainer("discarpet").get().getMetadata().getVersion().getFriendlyString();
MutableText text = new LiteralText("Discarpet version " + version).formatted(Formatting.BLUE);
text.append("\nFor help, see the ");
text.append(new LiteralText("documentation").setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/replaceitem/carpet-discarpet/blob/master/docs/Full.md")).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to get to the Discarpet documentation"))).withFormatting(Formatting.UNDERLINE).withColor(Formatting.DARK_BLUE)));
commandContext.getSource().sendFeedback(text, true);
return 1;
}).then(literal("list").executes(commandContext -> {
Set<String> botIDs = Discarpet.discordBots.keySet();
final LiteralText t;
if (botIDs.size() == 0) {
t = (LiteralText) new LiteralText("There are no bots active:\n").formatted(Formatting.RED);
} else {
t = (LiteralText) new LiteralText("There are " + botIDs.size() + " bots active\n").formatted(Formatting.GREEN);
}
botIDs.forEach(id -> t.append(new LiteralText(id + "\n").formatted(Formatting.BLUE)));
commandContext.getSource().sendFeedback(t, true);
return botIDs.size();
})).then(literal("getInvite").then(CommandManager.argument("id", StringArgumentType.string()).suggests(BOTS).executes(commandContext -> {
String id = StringArgumentType.getString(commandContext, "id");
String invite = Discarpet.discordBots.get(id).getInvite();
Text text = ((new LiteralText("Click here to get the invite link for the bot")).styled((style) -> {
return style.withColor(Formatting.BLUE).withFormatting(Formatting.UNDERLINE).withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, invite)).withHoverEvent(new HoverEvent(net.minecraft.text.HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to open the invite link"))).withInsertion(invite);
}));
commandContext.getSource().sendFeedback(text, false);
return 1;
}))).then(literal("reload").executes(commandContext -> {
Discarpet.loadConfig(commandContext.getSource());
return 1;
})));
}
Aggregations