Search in sources :

Example 6 with MutableText

use of net.minecraft.text.MutableText in project KahzerxMod by otakucraft.

the class ServerPlayNetworkHandlerMixin method onGetDisplayName.

@Redirect(method = "handleMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;getDisplayName()Lnet/minecraft/text/Text;"))
private Text onGetDisplayName(ServerPlayerEntity instance) {
    MutableText name = (MutableText) instance.getDisplayName();
    if (BadgeExtension.isExtensionEnabled) {
        List<BadgeInstance> badges = BadgeExtension.playerBadges.get(instance.getUuidAsString());
        if (badges.size() != 0) {
            name.append(new LiteralText(" "));
        }
        for (int i = badges.size() - 1; i >= 0; i--) {
            int finalI = i;
            name.append(new LiteralText(badges.get(i).getBadge()).styled(style -> style.withColor(Formatting.byColorIndex(badges.get(finalI).getColorIndex()))));
            if (i < badges.size() - 2) {
                break;
            }
        }
    }
    return name;
}
Also used : MutableText(net.minecraft.text.MutableText) LiteralText(net.minecraft.text.LiteralText) Formatting(net.minecraft.util.Formatting) List(java.util.List) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Mixin(org.spongepowered.asm.mixin.Mixin) Redirect(org.spongepowered.asm.mixin.injection.Redirect) BadgeInstance(com.kahzerx.kahzerxmod.extensions.badgeExtension.BadgeInstance) MutableText(net.minecraft.text.MutableText) BadgeExtension(com.kahzerx.kahzerxmod.extensions.badgeExtension.BadgeExtension) Text(net.minecraft.text.Text) ServerPlayNetworkHandler(net.minecraft.server.network.ServerPlayNetworkHandler) At(org.spongepowered.asm.mixin.injection.At) BadgeInstance(com.kahzerx.kahzerxmod.extensions.badgeExtension.BadgeInstance) LiteralText(net.minecraft.text.LiteralText) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 7 with MutableText

use of net.minecraft.text.MutableText in project KahzerxMod by otakucraft.

the class BlockInfoExtension method getInfo.

public void getInfo(ServerCommandSource source, BlockPos pos, int page) {
    int x = pos.getX();
    int y = pos.getY();
    int z = pos.getZ();
    List<MutableText> msg = getBlockInfo(x, y, z, DimUtils.getWorldID(DimUtils.getDim(source.getWorld())), page);
    Collections.reverse(msg);
    source.sendFeedback(new LiteralText("======BlockInfo======"), false);
    int nLine = getLines(x, y, z, DimUtils.getWorldID(DimUtils.getDim(source.getWorld())));
    for (MutableText line : msg) {
        source.sendFeedback(line, false);
    }
    if (page > nLine) {
        // No pages.
        return;
    } else if (page == nLine && page == 1) {
        // There is only 1 page.
        source.sendFeedback(new LiteralText(String.format("%d/%d.", page, nLine)), false);
    } else if (page == 1) {
        // First page but there are more
        MutableText pages = BlockInfoUtils.getPages(page, nLine);
        MutableText next = BlockInfoUtils.getNext(x, y, z, page);
        source.sendFeedback(new LiteralText("").append(pages).append(next).append(BlockInfoUtils.getHelp(x, y, z)), false);
    } else if (page == nLine) {
        // The last page.
        MutableText prev = BlockInfoUtils.getPrev(x, y, z, page);
        MutableText pages = BlockInfoUtils.getPages(page, nLine);
        source.sendFeedback(new LiteralText("").append(prev).append(pages).append(BlockInfoUtils.getHelp(x, y, z)), false);
    } else {
        // Have pages before and after the one you are in.
        MutableText prev = BlockInfoUtils.getPrev(x, y, z, page);
        MutableText pages = BlockInfoUtils.getPages(page, nLine);
        MutableText next = BlockInfoUtils.getNext(x, y, z, page);
        source.sendFeedback(new LiteralText("").append(prev).append(pages).append(next).append(BlockInfoUtils.getHelp(x, y, z)), false);
    }
}
Also used : MutableText(net.minecraft.text.MutableText) LiteralText(net.minecraft.text.LiteralText)

Example 8 with MutableText

use of net.minecraft.text.MutableText in project KahzerxMod by otakucraft.

the class BlockInfoExtension method getBlockInfo.

public List<MutableText> getBlockInfo(int x, int y, int z, int dim, int page) {
    List<MutableText> msg = new ArrayList<>();
    try {
        String q = "SELECT amount, action, date, playerName, block FROM `action_logger` " + "WHERE posX = ? AND posY = ? AND posZ = ? AND dim = ? ORDER BY id DESC LIMIT 10 OFFSET ?;";
        PreparedStatement ps = this.conn.prepareStatement(q);
        ps.setInt(1, x);
        ps.setInt(2, y);
        ps.setInt(3, z);
        ps.setInt(4, dim);
        ps.setInt(5, (page - 1) * 10);
        ResultSet rs = ps.executeQuery();
        int i = 0;
        while (rs.next() && i <= 10) {
            MutableText line = BlockInfoUtils.buildLine(rs);
            msg.add(line);
            i++;
        }
        if (msg.isEmpty()) {
            msg.add(new LiteralText("No logs :("));
        }
        rs.close();
        ps.close();
    } catch (SQLException throwables) {
        throwables.printStackTrace();
        msg.clear();
        msg.add(new LiteralText("Error."));
    }
    return msg;
}
Also used : MutableText(net.minecraft.text.MutableText) ArrayList(java.util.ArrayList) LiteralText(net.minecraft.text.LiteralText)

Example 9 with MutableText

use of net.minecraft.text.MutableText in project meteor-client by MeteorDevelopment.

the class BookBot method onTick.

@EventHandler
private void onTick(TickEvent.Post event) {
    FindItemResult writableBook = InvUtils.find(Items.WRITABLE_BOOK);
    // Check if there is a book to write
    if (!writableBook.found()) {
        toggle();
        return;
    }
    // Move the book into hand
    if (!writableBook.isMainHand()) {
        InvUtils.move().from(writableBook.slot()).toHotbar(mc.player.getInventory().selectedSlot);
        return;
    }
    // If somehow it failed, just dont do anything until it tries again
    FindItemResult finalBook = InvUtils.findInHotbar(Items.WRITABLE_BOOK);
    if (!finalBook.isMainHand())
        return;
    // Check delay
    if (delayTimer > 0) {
        delayTimer--;
        return;
    }
    // Reset delay
    delayTimer = delay.get();
    if (mode.get() == Mode.Random) {
        int origin = onlyAscii.get() ? 0x21 : 0x0800;
        int bound = onlyAscii.get() ? 0x7E : 0x10FFFF;
        writeBook(// Generate a random load of ints to use as random characters
        random.ints(origin, bound).filter(i -> !Character.isWhitespace(i) && i != '\r' && i != '\n').iterator());
    } else if (mode.get() == Mode.File) {
        // Ignore if somehow the file got deleted
        if ((file == null || !file.exists()) && mode.get() == Mode.File) {
            info("No file selected, please select a file in the GUI.");
            toggle();
            return;
        }
        // Handle the file being empty
        if (file.length() == 0) {
            MutableText message = new LiteralText("");
            message.append(new LiteralText("The bookbot file is empty! ").formatted(Formatting.RED));
            message.append(new LiteralText("Click here to edit it.").setStyle(Style.EMPTY.withFormatting(Formatting.UNDERLINE, Formatting.RED).withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, file.getAbsolutePath()))));
            info(message);
            toggle();
            return;
        }
        // Read each line of the file and construct a string with the needed line breaks
        try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
            StringBuilder file = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                file.append(line).append('\n');
            }
            reader.close();
            // Write the file string to a book
            writeBook(file.toString().chars().iterator());
        } catch (IOException ignored) {
            error("Failed to read the file.");
        }
    }
}
Also used : MutableText(net.minecraft.text.MutableText) ClickEvent(net.minecraft.text.ClickEvent) FindItemResult(meteordevelopment.meteorclient.utils.player.FindItemResult) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) NbtString(net.minecraft.nbt.NbtString) IOException(java.io.IOException) LiteralText(net.minecraft.text.LiteralText) EventHandler(meteordevelopment.orbit.EventHandler)

Example 10 with MutableText

use of net.minecraft.text.MutableText in project FZMM-Mod by Zailer43.

the class GradientLogic method getGradient.

public static MutableText getGradient(String message, byte red, byte green, byte blue, byte red2, byte green2, byte blue2, Style style) {
    List<String> messageList = splitString(message);
    int gradientLength = messageList.size();
    byte[] gradientRed = getByteGradient(red, red2, gradientLength);
    byte[] gradientGreen = getByteGradient(green, green2, gradientLength);
    byte[] gradientBlue = getByteGradient(blue, blue2, gradientLength);
    MutableText gradientText = LiteralText.EMPTY.copy();
    for (int i = 0; i != gradientLength; i++) {
        int rgb = rgbToInt(gradientRed[i], gradientGreen[i], gradientBlue[i]);
        gradientText.append(new LiteralText(String.valueOf(messageList.get(i))).setStyle(style.withColor(TextColor.fromRgb(rgb))));
    }
    return gradientText;
}
Also used : MutableText(net.minecraft.text.MutableText) LiteralText(net.minecraft.text.LiteralText)

Aggregations

MutableText (net.minecraft.text.MutableText)40 LiteralText (net.minecraft.text.LiteralText)34 HoverEvent (net.minecraft.text.HoverEvent)8 ClickEvent (net.minecraft.text.ClickEvent)7 Text (net.minecraft.text.Text)7 Formatting (net.minecraft.util.Formatting)6 List (java.util.List)5 TranslatableText (net.minecraft.text.TranslatableText)5 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)4 CommandSource (net.minecraft.command.CommandSource)3 JsonObject (com.google.gson.JsonObject)2 JsonPrimitive (com.google.gson.JsonPrimitive)2 SINGLE_SUCCESS (com.mojang.brigadier.Command.SINGLE_SUCCESS)2 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)2 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Locale (java.util.Locale)2