Search in sources :

Example 66 with Text

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);
    }
}
Also used : MutableText(net.minecraft.text.MutableText) NbtCompound(net.minecraft.nbt.NbtCompound) LiteralText(net.minecraft.text.LiteralText) MutableText(net.minecraft.text.MutableText) Text(net.minecraft.text.Text) LiteralText(net.minecraft.text.LiteralText) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 67 with Text

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;
    });
}
Also used : HashMap(java.util.HashMap) ClientMeasureBox(win.baruna.blockmeter.measurebox.ClientMeasureBox) ArrayList(java.util.ArrayList) TranslatableText(net.minecraft.text.TranslatableText) Text(net.minecraft.text.Text) ArrayList(java.util.ArrayList) List(java.util.List)

Example 68 with Text

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
    }
}
Also used : ArrayList(java.util.ArrayList) LiteralText(net.minecraft.text.LiteralText) Text(net.minecraft.text.Text) LiteralText(net.minecraft.text.LiteralText)

Example 69 with Text

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());
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) LiteralText(net.minecraft.text.LiteralText) TranslatableText(net.minecraft.text.TranslatableText) Text(net.minecraft.text.Text) LiteralText(net.minecraft.text.LiteralText) SubscribeEvent(com.jab125.thonkutil.api.annotations.SubscribeEvent)

Example 70 with Text

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;
    })));
}
Also used : Discarpet(Discarpet.Discarpet) FabricLoader(net.fabricmc.loader.api.FabricLoader) LiteralText(net.minecraft.text.LiteralText) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) Set(java.util.Set) CommandManager.literal(net.minecraft.server.command.CommandManager.literal) HoverEvent(net.minecraft.text.HoverEvent) CommandManager(net.minecraft.server.command.CommandManager) CommandSource(net.minecraft.command.CommandSource) StringArgumentType(com.mojang.brigadier.arguments.StringArgumentType) Style(net.minecraft.text.Style) Formatting(net.minecraft.util.Formatting) ClickEvent(net.minecraft.text.ClickEvent) MutableText(net.minecraft.text.MutableText) Text(net.minecraft.text.Text) SuggestionProvider(com.mojang.brigadier.suggestion.SuggestionProvider) MutableText(net.minecraft.text.MutableText) HoverEvent(net.minecraft.text.HoverEvent) ClickEvent(net.minecraft.text.ClickEvent) LiteralText(net.minecraft.text.LiteralText) MutableText(net.minecraft.text.MutableText) Text(net.minecraft.text.Text) LiteralText(net.minecraft.text.LiteralText)

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