Search in sources :

Example 1 with BookUpdateC2SPacket

use of net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket in project BleachHack by BleachDrinker420.

the class CmdRbook method onCommand.

@Override
public void onCommand(String alias, String[] args) throws Exception {
    ItemStack item = mc.player.getInventory().getMainHandStack();
    if (item.getItem() != Items.WRITABLE_BOOK) {
        BleachLogger.error("Not Holding A Writable Book!");
        return;
    }
    int pages = args.length >= 1 && NumberUtils.isCreatable(args[0]) ? NumberUtils.createNumber(args[0]).intValue() : 100;
    int startChar = args.length >= 2 && NumberUtils.isCreatable(args[1]) ? NumberUtils.createNumber(args[1]).intValue() : 0;
    int endChar = args.length >= 3 && NumberUtils.isCreatable(args[2]) ? NumberUtils.createNumber(args[2]).intValue() : 0x10FFFF;
    int pageChars = args.length >= 4 && NumberUtils.isCreatable(args[3]) ? NumberUtils.createNumber(args[3]).intValue() : 210;
    List<String> textSplit = new ArrayList<>();
    for (int t = 0; t < pages; t++) textSplit.add(RandomStringUtils.random(pageChars, startChar, endChar, false, false));
    mc.player.networkHandler.sendPacket(new BookUpdateC2SPacket(mc.player.getInventory().selectedSlot, textSplit, Optional.empty()));
    BleachLogger.info("Written book (" + pages + " pages, " + pageChars + " chars/page)");
}
Also used : BookUpdateC2SPacket(net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 2 with BookUpdateC2SPacket

use of net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket in project meteor-client by MeteorDevelopment.

the class BookBot method writeBook.

private void writeBook(PrimitiveIterator.OfInt chars) {
    ArrayList<String> pages = new ArrayList<>();
    for (int pageI = 0; pageI < (mode.get() == Mode.File ? 100 : this.pages.get()); pageI++) {
        // Check if the stream is empty before creating a new page
        if (!chars.hasNext())
            break;
        StringBuilder page = new StringBuilder();
        for (int lineI = 0; lineI < 13; lineI++) {
            // Check if the stream is empty before creating a new line
            if (!chars.hasNext())
                break;
            double lineWidth = 0;
            StringBuilder line = new StringBuilder();
            while (true) {
                // Check if the stream is empty
                if (!chars.hasNext())
                    break;
                // Get the next character
                int nextChar = chars.nextInt();
                // Ignore newline chars when writing lines, should already be organised
                if (nextChar == '\r' || nextChar == '\n')
                    break;
                // Make sure the character will fit on the line
                double charWidth = ((TextHandlerAccessor) mc.textRenderer.getTextHandler()).getWidthRetriever().getWidth(nextChar, Style.EMPTY);
                if (lineWidth + charWidth > 114)
                    break;
                // Append it to the line
                line.appendCodePoint(nextChar);
                lineWidth += charWidth;
            }
            // Append the line to the page
            page.append(line).append('\n');
        }
        // Append page to the page list
        pages.add(page.toString());
    }
    // Get the title with count
    String title = name.get();
    if (count.get() && bookCount != 0)
        title += " #" + bookCount;
    // Write data to book
    mc.player.getMainHandStack().setSubNbt("title", NbtString.of(title));
    mc.player.getMainHandStack().setSubNbt("author", NbtString.of(mc.player.getGameProfile().getName()));
    // Write pages NBT
    NbtList pageNbt = new NbtList();
    pages.stream().map(NbtString::of).forEach(pageNbt::add);
    if (!pages.isEmpty())
        mc.player.getMainHandStack().setSubNbt("pages", pageNbt);
    // Send book update to server
    mc.player.networkHandler.sendPacket(new BookUpdateC2SPacket(mc.player.getInventory().selectedSlot, pages, Optional.of(title)));
    bookCount++;
}
Also used : BookUpdateC2SPacket(net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket) ArrayList(java.util.ArrayList) NbtList(net.minecraft.nbt.NbtList) NbtString(net.minecraft.nbt.NbtString)

Example 3 with BookUpdateC2SPacket

use of net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket in project Client by MatHax.

the class BookDupeCommand method build.

@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
    builder.executes(context -> {
        FindItemResult book = InvUtils.findInHotbar(Items.WRITABLE_BOOK);
        if (book.getHand() == null)
            error("No book found, you must be holding a writable book!");
        else {
            int i = book.isMainHand() ? mc.player.getInventory().selectedSlot : 40;
            mc.player.networkHandler.sendPacket(new BookUpdateC2SPacket(i, DUPE_PAGES, Optional.of("Dupe Book")));
        }
        return SINGLE_SUCCESS;
    });
}
Also used : BookUpdateC2SPacket(net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket) FindItemResult(mathax.client.utils.player.FindItemResult)

Example 4 with BookUpdateC2SPacket

use of net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket in project meteor-client by MeteorDevelopment.

the class EditBookTitleAndAuthorScreen method initWidgets.

@Override
public void initWidgets() {
    WTable t = add(theme.table()).expandX().widget();
    t.add(theme.label("Title"));
    WTextBox title = t.add(theme.textBox(itemStack.getOrCreateNbt().getString("title"))).minWidth(220).expandX().widget();
    t.row();
    t.add(theme.label("Author"));
    WTextBox author = t.add(theme.textBox(itemStack.getNbt().getString("author"))).minWidth(220).expandX().widget();
    t.row();
    t.add(theme.button("Done")).expandX().widget().action = () -> {
        itemStack.getNbt().putString("author", author.get());
        itemStack.getNbt().putString("title", title.get());
        BookScreen.Contents contents = new BookScreen.WrittenBookContents(itemStack);
        List<String> pages = new ArrayList<>(contents.getPageCount());
        for (int i = 0; i < contents.getPageCount(); i++) pages.add(contents.getPage(i).getString());
        mc.getNetworkHandler().sendPacket(new BookUpdateC2SPacket(hand == Hand.MAIN_HAND ? mc.player.getInventory().selectedSlot : 40, pages, Optional.of(title.get())));
        close();
    };
}
Also used : BookUpdateC2SPacket(net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket) WTable(meteordevelopment.meteorclient.gui.widgets.containers.WTable) BookScreen(net.minecraft.client.gui.screen.ingame.BookScreen) ArrayList(java.util.ArrayList) WTextBox(meteordevelopment.meteorclient.gui.widgets.input.WTextBox)

Example 5 with BookUpdateC2SPacket

use of net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket in project Client by MatHax.

the class EditBookTitleAndAuthorScreen method initWidgets.

@Override
public void initWidgets() {
    WTable t = add(theme.table()).expandX().widget();
    t.add(theme.label("Title"));
    WTextBox title = t.add(theme.textBox(itemStack.getOrCreateNbt().getString("title"))).minWidth(220).expandX().widget();
    t.row();
    t.add(theme.label("Author"));
    WTextBox author = t.add(theme.textBox(itemStack.getNbt().getString("author"))).minWidth(220).expandX().widget();
    t.row();
    t.add(theme.button("Done")).expandX().widget().action = () -> {
        itemStack.getNbt().putString("author", author.get());
        itemStack.getNbt().putString("title", title.get());
        BookScreen.Contents contents = new BookScreen.WrittenBookContents(itemStack);
        List<String> pages = new ArrayList<>(contents.getPageCount());
        for (int i = 0; i < contents.getPageCount(); i++) pages.add(contents.getPage(i).getString());
        mc.getNetworkHandler().sendPacket(new BookUpdateC2SPacket(hand == Hand.MAIN_HAND ? mc.player.getInventory().selectedSlot : 40, pages, Optional.of(title.get())));
        close();
    };
}
Also used : BookUpdateC2SPacket(net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket) WTable(mathax.client.gui.widgets.containers.WTable) BookScreen(net.minecraft.client.gui.screen.ingame.BookScreen) ArrayList(java.util.ArrayList) WTextBox(mathax.client.gui.widgets.input.WTextBox)

Aggregations

BookUpdateC2SPacket (net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket)6 ArrayList (java.util.ArrayList)5 BookScreen (net.minecraft.client.gui.screen.ingame.BookScreen)2 NbtList (net.minecraft.nbt.NbtList)2 NbtString (net.minecraft.nbt.NbtString)2 WTable (mathax.client.gui.widgets.containers.WTable)1 WTextBox (mathax.client.gui.widgets.input.WTextBox)1 FindItemResult (mathax.client.utils.player.FindItemResult)1 WTable (meteordevelopment.meteorclient.gui.widgets.containers.WTable)1 WTextBox (meteordevelopment.meteorclient.gui.widgets.input.WTextBox)1 ItemStack (net.minecraft.item.ItemStack)1